Changeset 231

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

Show an animation (expanding bubble) when ships respawn.

Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/NEWS.txt

    r229 r231  
     1January 5, 2006: Happy New Year! 
     2 
     3  - Show an animation (expanding bubble) when ships respawn. 
     4 
    15December 25, 2006: Released version 0.9.3: the Christmas release. 
    26 
  • 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.""" 
  • trunk/src/pyspacewar/version.py

    r229 r231  
    66 
    77svn_revision = "$Revision$"[11:-2] 
    8 version = "0.9.3" 
     8version = "0.9.3svn" 
    99 
    1010if version.endswith('svn'): 
  • trunk/src/pyspacewar/world.py

    r201 r231  
    552552        self.frags = 0 
    553553        self.dead = False 
     554        self.spawn_time = 0 # the value of world.time when last respawned 
    554555 
    555556    def _set_direction(self, direction): 
     
    660661        self.dead = False 
    661662        self.health = 1.0 
     663        if self.world: 
     664            self.spawn_time = self.world.time 
    662665 
    663666    def launch(self):