generated from mwc/project_game
This round, i was able to add the food and set up the collisions but after i edited some parts, the game just started crashing everytime.
It worked up until I got to test to take away the food and add it.
This commit is contained in:
18
food.py
Normal file
18
food.py
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
import random
|
||||
|
||||
class Food:
|
||||
name = "food"
|
||||
character = "*"
|
||||
|
||||
def __init__(self, board_size):
|
||||
self.board_width, self.board_height = board_size
|
||||
self.position = self._random_position()
|
||||
|
||||
def _random_position(self):
|
||||
x = random.randint(0, self.board_width - 1)
|
||||
y = random.randint(0, self.board_height - 1)
|
||||
return (x, y)
|
||||
|
||||
def respawn(self):
|
||||
self.position = self._random_position()
|
||||
Reference in New Issue
Block a user