예제 #1
0
class MainGameScene(Scene):
    def __init__(self):
        self.db = Database()
        self.db['points'] = 0
        self.db['points_per_click'] = 1
        self.db['speed'] = 10
        super(MainGameScene, self).__init__()
        self.background = Background((0, 123, 228))
        self.rails = MovingRail()
        self.label = TextLabel("Points: {}".format(self.db['points']),
                               os.path.join("Resources",
                                            Database()['font']), 16, (50, 18))
        self.train = Vehicle()
        self.train_rect = self.train.get_rect()
        self.button = Button(60, 200, 32, "Shop", (100, 100))
        self.button_rect = self.button.get_rect()
        print(self.train_rect)

    def render(self, screen):
        self.background.render(screen)
        self.rails.render(screen)
        self.label.render(screen)
        self.train.render(screen)
        self.button.render(screen)

    def update(self, delta_time: float):
        self.rails.update(delta_time)
        self.label.update_text("Points: {}".format(self.db['points']))

    def handle_event(self, event: pygame.event):
        if event.type == pygame.MOUSEBUTTONDOWN:
            if self.train_rect.collidepoint(event.pos):
                self.db['points'] += self.db['points_per_click']
            elif self.button_rect.collidepoint(event.pos):
                Director().set_scene(ShopScene())
예제 #2
0
 def __init__(self):
     self.db = Database()
     super().__init__()
     self.background = Background((0, 123, 228))
     self.button = Button(60,
                          200,
                          32,
                          "Shop", (100, 100),
                          color=(144, 191, 51))
     self.button_rect = self.button.get_rect()
     self.label = TextLabel("Points: {}".format(self.db['points']),
                            "Resources/F77-Minecraft.ttf", 16, (50, 18))
     self.ten_km_up = Button(60,
                             350,
                             24,
                             "+10km/h (50 pts)", (200, 370),
                             color=(144, 191, 51))
     self.hundred_km_up = Button(60,
                                 350,
                                 24,
                                 "+100km/h (300 pts)", (200, 280),
                                 color=(144, 191, 51))
     self.five_hundred_km_up = Button(60,
                                      350,
                                      24,
                                      "+500km/h (1000 pts)", (200, 190),
                                      color=(144, 191, 51))
     self.double_click_points = Button(60,
                                       350,
                                       24,
                                       "2X pts. (200 pts)", (600, 370),
                                       color=(144, 191, 51))
예제 #3
0
파일: Menu.py 프로젝트: Azimusss/Snake
 def __init__(self):
     pygame.display.set_mode((WIN_WIDHT, WIN_HEIGH))  # создание окна
     self.start_b = Button(('button_on.png', 'button_hover.png', 'button_click.png'),
                           path=BUTTONS_PATH, pos=(410, 224), text='Start', function=self.start_game)
     self.top_b = Button(('button_on.png', 'button_hover.png', 'button_click.png'),
                           path=BUTTONS_PATH, pos=(410, 287), text='Top Records', function=self.start_top)
     # self.setting_b = Button(('button_on.png', 'button_hover.png', 'button_click.png'),
     #                       path=BUTTONS_PATH, pos=(410, 350), text='Setting', function=None)
     self.exit_b = Button(('button_on.png', 'button_hover.png', 'button_click.png'),
                           path=BUTTONS_PATH, pos=(410, 350), text='Exit', function=self.close)
     self.done = True
예제 #4
0
def generateButtons():
    buttons = []
    buttons.append(
        Button("Choose Pathfinder Button", 100, 10, 270, 80,
               "Choose Pathfinder", 40, WIN))
    buttons.append(Button("Reset Button", 1170, 10, 100, 35, "Reset", 25, WIN))
    buttons.append(Button("Run Button", 1290, 10, 100, 35, "Run", 25, WIN))
    buttons.append(Button("Stop Button", 1290, 55, 100, 35, "Stop", 25, WIN))
    buttons.append(
        Button("Resume Button", 1170, 55, 100, 35, "Resume", 25, WIN, False))
    return buttons
예제 #5
0
파일: Menu.py 프로젝트: kotland/Snow
 def __init__(self, num_snows_scroll=50, background=BACKGROUNG_IMG, wind_power=50):
     pygame.init()
     self.num_snows_scroll = num_snows_scroll
     self.screen = pygame.display.set_mode((500, 500))
     self.btn_start = Button(pos=(150, 150), image_names=('button_on.png', 'button_hover.png', 'button_click.png'),
                             path=BUTTON_IMAGE_PATH, function=self.on_btn_start, text='Start! ', w=200)
     self.btn_settings = Button(pos=(150, 205),
                                image_names=('button_on.png', 'button_hover.png', 'button_click.png'),
                                path=BUTTON_IMAGE_PATH, function=self.on_btn_settings, text='Settings ', w=200)
     self.btn_exit = Button(pos=(150, 260), image_names=('button_on.png', 'button_hover.png', 'button_click.png'),
                            path=BUTTON_IMAGE_PATH, function=self.on_btn_exit, text='Exit ', w=200)
     self.work = True
     self.background = background
     self.background_image = pygame.transform.scale(load_image(self.background, 0, IMAGE_PATH), PLATFORM)
     self.wind_power = wind_power
예제 #6
0
 def __init__(self):
     self.db = Database()
     self.db['points'] = 0
     self.db['points_per_click'] = 1
     self.db['speed'] = 10
     super(MainGameScene, self).__init__()
     self.background = Background((0, 123, 228))
     self.rails = MovingRail()
     self.label = TextLabel("Points: {}".format(self.db['points']),
                            os.path.join("Resources",
                                         Database()['font']), 16, (50, 18))
     self.train = Vehicle()
     self.train_rect = self.train.get_rect()
     self.button = Button(60, 200, 32, "Shop", (100, 100))
     self.button_rect = self.button.get_rect()
     print(self.train_rect)
예제 #7
0
def generateDropDownPathfinder():
    dropDown = []
    dropDown.append(
        Button("A* Algorithm Button", 100, 90, 270, 80, "A* Algorithm", 40,
               WIN, False))
    dropDown.append(
        Button("Dijkstra's Algorithm Button", 100, 170, 270, 80,
               "Dijkstra's Algorithm", 38, WIN, False))
    dropDown.append(
        Button("Breadth-First Search Button", 100, 250, 270, 80,
               "Breadth-First Search", 35, WIN, False))
    dropDown.append(
        Button("Depth-First Search BUtton", 100, 330, 270, 80,
               "Depth-First Search", 38, WIN, False))
    dropDown.append(
        Button("Greedy Algorithm Button", 100, 410, 270, 80,
               "Greedy Algorithm", 38, WIN, False))
    return dropDown
예제 #8
0
파일: Settings.py 프로젝트: kotland/Snow
    def __init__(self, background=BACKGROUNG_IMG, pos=(0, 0), size=(20, 20)):
        pygame.init()
        self.screen = pygame.display.set_mode((500, 500))
        self.btn_select_background = Button(pos=(150, 275),
                                        image_names=('button_on.png', 'button_hover.png', 'button_click.png'),
                                        path=BUTTON_IMAGE_PATH,
                                        function=self.on_btn_select_background, text=' Background ', w=200)
        self.btn_back_to_menu = Button(pos=(150, 330), image_names=('button_on.png', 'button_hover.png',
                                                                    'button_click.png'),
                                       path=BUTTON_IMAGE_PATH,
                                       function=self.on_btn_back_to_menu, text='Back to menu', w=200)

        self.scrollbar = ScrollBar(150, 150, min_num=50, max_num=5000, text='Number snow') # изменение кол-ва снежинок
        self.scrollbar_wind = ScrollBar(150, 220, min_num=5, max_num=500, text='Wind power') # изменение силы ветра
        self.work = True
        self.num_snows_scroll = None
        self.background = background
        self.background_image = pygame.transform.scale(load_image(self.background, 0, IMAGE_PATH), PLATFORM)
        self.rect = pygame.Rect(pos, size)
예제 #9
0
파일: Menu.py 프로젝트: kotland/Snow
class Menu:
    def __init__(self, num_snows_scroll=50, background=BACKGROUNG_IMG, wind_power=50):
        pygame.init()
        self.num_snows_scroll = num_snows_scroll
        self.screen = pygame.display.set_mode((500, 500))
        self.btn_start = Button(pos=(150, 150), image_names=('button_on.png', 'button_hover.png', 'button_click.png'),
                                path=BUTTON_IMAGE_PATH, function=self.on_btn_start, text='Start! ', w=200)
        self.btn_settings = Button(pos=(150, 205),
                                   image_names=('button_on.png', 'button_hover.png', 'button_click.png'),
                                   path=BUTTON_IMAGE_PATH, function=self.on_btn_settings, text='Settings ', w=200)
        self.btn_exit = Button(pos=(150, 260), image_names=('button_on.png', 'button_hover.png', 'button_click.png'),
                               path=BUTTON_IMAGE_PATH, function=self.on_btn_exit, text='Exit ', w=200)
        self.work = True
        self.background = background
        self.background_image = pygame.transform.scale(load_image(self.background, 0, IMAGE_PATH), PLATFORM)
        self.wind_power = wind_power

    def on_btn_exit(self):
        sys.exit()

    def on_btn_start(self):
        self.work = False
        win_snow = Program(self.num_snows_scroll, background=self.background if self.background else None,
                           wind_power=self.wind_power)
        win_snow.run()
        # print('start')

    def on_btn_settings(self):
        self.work = False
        win_settings = Settings(background=self.background)
        win_settings.run()

    def render(self):
        self.btn_start.render(self.screen)
        self.btn_settings.render(self.screen)
        self.btn_exit.render(self.screen)

    def event(self, event):
        self.btn_start.event(event)
        self.btn_settings.event(event)
        self.btn_exit.event(event)

    def run(self):
        while self.work:
            self.screen.blit(self.background_image, (0, 0))

            for event in pygame.event.get():
                self.event(event)
                if event.type == pygame.QUIT:
                    sys.exit()

                    # self.update(0)
            self.render()

            pygame.display.flip()
예제 #10
0
파일: Menu.py 프로젝트: Azimusss/Snake
class Menu:
    def __init__(self):
        pygame.display.set_mode((WIN_WIDHT, WIN_HEIGH))  # создание окна
        self.start_b = Button(('button_on.png', 'button_hover.png', 'button_click.png'),
                              path=BUTTONS_PATH, pos=(410, 224), text='Start', function=self.start_game)
        self.top_b = Button(('button_on.png', 'button_hover.png', 'button_click.png'),
                              path=BUTTONS_PATH, pos=(410, 287), text='Top Records', function=self.start_top)
        # self.setting_b = Button(('button_on.png', 'button_hover.png', 'button_click.png'),
        #                       path=BUTTONS_PATH, pos=(410, 350), text='Setting', function=None)
        self.exit_b = Button(('button_on.png', 'button_hover.png', 'button_click.png'),
                              path=BUTTONS_PATH, pos=(410, 350), text='Exit', function=self.close)
        self.done = True

    def close(self):
        sys.exit()

    def update(self):
        pass

    def events(self, event):
        self.start_b.event(event)
        # self.setting_b.event(event)
        self.top_b.event(event)
        self.exit_b.event(event)

    def render(self, screen):
        self.start_b.render(screen)
        # self.setting_b.render(screen)
        self.top_b.render(screen)
        self.exit_b.render(screen)

    def start_game(self):
        pygame.font.init()
        snake = Snake((4, 4), (0, 0, 0), (255, 255, 255),
                  (pygame.K_a, pygame.K_d, pygame.K_w, pygame.K_s),
                  4, 4, menu=Menu())
        snake.run_snake()

    def start_top(self):
        top = Top()
        top.run()

    def run(self):
        pygame.init()
        pygame.font.init()
        pygame.display.set_caption('Menu')
        game_screen = pygame.Surface((WIN_WIDHT, WIN_HEIGH))
        screen = pygame.display.get_surface()
        clock = pygame.time.Clock()
        while self.done:  # главный цикл программы
            for event in pygame.event.get():  # цикл обработки очереди событий окна
                if event.type == pygame.QUIT:
                    sys.exit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        sys.exit()
                self.events(event)
            pygame.display.update()
            clock.tick(FPS)
            screen.fill((10, 20, 30))
            game_screen.fill((10, 20, 30))
            self.render(screen)
예제 #11
0
class ShopScene(Scene):
    def __init__(self):
        self.db = Database()
        super().__init__()
        self.background = Background((0, 123, 228))
        self.button = Button(60,
                             200,
                             32,
                             "Shop", (100, 100),
                             color=(144, 191, 51))
        self.button_rect = self.button.get_rect()
        self.label = TextLabel("Points: {}".format(self.db['points']),
                               "Resources/F77-Minecraft.ttf", 16, (50, 18))
        self.ten_km_up = Button(60,
                                350,
                                24,
                                "+10km/h (50 pts)", (200, 370),
                                color=(144, 191, 51))
        self.hundred_km_up = Button(60,
                                    350,
                                    24,
                                    "+100km/h (300 pts)", (200, 280),
                                    color=(144, 191, 51))
        self.five_hundred_km_up = Button(60,
                                         350,
                                         24,
                                         "+500km/h (1000 pts)", (200, 190),
                                         color=(144, 191, 51))
        self.double_click_points = Button(60,
                                          350,
                                          24,
                                          "2X pts. (200 pts)", (600, 370),
                                          color=(144, 191, 51))

    def render(self, screen: pygame.Surface):
        self.background.render(screen)
        self.button.render(screen)
        self.label.render(screen)
        self.ten_km_up.render(screen)
        self.hundred_km_up.render(screen)
        self.five_hundred_km_up.render(screen)
        self.double_click_points.render(screen)

    def update(self, delta_time: float):
        self.label.update_text("Points: {}".format(self.db['points']))

    def handle_event(self, event: pygame.event):
        if event.type == pygame.MOUSEBUTTONDOWN:
            if self.button_rect.collidepoint(event.pos):
                Director().pop_scene()
            elif self.ten_km_up.get_rect().collidepoint(event.pos):
                if self.db['points'] >= 50:
                    self.db['speed'] += 10
                    self.db['points'] -= 50
            elif self.hundred_km_up.get_rect().collidepoint(event.pos):
                if self.db['points'] >= 300:
                    self.db['speed'] += 100
                    self.db['points'] -= 300
            elif self.five_hundred_km_up.get_rect().collidepoint(event.pos):
                if self.db['points'] >= 1000:
                    self.db['speed'] += 500
                    self.db['points'] -= 1000
            elif self.double_click_points.get_rect().collidepoint(event.pos):
                if self.db['points'] >= 200:
                    self.db['points_per_click'] *= 2
                    self.db['points'] -= 200
예제 #12
0
def main_loop(surface):
    global selected_mission, active_mission
    playing = True
    loop_count = 0
    
    player_image_list = [player_standing_img, player_standing_img_reverse, player_crouching_img, player_crouching_img_reverse]
    enemy_image_list = [rioter_standing_img, rioter_standing_img_reverse, rioter_crouching_img, rioter_crouching_img_reverse]
    
    #Create Objects
    weapon = Weapon("AK47", "better than arun", 0, 4, AK47_image, [30,10], 30, 900, 900, 900, 1, 10, 0, 2)
    weapon2 = Weapon("P90", "memes", 3, 3, P90_image, [30,10], 50, 1080, 450, 1080, 2, 20, 30, 2)    
    floor = gameObject([0, HEIGHT * 0.9], [WIDTH, HEIGHT * 0.1], (124,246,123))
    obstacle_group.append(floor)
    obs1 = gameObject([800,floor.get_pos()[1] - 100], [100,100], black)
    obs2 = gameObject([500,floor.get_pos()[1] - 100], [100,100], black)
    obs3 = gameObject([200,floor.get_pos()[1] - 100], [100,100], black)
    player = Player([50, HEIGHT * 0.9 - 150], [65, 150], 35, player_image_list, weapon, 90000, 0)
    player_group.append(player)
    
    #Create Missions
    mission1 = Mission("Madison Field Hospital", "Way too hard for Arun", 3, 1100, player)
    
    mission1.add_cover(obs1)
    mission1.add_cover(obs2)
    mission1.add_cover(obs3)
    
    enemy = Gunner([600,300], [65,150], 40, enemy_image_list, Weapon("AK47", "BLow STUFF UP", 0, 1, AK47_image, [30,10], 30, 800, 900, 900, 2, 10), 10000, 10, 20000, True, "Glass")
    enemy1 = Gunner([400,300], [65,150], 40, enemy_image_list, Weapon("AUG", "BLow STUFF UP", 0, 2, AK47_image, [30,10], 35, 900, 850, 950, 2, 10), 10000, 10)
    enemy2 = Gunner([800,300], [65,150], 40, enemy_image_list, Weapon("MP5", "BLow STUFF UP", 1, 3, P90_image, [30,10], 50, 2000, 700, 1300, 1, 10), 10000, 10)
    enemy3 = Rusher([400,300], [65,150], 40, enemy_image_list, Weapon("XM012", "BLow STUFF UP", 3, 4, XM_image, [30,10], 2, 200, 2000, 80, 3, 10), 10000, 10)
    enemy4 = Rusher([700,300], [65,150], 40, enemy_image_list, Weapon("Sawed Off", "BLow STUFF UP", 3, 1, XM_image, [30,10], 2, 100, 2000, 80, 2, 10), 10000, 10)
    enemy5 = Marksman([900,300], [65,150], 40, enemy_image_list, Weapon("Custom M44", "BLow STUFF UP", 4, 2, AWP_image, [30,10], 10, 200, 25000, 100, 3, 10), 10000, 10, 20000)
    enemy6 = Marksman([800,300], [65,150], 40, enemy_image_list, Weapon("Huntsman Rifle", "BLow STUFF UP", 4, 3, DEAGLE_image, [30,10], 14, 200, 18000, 300, 4, 10), 10000, 10, 20000)
    enemy7 = Marksman([600,300], [65,150], 40, enemy_image_list, Weapon("Custom M34", "BLow STUFF UP", 4, 4, AWP_image, [30,10], 7, 200, 50000, 20, 3, 10), 10000, 10, 20000, True, "Totomosic")
    
    mission1.add_enemy(enemy, 3)
    mission1.add_enemy(enemy1, 1)
    mission1.add_enemy(enemy2, 2)
    mission1.add_enemy(enemy3, 1)
    mission1.add_enemy(enemy4, 1)
    mission1.add_enemy(enemy5, 2)
    mission1.add_enemy(enemy6, 2)
    mission1.add_enemy(enemy7, 3)
    
    selected_mission = mission1
    active_mission = []
    
    #Extractable Items Menu
    extractable_items_menu = Menu([0,0], [WIDTH - 100, HEIGHT - 100], green, 128, False)
    
    title = Text("Extrable Items", [WIDTH * 0.45, HEIGHT * 0.1], white, 50, "impact")
    divider = gameObject([50, HEIGHT * 0.2], [extractable_items_menu.get_size()[0] - 100, 10], black)

    extract_group = List_Block([WIDTH * 0.07, HEIGHT * 0.27], [WIDTH * 0.4, HEIGHT * 0.5], red, 200, 5, 3)
    list_group.append(extract_group)
    
    pack_menu(extractable_items_menu, [title, divider, extract_group])
    
    #Primary Weapons Menu
    primary_weapons_menu = Menu([0,0], [WIDTH - 100, HEIGHT - 100], orange, 128, False)
    
    inventory_list = List_Block([WIDTH * 0.07, HEIGHT * 0.27], [WIDTH * 0.4, HEIGHT * 0.5], red, 200, 5, 3)
    list_group.append(inventory_list)
    player.add_inventory_item(weapon)
    player.add_inventory_item(weapon2)
    
    weapon_info = Button([WIDTH * 0.55, HEIGHT * 0.27], [WIDTH * 0.3, HEIGHT * 0.5], red, red, 128, [])
    weapon_info.add_text("Name: ", [weapon_info.get_size()[0] / 2, weapon_info.get_size()[1] * 0.2], black, 30, "impact", True, False, [], lambda: player.get_selected_weapon().get_name())
    weapon_info.add_text("DPS: ", [weapon_info.get_size()[0] / 2, weapon_info.get_size()[1] * 0.4], black, 30, "impact", True, False, [], lambda: player.get_selected_weapon().get_dps())
    weapon_info.add_text("Damage: ", [weapon_info.get_size()[0] / 2, weapon_info.get_size()[1] * 0.6], black, 30, "impact", True, False, [], lambda: player.get_selected_weapon().get_damage())
    weapon_info.add_text("RPM: ", [weapon_info.get_size()[0] / 2, weapon_info.get_size()[1] * 0.8], black, 30, "impact", True, False, [], lambda: player.get_selected_weapon().get_firerate())
    
    title = Text("Primary Weapons", [WIDTH * 0.45, HEIGHT * 0.1], white, 50, "impact")
    divider = gameObject([50, HEIGHT * 0.2], [primary_weapons_menu.get_size()[0] - 100, 10], black)
    
    equip_button = Button([WIDTH * 0.51, HEIGHT * 0.78], [WIDTH * 0.1, HEIGHT * 0.05], blue, (0,0,255), 128, [lambda: player.set_equipped_primary_weapon(player.get_selected_weapon())])
    equip_button.add_text("Equip", [equip_button.get_size()[0] / 2, equip_button.get_size()[1] / 2], white, 20, "impact")
    remove_button = Button([WIDTH * 0.62, HEIGHT * 0.78], [WIDTH * 0.16, HEIGHT * 0.05], red, (255,0,0), 128, [lambda: create_confirmation_menu("Are you sure you want to deconstruct the " + player.get_selected_weapon().get_name() + "?", [WIDTH * 0.2, HEIGHT * 0.1], [WIDTH * 0.6, HEIGHT * 0.1], purple, 200, [lambda: remove_list_item(inventory_list, player.get_selected_weapon().get_name()), lambda: player.remove_inventory_item(player.get_selected_weapon())])])
    remove_button.add_text("Deconstruct Item", [remove_button.get_size()[0] / 2, remove_button.get_size()[1] / 2], white, 20, "impact")
    mod_button = Button([WIDTH * 0.79, HEIGHT * 0.78], [WIDTH * 0.1, HEIGHT * 0.05], blue, (0,0,255), 128, [lambda: player.set_equipped_primary_weapon(player.get_selected_weapon())])
    mod_button.add_text("Mod", [mod_button.get_size()[0] / 2, mod_button.get_size()[1] / 2], white, 20, "impact")
    
    back_button = Button([WIDTH * 0.01, HEIGHT * 0.02], [50,20], green, (0,255,0), 200, [lambda: main_menu.set_selected_menu(inventory_menu)])
    back_button.add_text("Back", [back_button.get_size()[0] / 2, back_button.get_size()[1] / 2], white, 15, "impact")
    
    pack_menu(primary_weapons_menu, [inventory_list, back_button, title, divider, weapon_info, equip_button, remove_button, mod_button])
    
    #Inventory menu
    inventory_menu = Menu([0,0], [WIDTH - 100, HEIGHT - 100], (255,200,200), 128, False)
    
    primary_weapons_button = Button([WIDTH * 0.04, HEIGHT * 0.37], [WIDTH * 0.25, HEIGHT * 0.2], red, (255,0,0), 200, [lambda: main_menu.set_selected_menu(primary_weapons_menu)])
    primary_weapons_button.add_text("Primary Weapons", [primary_weapons_button.get_size()[0] / 2, primary_weapons_button.get_size()[1] / 2], white, 30, "impact")
    extract_items_button = Button([WIDTH * 0.04, HEIGHT * 0.6], [WIDTH * 0.25, HEIGHT * 0.2], red, (255,0,0), 200, [lambda: main_menu.set_selected_menu(extractable_items_menu)])
    extract_items_button.add_text("Extractable Items", [primary_weapons_button.get_size()[0] / 2, primary_weapons_button.get_size()[1] / 2], white, 30, "impact")
    mask_armor_button = Button([WIDTH * 0.32, HEIGHT * 0.37], [WIDTH * 0.25, HEIGHT * 0.2], red, (255,0,0), 200, [lambda: main_menu.set_selected_menu(inventory_menu)])
    mask_armor_button.add_text("Masks", [primary_weapons_button.get_size()[0] / 2, primary_weapons_button.get_size()[1] / 2], white, 30, "impact")
    chest_armor_button = Button([WIDTH * 0.32, HEIGHT * 0.6], [WIDTH * 0.25, HEIGHT * 0.2], red, (255,0,0), 200, [lambda: main_menu.set_selected_menu(inventory_menu)])
    chest_armor_button.add_text("Chest Armor", [primary_weapons_button.get_size()[0] / 2, primary_weapons_button.get_size()[1] / 2], white, 30, "impact")
    backpack_armor_button = Button([WIDTH * 0.6, HEIGHT * 0.37], [WIDTH * 0.25, HEIGHT * 0.2], red, (255,0,0), 200, [lambda: main_menu.set_selected_menu(inventory_menu)])
    backpack_armor_button.add_text("Backpacks", [primary_weapons_button.get_size()[0] / 2, primary_weapons_button.get_size()[1] / 2], white, 30, "impact")
    gloves_armor_button = Button([WIDTH * 0.6, HEIGHT * 0.6], [WIDTH * 0.25, HEIGHT * 0.2], red, (255,0,0), 200, [lambda: main_menu.set_selected_menu(inventory_menu)])
    gloves_armor_button.add_text("Gloves", [primary_weapons_button.get_size()[0] / 2, primary_weapons_button.get_size()[1] / 2], white, 30, "impact")
    
    back_button = Button([WIDTH * 0.01, HEIGHT * 0.02], [50,20], green, (0,255,0), 200, [lambda: main_menu.set_selected_menu(main_menu)])
    back_button.add_text("Back", [back_button.get_size()[0] / 2, back_button.get_size()[1] / 2], white, 15, "impact")
    
    firearms_display = Button([WIDTH * 0.025, HEIGHT * 0.08], [WIDTH * 0.25, HEIGHT * 0.2], red, red, 150, [])
    firearms_display.add_text("", [firearms_display.get_size()[0] / 2, firearms_display.get_size()[1] / 1.2], white, 20, "impact", True, False, [], lambda: player.get_attributes()[0])
    firearms_display.add_text("", [firearms_display.get_size()[0] / 2, firearms_display.get_size()[1] / 2], white, 40, "impact", True, False, [], lambda: player.get_equipped_primary_weapon().get_dps())
    stamina_display = Button([WIDTH * 0.325, HEIGHT * 0.08], [WIDTH * 0.25, HEIGHT * 0.2], blue, blue, 150, [])
    stamina_display.add_text("", [firearms_display.get_size()[0] / 2, firearms_display.get_size()[1] / 1.2], white, 20, "impact", True, False, [], lambda: player.get_attributes()[1])
    stamina_display.add_text("", [firearms_display.get_size()[0] / 2, firearms_display.get_size()[1] / 2], white, 40, "impact", True, False, [], lambda: player.get_max_health())
    electronics_display = Button([WIDTH * 0.625, HEIGHT * 0.08], [WIDTH * 0.25, HEIGHT * 0.2], green, green, 150, [])
    electronics_display.add_text("", [firearms_display.get_size()[0] / 2, firearms_display.get_size()[1] / 2], white, 40, "impact", True, False, [], lambda: player.get_attributes()[2] * 10)
    electronics_display.add_text("", [firearms_display.get_size()[0] / 2, firearms_display.get_size()[1] / 1.2], white, 20, "impact", True, False, [], lambda: player.get_attributes()[2])
        
    divider = gameObject([50, HEIGHT * 0.33], [inventory_menu.get_size()[0] - 100, 10], black)
    
    pack_menu(inventory_menu, [back_button, extract_items_button, extractable_items_menu, primary_weapons_button, mask_armor_button, chest_armor_button, backpack_armor_button, gloves_armor_button, firearms_display, stamina_display, electronics_display, divider])
    
    #Mission Menu
    mission_menu = Menu([0,0], [WIDTH - 100, HEIGHT - 100], purple, 128, False)
    
    title = Text("Missions", [WIDTH * 0.45, HEIGHT * 0.1], white, 50, "impact")
    divider = gameObject([50, HEIGHT * 0.2], [primary_weapons_menu.get_size()[0] - 100, 10], black)
    back_button = Button([WIDTH * 0.01, HEIGHT * 0.02], [50,20], green, (0,255,0), 200, [lambda: main_menu.set_selected_menu(main_menu)])
    back_button.add_text("Back", [back_button.get_size()[0] / 2, back_button.get_size()[1] / 2], white, 15, "impact")
    
    play_button = Button([WIDTH * 0.63, HEIGHT * 0.78], [WIDTH * 0.14, HEIGHT * 0.05], red, (255,0,0), 128, [lambda: activate_selected_mission()])
    play_button.add_text("Play Mission", [play_button.get_size()[0] / 2, play_button.get_size()[1] / 2], white, 20, "impact")
    
    mission_info = Button([WIDTH * 0.55, HEIGHT * 0.27], [WIDTH * 0.3, HEIGHT * 0.5], red, red, 128, [])
    mission_info.add_text("", [weapon_info.get_size()[0] / 2, weapon_info.get_size()[1] * 0.2], black, 30, "impact", True, False, [], lambda: selected_mission.get_name())
    mission_info.add_text("", [weapon_info.get_size()[0] / 2, weapon_info.get_size()[1] * 0.4], black, 30, "impact", True, False, [], lambda: selected_mission.get_desc())
    mission_info.add_text("Rec level: ", [weapon_info.get_size()[0] / 2, weapon_info.get_size()[1] * 0.6], black, 30, "impact", True, False, [], lambda: selected_mission.get_level())    
    
    mission_list = List_Block([WIDTH * 0.07, HEIGHT * 0.27], [WIDTH * 0.4, HEIGHT * 0.5], blue, 200, 5, 3)
    list_group.append(mission_list)
    
    pack_menu(mission_menu, [mission_info, mission_list, title, divider, back_button, play_button])
    
    #MAIN Menu
    main_menu = Menu([50,50], [WIDTH - 100, HEIGHT - 100], blue, 128, False)
    
    author = Text("Jordan Morrison's", [WIDTH * 0.35, HEIGHT * 0.15], orange, 20, "impact")
    title = Text("The Multiplication", [WIDTH * 0.45, HEIGHT * 0.2], white, 50, "impact")
    divider = gameObject([50, HEIGHT * 0.3], [main_menu.get_size()[0] - 100, 10], black)
    
    close_button = Button([main_menu.get_size()[0] - 60, 10], [50,20], red, (255,0,0), 200, [lambda: main_menu.set_show(False), lambda: weapon_hud.set_show(True)])
    close_button.add_text("X", [25,10], white, 20, "tahoma")
    
    inventory_menu_button = Button([WIDTH * 0.32, HEIGHT * 0.6], [WIDTH * 0.25, HEIGHT * 0.2], red, (255,0,0), 200, [lambda: main_menu.set_selected_menu(inventory_menu)])
    inventory_menu_button.add_text("Inventory", [inventory_menu_button.get_size()[0] / 2, inventory_menu_button.get_size()[1] / 2], white, 30, "impact")
    inventory_menu_button.add_text("0/", [inventory_menu_button.get_size()[0] / 2, inventory_menu_button.get_size()[1] / 1.2], white, 20, "impact", True, False, [], lambda: player.get_inventory_capacity())
    settings_menu_button = Button([WIDTH * 0.32, HEIGHT * 0.37], [WIDTH * 0.25, HEIGHT * 0.2], red, (255,0,0), 200, [lambda: main_menu.set_selected_menu(inventory_menu)])
    settings_menu_button.add_text("Settings", [inventory_menu_button.get_size()[0] / 2, inventory_menu_button.get_size()[1] / 2], white, 30, "impact")
    abilities_menu_button = Button([WIDTH * 0.04, HEIGHT * 0.6], [WIDTH * 0.25, HEIGHT * 0.2], red, (255,0,0), 200, [lambda: main_menu.set_selected_menu(inventory_menu)])
    abilities_menu_button.add_text("Abilities", [inventory_menu_button.get_size()[0] / 2, inventory_menu_button.get_size()[1] / 2], white, 30, "impact")
    missions_menu_button = Button([WIDTH * 0.6, HEIGHT * 0.6], [WIDTH * 0.25, HEIGHT * 0.2], red, (255,0,0), 200, [lambda: main_menu.set_selected_menu(mission_menu)])
    missions_menu_button.add_text("Missions", [inventory_menu_button.get_size()[0] / 2, inventory_menu_button.get_size()[1] / 2], white, 30, "impact")
    DZ_menu_button = Button([WIDTH * 0.04, HEIGHT * 0.37], [WIDTH * 0.25, HEIGHT * 0.2], red, (255,0,0), 200, [lambda: main_menu.set_selected_menu(inventory_menu)])
    DZ_menu_button.add_text("Dark Zone", [inventory_menu_button.get_size()[0] / 2, inventory_menu_button.get_size()[1] / 2], white, 30, "impact")
    blank_menu_button = Button([WIDTH * 0.6, HEIGHT * 0.37], [WIDTH * 0.25, HEIGHT * 0.2], red, (255,0,0), 200, [lambda: print_credits()])
    blank_menu_button.add_text("Credits", [inventory_menu_button.get_size()[0] / 2, inventory_menu_button.get_size()[1] / 2], white, 30, "impact")
    
    pack_menu(main_menu, [inventory_menu, mission_menu, extractable_items_menu, primary_weapons_menu, author, title, divider, close_button, inventory_menu_button, settings_menu_button, abilities_menu_button, missions_menu_button, DZ_menu_button, blank_menu_button])
    menu_group.append(main_menu)
    
    #Weapon HUD Menu
    weapon_hud = Menu([WIDTH * 0.7, HEIGHT * 0.1], [WIDTH * 0.25, HEIGHT * 0.15], red, 200)
    weapon_hud.add_border()
    
    health_segment_1 = Loading_Bar([weapon_hud.get_size()[0] * 0.08, weapon_hud.get_size()[1] * 0.1], [75, 20], (0,255,0), black, 200, 255, 2, True, [], [lambda: player.get_current_health(), lambda: player.get_max_health() / 3.0])
    health_segment_2 = Loading_Bar([weapon_hud.get_size()[0] * 0.37, weapon_hud.get_size()[1] * 0.1], [76, 20], (0,255,0), black, 200, 255, 2, True, [], [lambda: player.get_current_health() - player.get_max_health() / 3.0, lambda: player.get_max_health() / 3.0])
    health_segment_3 = Loading_Bar([weapon_hud.get_size()[0] * 0.66, weapon_hud.get_size()[1] * 0.1], [75, 20], (0,255,0), black, 200, 255, 2, True, [], [lambda: player.get_current_health() - player.get_max_health() * 2 / 3.0, lambda: player.get_max_health() / 3.0])
    
    weapon_name_text = Text("", [weapon_hud.get_size()[0] * 0.3, weapon_hud.get_size()[1] * 0.55], white, 20, "impact", True, False, [], lambda: player.get_equipped_primary_weapon().get_name())
    weapon_type_text = Text("", [weapon_hud.get_size()[0] * 0.3, weapon_hud.get_size()[1] * 0.8], yellow, 20, "impact", True, False, [], lambda: number_to_text(player.get_equipped_primary_weapon().get_type(), type_dict))
    weapon_ammo_text = Text("", [weapon_hud.get_size()[0] * 0.7, weapon_hud.get_size()[1] * 0.55], white, 20, "impact", True, False, [], lambda: player.get_equipped_primary_weapon().get_current_ammo())
    weapon_max_ammo_text = Text("", [weapon_hud.get_size()[0] * 0.7, weapon_hud.get_size()[1] * 0.8], white, 20, "impact", True, False, [], lambda: player.get_equipped_primary_weapon().get_total_ammo())
    
    pack_menu(weapon_hud, [weapon_name_text, weapon_type_text, weapon_ammo_text, weapon_max_ammo_text, health_segment_1, health_segment_2, health_segment_3])
    menu_group.append(weapon_hud)
    
    #HUD Menu
    hud = Menu([0,0], [0,0], BG_COLOR, 0)
    
    xp_bar = Loading_Bar([WIDTH / 1.9, HEIGHT * 0.05], [WIDTH * 0.35, HEIGHT * 0.03], purple, black, 255, 255, 2, True, [], [lambda: player.get_xp(), lambda: player.get_xp_list()[player.get_level()]])
    level_text = Text("", [WIDTH * 0.935, HEIGHT * 0.065], black, 30, "impact", True, False, [], lambda: player.get_level())
    weapon_hud_close_button = Button([weapon_hud.get_pos()[0] + weapon_hud.get_size()[0], weapon_hud.get_pos()[1]], [WIDTH * 0.0252, WIDTH * 0.0252], blue, (0,0,255), 128, [lambda: weapon_hud.toggle_show()])
    toggle_text = Text("^", [weapon_hud.get_pos()[0] + weapon_hud.get_size()[0] * 0.65, weapon_hud.get_pos()[1]], black, 15, "tahoma")
    
    pack_menu(hud, [xp_bar, level_text, weapon_hud_close_button, toggle_text])
    menu_group.append(hud)
    
    update_list_block(inventory_list, player.get_inventory_list(), [player.set_selected_weapon])
    update_list_block(mission_list, [mission1], [set_selected_mission])
    
    while playing:
    
        mouse_pos = pygame.mouse.get_pos()
        mouse_pressed = pygame.mouse.get_pressed()
        
        #Logic
        #Update Menus
        weapon_hud.set_pos([WIDTH * 0.6, xp_bar.get_pos()[1] + xp_bar.get_size()[1]])
        toggle_text.set_pos([weapon_hud.get_pos()[0] + weapon_hud.get_size()[0] + WIDTH * 0.01251, weapon_hud.get_pos()[1] + WIDTH * 0.01251])
        weapon_hud_close_button.set_pos([weapon_hud.get_pos()[0] + weapon_hud.get_size()[0], weapon_hud.get_pos()[1]])
        
        if main_menu.get_show():
            weapon_hud.set_show(False)
        
        if weapon_hud.get_show():
            toggle_text.set_text("v")
        else:
            toggle_text.set_text("^")
                
        for person in player_group:
            test_collisions(person, obstacle_group)
            if person.get_xp() >= person.get_xp_list()[person.get_level()]:
                player_level_up = pygame.USEREVENT + 1
                player_level_up_event = pygame.event.Event(player_level_up, person=person)
                pygame.event.post(player_level_up_event)
            
        for mission in active_mission:
            if mission.get_active():
                for enemy in mission.get_enemies():
                    test_collisions(enemy, obstacle_group)
                    test_collisions(enemy, mission.get_covers())
                test_collisions(player, mission.get_covers())
                
        for extraction in extraction_group:
            if player.collision([extraction.get_pos()[0] - 10, extraction.get_pos()[1] - 10, 20, 20]):
                for item in player.get_extracted_items():
                    player.add_inventory_item(item)   
                    player.remove_extracted_item(item)
                
        if player.get_update_inv():
            update_list_block(inventory_list, player.get_inventory_list(), [player.set_selected_weapon])    
            player.set_update_inv(False)  
            
        for drop in drop_group:
            if player.collision([drop.get_pos()[0], drop.get_pos()[1], drop.get_size()[0], drop.get_size()[1]]):
                for item in drop.get_items():
                    player.add_extracted_item(item)
                drop_group.remove(drop)
                update_list_block(extract_group, player.get_extracted_items(), [])
         
        #Bullet Detection     
        #Detection for enemies associated with a mission                  
        for mission in active_mission:
            if mission.get_active():
                for enemy in mission.get_enemies():
                    if bullet_collisions(player, enemy, mission.get_covers()):
                        if random.randrange(0,enemy.get_equipped_primary_weapon().get_rank() + 1) == 0:
                            drop = Drop([enemy.get_pos()[0] + 10, enemy.get_pos()[1] - 300], [enemy.get_size()[0] - 10, enemy.get_size()[1] + 300], enemy.get_equipped_primary_weapon().get_color(), 100, [enemy.get_equipped_primary_weapon()], 1800)
                            drop_group.append(drop)
                        mission.remove_enemy(enemy)
                        player.add_xp((enemy.get_level() + 1) * 10)
                    bullet_collisions(enemy, player, mission.get_covers())
                    
        #Detection for enemies with no association to missions
        for enemy in enemy_group:
            if bullet_collisions(player, enemy, obstacle_group):
                if random.randrange(0,enemy.get_equipped_primary_weapon().get_rank() + 1) == 0:
                    drop = Drop([enemy.get_pos()[0] + 10, enemy.get_pos()[1] - 300], [enemy.get_size()[0] - 10, enemy.get_size()[1] + 300], enemy.get_equipped_primary_weapon().get_color(), 100, [enemy.get_equipped_primary_weapon()], 1800)
                    drop_group.append(drop)
                enemy_group.remove(enemy)
            bullet_collisions(enemy, player, obstacle_group)
                                                   
        #Event Handling
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
                
            if event.type == player_level_up:
                event.person.set_level(event.person.get_level() + 1)
                event.person.set_xp(event.person.get_xp() - event.person.get_xp_list()[event.person.get_level() - 1])
                
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_a:
                    player.set_vel([-2, player.get_vel()[1]])
                if event.key == pygame.K_d:
                    player.set_vel([2, player.get_vel()[1]])
                if event.key == pygame.K_w:
                    player.jump(12)
                if event.key == pygame.K_LCTRL:
                    player.set_crouching(True)
                if event.key == pygame.K_SPACE:
                    player.set_shooting(True)
                if event.key == pygame.K_r:
                    player.force_reload()
                if event.key == pygame.K_e:
                    test_extraction = Extraction(player, [player.get_pos()[0],300], [WIDTH,HEIGHT], 90, 25)
                    extraction_group.append(test_extraction)
                
                if event.key == pygame.K_p:
                    main_menu.toggle_show()
                if event.key == pygame.K_ESCAPE:
                    main_menu.set_selected_menu(main_menu)
                    main_menu.set_show(False)
                    weapon_hud.set_show(True)
                
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_a:
                    player.set_vel([0, player.get_vel()[1]])
                if event.key == pygame.K_d:
                    player.set_vel([0, player.get_vel()[1]])
                if event.key == pygame.K_LCTRL:
                    player.set_crouching(False)
                if event.key == pygame.K_SPACE:
                    player.set_shooting(False)
                    
            if event.type == pygame.MOUSEBUTTONDOWN:
                for list_block in list_group:
                    if mouse_pos[0] > list_block.get_pos()[0] and mouse_pos[0] < list_block.get_pos()[0] + list_block.get_size()[0]:
                        if mouse_pos[1] > list_block.get_pos()[1] and mouse_pos[1] < list_block.get_pos()[1] + list_block.get_size()[1]:
                            if event.button == 4:
                                list_block.scroll_list(-1)
                            if event.button == 5:
                                list_block.scroll_list(1)
                                     
        #Update Display
        surface.fill(BG_COLOR)
        
        pygame.draw.circle(surface, (0,0,0), [int(WIDTH * 0.935), int(HEIGHT * 0.065)], int(WIDTH * 0.03 + 5))
        pygame.draw.circle(surface, (255,153,153), [int(WIDTH * 0.935), int(HEIGHT * 0.065)], int(WIDTH * 0.03))
        
        floor.update()
        floor.draw(surface)
        
        if len(conf_menu_group) > 1:
            conf_menu_group.pop()
        for menu in conf_menu_group:
            if menu.get_response():
                conf_menu_group.remove(menu)
                
        if len(extraction_group) > 1:
            extraction_group.pop()
        for extraction in extraction_group:
            if extraction.update():
                extraction_group.remove(extraction)
            extraction.draw(surface)
            
        for drop in drop_group:
            if drop.update():
                drop_group.remove(drop)
            drop.draw(surface)
        
        process_object_group(active_mission, surface)
        process_object_group(player_group, surface)
        process_object_group(enemy_group, surface)
        cover_group = []
        for obstacle in obstacle_group:
            if obstacle != floor:
                cover_group.append(obstacle)
        for enemy in enemy_group:
            enemy.AI(cover_group, player)
        process_object_group(timer_group, surface)
        process_object_group(text_group, surface)
        process_object_group(obstacle_group, surface)
        process_object_group(button_group, surface)
        process_object_group(menu_group, surface)
        process_object_group(conf_menu_group, surface)
                
        pygame.display.update()
        clock.tick(Updates_per_second)
        
        loop_count += 1
예제 #13
0
파일: Settings.py 프로젝트: kotland/Snow
class Settings:
    def __init__(self, background=BACKGROUNG_IMG, pos=(0, 0), size=(20, 20)):
        pygame.init()
        self.screen = pygame.display.set_mode((500, 500))
        self.btn_select_background = Button(pos=(150, 275),
                                        image_names=('button_on.png', 'button_hover.png', 'button_click.png'),
                                        path=BUTTON_IMAGE_PATH,
                                        function=self.on_btn_select_background, text=' Background ', w=200)
        self.btn_back_to_menu = Button(pos=(150, 330), image_names=('button_on.png', 'button_hover.png',
                                                                    'button_click.png'),
                                       path=BUTTON_IMAGE_PATH,
                                       function=self.on_btn_back_to_menu, text='Back to menu', w=200)

        self.scrollbar = ScrollBar(150, 150, min_num=50, max_num=5000, text='Number snow') # изменение кол-ва снежинок
        self.scrollbar_wind = ScrollBar(150, 220, min_num=5, max_num=500, text='Wind power') # изменение силы ветра
        self.work = True
        self.num_snows_scroll = None
        self.background = background
        self.background_image = pygame.transform.scale(load_image(self.background, 0, IMAGE_PATH), PLATFORM)
        self.rect = pygame.Rect(pos, size)

    def on_btn_back_to_menu(self):
        from Classes.Menu import Menu

        self.work = False
        num_snows_scroll = self.scrollbar.get_num()  # кол-во снежинок = значение снежинок на скроллинге
        wind_power = self.scrollbar_wind.get_num()
        print("from sc = ", num_snows_scroll)
        win_snow = Menu(num_snows_scroll, wind_power=wind_power)
        win_snow.run()

    def on_btn_select_background(self):
        from Classes.Background import SelectBackground

        win_snow = SelectBackground(background=self.background)
        win_snow.run()
        print('Background')

    def draw(self):
        pygame.draw.rect(self.screen, (10, 100, 100), Rect((145, 127), (212, 140)))

    def render(self):
        self.screen.blit(self.screen, self.rect)
        self.btn_back_to_menu.render(self.screen)
        self.btn_select_background.render(self.screen)
        self.scrollbar.render(self.screen)
        self.scrollbar_wind.render(self.screen)

    def event(self, event):
        self.btn_back_to_menu.event(event)
        self.btn_select_background.event(event)
        self.scrollbar.event(event)
        self.scrollbar_wind.event(event)

    def run(self):
        while self.work:
            self.screen.blit(self.background_image, (0, 0))
            self.draw()

            for event in pygame.event.get():
                self.event(event)
                if event.type == pygame.QUIT:
                    sys.exit()

                    # self.update(0)
            self.render()

            pygame.display.flip()
예제 #14
0
            return False

    def num_scroll(self):
        """
        Метод переводящий, цифру положения ползунка в текст, для рендера
        """
        if self.max_num != 0:  # если максимальное значение ползунка не равно 0 (чтобы не было деления на ноль)
            self.num_text = Text(self.num, self.x_scroll + 19, self.y +
                                 25)  # и получившееся значение в текст
        else:
            self.num = str(self.min_num)
            self.num_text = Text(str(self.num), self.x_scroll + 19,
                                 self.y + 25)
        change_scroll = pygame.event.Event(CHANGE_SCROLL,
                                           num=self.num,
                                           sender=self)
        pygame.event.post(change_scroll)

    def get_num(self):
        return self.num

    def update(self, dt):
        pass


if __name__ == "__main__":
    main = PyMain()
    scroll = ScrollBar(50, 50, max_num=50, text="Demo Scrolling")
    btn = Button()
    main.add_render_object(scroll)
    main.MainLoop()