def createRace(self): self.hud.hide() # Hides the HUD because cycles are about to be destroyed. self.destroyRace() # removes any existing race components. self.track = Track() # Creates the track self.cycles.append(Cycle(self.inputManager, self.track, 1, "Bert")) self.cycles.append(Cycle(self.inputManager, self.track, 2, "Ernie", ai = True)) self.cycles.append(Cycle(self.inputManager, self.track, 3, "William", ai = True)) self.cycles.append(Cycle(self.inputManager, self.track, 4, "Patrick", ai = True)) # Creates 1 player controlled cycle and 3 AI controlled cycles. self.hud.setCycle(self.cycles[0]) self.hud.show() # Sets the hude to report on the player cycle, and makes it visible. self.setCameraFollow(self.cycles[0]) # Attaches the camera to one cycle return
def createDemoRace(self): self.hud.hide() # Hides the HUD during the demo. self.destroyRace() # removes any existing race components. self.track = Track() # Creates the track self.cycles.append(Cycle(self.inputManager, self.track, 1, "Bert", ai = True)) self.cycles.append(Cycle(self.inputManager, self.track, 2, "Ernie", ai = True)) self.cycles.append(Cycle(self.inputManager, self.track, 3, "William", ai = True)) self.cycles.append(Cycle(self.inputManager, self.track, 4, "Patrick", ai = True)) # Creates 4 AI controlled cycles. self.setCameraHigh(self.cycles[0]) # Attaches the camera to one cycle self.startRace(1) # Starts the race after 1 second delay. return
def __init__(self): base.disableMouse() base.setBackgroundColor(0, 0, 0) self.track = Track() self.cycle = Cycle() taskMgr.doMethodLater(10, self.debugTask, "Debug Task")
def __init__(self): base.disableMouse() # Turns off the default mouse-camera controls in Panda3D. base.setBackgroundColor(0, 0, 0) # Sets the background to black. self.inputManager = InputManager() # Creates an InputManager to handle all of the user input in the game. self.track = Track() # Creates the track the cycles will race on. self.cycle1 = Cycle(self.inputManager, self.track, 1, "Bert", ai=False) self.cycle2 = Cycle(self.inputManager, self.track, 2, "Ernie") # Creates one uncontrolled cycle, and one player controlled cycle. taskMgr.doMethodLater(10, self.debugTask, "Debug Task") # Tells the debugTask to run once every ten seconds. The debug task is a good # place to put various data print outs about the game to help with debugging. self.filters = CommonFilters(base.win, base.cam) filterok = self.filters.setBloom(blend=(0, 0, 0, 1), desat=-0.5, intensity=3.0, size=2) render.setShaderAuto()
def __init__(self): base.disableMouse() base.setBackgroundColor(0, 0, 0) self.track = Track() self.cycle = Cycle() base.camera.reparentTo(self.cycle) base.camera.setY(base.camera, -5) taskMgr.doMethodLater(10, self.debugTask, "Debug Task")
def __init__(self): base.disableMouse() base.setBackgroundColor(0, 0, 0) self.inputManager = InputManager() self.track = Track() self.cycle1 = Cycle(self.inputManager, self.track, 1, "Bert", ai=False) self.cycle2 = Cycle(self.inputManager, self.track, 2, "Ernie") taskMgr.doMethodLater(10, self.debugTask, "Debug Task")
def createRace(self): self.destroyRace() # removes any existing race components. self.track = Track() # Creates the track self.cycles.append(Cycle(self.inputManager, self.track, 1, "Bert")) self.cycles.append( Cycle(self.inputManager, self.track, 2, "Ernie", ai=True)) self.cycles.append( Cycle(self.inputManager, self.track, 3, "William", ai=True)) self.cycles.append( Cycle(self.inputManager, self.track, 4, "Patrick", ai=True)) # Creates 1 player controlled cycle and 3 AI controlled cycles. self.setCameraFollow(self.cycles[0]) # Attaches the camera to one cycle return
def __init__(self): self.speed = 0 self.throttle = 0 self.maxSpeed = 200 self.accel = 25 self.handling = 20 base.disableMouse() base.setBackgroundColor(0, 0, 0) self.track = Track() self.cycle = loader.loadModel("../Models/Cycle.bam") self.cycle.reparentTo(render) self.cycle.setPos(2, 15, 0) base.camera.reparentTo(self.cycle) base.camera.setY(base.camera, -5) self.keyMap = { "w": False, "s": False, "a": False, "d": False, "mouse1": False, "mouse3": False } taskMgr.add(self.cycleControl, "Cycle Control") taskMgr.doMethodLater(10, self.debugTask, "Debug Task") self.accept("w", self.setKey, ["w", True]) self.accept("s", self.setKey, ["s", True]) self.accept("a", self.setKey, ["a", True]) self.accept("d", self.setKey, ["d", True]) self.accept("mouse1", self.setKey, ["mouse1", True]) self.accept("mouse3", self.setKey, ["mouse3", True]) self.accept("w-up", self.setKey, ["w", False]) self.accept("s-up", self.setKey, ["s", False]) self.accept("a-up", self.setKey, ["a", False]) self.accept("d-up", self.setKey, ["d", False]) self.accept("mouse1-up", self.setKey, ["mouse1", False]) self.accept("mouse3-up", self.setKey, ["mouse3", False])
class Race: def __init__(self, inputManager, hud): self.inputManager = inputManager #gets a reference to the inputManager to pass on to the player cycle self.cycles = [] # creates a list to store cycles self.track = None # creates a variable to store the track. self.hud = hud # stores a reference to the HUD. def createDemoRace(self): self.hud.hide() # Hides the HUD during the demo. self.destroyRace() # removes any existing race components. self.track = Track() # Creates the track self.cycles.append(Cycle(self.inputManager, self.track, 1, "Bert", ai = True)) self.cycles.append(Cycle(self.inputManager, self.track, 2, "Ernie", ai = True)) self.cycles.append(Cycle(self.inputManager, self.track, 3, "William", ai = True)) self.cycles.append(Cycle(self.inputManager, self.track, 4, "Patrick", ai = True)) # Creates 4 AI controlled cycles. self.setCameraHigh(self.cycles[0]) # Attaches the camera to one cycle self.startRace(1) # Starts the race after 1 second delay. return #createDemoRace: Creates all the components for a demo race. def createRace(self): self.hud.hide() # Hides the HUD because cycles are about to be destroyed. self.destroyRace() # removes any existing race components. self.track = Track() # Creates the track self.cycles.append(Cycle(self.inputManager, self.track, 1, "Bert")) self.cycles.append(Cycle(self.inputManager, self.track, 2, "Ernie", ai = True)) self.cycles.append(Cycle(self.inputManager, self.track, 3, "William", ai = True)) self.cycles.append(Cycle(self.inputManager, self.track, 4, "Patrick", ai = True)) # Creates 1 player controlled cycle and 3 AI controlled cycles. self.hud.setCycle(self.cycles[0]) self.hud.show() # Sets the hude to report on the player cycle, and makes it visible. self.setCameraFollow(self.cycles[0]) # Attaches the camera to one cycle return #createRace: Creates all the components for a regular race. def setCameraFollow(self, cycle): base.camera.reparentTo(cycle.dirNP) base.camera.setPos(0, -15, 3) # Connects the camera to dirNP so the camera will follow and # rotate with that node. Also moves it backward 5 meters. return # setCameraFollow: sets the camera behind and slightly above a cycle # and puts it in follow mode. def setCameraHigh(self, cycle): base.camera.reparentTo(cycle.dirNP) # Connects the camera to dirNP so the camera will follow and # rotate with that node. base.camera.setPos(0, 30, 30) base.camera.lookAt(cycle.root) # Moves the camera ahead of the cycle and up, and then points # it at the cycle. return # setCameraHigh: sets the camera in front of and above a cycle # and puts it in follow mode. def startRace(self, delay): taskMgr.doMethodLater(delay, self.startCycles, "Start Cycles") return # startRace: sets up startCycles to be called after a delay. def startCycles(self, task): for C in self.cycles: C.active = True return task.done # startCycles: activates the cycles. def destroyRace(self): if(self.track != None): self.track.destroy() # If a track already exists, this removes it. for C in self.cycles: C.destroy() del self.cycles[0:4] # removes any cycles already in existance. return # destroyRace: removes any existing race components.