def editor_input( self, event ): if event.type == QUIT: sys.exit(0) elif self.config.keys_menu.matches( event ): self.menu_screen() if self.level != None: self.editor_redraw_screen() elif self.config.keys_volup.matches( event ): self.config.volume = self.sound_mgr.increase_volume() self.config.save() elif self.config.keys_voldown.matches( event ): self.config.volume = self.sound_mgr.decrease_volume() self.config.save() elif self.config.keys_editor_placewall.matches( event ): x = self.cursor[0] y = self.cursor[1] if self.cursvh == CURS_HOR: self.level.lines_hor[y][x] = 1 - self.level.lines_hor[y][x] self.editor_redraw_lines( ( (CURS_HOR,(x,y)), ) ) else: self.level.lines_ver[y][x] = 1 - self.level.lines_ver[y][x] self.editor_redraw_lines( ( (CURS_VER,(x,y)), ) ) elif self.config.keys_editor_placestart.matches( event ): if event.type == MOUSEBUTTONDOWN: self.editor_move_mouse( event ) oldpos = self.level.position self.level.position = [ self.cursor[0], self.cursor[1] ] if self.level.position[0] >= self.config.arena_size[0]: self.level.position[0] = self.config.arena_size[0] - 1 if self.level.position[1] > self.config.arena_size[1] - 1: self.level.position[1] = self.config.arena_size[1] - 1 self.editor_move_position( oldpos, self.level.position ) elif event.type == EVENTTYPE_MOVE: self.move_again() elif event.type == MOUSEMOTION: self.editor_move_mouse( event ) else: if self.config.keys_editor_left.matches( event ): self.move_left() pygame.time.set_timer( EVENTTYPE_MOVE, MOVE_TICK_TIME ) elif self.config.keys_editor_right.matches( event ): self.move_right() pygame.time.set_timer( EVENTTYPE_MOVE, MOVE_TICK_TIME ) elif self.config.keys_editor_up.matches( event ): self.move_up() pygame.time.set_timer( EVENTTYPE_MOVE, MOVE_TICK_TIME ) elif self.config.keys_editor_down.matches( event ): self.move_down() pygame.time.set_timer( EVENTTYPE_MOVE, MOVE_TICK_TIME ) elif( ( self.direction == level.DIR_LEFT and self.config.keys_editor_left_release.matches( event ) ) or ( self.direction == level.DIR_RIGHT and self.config.keys_editor_right_release.matches( event ) ) or ( self.direction == level.DIR_UP and self.config.keys_editor_up_release.matches( event ) ) or ( self.direction == level.DIR_DOWN and self.config.keys_editor_down_release.matches( event ) ) ): mopelib.clear_events( EVENTTYPE_MOVE )
def intro_input( event, config, intro_mode ): if event.type == QUIT: sys.exit(0) elif config.keys_volup.matches( event ): config.volume = sound_mgr.increase_volume() config.save() elif config.keys_voldown.matches( event ): config.volume = sound_mgr.decrease_volume() config.save() else: if event.type == EVENTTYPE_TITLE: intro_mode += 1 if intro_mode == INTRO_MODE_ENDED: intro_mode = INTRO_MODE_TITLE intro_draw_something( intro_mode ) elif config.keys_menu.matches( event ): mopelib.clear_events( EVENTTYPE_TITLE ) start_game = general_menu_screen( config, None ) if start_game: intro_mode = INTRO_MODE_ENDED else: intro_draw_something( intro_mode ) pygame.time.set_timer( EVENTTYPE_TITLE, TITLE_TICK_TIME ) elif config.keys_startgame.matches( event ): intro_mode = INTRO_MODE_ENDED return intro_mode
def inlevel_input( event, gamestate ): if event.type == QUIT: sys.exit(0) elif( ( event.type == pygame.ACTIVEEVENT and event.state == 2 ) or config.keys_menu.matches( event ) ): general_menu_screen( config, gamestate ) gamestate.old_dim = -2 inlevel_redraw_screen( gamestate ) elif config.keys_volup.matches( event ): config.volume = sound_mgr.increase_volume() config.save() elif config.keys_voldown.matches( event ): config.volume = sound_mgr.decrease_volume() config.save() elif event.type == EVENTTYPE_FADE: gamestate.fade_event() inlevel_redraw_screen( gamestate ) elif event.type == EVENTTYPE_TIMER: gamestate.timer_tick() if gamestate.alive == level.INGAME_DEAD: finishedlevel_mainloop( gamestate ) gamestate.same_level() else: inlevel_redraw_screen( gamestate ) elif event.type == EVENTTYPE_MOVE: #sound_mgr.play_sample( "waddles" ) gamestate.cur_lev.move_again( gamestate ) inlevel_redraw_screen( gamestate ) else: if config.keys_left.matches( event ): #sound_mgr.play_sample( "waddles" ) gamestate.cur_lev.move_left( gamestate ) inlevel_redraw_screen( gamestate ) pygame.time.set_timer( EVENTTYPE_MOVE, MOVE_TICK_TIME ) elif config.keys_right.matches( event ): #sound_mgr.play_sample( "waddles" ) gamestate.cur_lev.move_right( gamestate ) inlevel_redraw_screen( gamestate ) pygame.time.set_timer( EVENTTYPE_MOVE, MOVE_TICK_TIME ) elif config.keys_up.matches( event ): #sound_mgr.play_sample( "waddles" ) gamestate.cur_lev.move_up( gamestate ) inlevel_redraw_screen( gamestate ) pygame.time.set_timer( EVENTTYPE_MOVE, MOVE_TICK_TIME ) elif config.keys_down.matches( event ): #sound_mgr.play_sample( "waddles" ) gamestate.cur_lev.move_down( gamestate ) inlevel_redraw_screen( gamestate ) pygame.time.set_timer( EVENTTYPE_MOVE, MOVE_TICK_TIME ) elif( ( gamestate.cur_lev.direction == level.DIR_LEFT and config.keys_left_release.matches( event ) ) or ( gamestate.cur_lev.direction == level.DIR_RIGHT and config.keys_right_release.matches( event ) ) or ( gamestate.cur_lev.direction == level.DIR_UP and config.keys_up_release.matches( event ) ) or ( gamestate.cur_lev.direction == level.DIR_DOWN and config.keys_down_release.matches( event ) ) ): mopelib.clear_events( EVENTTYPE_MOVE )
def intro_mainloop( config ): intro_draw_title() pygame.display.update() pygame.time.set_timer( EVENTTYPE_TITLE, TITLE_TICK_TIME ) intro_mode = INTRO_MODE_TITLE while intro_mode < INTRO_MODE_ENDED: intro_mode = intro_input( pygame.event.wait(), config, intro_mode ) mopelib.clear_events( EVENTTYPE_TITLE )
def finishedlevel_mainloop( gamestate ): mopelib.clear_events( EVENTTYPE_MOVE ) mopelib.clear_events( EVENTTYPE_FADE ) gamestate.dim = 0.5 inlevel_redraw_screen( gamestate ) write_text( "Out of time!", (255,255,255), 0.125, 0.45 ) waiting = True write_text( "Press %s to try again." % config.keys_startgame.name, (255,255,255), 0.05, 0.8 ) pygame.display.update() while waiting: waiting = finishedgame_input( pygame.event.wait(), waiting )
def finishedgame_mainloop( config, gamestate ): mopelib.clear_events( EVENTTYPE_MOVE ) mopelib.clear_events( EVENTTYPE_FADE ) if gamestate.alive == level.INGAME_WON: config.start_level = 0 config.save() gamestate.dim = 0.5 inlevel_redraw_screen( gamestate ) write_text( "Congratulations!", (255,255,255), 0.125, 0.38 ) write_text( "You won!", (255,255,255), 0.125, 0.52 ) waiting = True write_text( "Press %s" % config.keys_startgame.name, (255,255,255), 0.05, 0.8 ) pygame.display.update() while waiting: waiting = finishedgame_input( pygame.event.wait(), waiting ) ingame_surface_background.fill( config.colour_background )
def inlevel_mainloop( config, gamestate ): gamestate.start_fade() inlevel_redraw_screen( gamestate ) gc.disable() pygame.time.set_timer( EVENTTYPE_TIMER, TIMER_TICK_TIME ) while gamestate.alive == level.INGAME_ALIVE: inlevel_input( pygame.event.wait(), gamestate ) gc.enable() mopelib.clear_events( EVENTTYPE_TIMER ) mopelib.clear_events( EVENTTYPE_FADE ) mopelib.clear_events( EVENTTYPE_MOVE ) ingame_surface_background.fill( config.colour_background )
def fade_event( self ): self.dim -= 0.1 if self.dim <= 1: self.dim = 1 mopelib.clear_events( EVENTTYPE_FADE )