physics engine problem
I passed the first step but now I'm stuck on the second one when I try to stop the ball at the left wall it doesn't work here is my program
_________________________________________________________________________1 main.py
import ball
import graphics
output_width = 19
ball_position = 1
ball_speed = 5
for time_step in range(100):
# Show the ball's position at the current time step.
print(graphics.show_screen(ball_position, output_width))
ball_position = ball.move(ball_position, ball_speed, output_width)
ball_speed = ball.maybe_bounce (ball_position, ball_speed, output_width)
2 ball.py
"""Simulates a ball's movement and collision with the edges of a screen."""
def move(position, speed, right_wall):
"""Returns the ball's new position after one time step.
The ball moves in straight line at the given speed.
"""
pos_speed = position + speed
if pos_speed > right_wall:
return right_wall
return pos_speed
left_wall = 0
if pos_speed < left_wall:
return left_wall
def maybe_bounce(position, speed, right_wall):
"""Returns the ball's new speed, which stays the same unless the ball
bounces off of a wall.
"""
if position >= right_wall:
# Reverses direction and loses a bit of speed.
speed = speed * -0.75
return speed
_________________________________________________________________________
how do I make the ball stop at the left wall
Please sign in to leave a comment.