Synt4xErr0r 7
Synt4xErr0r 7

Reputation: 35

Why isn't one of these turtle objects moving?

I have this piece of code that has a block which moves towards the player. The player avoids this block by clicking to jump (basically Flappy Bird). if the player touches the ground, they lose, and if they touch the block, they also lose.

It was working fine, until I implemented the code that made the block/pipe move. While the block is moving, the player object doesn't move. Why?

Here is the code:

import turtle as t
import time
import math 
ii = 0
heading = 0
Screen = t.Screen()
Screen.title("Block")
Screen.bgcolor("white")
Screen.setup(1000, 1000, startx = 0, starty = 0)
xmin = -t.window_width()/2
xmax = t.window_width()/2
ymin = -t.window_height()/2
print(ymin)
ymax = t.window_height()/2
Block = t.Turtle()
Block.seth(heading)
Block.speed(0)
Block.penup()
pipe = t.Turtle()
pipe.shape('square')
pipe.color('green')
pipe.goto(x=500, y=0)
speed_y = 0
print("hi")
def flap(Block, p):
    global speed_y, heading
    speed_y = 0
    heading = 35
    pi = 0
    while True:
        if pi != 10:
            Block.sety(Block.ycor() + 5.5)
            pi += 1
        else:
            break
        
Screen.onkey(lambda:flap(Block, p), 'w')
Screen.onkey(lambda:flap(Block, p), 'space')
Screen.onkey(lambda:flap(Block, p), 'Up')
def isCollision(t1, t2):
    d = math.sqrt(math.pow(t1.xcor()-t2.xcor(),2) + math.pow(t1.ycor()-t2.ycor(),2))
    if d < 20:
        return True
    else:
        return False
def fun():
    global ii
    time.sleep(1)
    ii += 1
    json.dumps(ii)
    return ii
Screen.listen() 
def fall(Block, p):
    global speed_y, heading
    if speed_y == 0 or speed_y == 1:
        speed_y = speed_y + 2
    else:
        speed_y = speed_y+0.1
    y = Block.ycor()
    Block.sety(y-speed_y)
    heading = heading - 1
    return speed_y

def PipeLeft(pipe):
    x = pipe.ycor()
    pipe.setx(x-0.1)
while True:
    if isCollision(Block, pipe) == True:
        t.write("YOU LOSE", font = ("arial", 40, "bold"))
        time.sleep(4)
        break
    PipeLeft(pipe)
    fall(Block, p)
    if Block.ycor() <= -350.5 or Block.ycor() >= 600:
        Block.sety(-350.5)
        t.write("YOU LOSE", font = ("arial", 40, "bold"))
        time.sleep(4)
        break

Upvotes: 0

Views: 51

Answers (0)

Related Questions