Added snake sprite
This commit is contained in:
@@ -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