Question: Below is the code for a Ball class, which illustrate the bouncing of the balls in X and Y coordinates. class Ball: def __init__ (self,

Below is the code for a Ball class, which illustrate the bouncing of the balls in X and Y coordinates.

class Ball:

def __init__ (self, x, y, vx, vy):

self.xPos = x

self.yPos = y

self.xVec = vx

self.yVec = vy

def getXPos(self):

return self.xPos

def getYPos(self):

return self.yPos

def getXVel(self):

return self.xVel

def getYVel(self):

return self.yVel

def advance(self, timestep=1):

self.xPos += self.xVel *timestep

self.yPos += self.yVel *timestep

Write a bounce method for the class that multiplies both the y-coordinate

and y-velocity by -1.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!