We already have rudimentary throttle control, in that we can set the throttle to maximum forward or maximum reverse, but we need finer control than that for our game. We'll create a new method for this:
Just below the end of the
cycleControl()
method, add a new method that looks like the following code:def adjustThrottle(self, dir, dt): if(dir == "up"): self.throttle += .25 * dt if(self.throttle > 1 ): self.throttle = 1 else: self.throttle -= .25 * dt if(self.throttle < -1 ): self.throttle = -1
Next, we can simply delete these lines from the
cycleControl()
method:else:
self.throttle = 0
Now we need to change the lines where we set our throttle to use the new
adjustThrottle()
method. Change the line that setsself.throttle = 1
to:self.adjustThrottle("up", dt)
Change the line that sets
self.throttle = -1
to:self.adjustThrottle("down", dt)
Check
chp04_04.py
in theChapter04/Examples
folder, if you need to see the code.Save...