def __init__(self, game, player): self.game = game self.group = game.grenades pygame.sprite.Sprite.__init__(self, self.group) self.player = player self.image = textures.get_image("textures/weapons/tome_" + self.player.character + ".png") self.pos = vect(self.player.rect.center) + vect(-30, -15) self.rect = pygame.rect.Rect(self.pos, (1, 1)) dir = pygame.mouse.get_pos() rel_x, rel_y = dir[0] - (self.pos.x + game.camera.x), dir[1] - ( self.pos.y + game.camera.y) rel_n = math.sqrt(rel_x * rel_x + rel_y * rel_y) self.vel = vect(rel_x / rel_n, rel_y / rel_n) * GRENADE_SPEED self.last_update = 0 self.explosion = {} for i in range(1, 25): e = "0" + str(i) e = e[-2:] + ".png" self.explosion[i] = pygame.transform.scale( textures.get_image(path.join("textures/weapons/explode", e)), (60, 60)) self.current_frame = 0 self.last_update = 0 self.health_bar = pygame.rect.Rect(self.rect.midtop + vect(-30, -10), vect(self.rect.width, 5))
def __init__(self, game, character): pygame.sprite.Sprite.__init__(self) self.game = game self.character = character self.facing = 1 self.faces = textures.get_faces(self.character) self.image = self.faces[self.facing] self.rect = self.image.get_rect() self.pos = vect(0, 0) self.vel = vect(0, 0) self.acc = vect(0, 0) self.health = PLAYER_HEALTH self.dead = 0 self.explosion = {} for i in range(1, 25): e = "0" + str(i) e = e[-2:] + ".png" self.explosion[i] = pygame.transform.scale( textures.get_image( path.join("textures", self.character, "explosion", e)), (60, 60)) self.current_frame = 0 self.last_update = 0 self.health_bar = pygame.rect.Rect(self.rect.midtop + vect(-30, -10), vect(self.rect.width, 5))
def take_turn(self): now = pygame.time.get_ticks() - self.start_tick seconds = TURN_TIME - int((now - self.turn_time) / 1000) - 1 seconds_str = "0" + str(seconds) seconds_str = seconds_str[-2:] col = BLACK if now - self.turn_time > TURN_TIME * 1000 - 5000: col = RED scroll = pygame.transform.scale( textures.get_image("textures/scroll.png"), (60, 60)) self.screen.blit(scroll, (50, HEIGHT - 100)) self.screen.blit(FONT_TIME.render(seconds_str, 1, col), (65, HEIGHT - 82)) if now - self.turn_time > TURN_TIME * 1000 or ( self.teams[self.turn].left_bullets == 0 and self.teams[self.turn].left_grenades == 0 and len(self.grenades) == 0 and len(self.bullets) == 0): self.turn_time = now self.teams[self.turn].left_grenades = 1 self.teams[self.turn].left_bullets = 3 self.turn = 1 - self.turn self.teams[self.turn].active = 1 self.teams[1 - self.turn].active = 0 self.teams[1 - self.turn].players[self.teams[ 1 - self.turn].chosen_player].vel = vect(0, 0) self.teams[1 - self.turn].players[self.teams[ 1 - self.turn].chosen_player].acc = vect(0, 0)
def show_game_over_screen(self): waiting = True while waiting: self.tps_clock.tick(30) background = pygame.transform.scale( textures.get_image("textures/instructions.jpg"), (1280, 720)) self.screen.blit(background, (0, 0)) win = self.resources.loc[self.resources["K"] == "K_win"][ self.language].values[0] info = str(self.teams[self.winner() - 1].team_name) + win back = self.resources.loc[self.resources["K"] == "K_press"][ self.language].values[0] self.screen.blit(FONT_MENU.render(info, 1, WHITE), (WIDTH / 2 - 300, 10)) self.screen.blit(FONT_MENU.render(back, 1, WHITE), (WIDTH / 2 - 300, 400)) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit(0) if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: waiting = False pygame.display.flip()
def __init__(self, game, player): self.game = game self.group = self.game.map.objects pygame.sprite.Sprite.__init__(self, self.group) self.image = pygame.transform.scale(textures.get_image("textures/grave.png"), (60, 60)) self.player = player self.rect = self.image.get_rect() self.pos = vect(self.player.rect.center) self.rect.center = self.player.rect.center - vect(0, -5)
def __init__(self, game, player): self.game = game self.group = game.bullets pygame.sprite.Sprite.__init__(self, self.group) self.player = player self.image = textures.get_image("textures/weapons/bullet_" + self.player.character + ".png") self.pos = vect(self.player.rect.center) + vect(-30, -15) self.rect = pygame.rect.Rect(self.pos, (1, 1)) self.vel = vect(self.player.facing, 0) * BULLET_SPEED self.spawn_time = pygame.time.get_ticks()
def show_start_screen(self): waiting = True while waiting: self.tps_clock.tick(30) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit(0) background = pygame.transform.scale( textures.get_image("textures/background.png"), (1280, 720)) menu = textures.get_image("textures/menu.png") title = textures.get_image("textures/wizards.png") copyright = "(C) 2018 Mateusz Kobyłka" self.screen.blit(background, (0, 0)) self.screen.blit(menu, (WIDTH / 2 - 200, HEIGHT - 400)) self.screen.blit(FONT_DETAIL.render(copyright, 1, WHITE), (WIDTH - 220, HEIGHT - 20)) self.screen.blit(title, (WIDTH / 2 - 850 / 2, 0)) textures.text_to_button( self, self.resources.loc[self.resources["K"] == "K_play"][ self.language].values[0], WIDTH / 2 - 300 / 2, 340, 300, 50, FONT_MENU, BLACK, WHITE, "play") textures.text_to_button( self, self.resources.loc[self.resources["K"] == "K_options"][ self.language].values[0], WIDTH / 2 - 300 / 2, 440, 300, 50, FONT_MENU, BLACK, WHITE, "options") textures.text_to_button( self, self.resources.loc[self.resources["K"] == "K_instructions"][ self.language].values[0], WIDTH / 2 - 300 / 2, 540, 300, 50, FONT_MENU, BLACK, WHITE, "instructions") textures.text_to_button( self, self.resources.loc[self.resources["K"] == "K_quit"][ self.language].values[0], WIDTH / 2 - 300 / 2, 640, 300, 50, FONT_MENU, BLACK, WHITE, "quit") pygame.display.flip()
def __init__(self, pos, image): pygame.sprite.Sprite.__init__(self) self.image = textures.get_image(image) self.rect = self.image.get_rect() self.rect.x = pos.x self.rect.y = pos.y
def instructions_screen(self): waiting = True while waiting: self.tps_clock.tick(30) background = pygame.transform.scale( textures.get_image("textures/instructions.jpg"), (1280, 720)) topinfo = textures.get_image("textures/hang.png") sign = pygame.transform.scale( textures.get_image("textures/arrow_back.png"), (100, 100)) leftright = pygame.transform.scale( textures.get_image("textures/instructions/leftright.png"), (196, 50)) up = pygame.transform.scale( textures.get_image("textures/instructions/up.png"), (196, 50)) space = pygame.transform.scale( textures.get_image("textures/instructions/space.png"), (196, 50)) b = pygame.transform.scale( textures.get_image("textures/instructions/B.png"), (196, 50)) tab = pygame.transform.scale( textures.get_image("textures/instructions/tab.png"), (196, 50)) self.screen.blit(background, (0, 0)) self.screen.blit(sign, (50, HEIGHT - 100)) self.screen.blit(topinfo, (WIDTH / 2 - 200, 0)) self.screen.blit(leftright, (40, 150)) self.screen.blit(up, (40, 250)) self.screen.blit(space, (40, 350)) self.screen.blit(b, (40, 450)) self.screen.blit(tab, (40, 550)) leftright_info = self.resources.loc[ self.resources["K"] == "K_move"][self.language].values[0] up_info = self.resources.loc[self.resources["K"] == "K_up"][ self.language].values[0] space_info = self.resources.loc[self.resources["K"] == "K_space"][ self.language].values[0] b_info = self.resources.loc[self.resources["K"] == "K_b"][ self.language].values[0] tab_info = self.resources.loc[self.resources["K"] == "K_tab"][ self.language].values[0] self.screen.blit(FONT_OPTIONS.render(leftright_info, 1, WHITE), (340, 150)) self.screen.blit(FONT_OPTIONS.render(up_info, 1, WHITE), (340, 250)) self.screen.blit(FONT_OPTIONS.render(space_info, 1, WHITE), (340, 350)) self.screen.blit(FONT_OPTIONS.render(b_info, 1, WHITE), (340, 450)) self.screen.blit(FONT_OPTIONS.render(tab_info, 1, WHITE), (340, 550)) instructions = self.resources.loc[self.resources["K"] == "K_instructions"][ self.language].values[0] self.screen.blit(FONT_MENU.render(instructions, 1, WHITE), (WIDTH / 2 - 110, 30)) back_button = pygame.rect.Rect(vect(50, HEIGHT - 80), vect(100, 30)) textures.text_to_button( self, self.resources.loc[self.resources["K"] == "K_back"][ self.language].values[0], back_button.x, back_button.y, back_button.width, back_button.height, FONT_OPTIONS, BLACK, WHITE, "back") for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit(0) pygame.display.flip()
def options_screen(self): waiting = True team1_name = textures.Input_box(WIDTH / 4 - (186 / 2), 2 * HEIGHT / 10 - 10, 186, 40, self.teams[0].team_name, FONT_PLAYERS) team2_name = textures.Input_box(3 * WIDTH / 4 - (186 / 2), 2 * HEIGHT / 10 - 10, 186, 40, self.teams[1].team_name, FONT_PLAYERS) while waiting: self.tps_clock.tick(30) background = pygame.transform.scale( textures.get_image("textures/options.png"), (1280, 720)) topinfo = textures.get_image("textures/hang.png") sign = pygame.transform.scale( textures.get_image("textures/arrow_back.png"), (100, 100)) frame = pygame.transform.scale( textures.get_image("textures/frame.png"), (186, 238)) character_1 = textures.get_character( self.teams[0].player_1.character) character_2 = textures.get_character( self.teams[1].player_1.character) switch_l1 = pygame.transform.scale( textures.get_image("textures/switch_l_" + self.teams[0].player_1.character + ".png"), (25, 25)) switch_r1 = pygame.transform.scale( textures.get_image("textures/switch_r_" + self.teams[0].player_1.character + ".png"), (25, 25)) switch_l2 = pygame.transform.scale( textures.get_image("textures/switch_l_" + self.teams[1].player_1.character + ".png"), (25, 25)) switch_r2 = pygame.transform.scale( textures.get_image("textures/switch_r_" + self.teams[1].player_1.character + ".png"), (25, 25)) language = pygame.transform.scale( textures.get_image("textures/" + self.language + ".png"), (64, 64)) sound = pygame.transform.scale( textures.get_image("textures/megaphone" + str(self.sound) + ".png"), (64, 64)) save = pygame.transform.scale( textures.get_image("textures/save.png"), (64, 64)) versus = pygame.transform.scale( textures.get_image("textures/versus.png"), (120, 100)) self.screen.blit(background, (0, 0)) self.screen.blit(topinfo, (WIDTH / 2 - 200, 0)) self.screen.blit(sign, (50, HEIGHT - 100)) self.screen.blit(frame, (WIDTH / 4 - (186 / 2), HEIGHT / 4)) self.screen.blit(frame, (3 * WIDTH / 4 - (186 / 2), HEIGHT / 4)) self.screen.blit(character_1, (WIDTH / 4 - (186 / 2) + 25, HEIGHT / 4 + 30)) self.screen.blit(character_2, (3 * WIDTH / 4 - (186 / 2) + 25, HEIGHT / 4 + 30)) self.screen.blit(switch_l1, (WIDTH / 4 - (186 / 2) - 40, HEIGHT / 4 + 248)) self.screen.blit(switch_r1, (WIDTH / 4 + (186 / 2) + 10, HEIGHT / 4 + 248)) self.screen.blit(switch_l2, (3 * WIDTH / 4 - (186 / 2) - 40, HEIGHT / 4 + 248)) self.screen.blit(switch_r2, (3 * WIDTH / 4 + (186 / 2) + 10, HEIGHT / 4 + 248)) options = self.resources.loc[self.resources["K"] == "K_options"][ self.language].values[0] self.screen.blit(FONT_MENU.render(options, 1, WHITE), (WIDTH / 2 - 55, 30)) character_1_type = self.resources.loc[self.resources["K"] == "K_class"][self.language].values[0] + \ self.teams[0].player_1.character character_2_type = self.resources.loc[self.resources["K"] == "K_class"][self.language].values[0] + \ self.teams[1].player_1.character self.screen.blit( FONT_PLAYERS.render( character_1_type, 1, textures.get_team_color(self.teams[0].player_1.character)), (WIDTH / 4 - (186 / 2), HEIGHT / 4 + 250)) self.screen.blit( FONT_PLAYERS.render( character_2_type, 1, textures.get_team_color(self.teams[1].player_1.character)), (3 * WIDTH / 4 - (186 / 2), HEIGHT / 4 + 250)) self.screen.blit(language, (WIDTH / 2 - 32, 5 * HEIGHT / 7)) self.screen.blit(sound, (WIDTH / 2 - 32, 6 * HEIGHT / 7)) self.screen.blit(save, (WIDTH - 80, 6 * HEIGHT / 7 + 10)) self.screen.blit(versus, (WIDTH / 2 - 60, HEIGHT / 2 - 100)) self.screen.blit( FONT_OPTIONS.render( self.resources.loc[self.resources["K"] == "K_player"][ self.language].values[0] + " 1", 1, textures.get_team_color(self.teams[0].player_1.character)), (WIDTH / 4 - (186 / 2), HEIGHT / 10)) self.screen.blit( FONT_OPTIONS.render( self.resources.loc[self.resources["K"] == "K_player"][ self.language].values[0] + " 2", 1, textures.get_team_color(self.teams[1].player_1.character)), (3 * WIDTH / 4 - (186 / 2), HEIGHT / 10)) back_button = pygame.rect.Rect(vect(50, HEIGHT - 80), vect(100, 30)) textures.text_to_button( self, self.resources.loc[self.resources["K"] == "K_back"][ self.language].values[0], back_button.x, back_button.y, back_button.width, back_button.height, FONT_OPTIONS, BLACK, WHITE, "back") for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit(0) elif event.type == pygame.MOUSEBUTTONDOWN: textures.switch_character_type_button( self, 0, WIDTH / 4 - (186 / 2) - 40, HEIGHT / 4 + 248, 25, 25, "backward") textures.switch_character_type_button( self, 0, WIDTH / 4 + (186 / 2) + 10, HEIGHT / 4 + 248, 25, 25, "forward") textures.switch_character_type_button( self, 1, 3 * WIDTH / 4 - (186 / 2) - 40, HEIGHT / 4 + 248, 25, 25, "backward") textures.switch_character_type_button( self, 1, 3 * WIDTH / 4 + (186 / 2) + 10, HEIGHT / 4 + 248, 25, 25, "forward") textures.switch_language_button(self, WIDTH / 2 - 32, 5 * HEIGHT / 7, 64, 64) textures.switch_sound_button(self, WIDTH / 2 - 32, 6 * HEIGHT / 7, 64, 64) textures.save_button(self, WIDTH - 80, 6 * HEIGHT / 7 + 10, 64, 64) team1_name.handle_event(event) team2_name.handle_event(event) team1_name.draw(self.screen) team2_name.draw(self.screen) self.teams[0].team_name = team1_name.text self.teams[1].team_name = team2_name.text pygame.display.flip()