Beispiel #1
0
 def setUp(self):
     pygame.mixer.init()
     self.player = PlayerSprite()
     self.invScreen = InventoryScreen(self.player)
     self.invScreen.lines = ['Test1', 'Test2']
     State.screens = []
     State.push_screen(self.invScreen)
Beispiel #2
0
    def handle_keyboard(self, events):
        '''
        Function to handle the keyboard events and act accordingly

        @param events - The list of events from the game
        '''

        self.keyboard_input = { 
            key: (new_val, new_val) 
            for key, (old_val, new_val) 
            in self.keyboard_input.items() 
        }
	

        for event in events:
            if not hasattr(event, 'key'): 
                continue
            if event.type == KEYDOWN:
                if event.key == K_p:
                    State.push_screen(PauseScreen(self.player, self.tileMap))
                if event.key == K_i:
                    State.push_screen(InventoryScreen(self.player))

            if event.key in self.keyboard_input:
                (old_val, new_val) = self.keyboard_input[event.key]
                self.keyboard_input[event.key] = (new_val, event.type)
Beispiel #3
0
    def update(self, events):
        '''
        Updates the screen when an event happens 

        @param - list of game events
        '''
        for event in events:
            if not hasattr(event, 'key'):
                continue
            if event.type == KEYDOWN:
                if event.key == K_RETURN:
                    if self.currLine == GameMenuScreenLine.NewGame:
			gui = EnterSaveNameGUI()
			save_name = gui.saveName
			if len(save_name) <= 0:
				continue
			load(NEW_GAME_DIR)
			State.save_name = save_name
                        State.push_screen(gameScreen.GameScreen(CURRENT_GAME_DIR))
                    elif self.currLine == GameMenuScreenLine.LoadGame:
			State.push_screen(loadGameScreen.LoadGameScreen())
                    elif self.currLine == GameMenuScreenLine.Exit:
                        sys.exit(0)
                else:
                    super(GameMenuScreen, self).interact(event)
Beispiel #4
0
    def update(self, events):
	'''
        Updates the screen when an event happens 

        @param - list of game events
        '''
        for event in events:
            if not hasattr(event, 'key'): 
                continue
            if event.type == KEYDOWN:
                if event.key == K_p:
                    State.pop_screen()
		elif event.key == K_RETURN:
			self.sounds['select'].play()
			if self.currLine == PauseScreenLines.Resume:
				State.pop_screen()
			if self.currLine == PauseScreenLines.Save:
                            self.tileMap.save(self.player)
                            save(USER_SAVES_DIR + State.save_name)
			elif self.currLine == PauseScreenLines.Quit:
				State.pop_screen()
				State.pop_screen()
		elif event.key == K_i:
		    State.push_screen(InventoryScreen(self.player))
		else:
		    super(PauseScreen, self).interact(event)
Beispiel #5
0
 def victory(self):
     '''
     Once the victory condition has been met, it will push the victory screen to state
     '''
     State.push_screen(
         VictoryScreen(
             TileMap.width*TileMap.BLOCK_SIZE[0], 
             TileMap.height*TileMap.BLOCK_SIZE[1]
         )
     )
Beispiel #6
0
    def update(self, events):
        '''
        Updates everything in the game

        This includes: 
            - checking to see if the final condition has been met
            - handling keybour events
            - Checking kill count
            - Having each enemy call their act functions
            - Checking collisions
            - Updating each tile
            - Checking the health of the player

        '''
        if State.boss_ready:
            self.gate_group.empty()
            self.tileMap.tile.gates = []

        self.handle_keyboard(events)
        self.player.handle_input(self.keyboard_input, self.tileMap.tile, self.bullet_group)
        self.player.check_count()
        
        for enemy in self.enemy_group:
            enemy.act(self.tileMap.tile)

        for shooter in self.shooters:
            (px, py) = self.player.coords
            if shooter.shouldShoot(px, py): 
                shooter.shoot(shooter, self.enemy_bullet_group)

        self.check_collisions()

        if(self.tileMap.update(self.player, self.enemy_group)):
            self.bullet_group.update()
            self.enemy_bullet_group.update()
            self.player_group.update()
            self.enemy_group.update()
        else:
            self.reset_sprite_groups()

        if self.player.health <= 0:
            self.player.lives -= 1
            if self.player.lives <= 0:
                State.push_screen(
                    GameOverScreen(
                        TileMap.width*TileMap.BLOCK_SIZE[0], 
                        TileMap.height*TileMap.BLOCK_SIZE[1]
                    )
                )
            else:
                self.tileMap.set_tile(self.player, 0, 0)
                self.player.health = self.player.std_health
                self.player.coords = (5, 5)
                self.reset_sprite_groups()
Beispiel #7
0
    def update(self, events):
        '''
        Updates the screen when an event happens 

        @param - list of game events
        '''
        for event in events:
            if not hasattr(event, 'key'):
                continue
            if event.type == KEYDOWN:
                if event.key == K_RETURN:
                    if self.currLine == VictoryScreenLine.Menu:
                        State.push_screen(gameMenuScreen.GameMenuScreen())
                    elif self.currLine == VictoryScreenLine.Exit:
                        sys.exit(0)
                else:
                    super(VictoryScreen, self).interact(event)
Beispiel #8
0
	def update(self, events):
		'''
        Updates the screen when an event happens 

        @param - list of game events
        '''
		for event in events:
			if not hasattr(event, 'key'):
				continue
			if event.type == KEYDOWN:
				if event.key == K_RETURN:
					if self.currLine == LoadGameScreenLine.ReturnToMainMenu:
						State.pop_screen()
						continue
					save_name = self.lines[self.currLine]
					load(USER_SAVES_DIR + save_name)
					State.save_name = save_name
					State.pop_screen()
					State.push_screen(gameScreen.GameScreen(CURRENT_GAME_DIR))
				else:
					super(LoadGameScreen, self).interact(event)