Our cycle needs to accelerate at a constant rate until it reaches the throttle setting, or decelerate to the throttle, if necessary. This will take two things to make happen, some new variables and two new methods.
To start with, we're going to add some variable declarations at the beginning of our
__init__
method. Place this code right below the line where we define the__init__
method.self.speed = 0 self.throttle = 0 self.maxSpeed = 200 self.accel = 25
We also want to add a new method to our
World
class. Add this code to the end of theWorld
class, right above the line that setsw = World()
def speedCheck(self, dt): tSetting = (self.maxSpeed * self.throttle) if(self.speed < tSetting): if((self.speed + (self.accel * dt)) > tSetting): self.speed = tSetting else: self.speed += (self.accel * dt) elif(self.speed > tSetting): if((self.speed - (self.accel * dt)) < tSetting): ...