def text(self): if self.__text is None: from Classes.Text import Text if (self.startupArguments.isMain and not self.startupArguments.translate): self.__text = Text(self.config.language) else: self.__text = Text('en_EN') return self.__text
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 __init__(self, x, y, min_num=0, max_num=20, text=None): # картинка ползунка: self.scroll_image = load_image('scroll.png', os.path.join(BASE_DIR, 'Images')) # картинка поля, по которому катается ползунок: self.scrollbar_image = load_image('scrollbar.png', os.path.join(BASE_DIR, 'Images'), 1) self.x = x self.y = y self.x_scroll = x # координата х ползунка, сначала равна координате поля self.min_num = min_num self.max_num = max_num # максимальное значение ползунка self.num_text = False # текст с циферкой значения ползунка, который выводится под ползунком self.MouseOnScroll = False # ползунок отпущен self.rect = self.scroll_image.get_rect() self.rect.move_ip(self.x_scroll, self.y) self.num = 0 # значение ползунка, по умолчанию 0 self.num_scroll( ) # метод, преобразующий значение ползунка в текст, который потом выводится на экран self.text = None # подпись к ползунку if text: """ если объекту передана подпись, то она создается в виде текста над ползунком """ self.text = Text(text, x=self.x, y=self.y - 20)
def add_text_message(): is_login(request.headers) body = request.form header = request.headers return Text.add(header["Id"], body[TextMessageModelVN.ReceiverId], body[TextMessageModelVN.Text], body[TextMessageModelVN.Date], body[TextMessageModelVN.EventId])
def bullet_collisions(player, enemy, obstacle_list): for bullet in player.get_equipped_primary_weapon().get_bullet_list(): for obstacle in obstacle_list: if bullet.collision([obstacle.get_pos()[0], obstacle.get_pos()[1], obstacle.get_size()[0], obstacle.get_size()[1]]): player.get_equipped_primary_weapon().remove_bullet(bullet) if bullet.collision([enemy.get_pos()[0], enemy.get_pos()[1], enemy.get_size()[0], enemy.get_size()[1]]): damage = bullet.get_damage() text_color = black if player.get_equipped_primary_weapon().get_crit_chance() > random.randrange(0,100): damage *= player.get_equipped_primary_weapon().get_crit_mult() text_color = purple if bullet.collision([enemy.get_pos()[0], enemy.get_pos()[1], enemy.get_size()[0], 30]): damage *= player.get_equipped_primary_weapon().get_headshot_mult() text_color = orange enemy.remove_health(damage) player.get_equipped_primary_weapon().remove_bullet(bullet) damage_text = Text(str(int(damage)), [random.choice([enemy.get_pos()[0] - 50, enemy.get_pos()[0] + enemy.get_size()[0] + 50]), enemy.get_pos()[1] + 10], text_color, 30, "impact", True, 20) text_group.append(damage_text) if enemy.get_current_health() <= 0: return True else: return False
def main(): pg.init() clock = pg.time.Clock() font = pg.font.Font(os.path.join(data_dir, "Apple_II.ttf"), 16) textSurface = font.render("Score", True, (255, 255, 255)) # Don't know what this does but don't touch it if pg.get_sdl_version()[0] == 2: pg.mixer.pre_init(44100, 32, 2, 1024) pg.init() # This might be broken # Set the display mode winstyle = 0 # |FULLSCREEN bestdepth = pg.display.mode_ok(SCREENRECT.size, winstyle, 32) screen = pg.display.set_mode(SCREENRECT.size, winstyle, bestdepth) pg.display.set_caption("Nabonkers!") icon = load_image('icon.png') icon = pg.transform.scale(icon, (32, 32)) pg.display.set_icon(icon) # ------------------------------------------------------------------------------------------------------------------ nabungaFrames = [ load_image('nabunga0.png'), load_image('nabunga1.png'), load_image('nabunga2.png'), load_image('nabunga3.png') ] bonkedFrame = load_image('nabunga_hit.png') bonkerFrames = [load_image('bonker0.png'), load_image('bonker1.png')] waterFrames = [ load_image('w0.jpg', False), load_image('w1.jpg', False), load_image('w2.png') ] cloudFrame = [load_image('c.jpg', False)] Water.frames = waterFrames Clouds.frames = cloudFrame Nabunga.frames = nabungaFrames Nabunga.bonkedFrame = bonkedFrame Bonker.frames = bonkerFrames map = load_image('map.jpg', False) title = load_image('title.jpg', False) background = pg.Surface(screen.get_size()).convert() background.blit(title, (0, 0)) background.blit(textSurface, (10, 10)) screen.blit(background, (0, 0)) pg.display.flip() # ------------------------------------------------------------------------------------------------------------------ hitSounds = [load_sound('track2.wav'), load_sound('track3.wav')] missSound = load_sound('track5.wav') # ------------------------------------------------------------------------------------------------------------------ # Define pop-up coordinates; dimensions for nabunga0.png holes = [] # left top width height topBottom = 650 topTop = 455 l = 66 w, h = 32, 37 # of nabunga0 # bottom row for i in range(0, 9, 2): left = i * 100 + l rect = pg.Rect(left, topBottom, w, h) holes.append(rect) # top row for i in range(1, 8, 2): left = i * 100 + l rect = pg.Rect(left, topTop, w, h) holes.append(rect) # len(holes) = 9 # ------------------------------------------------------------------------------------------------------------------ nabungas = pg.sprite.Group() last_nabunga = pg.sprite.GroupSingle() all = pg.sprite.LayeredDirty() menu = pg.sprite.Group() Nabunga.containers = nabungas bonker = Bonker() clouds = Clouds(SCREENRECT) water = Water() titleText = Text(load_image('titleText.png'), 'title') subtitleText = Text(load_image('subtitleText.png'), 'subtitle') menu.add(titleText) menu.add(subtitleText) font = pg.font.Font(os.path.join(data_dir, "Apple_II.ttf"), 12) score = Text(font, 'score') track1, track2, track3 = Text(font, 'track1'), Text(font, 'track2'), \ Text(font, 'track3') all.add(bonker, layer=bonker.layer) all.add(clouds, layer=clouds.layer) all.add(water, layer=clouds.layer) all.add(score) all.add(track1) all.add(track2) all.add(track3) music = load_sound('music2.wav') music.play(-1) music.set_volume(0.3) going = True time = 100 timer2 = time gameState = False while going: escapeState = pg.key.get_pressed() if escapeState[pg.K_ESCAPE]: going = False if escapeState[pg.K_m]: music.stop() if track1.get_rect().colliderect(bonker.rect): if pg.mouse.get_pressed()[0]: music.stop() music = load_sound('music0.wav') music.play(-1) if track2.get_rect().colliderect(bonker.rect): if pg.mouse.get_pressed()[0]: music.stop() music = load_sound('music1.wav') music.play(-1) if track3.get_rect().colliderect(bonker.rect): if pg.mouse.get_pressed()[0]: music.stop() music = load_sound('music2.wav') music.play(-1) ######################################################################## if not gameState: #menu.update() keyState = pg.key.get_pressed() if keyState[pg.K_RETURN]: gameState = True print('pressed enter') if titleText.get_rect().collidepoint(pg.mouse.get_pos()): print('touching') titleText.mouseover() if subtitleText.get_rect().collidepoint(pg.mouse.get_pos()): print('touching') subtitleText.mouseover() for event in pg.event.get(): if event.type == pg.QUIT: going = False menu.update() screen.blit(background, (0, 0)) menu.draw(screen) pg.display.flip() if gameState: pg.mouse.set_visible(0) all.clear(screen, background) all.update() background.blit(map, (0, 0)) if timer2 != 0: timer2 -= 1 else: for hole in holes: chance = randint(1, 4) if hole not in OCCUPIED and chance == 1: if last_nabunga: last_nabunga.sprite.state = DOWN n = Nabunga(hole, 40, 0, holes.index(hole), OCCUPIED) OCCUPIED.append(hole) all.add(n, layer=Nabunga.layer) timer2 = time hitsMade = 0 # Really means hitMade for event in pg.event.get(): if event.type == pg.QUIT: going = False elif event.type == pg.MOUSEBUTTONDOWN: bonker.bonkState = True for nabunga in nabungas: # print(nabunga.name) bonker.bonk(nabunga) hitbox = bonker.rect.inflate(1, 1) if hitbox.colliderect( nabunga.rect) and nabunga.getState() in [ UP, STEADY ]: nabunga.bonk() hitsMade += 1 score.increment() if hitsMade > 0: index = randint(0, (len(hitSounds) - 1)) hitSounds[index].play() elif hitsMade == 0: missSound.play() elif event.type == pg.MOUSEBUTTONUP: bonker.resetBonkState() hitsMade = 0 dirty = all.draw(screen) pg.display.update(dirty) pg.event.pump() clock.tick(40) pg.quit()
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
def PrintError(*args, **kwargs): pass def PrintNotice(*args, **kwargs): pass def PrintStack(skip=0): pass def PrintTraceback(msg=None, skip=0, source=None, excInfo=None): pass config = Config() debugLevel = config.logDebug colour = Colour() text = Text('en_US') actionThread = ActionThread() eventThread = EventThread() pluginManager = PluginManager() scheduler = Scheduler() def TriggerEvent(suffix, payload=None, prefix="Main", source=eg): pass def TriggerEnduringEvent(suffix, payload=None, prefix="Main", source=eg): pass from WinApi.SendKeys import SendKeysParser SendKeys = SendKeysParser() PluginClass = PluginBase