Update of GameObjects module
Code cleanup
This commit is contained in:
@@ -193,7 +193,7 @@ class Player(GameObject_new):
|
||||
|
||||
def move(self, *speed:int):
|
||||
MOVE_SPEED = 1
|
||||
if(self.__test_counter == 15):
|
||||
if(self.__test_counter == 10):
|
||||
self.__test_counter = 0
|
||||
if(self.__movedirection['up']):
|
||||
if(not speed): self._position[1] -= MOVE_SPEED
|
||||
@@ -221,7 +221,7 @@ class Player(GameObject_new):
|
||||
self.__test_counter+=1
|
||||
|
||||
def draw(self):
|
||||
if(self.__test_counter == 15):
|
||||
if(self.__test_counter == 10):
|
||||
self.__snake_body.insert(0, list(self._position))
|
||||
counter = 0
|
||||
for pos in self.__snake_body:
|
||||
@@ -232,7 +232,7 @@ class Player(GameObject_new):
|
||||
counter += 1
|
||||
counter = 0
|
||||
#print(pos)
|
||||
if(self.__test_counter == 15):
|
||||
if(self.__test_counter == 10):
|
||||
self.__snake_body.pop()
|
||||
|
||||
def collide_fruit(self, rect:pygame.Rect):
|
||||
@@ -245,7 +245,6 @@ class Player(GameObject_new):
|
||||
count = len(self.__snake_body)
|
||||
for elements in range(1, count):
|
||||
if(self.get_position() == self.__snake_body[elements]):
|
||||
print("Game Over!")
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -264,12 +263,28 @@ class Player(GameObject_new):
|
||||
def get_player_rect(self):
|
||||
return self.__player_rect
|
||||
|
||||
def inc_score(self, points:int):
|
||||
self._score += points
|
||||
|
||||
|
||||
class Fruit(GameObject_new):
|
||||
def __init__(self, name: str, surface: pygame.Surface, surface_size: tuple, init_pos_x, init_pos_y, visibility: bool = True) -> None:
|
||||
def __init__(self, name: str, surface: pygame.Surface, surface_size: tuple, init_pos_x, init_pos_y, visibility: bool = True, rect_size:int = 10, color:tuple = (0,0,0), score_points = 0) -> None:
|
||||
super().__init__(name, surface, surface_size, init_pos_x, init_pos_y, visibility)
|
||||
|
||||
pass
|
||||
self.__score_points = score_points
|
||||
self.__rect:pygame.Rect
|
||||
self.__rect_size = rect_size
|
||||
self.__color = color
|
||||
|
||||
def draw(self):
|
||||
self.__rect = pygame.draw.rect(self._surface, self.__color, (self._position[0], self._position[1], self.__rect_size, self.__rect_size))
|
||||
|
||||
def get_rect(self) -> pygame.Rect:
|
||||
return self.__rect
|
||||
|
||||
def get_score_points(self) -> int:
|
||||
return self.__score_points
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user