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()
how can I change xcor and ycor of the turtle if i am using classes
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
How can i change the direction of the ball based on player's xcor and ycor collisions | MohammedSohail | 0 | 2,321 |
May-25-2020, 08:39 AM Last Post: MohammedSohail |
|
wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' | Shadower | 1 | 7,233 |
Feb-06-2019, 01:25 AM Last Post: woooee |
|
Help! Turtle not working, even when we click the turtle demo in IDLE nothing happens. | BertyBee | 3 | 7,385 |
Jan-04-2019, 02:44 AM Last Post: SheeppOSU |
|
Using classes? Can I just use classes to structure code? | muteboy | 5 | 6,385 |
Nov-01-2017, 04:20 PM Last Post: metulburr |
Users browsing this thread: 1 Guest(s)