day 20
This commit is contained in:
22
020/food.py
Normal file
22
020/food.py
Normal file
@ -0,0 +1,22 @@
|
||||
from turtle import Turtle
|
||||
import random
|
||||
|
||||
class Food:
|
||||
def __init__(self, screen_x_size, screen_y_size):
|
||||
self.turtle = Turtle(shape="square")
|
||||
self.turtle.color("cyan")
|
||||
self.turtle.pu()
|
||||
|
||||
x_limit = int((screen_x_size-20)/40)
|
||||
y_limit = int((screen_y_size-20)/40)
|
||||
|
||||
x_pos = random.randint(-x_limit, x_limit)*20
|
||||
y_pos = random.randint(-y_limit, y_limit)*20
|
||||
self.turtle.teleport(x=x_pos, y=y_pos)
|
||||
|
||||
|
||||
def get_position(self):
|
||||
return self.turtle.xcor(), self.turtle.ycor()
|
||||
|
||||
def hide(self):
|
||||
self.turtle.hideturtle()
|
||||
Reference in New Issue
Block a user