To start with, we're going to make a simple class for the track in our game and import it into our main file.
Start by opening up the file
chp04_07.py
and resave it in theChapter05
folder asWorldClass_01.py
.Next, open a new blank document in Notepad++ and save it as
TrackClass_01.py
.In the new file, add the following lines of code at the very top:
class Track: def __init__(self):
The next step is to copy a few lines from
WorldClass_01.py
, specifically the lines where we load our track, reparent it, and reposition it. Once you've copied the lines to the clipboard, you can delete them from theWorldClass_01.py
file. These are the lines we're referring to:self.track = loader.loadModel("../Models/Track.egg") self.track.reparentTo(render) self.track.setPos(0,0,-5)
Go back to the file
TrackCLass_01.py
and paste the three lines into the__init__
method, like so:def __init__(self): self.track = loader.loadModel("../Models/Track...