# This tutorial provides an example of creating a character # and having it walk around using PandAI and dynamic obstacle # pathfinding
#for directx window and functions import direct.directbase.DirectStart #for most bus3d stuff from pandac.PandaModulesimport* #for directx object support from direct.showbase.DirectObjectimport DirectObject #for intervals from direct.interval.IntervalGlobalimport* #for FSM from direct.fsmimport FSM from direct.fsmimport State #for tasks from direct.taskimport Task #for Actors from direct.actor.Actorimport Actor #for math importmath importrandom #for system commands importrandom, sys, os, math #for directGUI from direct.gui.DirectGuiimport* from direct.gui.OnscreenTextimport OnscreenText
# Figure out what directory this program is in. MYDIR=os.path.abspath(sys.path[0]) MYDIR=Filename.fromOsSpecific(MYDIR).getFullpath()
font = loader.loadFont("cmss12")
# Function to put instructions on the screen. def addInstructions(pos, msg): return OnscreenText(text=msg, style=1, fg=(1,1,1,1), font = font, pos=(-1.3, pos), align=TextNode.ALeft, scale = .05)
# Function to put title on the screen. def addTitle(text): return OnscreenText(text=text, style=1, fg=(1,1,1,1), font = font, pos=(1.3,-0.95), align=TextNode.ARight, scale = .07)
class World(DirectObject):
def__init__(self):
self.keyMap = {"left":0, "right":0, "forward":0}
#base.disableMouse() base.cam.setPosHpr(0,-210,135,0,327,0) self.done = [] for i inrange(4): self.done.append(False) self.toggle = False self.firstTime = False
self.title = addTitle("Pandai Tutorial: Dynamic Avoidance of Moving Obstacles") self.inst1 = addInstructions(0.95, "[ESC]: Quit") self.inst2 = addInstructions(0.90, "[Arrow Keys]: Move the blue Ralph") self.inst3 = addInstructions(0.85, "Try and move the blue Ralph in the path of the other Ralphs")
# Create the main character, Ralph self.ralph = [] self.positions = [] self.positions_new = [] for i inrange(4): self.ralph.append(Actor("models/ralph", {"run":"models/ralph-run", "walk":"models/ralph-walk"})) self.ralph[i].reparentTo(render) self.ralph[i].setScale(2)