Exemplo n.º 1
0
    def update(self, elapsed):
        Painter.update(self, elapsed)
        self.set_dirty() # always dirty

        # choose steering
        if self._target:
            # steer toward target
            target_direction = math.atan((self._target.x - self._relative_position.x)/(self._target.y - self._relative_position.y))
            if self._target.y < self._relative_position.y:
                target_direction += math.pi
            target_direction %= math.pi * 2
            delta = (target_direction - self._direction)
            if (target_direction > self._direction and delta < math.pi) or (target_direction < self._direction and math.fabs(delta) > math.pi):
                self._direction = (self._direction + 0.1) % (math.pi * 2)
            else:
                self._direction = (self._direction - 0.1) % (math.pi * 2)
        else:
            # wander
            self._direction += (random.random() - 0.5) % (math.pi * 2)

        # update position
        distance = elapsed * Human.SPEED * self._scale
        self.set_relative_position(self._relative_position + Point(math.sin(self._direction) * distance, math.cos(self._direction) * distance))

        self._rotation = self._direction

        
        """
Exemplo n.º 2
0
 def update(self, elapsed):
     Painter.update(self, elapsed)
     self.set_dirty()
     self.__age += elapsed
     if self.expired():
         self._parent_painter.remove(self)
     else:
         progress = self.__age / float(Ping.TIMEOUT)
         color = pygame.color.Color(255, 0, 0, 255 - int(255 * progress))
         self._surface.fill(pygame.Color(0,0,0,0))
         pygame.draw.circle(self._surface, color, (Ping.RADIUS, Ping.RADIUS), max(4, int(Ping.RADIUS * progress)), 1)
     self.set_surface(self._surface)
Exemplo n.º 3
0
 def update(self, elapsed):
     Painter.update(self, elapsed)
     self.set_surface(Painter.font.render("FPS: %0.2f" % GameState.clock.get_fps(), True, (255,255,255)))
Exemplo n.º 4
0
    def update(self, elapsed):
        Painter.update(self, elapsed)
#        self._surface = terrain#.subsurface(self._view)
        # ugly hack to pre-populate the grid
        """