Show
Ignore:
Timestamp:
01/04/07 02:50:21 (5 years ago)
Author:
mg
Message:

Show an animation (expanding bubble) when ships respawn.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/pyspacewar/ui.py

    r228 r231  
    172172 
    173173 
     174def linear(x, xmax, y1, y2): 
     175    """Calculate a linear transition from y1 to y2 as x moves from 0 to xmax. 
     176 
     177        >>> for x in range(10): 
     178        ...     print '*' * int(linear(x, 9, 1, 10)) 
     179        * 
     180        ** 
     181        *** 
     182        **** 
     183        ***** 
     184        ****** 
     185        ******* 
     186        ******** 
     187        ********* 
     188        ********** 
     189 
     190    """ 
     191    return y1 + (y2 - y1) * float(x) / xmax 
     192 
     193 
    174194def smooth(x, xmax, y1, y2): 
    175195    """Calculate a smooth transition from y1 to y2 as x moves from 0 to xmax. 
     
    192212    value = 1 / (1 + math.exp(-t)) 
    193213    return y1 + (y2 - y1) * value 
    194  
    195214 
    196215 
     
    17351754    visibility_margin = 120 # Keep ships at least 120px from screen edges 
    17361755 
     1756    respawn_animation = 100 # Time (game ticks) to show respawn animation 
     1757 
    17371758    _ui_mode = None         # Previous user interface mode 
    17381759 
     
    22332254            color = colorblend(color, (0x20, 0x20, 0x20), 0.2) 
    22342255            color = colorblend(color, (0, 0, 0), ratio) 
     2256        elif self.game.world.time - ship.spawn_time < self.respawn_animation: 
     2257            self.draw_Ship_spawn_animation(ship) 
    22352258        direction_vector = ship.direction_vector * ship.size 
    22362259        side_vector = direction_vector.perpendicular() 
     
    23162339        return (front, back, left_front, left_back, right_front, right_back) 
    23172340 
     2341    def draw_Ship_spawn_animation(self, ship): 
     2342        sp = self.viewport.screen_pos(ship.position) 
     2343        color = self.ship_colors[ship.appearance] 
     2344        t = math.sqrt((self.game.world.time - ship.spawn_time) 
     2345                      / self.respawn_animation) 
     2346        radius = linear(t, 1, 1, 100) 
     2347        color = colorblend((0, 0, 0), color, linear(t, 1, 0.2, 0.9)) 
     2348        pygame.draw.circle(self.screen, color, sp, int(radius), 1) 
     2349 
    23182350    def update_missile_trails(self): 
    23192351        """Update missile trails."""