Changeset 258

Show
Ignore:
Timestamp:
01/10/07 02:35:05 (5 years ago)
Author:
mg
Message:

Add a couple of (hardcoded) options: lightweight, show_background.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/lightweight/src/pyspacewar/ui.py

    r256 r258  
    730730 
    731731 
     732class HUDShipInfoLite(HUDInfoPanel): 
     733    """Heads-up ship status display (lightweight version).""" 
     734 
     735    def __init__(self, ship, font, xalign=0, yalign=0, 
     736                 colors=HUDInfoPanel.STD_COLORS): 
     737        HUDInfoPanel.__init__(self, font, 12, 1.75, xalign, yalign, colors) 
     738        self.ship = ship 
     739        self.surface.set_alpha(255) # should be faster, I hope 
     740 
     741    def draw(self, surface): 
     742        self.draw_rows(surface, 
     743                ('frags', '%d' % self.ship.frags),) 
     744        x, y = self.position(surface) 
     745        x += 1 
     746        y += self.height - 5 
     747        w = max(0, int((self.width - 4) * self.ship.health)) 
     748        pygame.draw.rect(surface, self.color2, (x, y, self.width-2, 4), 1) 
     749        surface.fill(self.color1, (x+1, y+1, w, 2)) 
     750 
     751 
    732752class HUDCompass(HUDElement): 
    733753    """Heads-up ship compass display. 
     
    18111831    fullscreen_mode = None          # Desired video mode (w, h) 
    18121832    show_missile_trails = True      # Show missile trails by default 
     1833    show_background = False         # Show background image 
    18131834    music = True                    # Do we have background music? 
    18141835    sound = True                    # Do we have sound effects? 
    18151836    sound_in_vacuum = True          # Can you hear what happens to AI ships? 
    18161837    show_debug_info = False         # Hide debug info by default 
     1838    lightweight_hud = True          # Smaller HUD (for PDAs and such) 
    18171839    desired_zoom_level = 1.0        # The desired zoom level 
    18181840 
     
    21962218                        ]), 
    21972219            ]) 
    2198         self.hud = HUDCollection([ 
    2199             HUDShipInfo(self.ships[0], self.hud_font, 1, 0), 
    2200             HUDShipInfo(self.ships[1], self.hud_font, 0, 0, 
    2201                         HUDShipInfo.GREEN_COLORS), 
    2202             HUDCompass(self.game.world, self.ships[0], self.viewport, 1, 1, 
    2203                        HUDCompass.BLUE_COLORS), 
    2204             HUDCompass(self.game.world, self.ships[1], self.viewport, 0, 1, 
    2205                        HUDCompass.GREEN_COLORS), 
    2206         ]) 
     2220        if self.lightweight_hud: 
     2221            self.hud = HUDCollection([ 
     2222                HUDShipInfoLite(self.ships[0], self.hud_font, 1, 0), 
     2223                HUDShipInfoLite(self.ships[1], self.hud_font, 0, 0, 
     2224                                HUDShipInfo.GREEN_COLORS), 
     2225            ]) 
     2226        else: 
     2227            self.hud = HUDCollection([ 
     2228                HUDShipInfo(self.ships[0], self.hud_font, 1, 0), 
     2229                HUDShipInfo(self.ships[1], self.hud_font, 0, 0, 
     2230                            HUDShipInfo.GREEN_COLORS), 
     2231                HUDCompass(self.game.world, self.ships[0], self.viewport, 1, 1, 
     2232                           HUDCompass.BLUE_COLORS), 
     2233                HUDCompass(self.game.world, self.ships[1], self.viewport, 0, 1, 
     2234                           HUDCompass.GREEN_COLORS), 
     2235            ]) 
    22072236 
    22082237    def _keep_ships_visible(self): 
     
    24672496            start = time.time() 
    24682497            self._keep_ships_visible() 
    2469             self.screen.blit(self.background_surface, (0, 0)) 
     2498            if self.show_background: 
     2499                self.screen.blit(self.background_surface, (0, 0)) 
     2500            else: 
     2501                self.screen.fill((0, 0, 0)) 
    24702502            if self.show_missile_trails: 
    24712503                self.draw_missile_trails()