def __init__(self, inputManager, track, startPos, name, ai=None): self.inputManager = inputManager # Stores a reference to the InputManager to access user input. self.setupVarsNPs(startPos, name) self.setupCollisions() # Sets up initial variables, NodePaths, and collision objects. self.track = track # Stores a reference to the track. self.lanes = self.track.trackLanes.lanes # gets a reference to the lanes on the track, to shorten the variable name. startingLane = self.track.trackLanes.getNearestMarker(self).lane # Gets the lane for the closest marker to the cycle. self.uc1 = self.lanes[startingLane][0] self.uc2 = self.lanes[startingLane][1] self.uc3 = self.lanes[startingLane][2] # Sets up 3 variables to store references to the 3 up-coming markers on the # track, ahead of the cycle. These are used by the AI to steer, and by player # cycles to measure progress along the track. if (ai == True): self.ai = CycleAI(self) # if the ai input is passed anything, it won't default to None, and the cycle will create # an AI to control itself. elif (ai == None): self.ai = None taskMgr.add(self.cycleControl, "Cycle Control") # If the cycle isn't using an AI, activate player control. # With this set up, if AI == False, the cycle will be completely uncontrolled. self.setupLight()
def __init__(self, inputManager, track, startPos, name, ai=None): self.inputManager = inputManager # Stores a reference to the InputManager to access user input. self.setupVarsNPs(startPos, name) self.setupCollisions() # Sets up initial variables, NodePaths, and collision objects. self.track = track # Stores a reference to the track. self.lanes = self.track.trackLanes.lanes # gets a reference to the lanes on the track, to shorten the variable name. startingLane = self.track.trackLanes.getNearestMarker(self).lane # Gets the lane for the closest marker to the cycle. self.uc1 = self.lanes[startingLane][0] self.uc2 = self.lanes[startingLane][1] self.uc3 = self.lanes[startingLane][2] # Sets up 3 variables to store references to the 3 up-coming markers on the # track, ahead of the cycle. These are used by the AI to steer, and by player # cycles to measure progress along the track. if (ai == True): self.ai = CycleAI(self) # if the ai input is passed anything, it won't default to None, and the cycle will create # an AI to control itself. elif (ai == None): self.ai = None taskMgr.add(self.cycleControl, "Cycle Control", sort=int(self.root.getY() + 100)) # If the cycle isn't using an AI, activate player control. The cycle is also given a unique # sort value based on it's distance from the finish line. The unique sort value fixes a bug # in the AI aim code that can cause jittering in the aim when the tasks that control the # cycles don't execute in the same order every frame. # With this set up, if AI == False, the cycle will be completely uncontrolled. self.setupLight()
def __init__(self, inputManager, track, ai=None): self.inputManager = inputManager self.setupVarsNPs() self.track = track # Stores a reference to the track. self.lanes = self.track.trackLanes.lanes # gets a reference to the lanes on the track, to shorten the variable name. startingLane = self.track.trackLanes.getNearestMarker(self).lane # Gets the lane for the closest marker to the cycle. self.uc1 = self.lanes[startingLane][0] self.uc2 = self.lanes[startingLane][1] self.uc3 = self.lanes[startingLane][2] # Sets up 3 variables to store references to the 3 up-coming markers on the # track, ahead of the cycle. These are used by the AI to steer, and by player # cycles to measure progress along the track. if (ai != None): self.ai = CycleAI(self) # if the ai input is passed anything, it won't default to None, and the cycle will create # an AI to control itself. else: taskMgr.add(self.cycleControl, "Cycle Control")