May-22-2020, 01:34 PM
import turtle import time #I have been creating a flappy bird game using turtle module in python #I have come across a problem where i can't change the xcor and ycor of the pipes #please check the class and help me #creating the screen win = turtle.Screen() win.bgpic("C://Users//User//Desktop//flappy bird background.png") win.tracer(0) #creating the player bird = turtle.Turtle() bird.speed(0) bird.shape("turtle") bird.color("red") bird.penup() bird.goto(-200, 0) bird.dx = 0 bird.dy = 1 #creating pipes class pipe(object): def __init__(self, x,y,shape,width, height): self.x = x self.y = y self.shape = shape self.width = width self.height = height pipe = turtle.Turtle() pipe.speed(0) pipe.shape(self.shape) pipe.color("green") pipe.shapesize(stretch_wid=self.width, stretch_len=self.height) pipe.penup() pipe.goto(self.x, self.y) pipe.dx = -3 pipe.dy = 0 object1 = pipe(-100, 200, "square", 10, 2) object2 = pipe(-100, -200, "square", 18, 2) object3 = pipe(100, 200, "square", 14, 2) object4 = pipe(100, -200, "square", 16, 2) #gravity variable gravity = -0.9 #functions area def go_up(): bird.dy += 10 if bird.dy > 10: bird.dy = 10 #keyboard binding turtle.listen() turtle.onkeypress(go_up, "space") while True: time.sleep(0.09) win.update() bird.forward(2) #applying gravity for the game bird.dy += gravity #move the player y = bird.ycor() y += bird.dy bird.sety(y) y = bird.ycor() if y < -240: y = -240 bird.sety(y) win.mainloop()