This example will mostly involve taking code we've already written and moving it to a new file. Be sure to follow along carefully so we don't move any code we don't want to move.
First, create a blank file in Notepad++ and save it as
CycleClass_01.py
.Add the following two lines to the new file:
class Cycle(DirectObject): def __init__(self):
Next, cut the following lines that declare the speed, acceleration, turning, and other cycle variables from
WorldClass_01.py
, and paste them into the__init__
method of theCycle
class.self.speed = 0 self.throttle = 0 self.maxSpeed = 200 self.accel = 25 self.handling = 20
Do the same to these lines, which load the cycle model, and reparent and reposition it. They also need to be in the
Cycle
class'__init__
method.self.cycle = loader.loadModel("../Models/Cycle.bam") self.cycle.reparentTo(render) self.cycle.setPos(2,15,0)
The line where the
cycleControl
task is added to the task manager...