def draw(self): self.fps_time += self.delta if self.fps_time > 1: self.fps_time -= 1 self.fps = 0 self.screen.fill((0, 0, 0, 0)) self.world.draw(self.screen) self.world.OnGUI(self.screen) if self.DEBUG: self.world.debDraw(self.screen) Debug.draw(self.screen) pygame.display.flip() self.fps += 1 return
def followPath(self,delta): if not self.agent: self.agent = self.gameObject.getComponent("Navigator") return BT.State.Failed pos = self.gameObject.shape.Center() path = None if not self.data.has_key('path'): _pos = self.gameObject.shape.Center().xy() if self.data.has_key('targ'): _pos = self.data['targ'].xy() self.agent.SetPath(_pos) path = self.agent.path if not path: if self.data.has_key('targ'): self.data.pop('targ') return BT.State.Failed self.data['path'] = path else: path = self.data['path'] if path: waypoint = path.getWayPoint() if waypoint is None: self.data.pop('path') return BT.State.Failed Debug.drawLine(pos.xy(), waypoint.xy(), (0,255,0)) #pygame = Game.pygame #Game.pygame.draw.line( pygame.display.get_surface(), (0,255,0), waypoint.xy(), pos.xy() ) #print "waypoint" #pathstep = waypoint.sub(pos) #speed = self.speed*delta dist = pos.distance(waypoint) #print self.speed*delta*10 radius = self.gameObject.shape.Radius() if dist <= radius: #self.data.pop('path') if not path.getNextWaypoint( radius ): self.data.pop('path') return BT.State.Success self.moveToPosition(waypoint, delta) else: if self.data.has_key('path'): self.data.pop('path') return BT.State.Failed return BT.State.Running