From 8ae9947e23dd0d591e8b3d0dc0f2c0207e1e1fa4 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 28 Aug 2008 11:45:39 +0100 Subject: [PATCH] Now keep track of the live colours on GameState; so no longer pass them around explicitly; and shade each player out in turn when it dies. Contributed by Edmund Stephen-Smith. --- troncode.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/troncode.py b/troncode.py index ae8a27c..1478f69 100755 --- a/troncode.py +++ b/troncode.py @@ -342,8 +342,8 @@ def intro_mainloop( config ): mopelib.clear_events( EVENTTYPE_TITLE_TICK ) -def draw_pixel( gamestate, surface, colour, x, y, alive_colours ): - if colour in alive_colours: +def draw_pixel( gamestate, surface, colour, x, y ): + if colour in gamestate.alive_colours: col = colour else: col = mopelib.dim_colour( colour, gamestate.dim ) @@ -360,29 +360,23 @@ def inlevel_screen_blit( gamestate ): pygame.display.update() def inlevel_redraw_screen( gamestate, arrows, scores ): - alive_colours = [] - if gamestate.alive == INGAME_MOST_DEAD: - for player in gamestate.players: - if not gamestate.statuses[player]._dead: - alive_colours.append( player.GetColour() ) - gamestate.offscreen_buff = pygame.Surface( gamestate.config.screen_size ) gamestate.offscreen_buff.blit( ingame_surface_background, (0,0) ) for x, y, colour in gamestate.pixels_list: - draw_pixel( gamestate, gamestate.offscreen_buff, colour, x, y, alive_colours ) - inlevel_draw_players( gamestate, alive_colours ) + draw_pixel( gamestate, gamestate.offscreen_buff, colour, x, y ) + inlevel_draw_players( gamestate ) write_text_ingame( gamestate, scores ) # TODO: draw arrows inlevel_screen_blit( gamestate ) -def inlevel_draw_players( gamestate, alive_colours ): +def inlevel_draw_players( gamestate ): for player in gamestate.players: x, y = gamestate.GetPosition( player ) draw_pixel( gamestate, gamestate.offscreen_buff, player.GetColour(), - x, y, alive_colours ) + x, y ) def inlevel_update_screen( gamestate, scores ): - inlevel_draw_players( gamestate, [] ) + inlevel_draw_players( gamestate ) inlevel_screen_blit( gamestate ) @@ -474,6 +468,8 @@ class PlayerStatus: self._x -= 1 self._dead = gamestate.AddPixel( self._x, self._y, self._colour ) + if self._dead: + gamestate.alive_colours.remove( self._colour ) return self._dead @@ -567,12 +563,13 @@ class GameState: self.players.append( cls() ) self.alive = INGAME_TWO_ALIVE - self.dim = 1 + self.dim = 0.5 self.pixels_list = [] self.pixels_set = set() self.create_initial_pixels() + self.alive_colours = [] self.statuses = {} for player in self.players: x = random.randint( config.starting_border, config.arena_size[0] @@ -582,6 +579,7 @@ class GameState: dr = random.randint( DIR_UP, DIR_LEFT ) self.statuses[player] = PlayerStatus( x, y, dr, player ) self.AddPixel( x, y, player.GetColour() ) + self.alive_colours.append( player.GetColour() ) self._gameboard = GameBoard( self ) @@ -680,6 +678,7 @@ def inlevel_mainloop( config, gamestate, scores ): tick_counter = 0 gamestate.framerate = 0 + num_alive = len(gamestate.alive_colours) while gamestate.alive == INGAME_TWO_ALIVE: for evt in pygame.event.get(): @@ -695,6 +694,11 @@ def inlevel_mainloop( config, gamestate, scores ): elif tick_counter >= gamestate.framerate: tick_counter = 0 inlevel_redraw_screen( gamestate, False, scores ) + if num_alive != len(gamestate.alive_colours): + num_alive = len(gamestate.alive_colours) + # redraw with dead players dimmed + inlevel_redraw_screen( gamestate, False, scores ) + gc.enable() mopelib.clear_events( EVENTTYPE_INGAME_TICK ) @@ -760,7 +764,6 @@ def finishedlevel_input( event, waiting, gamestate, scores ): return waiting def finishedlevel_mainloop( gamestate, scores ): - gamestate.dim = 0.3 if not gamestate.any_humans: pygame.time.set_timer( EVENTTYPE_TITLE_TICK, TITLE_TICK_TIME ) @@ -1030,7 +1033,7 @@ else: troncode_version = mopelib.read_version( config ) - ingame_font = pygame.font.Font( None, int( config.screen_size[1] * 0.03 ) ) + ingame_font = pygame.font.Font( None, int( config.screen_size[1] * 0.02 ) ) menurender = mopelib.MenuRenderer( screen, config, ingame_surface_background, (128, 128, 128), (128, 255, 128), (128, 128, 128) ) -- 2.11.4.GIT