Added snake sprite
This commit is contained in:
BIN
data/models/snake_body_1.png
Normal file
BIN
data/models/snake_body_1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 180 B |
63
data/models/snake_head.svg
Normal file
63
data/models/snake_head.svg
Normal file
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="210mm"
|
||||
height="297mm"
|
||||
viewBox="0 0 210 297"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
sodipodi:docname="snake_head.svg"
|
||||
inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:zoom="0.72426347"
|
||||
inkscape:cx="673.78795"
|
||||
inkscape:cy="482.5592"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1009"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" />
|
||||
<defs
|
||||
id="defs1">
|
||||
<inkscape:path-effect
|
||||
effect="spiro"
|
||||
id="path-effect7"
|
||||
is_visible="true"
|
||||
lpeversion="1" />
|
||||
<inkscape:path-effect
|
||||
effect="spiro"
|
||||
id="path-effect1"
|
||||
is_visible="true"
|
||||
lpeversion="1" />
|
||||
</defs>
|
||||
<g
|
||||
inkscape:label="Ebene 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<path
|
||||
style="fill:#ff9955;stroke-width:0.264583"
|
||||
d="m 110.14207,106.30627 c 0.97733,-3.74444 1.10317,-7.708487 0.36531,-11.507378 -0.66809,-3.43968 -2.03122,-6.741683 -2.37454,-10.228783 -0.29,-2.945551 0.16205,-5.923884 0.93766,-8.780245 0.77562,-2.856361 1.87099,-5.613644 2.89813,-8.389496 0.73104,-1.975626 1.43062,-3.968708 2.36111,-5.858603 0.93048,-1.889896 2.10529,-3.68662 3.66657,-5.100807 1.40917,-1.276411 3.12732,-2.222108 4.97729,-2.660958 1.84998,-0.43885 3.82935,-0.361656 5.6168,0.286421 2.02972,0.735918 3.77162,2.197605 4.93174,4.018449 1.15498,1.812771 1.73416,3.927534 2.19188,6.027677 0.72732,3.337131 1.18861,6.730702 2.00923,10.046123 0.74801,3.022072 1.79996,6.019687 1.82656,9.132842 0.0251,2.940419 -0.8684,5.804829 -1.82656,8.584869 -1.32171,3.834844 -2.79483,7.663889 -3.28783,11.690039 -0.1187,0.96941 -0.17973,1.94587 -0.18265,2.92251"
|
||||
id="path7"
|
||||
inkscape:path-effect="#path-effect7"
|
||||
inkscape:original-d="m 110.14207,106.30627 c -9.19373,4.56642 0.36531,-7.6107 0.36531,-11.507378 0,-3.89668 -1.64391,-6.94096 -2.37454,-10.228783 -0.73063,-3.287821 2.43543,-11.50738 3.83579,-17.169741 1.40037,-5.662361 4.14022,-7.123616 6.02768,-10.95941 1.88745,-3.835794 6.88007,-1.826567 10.59409,-2.374537 3.71403,-0.547971 3.4096,2.73985 4.93174,4.018449 1.52214,1.278599 1.46125,4.201107 2.19188,6.027677 0.73063,1.826567 1.33948,6.575644 2.00923,10.046123 0.66974,3.470481 1.21771,6.027676 1.82656,9.132842 0.60886,3.105166 -1.21771,5.784133 -1.82656,8.584869 -0.60886,2.800739 -2.131,7.854244 -3.28783,11.690039 -1.15682,3.83579 -0.18265,1.88745 -0.18265,2.92251"
|
||||
transform="translate(-27.763837,-35.435424)"
|
||||
inkscape:export-filename="snake_head_1.png"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-ydpi="96" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.2 KiB |
BIN
data/models/snake_head_1.png
Normal file
BIN
data/models/snake_head_1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
@@ -174,9 +174,10 @@ class Player(GameObject_new):
|
||||
self._rect:pygame.Rect
|
||||
self.__snake_body = [[100,100+size], [100,100+size*2], [100,100+size*3], [100,size*5]]
|
||||
super().__init__(name, surface, surface_size, init_pos_x, init_pos_y, visibility)
|
||||
|
||||
__movedirection = {"up":False, "down":False, "left":False, "right":False}
|
||||
self.__snake = {"head":"data/models/snake_head_1.png", "body":"data/models/snake_body_1.png", "tail":""}
|
||||
|
||||
__movedirection = {"up":False, "down":False, "left":False, "right":False}
|
||||
|
||||
__test_counter = 0
|
||||
__player_rect:pygame.Rect
|
||||
|
||||
@@ -225,11 +226,38 @@ class Player(GameObject_new):
|
||||
self.__snake_body.insert(0, list(self._position))
|
||||
counter = 0
|
||||
for pos in self.__snake_body:
|
||||
if(counter == 0):
|
||||
self.__player_rect = pygame.draw.rect(self._surface, (0,0,0), pygame.Rect(pos[0], pos[1], self._size, self._size))
|
||||
if(counter == 0): #Only for the first part of the Snkae, this meens the head
|
||||
#self.__player_rect = pygame.draw.rect(self._surface, (0,0,0), pygame.Rect(pos[0], pos[1], self._size, self._size))
|
||||
surface = pygame.Surface((40,120))
|
||||
surface.fill((255,255,255))
|
||||
image = pygame.image.load(self.__snake["head"])
|
||||
image = pygame.transform.scale(image, (40, 60))
|
||||
if(self.__movedirection["right"]):
|
||||
image = pygame.transform.rotate(image, 270) #Rotates the Snakehead on directionchange
|
||||
surface = pygame.transform.rotate(surface, 270)
|
||||
if(self.__movedirection["left"]):
|
||||
image = pygame.transform.rotate(image, 90)
|
||||
surface = pygame.transform.rotate(surface, 90)
|
||||
if(self.__movedirection["up"]):
|
||||
image = pygame.transform.rotate(image, 0)
|
||||
surface = pygame.transform.rotate(surface, 0)
|
||||
if(self.__movedirection["down"]):
|
||||
image = pygame.transform.rotate(image, 180)
|
||||
surface = pygame.transform.rotate(surface, 180)
|
||||
surface.blit(image, (0,0))
|
||||
self.__player_rect = self._surface.blit(surface, (pos[0], pos[1]))
|
||||
else:
|
||||
pygame.draw.rect(self._surface, (0,0,0), pygame.Rect(pos[0], pos[1], self._size, self._size))
|
||||
#pygame.draw.rect(self._surface, (0,0,0), pygame.Rect(pos[0], pos[1], self._size, self._size))
|
||||
surface = pygame.Surface((40,40))
|
||||
surface.fill((255,255,255))
|
||||
image = pygame.image.load(self.__snake["body"])
|
||||
image = pygame.transform.scale(image, (30,40))
|
||||
image = pygame.transform.rotate(image, 270)
|
||||
surface.blit(image, (0,5))
|
||||
self._surface.blit(surface, (pos[0], pos[1]))
|
||||
#print((pos[0], pos[1]))
|
||||
counter += 1
|
||||
#TODO Insert elif for the last position of the array, this meens the tail
|
||||
counter = 0
|
||||
#print(pos)
|
||||
if(self.__test_counter == 10):
|
||||
@@ -245,6 +273,7 @@ class Player(GameObject_new):
|
||||
count = len(self.__snake_body)
|
||||
for elements in range(1, count):
|
||||
if(self.get_position() == self.__snake_body[elements]):
|
||||
print(F"Colidepositions Player: {self.get_position()} Object{self.__snake_body[elements]}") #For DEBUG only
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -284,9 +313,6 @@ class Fruit(GameObject_new):
|
||||
#self.__rect = pygame.draw.rect(self._surface, self.__color, (self._position[0], self._position[1], self.__rect_size, self.__rect_size))
|
||||
self.__rect = self._surface.blit(self.__image, self.get_position())
|
||||
|
||||
|
||||
|
||||
|
||||
def get_rect(self) -> pygame.Rect:
|
||||
return self.__rect
|
||||
|
||||
|
||||
Reference in New Issue
Block a user