day 20 - fixed collision issues
This commit is contained in:
17
020/food.py
17
020/food.py
@ -1,22 +1,23 @@
|
||||
from turtle import Turtle
|
||||
from turtle import Turtle, Screen
|
||||
import random
|
||||
|
||||
class Food:
|
||||
class Food(Turtle):
|
||||
def __init__(self, screen_x_size, screen_y_size):
|
||||
self.turtle = Turtle(shape="square")
|
||||
self.turtle.color("cyan")
|
||||
self.turtle.pu()
|
||||
super().__init__()
|
||||
self.shape("square")
|
||||
self.color("cyan")
|
||||
self.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)
|
||||
self.teleport(x=x_pos, y=y_pos)
|
||||
|
||||
|
||||
def get_position(self):
|
||||
return self.turtle.xcor(), self.turtle.ycor()
|
||||
return self.xcor(), self.ycor()
|
||||
|
||||
def hide(self):
|
||||
self.turtle.hideturtle()
|
||||
self.hideturtle()
|
||||
Reference in New Issue
Block a user