Beispiel #1
0
 def init():
     # Play game background music
     if not sound.background.isPlaying():
         sound.stopAll(600)
         sound.background.play(loops=-1,
                               withVolume=PgEss.config.sound.background,
                               fadetime=3000)
Beispiel #2
0
    def new():
        Grid = screens.game.map.grid.Grid

        # Check if nickname is valid
        if not screens.new_game.options.nickname.text.validateText(): return

        # Unload previous states
        screens.game.unload()

        # reset player
        Player.reset()

        # Set difficulty settings
        Difficulty.set()

        # Set grid to default hero, town and king
        Grid.clear()
        Grid.tiles[0][0].sprites = ['town', 'hero']
        Grid.tiles[7][7].sprites = ['king']

        # Generate random towns
        town_settings = Difficulty.get()
        Grid.randomiseTowns(town_settings['town_number'], town_settings['town_space'])

        # Calculate orb postion
        Orb.setLocation()
        Orb.canSense()

        # Set up store
        Store.setWeapons()

        # Set starting story
        story.in_town.display()

        # Set player stats for game screen
        Player.stats.display('day', screens.game.info.days)
        Player.stats.display('damage', screens.game.info.stats)
        Player.stats.display('defence', screens.game.info.stats)
        Player.stats.display('health', screens.game.info.stats)
        Player.stats.display('elixir', screens.game.info.stats)

        # Reset stats update
        screens.game.info.hero.stats.setText('', withDisplay=False)

        # Load screen
        screens.game.load(withSurfaces=['map', 'info', 'in_town'], refresh=True)

        # Switch to game screen
        screens.changeStack(type='load', screen='game')

        # Play game background music
        sound.stopAll(600)
        sound.game_background.play(loops=-1, withVolume=0.12, fadetime=10000)

        logger.info('Created new playerdata.')
Beispiel #3
0
    def haveEnemy():
        Grid = screens.game.map.grid.Grid

        # Reset
        Enemy.reset()

        # Not attack if hero is in town
        if Grid.heroInTown(): return False

        # Detect enemy present in grid
        for name in Enemy.enemies['list']:
            if name in Grid.tiles[Player.hero.row][Player.hero.column].sprites:
                # Play rat king music
                if name == 'king':
                    sound.stopAll(600)
                    sound.rat_king.play(
                        loops=-1,
                        withVolume=PgEss.config.sound.background + 0.24,
                        fadetime=3000)

                Enemy.load(name)
                # Load attack screen
                Attack.initSurface()
                return True

        # Calculate enemy appearing
        chance_number = randint(1, 100)
        if chance_number > Enemy.enemies['appear_chance']: return False

        # Get new enemy based on chance
        base = 0
        new_enemy = False
        chance_number = randint(1, 100)

        for name in Enemy.enemies['list']:
            if base < chance_number <= Enemy.enemies[name]['chance'] + base:
                Enemy.load(name)
                new_enemy = True

            base += Enemy.enemies[name]['chance']

        # Add enemy to grid
        if new_enemy:
            Grid.tiles[Player.hero.row][Player.hero.column].sprites.insert(
                0, Enemy.name)
            # Show attack screen if there is an enemy
            Attack.initSurface()
            return True

        return False
Beispiel #4
0
    def back():
        # Stop rat king music if its playing
        if sound.rat_king.isPlaying():
            sound.stopAll(600)
            sound.game_background.play(
                loops=-1,
                withVolume=PgEss.config.sound.background,
                fadetime=5000)

        # Return to in open selection screen
        screens.game.attack.unload()
        screens.game.map.load(withItems=['grid'], refresh=True)
        screens.game.info.load(withItems=['stats'], refresh=True)
        screens.game.in_open.load()
        screens.game.display()
Beispiel #5
0
    def game_end(type: str):
        screens.end_game.unload()

        # Stop game music, back to normal background music
        if not sound.background.isPlaying():
            sound.stopAll(200)
            sound.background.play(loops=-1,
                                  withVolume=PgEss.config.sound.background,
                                  fadetime=3000)

        end_game_screen = screens.end_game
        # Check if win screen is the one loaded
        if type == 'win':
            # Save to leaderboard
            end_game_screen.win.leaderboard.rankid = PlayerRank.add()

            # Set player leaderboard on win screen
            end_game_screen.win.leaderboard.postion.setText(str(
                PlayerRank.getPos()),
                                                            withDisplay=False)
            end_game_screen.win.leaderboard.nickname.setText(Player.nickname,
                                                             withDisplay=False)
            end_game_screen.win.leaderboard.days.setText(str(Player.stats.day),
                                                         withDisplay=False)

            # Load the changes
            end_game_screen.win.load(withItems='all', refresh=True)

            # Play win sound effect
            sound.win.play()

        # Check if gameover screen is the one loaded
        elif type == 'gameover':
            # Load the screen changes
            end_game_screen.gameover.load(withItems='all', refresh=True)

            # Play gameover sound effect
            sound.game_over.play()

        screens.changeStack(type='load', screen='end_game')