import turtle
# Make the play screen
wn = turtle.Screen()
wn.bgcolor("red")
# Make the play field
mypen = turtle.Turtle()
mypen.penup()
mypen.setposition(-300,-300)
mypen.pendown()
mypen.pensize(5)
for side in range(4):
mypen.forward(600)
mypen.left(90)
mypen.hideturtle()
# Make the object
player = turtle.Turtle()
player.color("black")
player.shape("circle")
player.penup()
# define directions( East, West , South , Nord )
def west():
player.setheading(180)
def east():
player.setheading(0)
def north():
player.setheading(90)
def south():
player.setheading(270)
# define forward
def forward():
player.forward(20)
# Wait for input
turtle.listen()
turtle.onkey(west, "a")
turtle.onkey(east, "d")
turtle.onkey(forward,"w")
turtle.onkey(north,"q")
turtle.onkey(south,"s")
if player.xcor() > 300 or player.xcor() < -300:
print("Game over")
if player.ycor() > 300 or player.ycor() < -300:
print("Game over")
So everything is working fine, till the If statements. When i go trough the play field it should give me a print " Game over ". The coordinates are right but it doesnt check the coordinates! What am i doing wrong ?
Aucun commentaire:
Enregistrer un commentaire