Beispiel #1
0
    def __init__(self, screen, manager, bg, title, part, partmax, waves):

        self.screen = screen
        self.manager = manager
        self.background = bg
        self.maxWaves = waves
        self.maker = GuiHelper(SW, SH, manager)
        hud_size = (650, 0, 650, 150)
        hud_rect = py.Rect(hud_size)

        hudW = 650
        hudH = 150
        halfw = int(650 / 2)

        # todo: container for hud and rest of ui elements

        self.hud = self.maker.make_panel(SW2, 75, 650, 140, 'HUD')

        part_string = 'Part: ' + str(part) + '/' + str(partmax)

        # left
        self.damage_label = self.maker.make_label(100, 15, 180, 20, '',
                                                  'hud_damage', self.hud)
        self.bps_label = self.maker.make_label(100, 35, 200, 20, '', 'hud_bps',
                                               self.hud)
        self.bspeed_label = self.maker.make_label(100, 55, 200, 20, '',
                                                  'hud_bspeed', self.hud)

        # middle section (stage info)
        self.title_label = self.maker.make_label(halfw - 35, 15, 150, 20,
                                                 title, 'hud_stage', self.hud)
        self.part_label = self.maker.make_label(halfw - 35, 35, 150, 20,
                                                part_string, 'hud_part',
                                                self.hud)
        self.wave_label = self.maker.make_label(halfw - 35, 55, 150, 20, '',
                                                'hud_wave', self.hud)
        self.score_label = self.maker.make_label(halfw - 35, 75, 150, 20, '',
                                                 'hud_part', self.hud)

        # right
        self.life_label = self.maker.make_label(halfw + 110, 15, 150, 20, '',
                                                'hud_life', self.hud)
        self.health_label = self.maker.make_label(halfw + 110, 35, 150, 20, '',
                                                  'hud_health', self.hud)
        self.money_label = self.maker.make_label(halfw + 110, 55, 150, 20, '',
                                                 'hud_money', self.hud)
        self.xp_label = self.maker.make_label(halfw + 110, 85, 75, 20, '',
                                              'hud_xp', self.hud)

        # right right
        self.pause_button = self.maker.make_button(halfw + 230, 45, 70, 50,
                                                   'menu', self.hud)
        self.time_label = self.maker.make_label(halfw + 230, 85, 150, 20, '',
                                                'hud_time', self.hud)
Beispiel #2
0
    def __init__(self, screen, bg, manager):
        self.screen = screen
        self.manager = manager
        self.screen = screen
        self.background = bg
        self.maker = GuiHelper(SW, SH, self.manager)

        self.leave_b = None
        self.player = None
        self.bullet_title = None
        self.current_label = None
        self.b_price = None
        self.stat_title = None
        self.current_label_stat = None
        self.stat_price = None
        self.money_label = None
        self.selected = None
        self.reset_track = None
Beispiel #3
0
    def __init__(self, width, height, manager):
        self.SW = width
        self.SH = height
        self.manager = manager

        # main menu
        self.play_b = None
        self.info_b = None
        self.quit_b = None

        # replay
        self.replay_b = None
        self.quit_replay_b = None

        # settings
        self.movement_selection = None
        self.screen_selection = None
        self.shoot_selection = None
        self.confirm_setting_b = None

        # next level
        self.next_level_b = None
        self.quit_next_level_b = None

        # profile select
        self.save_selection = None
        self.launch_hub_b = None
        self.quit_launcher_b = None

        # player hub
        self.cont_b = None
        self.store_b = None
        self.store2_b = None
        self.setting_b = None
        self.stats_b = None
        self.back_b = None
        self.player_panel = PlayerPanel(self.manager)
        self.pick_b = None
        self.pick_ddm = None

        # gui helper maker
        self.maker = GuiHelper(self.SW, self.SH, self.manager)
        self.SW2 = int(self.SW / 2)
        self.SH2 = int(self.SH / 2)
Beispiel #4
0
class Store:
    def __init__(self, screen, bg, manager):
        self.screen = screen
        self.manager = manager
        self.screen = screen
        self.background = bg
        self.maker = GuiHelper(SW, SH, self.manager)

        self.leave_b = None
        self.player = None
        self.bullet_title = None
        self.current_label = None
        self.b_price = None
        self.stat_title = None
        self.current_label_stat = None
        self.stat_price = None
        self.money_label = None
        self.selected = None
        self.reset_track = None

    def run(self, player):

        time_delta = 0
        runner = True
        clock = py.time.Clock()

        store_panel = self.maker.make_panel(SW2, SH2, 650, 800, 'store_panel')

        self.player = player
        self.selected = player.current_track

        # title and money
        self.maker.make_label(300, 25, 70, 20, 'Store', 'store_title',
                              store_panel)

        self.money_label = self.maker.make_label(
            150, 50, 150, 20, 'Money: ' + str(self.player.money),
            'store_pmoney', store_panel)
        self.point_label = self.maker.make_label(
            400, 50, 150, 20, 'Points: ' + str(self.player.player_points),
            'store_pmoney', store_panel)

        # store values
        buff_mutipliers = [1.15, 1.25, 1.5, 1.75, 2, 1.5, 2, 4, 8]
        game_multipliers = [1.05, 1.10, 1.20, 1.4, 1.7, 2, 2.5, 3.5, 5]

        self.leave_b = self.maker.make_button(300, 800, 100, 60, 'back', None)

        # ----------------------------------------- jet panel ----------------------------------------------------------
        string = []
        if self.player.current_track == 0:
            string = ['speed', 'damage']
        else:
            string = ['damage', 'speed']

        self.track_selector = self.maker.make_contained_drop_down_menu(
            100, 295, 100, 40, 'pick_ddm', string, store_panel)

        self.reset_track = self.maker.make_button(500, 295, 120, 40,
                                                  'reset track', store_panel)

        self.jet_title = self.maker.make_label(
            300, 110, 220, 20,
            'Jet Upgrades: ' + self.track_selector.selected_option + ' track',
            'store_buff', store_panel)
        jetpanel = self.maker.make_contained_panel(310, 200, 600, 140,
                                                   'jet_panel', store_panel)

        # bullet
        bullet_panel = self.maker.make_contained_panel(300, 30, 600, 70,
                                                       'health_panel',
                                                       jetpanel)

        self.bullet_title = self.maker.make_label(60, 35, 100, 20, 'Bullet ',
                                                  'store_ht', bullet_panel)
        self.current_label = self.maker.make_label(250, 35, 200, 20, '',
                                                   'store_hcl', bullet_panel)
        self.b_price = self.maker.make_label(430, 35, 100, 20, 'Price: ',
                                             'store_hprice', bullet_panel)

        bullet_buy_b = self.maker.make_button(550, 35, 50, 50, 'Buy',
                                              bullet_panel)

        # stat
        stat_panel = self.maker.make_contained_panel(300, 100, 600, 70,
                                                     'damage_panel', jetpanel)

        self.stat_title = self.maker.make_label(60, 35, 100, 20, 'Stats ',
                                                'store_ht', stat_panel)
        self.current_label_stat = self.maker.make_label(
            250, 35, 200, 20, '', 'store_dcl', stat_panel)
        self.stat_price = self.maker.make_label(430, 35, 100, 20, 'Price: ',
                                                'store_dprice', stat_panel)

        stat_buy_b = self.maker.make_button(550, 35, 50, 50, 'Buy', stat_panel)

        #  -------------------------------------------- buff panel ----------------------------------------------------
        self.maker.make_label(300, 340, 110, 20, 'Buff Upgrades', 'store_buff',
                              store_panel)
        buffpanel = self.maker.make_contained_panel(310, 430, 600, 140,
                                                    'buff_panel', store_panel)

        # offensive buffs
        offensive_panel = self.maker.make_contained_panel(
            300, 30, 600, 70, 'ob_panel', buffpanel)
        self.offensive_title = self.maker.make_label(
            60, 10, 100, 20, 'Offense ' + str(self.player.store[4]) + '/10',
            'store_obt', offensive_panel)
        self.dam_buff = self.maker.make_label(
            50, 30, 90, 20,
            'dam: ' + str(5 * self.player.offensive_buff_multiplier),
            'store_obb', offensive_panel)
        self.bps_buff = self.maker.make_label(
            50, 50, 90, 20,
            'bps: ' + str(300 * self.player.offensive_buff_multiplier),
            'store_obbm', offensive_panel)
        self.current_label_ob = self.maker.make_label(
            250, 35, 250, 20,
            'increase to ' + str(buff_mutipliers[self.player.store[4]]) + '%',
            'store_obcl', offensive_panel)
        self.ob_price = self.maker.make_label(
            430, 35, 100, 20, 'Price: ' + str((self.player.store[4] + 1) * 40),
            'store_obprice', offensive_panel)
        ob_buy_b = self.maker.make_button(550, 35, 50, 50, 'Buy',
                                          offensive_panel)

        # support buffs
        support_panel = self.maker.make_contained_panel(
            300, 100, 600, 70, 'sp_panel', buffpanel)
        self.support_title = self.maker.make_label(
            60, 10, 100, 20, 'Support ' + str(self.player.store[5]) + '/10',
            'store_spbt', support_panel)
        self.health_buff = self.maker.make_label(
            50, 30, 90, 20,
            'hp: ' + str(15 * self.player.offensive_buff_multiplier),
            'store_spb', support_panel)
        self.pspeed_buff = self.maker.make_label(
            60, 50, 110, 20,
            'p speed: ' + str(5 * self.player.offensive_buff_multiplier),
            'store_spbm', support_panel)
        self.current_label_sp = self.maker.make_label(
            250, 35, 250, 20, 'increase to:  ' +
            str(buff_mutipliers[self.player.store[5]]) + '%', 'store_spcl',
            support_panel)
        self.sp_price = self.maker.make_label(
            430, 35, 100, 20, 'Price: ' + str((self.player.store[5] + 1) * 40),
            'store_spprice', support_panel)
        sp_buy_b = self.maker.make_button(550, 35, 50, 50, 'Buy',
                                          support_panel)

        #  -------------------------------------------- game panel ----------------------------------------------------
        self.maker.make_label(300, 550, 120, 20, 'Game Upgrades', 'store_game',
                              store_panel)
        gamepanel = self.maker.make_contained_panel(310, 640, 600, 140,
                                                    'game_panel', store_panel)

        # money
        money_panel = self.maker.make_contained_panel(300, 30, 600, 70,
                                                      'mon_panel', gamepanel)
        self.money_title = self.maker.make_label(
            60, 10, 100, 20, 'Money ' + str(self.player.store[6]) + '/10',
            'store_mont', money_panel)
        self.money_cm = self.maker.make_label(
            50, 30, 90, 20,
            'current: ' + str(self.player.money_gain_multiplier), 'store_monb',
            money_panel)

        self.current_label_mon = self.maker.make_label(
            250, 35, 250, 20, 'increase to:  ' +
            str(game_multipliers[self.player.store[6]]) + '%', 'store_moncl',
            money_panel)
        self.mon_price = self.maker.make_label(
            430, 35, 100, 20, 'Price: ' + str((self.player.store[6] + 1) * 50),
            'store_monprice', money_panel)
        mon_buy_b = self.maker.make_button(550, 35, 50, 50, 'Buy', money_panel)

        # xp
        xp_panel = self.maker.make_contained_panel(300, 100, 600, 70,
                                                   'xp_panel', gamepanel)
        self.xp_title = self.maker.make_label(
            60, 10, 100, 20, 'XP ' + str(self.player.store[7]) + '/10',
            'store_xpbt', xp_panel)
        self.xp_cm = self.maker.make_label(
            50, 30, 90, 20, 'current: ' + str(self.player.xp_gain_multiplier),
            'store_xpb', xp_panel)
        self.current_label_xp = self.maker.make_label(
            250, 35, 250, 20, 'increase to:  ' +
            str(game_multipliers[self.player.store[7]]) + '%', 'store_xpcl',
            xp_panel)
        self.xp_price = self.maker.make_label(
            430, 35, 100, 20, 'Price: ' + str((self.player.store[7] + 1) * 50),
            'store_xpprice', xp_panel)
        xp_buy_b = self.maker.make_button(550, 35, 50, 50, 'Buy', xp_panel)

        # self.player.money = 1000

        while runner:

            time_delta = clock.tick(60)

            for event in py.event.get():
                if event.type == py.QUIT:
                    runner = False

                elif event.type == py.KEYDOWN:
                    # ESC
                    if event.key == K_ESCAPE:
                        runner = False

                elif event.type == py.USEREVENT:
                    if event.user_type == gui.UI_BUTTON_PRESSED:

                        # go back button
                        if event.ui_element == self.leave_b:
                            print('exited')
                            runner = False

                        elif event.ui_element == ob_buy_b:
                            if self.player.money >= (self.player.store[4] +
                                                     1) * 40:
                                self.buy(4)

                        elif event.ui_element == sp_buy_b:
                            if self.player.money >= (self.player.store[5] +
                                                     1) * 40:
                                self.buy(5)

                        elif event.ui_element == xp_buy_b:
                            if self.player.money >= (self.player.store[7] +
                                                     1) * 50:
                                self.buy(7)

                        elif event.ui_element == mon_buy_b:
                            if self.player.money >= (self.player.store[6] +
                                                     1) * 50:
                                self.buy(6)

                        elif event.ui_element == bullet_buy_b:
                            if self.player.player_points >= self.player.point_store[
                                    self.selected][0] + 1:
                                self.buy(0)

                        elif event.ui_element == stat_buy_b:
                            if self.player.player_points >= self.player.point_store[
                                    self.selected][1] + 1:
                                self.buy(1)

                        elif event.ui_element == self.reset_track:
                            self.player.player_points += self.player.point_store[
                                self.selected][2]
                            self.player.point_store[self.selected] = [0, 0, 0]
                            self.player.set_track()
                            print('reset ' +
                                  self.track_selector.selected_option +
                                  ' track')

                self.manager.process_events(event)

            self.screen.blit(self.background, (0, 0))

            self.update()

            self.manager.update(time_delta)
            self.manager.draw_ui(self.screen)

            py.display.update()

        return self.player

    def update(self):
        buff_mutipliers = [1.15, 1.25, 1.5, 1.75, 2, 1.5, 2, 4, 8]
        game_multipliers = [1.05, 1.10, 1.20, 1.4, 1.7, 2, 2.5, 3.5, 5]

        self.point_label.set_text('Points: ' + str(self.player.player_points))

        strings = [[
            'upgrade size', 'piercing bullets(2)', 'emp 30%', 'emp 60%',
            'piercing bullets(4)', 'maxed'
        ], ['bps', 'speed', 'bps', 'speed', 'bps', 'maxed']]

        # speed track else damage track
        if self.track_selector.selected_option == 'speed':
            self.selected = 0
            self.player.current_track = 0
            self.player.set_track()
            bullet = 'x' + str(self.player.point_store[0][0] + 2)
            self.current_label.set_text(bullet)
            self.current_label_stat.set_text(
                strings[1][self.player.point_store[0][1]])
        else:
            self.selected = 1
            self.player.current_track = 1
            self.player.set_track()
            self.current_label.set_text(
                strings[0][self.player.point_store[1][0]])
            self.current_label_stat.set_text('damage')

        self.jet_title.set_text('Jet Upgrades: ' +
                                self.track_selector.selected_option + ' track')

        # bullet
        self.bullet_title.set_text(
            'Bullet ' + str(self.player.point_store[self.selected][0]) + '/5')
        self.b_price.set_text(
            str('Points: ' +
                str(self.player.point_store[self.selected][0] + 1)))

        # stat
        self.stat_title.set_text(
            'Stats ' + str(self.player.point_store[self.selected][1]) + '/5')
        self.stat_price.set_text(
            str('Points: ' +
                str(self.player.point_store[self.selected][1] + 1)))

        self.money_label.set_text('Money: %.3f' % self.player.money)

        self.offensive_title.set_text('Offense ' + str(self.player.store[4]) +
                                      '/10')
        self.dam_buff.set_text('dam: %.2f' % 5 *
                               self.player.offensive_buff_multiplier)
        self.bps_buff.set_text('bps: %.2f' % 300 *
                               self.player.offensive_buff_multiplier)
        self.current_label_ob.set_text(
            'increase to: %.2f%s' %
            (buff_mutipliers[self.player.store[4]], '%'))
        self.ob_price.set_text('Price: ' +
                               str((self.player.store[4] + 1) * 40))

        self.support_title.set_text('Support ' + str(self.player.store[5]) +
                                    '/10')
        self.health_buff.set_text('hp: %.2f' % 15 *
                                  self.player.offensive_buff_multiplier)
        self.pspeed_buff.set_text('p speed: %.2f' % 5 *
                                  self.player.offensive_buff_multiplier)
        self.current_label_sp.set_text(
            'increase to: %.2f%s' %
            (buff_mutipliers[self.player.store[5]], '%'))
        self.sp_price.set_text('Price: ' +
                               str((self.player.store[5] + 1) * 40))

        self.money_title.set_text('Money ' + str(self.player.store[6]) + '/10')
        self.money_cm.set_text('current: %.2f' %
                               self.player.money_gain_multiplier)
        self.current_label_mon.set_text(
            'increase to: %.2f%s' %
            (game_multipliers[self.player.store[6]], '%'))
        self.mon_price.set_text('Price: ' +
                                str((self.player.store[6] + 1) * 50))

        self.xp_title.set_text('XP ' + str(self.player.store[7]) + '/10')
        self.xp_cm.set_text('current: ' + str(self.player.xp_gain_multiplier))
        self.current_label_xp.set_text(
            'increase to: %.2f%s' %
            (game_multipliers[self.player.store[7]], '%'))
        self.xp_price.set_text('Price: ' +
                               str((self.player.store[7] + 1) * 50))

    def buy(self, pos):

        if pos in range(0, 2):
            if self.player.point_store[self.selected][pos] >= 5:
                pass
            else:
                # take player points, give to the player, and increase the points spent in that track, and set track
                self.player.player_points -= self.player.point_store[
                    self.selected][pos] + 1
                self.player.point_store[self.selected][pos] += 1
                self.player.point_store[self.selected][
                    2] += self.player.point_store[self.selected][pos] + 1
                # debug heck if player goes below 0, fixed now tho
                if self.player.player_points < 0:
                    print('heck')
                    self.player.player_points = 0
                self.player.set_track()

        else:
            if pos in range(4, 6):

                buff_mutipliers = [1.15, 1.25, 1.5, 1.75, 2, 1.5, 2, 4, 8]

                self.player.money -= (self.player.store[pos] + 1) * 40

                if pos == 4:
                    self.player.offensive_buff_multiplier = buff_mutipliers[
                        self.player.store[pos]]
                else:
                    self.player.support_buff_multiplier = buff_mutipliers[
                        self.player.store[pos]]

            else:

                game_multipliers = [1.05, 1.10, 1.20, 1.4, 1.7, 2, 2.5, 3.5, 5]

                self.player.money -= (self.player.store[pos] + 1) * 50

                if pos == 6:
                    self.player.money_gain_multiplier = game_multipliers[
                        self.player.store[pos]]
                else:
                    self.player.xp_gain_multiplier = game_multipliers[
                        self.player.store[pos]]

            self.player.store[pos] += 1
            print(str(pos))
Beispiel #5
0
 def __init__(self, manager):
     self.manager = manager
     self.player = []
     self.stageinfo = []
     self.maker = GuiHelper(SW2, SW, self.manager)
Beispiel #6
0
class PlayerPanel:
    def __init__(self, manager):
        self.manager = manager
        self.player = []
        self.stageinfo = []
        self.maker = GuiHelper(SW2, SW, self.manager)

        # todo: container for ui elements

    def setPlayer(self, db):
        self.playerpanel = self.maker.make_panel(SW2 - 100, SH2, 430, 300, 'playerpanel')

        self.player = db['player']
        self.stageinfo = db['stage']
        self.times = db['times']

        height = 30

        self.stage_label = gui.elements.UILabel(relative_rect=py.Rect((30, height), (170, 20)),
                                                text=('Stage: ' + str(self.stageinfo[0] + 1) + ' Part: ' +
                                                      str(self.stageinfo[1] + 1)), manager=self.manager,
                                                container=self.playerpanel, object_id='stageL')

        lives_label = gui.elements.UILabel(relative_rect=py.Rect((30, height * 2), (170, 20)),
                                           text=('lives: ' + str(self.player['lives']) + '/' +
                                                 str(self.player['base_lives'])),
                                           manager=self.manager, container=self.playerpanel, object_id='livesL')

        hp_label = gui.elements.UILabel(relative_rect=py.Rect((30, height * 3), (170, 20)),
                                        text=('health: %.2f/%d' % (self.player['health'],
                                                                   self.player['maxHealth'])), object_id='hpL',
                                        manager=self.manager, container=self.playerpanel)

        dam_label = gui.elements.UILabel(relative_rect=py.Rect((30, height * 4), (170, 20)),
                                         text=('damage: %.2f/%d' % (self.player['damage'],
                                                                    self.player['damage_max'])), object_id='damL',
                                         manager=self.manager, container=self.playerpanel)

        pspeed_label = gui.elements.UILabel(relative_rect=py.Rect((30, height * 5), (170, 20)),
                                            text=('player speed: %.2f/%d' % (self.player['pspeed'],
                                                                             self.player['pspeed_max'])),
                                            object_id='pspeedL',
                                            manager=self.manager, container=self.playerpanel)

        bspeed_label = gui.elements.UILabel(relative_rect=py.Rect((30, height * 6), (170, 20)),
                                            text=('bullet speed: %.2f' % self.player['bspeed']), object_id='bspeedL',
                                            manager=self.manager, container=self.playerpanel)

        bps_label = gui.elements.UILabel(relative_rect=py.Rect((30, height * 7), (170, 20)),
                                         text=('bps: ' + str(self.player['bps']) + '/' +
                                               str(self.player['bps_max'])), manager=self.manager, object_id='bpsL',
                                         container=self.playerpanel)

        Level_label = gui.elements.UILabel(relative_rect=py.Rect((200, height), (170, 20)),
                                           text=("Player Level: " + str(self.player['level'])), manager=self.manager,
                                           container=self.playerpanel, object_id='stageL')

        xp_label = gui.elements.UILabel(relative_rect=py.Rect((200, height * 2), (170, 20)),
                                        text=("xp: %.2f" % self.player['xp']), manager=self.manager,
                                        container=self.playerpanel, object_id='stageL')

        score_label = gui.elements.UILabel(relative_rect=py.Rect((200, height * 3), (170, 20)),
                                           text=("score: " + str(self.player['score'])), manager=self.manager,
                                           container=self.playerpanel, object_id='stageL')

        money_label = gui.elements.UILabel(relative_rect=py.Rect((200, height * 4), (170, 20)),
                                           text=("money: %.2f" % self.player['money']), manager=self.manager,
                                           container=self.playerpanel, object_id='stageL')

        unlock_points_label = self.maker.make_label(285, (height * 5) + 10, 170, 20,
                                                    ('unlock points: ' + str(self.player['player_points'])),
                                                    'stageL',
                                                    self.playerpanel)
        string = ''

        if self.player['current_track'] == 0:
            string = 'speed'
        else:
            string = 'damage'

        self.maker.make_label(285, (height * 6) + 10, 170, 30, 'track: ' + string, 'playerpoints', self.playerpanel)
Beispiel #7
0
class HUD:
    def __init__(self, screen, manager, bg, title, part, partmax, waves):

        self.screen = screen
        self.manager = manager
        self.background = bg
        self.maxWaves = waves
        self.maker = GuiHelper(SW, SH, manager)
        hud_size = (650, 0, 650, 150)
        hud_rect = py.Rect(hud_size)

        hudW = 650
        hudH = 150
        halfw = int(650 / 2)

        # todo: container for hud and rest of ui elements

        self.hud = self.maker.make_panel(SW2, 75, 650, 140, 'HUD')

        part_string = 'Part: ' + str(part) + '/' + str(partmax)

        # left
        self.damage_label = self.maker.make_label(100, 15, 180, 20, '',
                                                  'hud_damage', self.hud)
        self.bps_label = self.maker.make_label(100, 35, 200, 20, '', 'hud_bps',
                                               self.hud)
        self.bspeed_label = self.maker.make_label(100, 55, 200, 20, '',
                                                  'hud_bspeed', self.hud)

        # middle section (stage info)
        self.title_label = self.maker.make_label(halfw - 35, 15, 150, 20,
                                                 title, 'hud_stage', self.hud)
        self.part_label = self.maker.make_label(halfw - 35, 35, 150, 20,
                                                part_string, 'hud_part',
                                                self.hud)
        self.wave_label = self.maker.make_label(halfw - 35, 55, 150, 20, '',
                                                'hud_wave', self.hud)
        self.score_label = self.maker.make_label(halfw - 35, 75, 150, 20, '',
                                                 'hud_part', self.hud)

        # right
        self.life_label = self.maker.make_label(halfw + 110, 15, 150, 20, '',
                                                'hud_life', self.hud)
        self.health_label = self.maker.make_label(halfw + 110, 35, 150, 20, '',
                                                  'hud_health', self.hud)
        self.money_label = self.maker.make_label(halfw + 110, 55, 150, 20, '',
                                                 'hud_money', self.hud)
        self.xp_label = self.maker.make_label(halfw + 110, 85, 75, 20, '',
                                              'hud_xp', self.hud)

        # right right
        self.pause_button = self.maker.make_button(halfw + 230, 45, 70, 50,
                                                   'menu', self.hud)
        self.time_label = self.maker.make_label(halfw + 230, 85, 150, 20, '',
                                                'hud_time', self.hud)

    def update(self, wave, score, score2, health, health2, lives, lives2,
               damage, damage2, bps, bps2, bspeed, money, xp, time):
        self.wave_label.set_text(
            ('wave: ' + str(wave) + '/' + str(self.maxWaves)))
        self.score_label.set_text(('Score: ' + str(score) + '/' + str(score2)))
        self.health_label.set_text('Health: %.2f/%d' % (health, health2))
        self.life_label.set_text(('Lives: ' + str(lives)) + '/' + str(lives2))
        self.damage_label.set_text('damage: %.2f/%d' % (damage, damage2))
        self.bps_label.set_text(
            ('bullets every: ' + str(bps) + 'ms' + '/' + str(bps2) + 'ms'))
        self.bspeed_label.set_text('bullet speed: %.2f' % bspeed)
        self.money_label.set_text('Money: $%.2f' % money)
        self.time_label.set_text('Time: ' + str(time) + 's')
        self.xp_label.set_text('XP: %.2f' % xp)

    # pause game with button or by pressing p
    def pause(self):
        pause_panel = self.maker.make_panel(SW2, SH2, 200, 200, 'pause_panel')
        cont_button = self.maker.make_button(90, 60, 80, 50, 'continue',
                                             pause_panel)
        exit_button = self.maker.make_button(90, 110, 80, 50, 'exit',
                                             pause_panel)

        exit = False
        runner = True
        clock = py.time.Clock()

        while (runner):

            time_delta = clock.tick(60)

            for event in py.event.get():
                if event.type == py.QUIT:
                    runner = False

                if event.type == py.KEYDOWN:
                    if event.key == K_p:
                        runner = False

                if event.type == py.USEREVENT:
                    if event.user_type == gui.UI_BUTTON_PRESSED:
                        if event.ui_element == self.pause_button or event.ui_element == cont_button:
                            runner = False

                        elif event.ui_element == exit_button:
                            exit = True
                            runner = False

                self.manager.process_events(event)

            self.screen.blit(self.background, (0, 0))

            self.manager.update(time_delta)
            self.manager.draw_ui(self.screen)

            py.display.update()

        cont_button.kill()
        exit_button.kill()
        pause_panel.kill()
        return exit
Beispiel #8
0
class GameMenu:
    def __init__(self, width, height, manager):
        self.SW = width
        self.SH = height
        self.manager = manager

        # main menu
        self.play_b = None
        self.info_b = None
        self.quit_b = None

        # replay
        self.replay_b = None
        self.quit_replay_b = None

        # settings
        self.movement_selection = None
        self.screen_selection = None
        self.shoot_selection = None
        self.confirm_setting_b = None

        # next level
        self.next_level_b = None
        self.quit_next_level_b = None

        # profile select
        self.save_selection = None
        self.launch_hub_b = None
        self.quit_launcher_b = None

        # player hub
        self.cont_b = None
        self.store_b = None
        self.store2_b = None
        self.setting_b = None
        self.stats_b = None
        self.back_b = None
        self.player_panel = PlayerPanel(self.manager)
        self.pick_b = None
        self.pick_ddm = None

        # gui helper maker
        self.maker = GuiHelper(self.SW, self.SH, self.manager)
        self.SW2 = int(self.SW / 2)
        self.SH2 = int(self.SH / 2)

    def main_menu(self):
        # buttonS2 = (70, 60)

        title = self.maker.make_label(self.SW2, 200, 1000, 110, 'WORLD FLYING SHOOTER', 'maintitle', None)

        button_s = (150, 60)
        height = self.SH2 + 20

        self.play_b = self.maker.make_button(self.SW2, height, button_s[0], button_s[1], 'Play', None)

        self.info_b = self.maker.make_button(self.SW2, height + 70, button_s[0], button_s[1], 'How to Play', None)

        self.quit_b = self.maker.make_button(self.SW2, height + (70 * 2), button_s[0], button_s[1], 'Quit', None)

    def replay_menu(self, string):
        title = self.maker.make_label(self.SW2, self.SH2 - 90, 260, 90, string, 'replay', None)

        button_s = (150, 60)

        self.replay_b = self.maker.make_button(self.SW2, self.SH2 + 100, button_s[0], button_s[1], 'play again',
                                               None)

        self.quit_replay_b = self.maker.make_button(self.SW2, self.SH2 + 200, button_s[0], button_s[1],
                                                    'back to hub',
                                                    None)

    def settings_menu(self):
        button_s = (150, 60)

        self.movement_selection = self.maker.make_selection_list(self.SW2, self.SH2 - 70, 200, 70,
                                                                 ['arrow keys', "wads keys", "mouse"], 'movementS',
                                                                 None)

        self.screen_selection = self.maker.make_selection_list(self.SW2, self.SH2 + 20, 200, 70,
                                                               ["fullscreen", "hardware accelerated",
                                                                "windowed"], 'screenS', None)

        self.shoot_selection = self.maker.make_selection_list(self.SW2, self.SH2 + 110, 200, 70,
                                                              ['auto', "space", "mouse"], 'shootS', None)

        self.confirm_setting_b = self.maker.make_button(self.SW2, self.SH2 + 300, button_s[0], button_s[1], 'exit'
                                                        , None)

    def next_level(self, string):
        label_size = (240, 90)
        button_s = (150, 60)

        title = self.maker.make_label(self.SW2, self.SH2 - 90, label_size[0], label_size[1], string, 'nextlevel',
                                      None)

        self.next_level_b = self.maker.make_button(self.SW2, self.SH2 + 100, button_s[0], button_s[1], string
                                                   , None)

        self.quit_next_level_b = self.maker.make_button(self.SW2, self.SH2 + 200, button_s[0], button_s[1],
                                                        'back to hub'
                                                        , None)

    # pick between file saves
    def load_menu(self, names):
        todo = ''
        # labelSize = (0, 0, 150, 40)
        # label_rect = pygame.Rect(labelSize)
        #
        # label_rect.bottomright = (int(- self.SW / 2) + 20, -700)
        # label1 = pygame_gui.elements.UILabel(relative_rect=label_rect, text='Pick a save',
        #                                      manager=self.manager, anchors=anchd, object_id='saveFL')
        #
        # shootDSize = (0, 0, 200, 150)
        # dD_rect = pygame.Rect(shootDSize)
        #
        # dD_rect.bottomright = (int(- self.SW / 2 + 50), -520)
        # self.savelist_selection = pygame_gui.elements.UISelectionList(dD_rect, names, object_id='loadS',
        #                                                         manager =self.manager, allow_multi_select=False,
        #                                                               anchors=anchd)
        #
        # buttonSize = (0, 0, 150, 60)
        # button_layout_rect = pygame.Rect(buttonSize)
        #
        # button_layout_rect.bottomright = (int(-self.SW / 2) + 20, -400)
        # self.loadConfirm_button = pygame_gui.elements.UIButton(relative_rect=button_layout_rect,
        #                                             text='Confirm', manager=self.manager,
        #                                             anchors=anchd)

    # save menu
    def save_menu(self, names):
        todo = ''

        # labelSize = (0, 0, 150, 40)
        # label_rect = pygame.Rect(labelSize)
        # labesize2 = (0,0,210,40)
        #
        # label_rect.bottomright = (int(- self.SW / 2) + 25, -700)
        # label1 = pygame_gui.elements.UILabel(relative_rect=label_rect, text='Pick a save',
        #                                     manager=self.manager, anchors=anchd, object_id='saveFL')
        #
        # shootDSize = (0, 0, 200, 150)
        # dD_rect = pygame.Rect(shootDSize)
        #
        # dD_rect.bottomright = (int(- self.SW / 2 + 50), -500)
        # self.savelist2_selection = pygame_gui.elements.UISelectionList(dD_rect, names, object_id= 'saveS',
        #                                                         manager= self.manager, allow_multi_select=False,
        #                                                                anchors=anchd)
        #
        # label_rect = pygame.Rect(labesize2)
        # label_rect.bottomright = (int(- self.SW / 2 + 60), -400)
        # label2 = pygame_gui.elements.UILabel(relative_rect=label_rect, text='Or new save',
        #                                      manager=self.manager, anchors=anchd, object_id='saveFL2')
        #
        # buttonSize = (0, 0, 150, 60)
        # button_layout_rect = pygame.Rect(buttonSize)
        #
        # button_layout_rect.bottomright = (int(-self.SW / 2) - 100, -170)
        # self.saveConfirm_button = pygame_gui.elements.UIButton(relative_rect=button_layout_rect,
        #                                             text='Confirm', manager=self.manager,
        #                                             anchors=anchd)
        #
        # button_layout_rect.bottomright = (int(-self.SW / 2) + 100, -170)
        # self.cancel_button = pygame_gui.elements.UIButton(relative_rect=button_layout_rect,
        #                                                        text='Cancel', manager=self.manager,
        #                                                        anchors=anchd)

    # description menu TODO
    def info_menu(self):
        todo = ''
        # labelSize = (0, 0, 500, 120)
        # label_rect = pygame.Rect(labelSize)
        #
        # label_rect.bottomright = (int(- self.SW / 2 + 200), -600)
        # title = pygame_gui.elements.UILabel(relative_rect=label_rect, text='no exit',
        #                                     manager=self.manager, anchors=anchd)

    # get player save or make a new one
    def launch_menu(self, names):
        label1 = self.maker.make_label(self.SW2, self.SH2 - 170, 210, 40, 'Load a Save', 'l1', None)

        self.save_selection = self.maker.make_selection_list(self.SW2, self.SH2, 200, 150, names, 'saveS', None)

        label2 = self.maker.make_label(self.SW2, self.SH2 + 120, 210, 40, 'Or New Profile', 'l2', None)

        self.launch_hub_b = self.maker.make_button(self.SW2 + 80, self.SH2 + 300, 150, 60, 'Go', None)
        self.quit_launcher_b = self.maker.make_button(self.SW2 - 80, self.SH2 + 300, 150, 60, 'Back', None)

    # player hub
    def player_hub(self, player_save, stages):
        # menu buttons
        self.cont_b = self.maker.make_button(400, 330, 150, 60, 'continue', None)
        self.pick_b = self.maker.make_button(350, 400, 50, 60, 'Go', None)
        self.pick_ddm = self.maker.make_drop_down_menu(425, 400, 100, 60, 'pick_ddm', stages)
        self.store_b = self.maker.make_button(400, 470, 150, 60, 'store', None)
        self.stats_b = self.maker.make_button(400, 610, 150, 60, 'stats', None)
        self.setting_b = self.maker.make_button(400, 680, 150, 60, 'settings', None)
        self.back_b = self.maker.make_button(400, 750, 150, 60, 'save and exit', None)

        # player info panel
        self.player_panel.setPlayer(player_save)
        #  ====================================== player name panel ==============================================
        name_panel = self.maker.make_panel(self.SW2 - 100, 100, 400, 180, 'namepanel')

        # title
        string = "Welcome Back " + str(player_save['name'])
        player_name = self.maker.make_label(200, 30, 300, 30, string, 'playername', name_panel)

        #  --------------------------------------------- times -----------------------------------------------------
        times = player_save['times']
        string = 'Created: ' + str(times[0])
        dob_label = self.maker.make_label(200, 60, 260, 20, string, 'dobL', name_panel)

        string = 'Last played: ' + str(times[1])
        last_save_label = self.maker.make_label(200, 90, 260, 20, string, 'time2L', name_panel)

        player = player_save['player']
        total_time = self.maker.make_label(200, 120, 260, 20, ('total game time: ' + str(player['time']) + 's'),
                                                'gametime', name_panel)