Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Turtle in Python I need some assistance for how to write the program. People say that turtle is generally easier so I hope to get
Turtle in Python
I need some assistance for how to write the program. People say that turtle is generally easier so I hope to get an accurate and faster response.
(Question at the bottom)
Current code needed for problem:
import turtle, math, randomclass Ball(turtle.Turtle): def __init__(self, px, py, vx, vy): turtle.Turtle.__init__(self) self.vx = vx self.vy = vy self.shape('circle') self.turtlesize(0.3) self.penup() self.setpos(px, py) def move(self): self.vy = self.vy - 0.981 new_px = self.xcor() + self.vx new_py = self.ycor() + self.vy if new_py 0: new_py = self.ycor() * 0.75 self.vy = -0.75 * self.vy self.setpos(new_px, new_py) def hit(self): print('space bar pressed') self.vx = -self.vx self.vy = 15class Game: def __init__(self): turtle.delay(0) turtle.tracer(0, 0) turtle.setworldcoordinates(-500, -500, 500, 500) self.ball = Ball( random.randint(-100, 100), random.randint(30, 100), random.randint(-12, 6), random.randint(4, 10) ) turtle.update() self.gameloop() turtle.onkeypress(self.ball.hit, "space") turtle.listen() turtle.mainloop() def gameloop(self): self.ball.move() turtle.update() turtle.ontimer(self.gameloop, 30)if __name__ == '__main__': Game()
Here is the problem:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started