class Game(ge.Platformer): """ Gaguita's Game """ title = 'Gaguita: Platformer Game' width = 1850 height = 1000 world_theme = 'brown' #background_color = (120, 213, 219) #background_near = SpriteList(use_spatial_hash=False) #background_fixed = SpriteList(use_spatial_hash=False) player_color = 'red' player_initial_tile = -2, 3 player_class = Player viewport_margin_horizontal = 900 viewport_margin_vertical = 0 player_score = 0 player_life = 3 count_frames = 0 jumping = False spike_collision = False enemy_collision = False start_sound = pyglet.media.load('gaguita/src/sounds/MattOglseby-3.wav') coin_sound = arcade.load_sound('gaguita/src/sounds/SFX1.wav') jump_sound = arcade.load_sound('gaguita/src/sounds/Sword-Swing.wav') life_sound = arcade.load_sound('gaguita/src/sounds/UI1.wav') life_lost_sound = arcade.load_sound('gaguita/src/sounds/SFX5.wav') enemy_killed_sound = arcade.load_sound( 'gaguita/src/sounds/Lazer-Ricochet.wav') level_sound = pyglet.media.Player() level_sound.loop = True level_sound.queue(start_sound) def init_world(self): self.level_sound.play() """ Gui's fase Part 1 """ self.world_theme = 'green' # primeiro bloco self.create_arrow('right', (1, 2)) self.create_foreground('other/plant/green-6', (3, 2)) self.create_tower(2, 8, coords=(-3, 0)) # torre / segundo bloco self.create_tower(4, 3, coords=(5, 0)) self.create_foreground('other/plant/green-4', (6, 4)) self.create_platform(1, coords=(7, 5)) self.create_enemy(2, direction='y', coords=(9, 6), walk_size=4) #enemy self.create_object('other/spikes/spikes-high', (8, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (9, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (10, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (11, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (12, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (13, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (14, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (15, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (16, 0), sprite_list=self.spikes) #spike # bloco cinzento / terceiro bloco self.create_block('grey', (11.5, 5.5)) #block #coin # bloco cinzento / quarto bloco self.create_block('grey', (15.5, 6.5)) # CAMINHO DE CIMA # ground / quinto bloco self.create_ground(5, coords=(18, 7), end='round') self.create_platform(3, coords=(20, 9)) self.create_foreground('other/plant/dark-4', (21, 9.89)) #plant # ground / sexto bloco self.create_foreground('other/plant/dark-6', (27, 7)) #plant self.create_ground(1, coords=(27, 6)) # ground / setimo bloco self.create_ground(2, coords=(31, 6), end='sharp') self.create_object('other/items/yellowCrystal', (34, 10), sprite_list=self.coins) #coin # CAMINHO DE BAIXO # torre / quinto bloco self.create_tower(5, 4, coords=(17, 0)) # ground / sexto bloco self.create_enemy(coords=(22, 3), walk_size=4) #enemy self.create_ground(4, coords=(22, 2), end='round') # groun / setimo bloco self.create_ground(6, coords=(27, 0)) self.create_object('other/spikes/spikes-high', (28, 1), sprite_list=self.spikes) #spike self.create_background('other/plant/top-read', (30, 4)) self.create_background('other/plant/bottom-2', (30, 3)) self.create_background('other/plant/stem-vertical', (30, 2)) self.create_background('other/plant/leaf-1', (30, 1)) # ground / oitavo bloco self.create_foreground('other/plant/dark-2', (35, 3)) #plant self.create_ground(1, coords=(35, 2)) # CAMINHO COMUM # tower / ultimo bloco self.create_object('other/items/discGreen', (38, 6), sprite_list=self.lifes) #life self.create_tower(5, 3, coords=(37, 0)) # Tiles self.create_foreground('tile/green/e2', (2, 0)) self.create_foreground('tile/green/e3', (6, 1)) self.create_foreground('tile/green/e3', (6, 2)) self.create_foreground('tile/green/e2', (18, 1)) self.create_foreground('tile/green/e2', (18, 2)) self.create_foreground('tile/green/e3', (19, 2)) self.create_foreground('tile/green/e2', (18, 3)) self.create_foreground('tile/green/e2', (38, 1)) self.create_foreground('tile/green/e2', (38, 2)) self.create_foreground('tile/green/e2', (39, 0)) self.create_foreground('tile/green/e2', (39, 3)) # Fim da parte super legal, agora comeca a super chata """ Italo's fase Part 2 """ self.world_theme = 'brown' self.create_tower(3, 17, coords=(42, 0)) self.create_foreground('other/plant/red-4', (43, 3)) self.create_arrow('right', (45, 3)) self.create_object('other/items/yellowCrystal', (45.5, 6), sprite_list=self.coins) #coin self.create_block('grey', (46, 5)) self.create_foreground('other/plant/red-5', (49, 3)) self.create_background('other/plant/top-read', (50, 6)) self.create_background('other/plant/bottom-2', (50, 5)) self.create_background('other/plant/stem-vertical', (50, 4)) self.create_background('other/plant/leaf-1', (50, 3)) self.create_background('other/plant/top-blue', (52, 7)) self.create_background('other/plant/leaf-2', (52, 6)) self.create_background('other/plant/leaf-1', (52, 5)) self.create_background('other/plant/leaf-2', (52, 4)) self.create_background('other/plant/stem-vertical', (52, 3)) self.create_background('other/plant/top-yellow', (53, 7)) self.create_background('other/plant/bottom-2', (53, 6)) self.create_background('other/plant/leaf-1', (53, 5)) self.create_background('other/plant/stem-vertical', (53, 4)) self.create_background('other/plant/leaf-1', (53, 3)) self.create_enemy(coords=(52, 3), walk_size=4) #enemy self.create_object('other/spikes/spikes-high', (54, 3), sprite_list=self.spikes) #spike self.create_object('other/items/yellowCrystal', (56.5, 6), sprite_list=self.coins) #coin self.create_block('grey', (57, 5)) self.create_foreground('other/plant/red-2', (57, 3)) self.create_tower(4, 2, coords=(59, 0)) self.create_tower(5, 3, coords=(61, 0)) self.create_foreground('other/plant/red-6', (62, 5)) self.create_ground(6, coords=(66, 2), end='sharp') self.create_enemy(coords=(66, 3), walk_size=6) #enemy self.create_foreground('other/plant/red-3', (67, 3)) self.create_object('other/spikes/spikes-high', (68, 3), sprite_list=self.spikes) #spike self.create_background('other/plant/top-read', (70, 6)) self.create_background('other/plant/bottom-2', (70, 5)) self.create_background('other/plant/leaf-1', (70, 4)) self.create_background('other/plant/leaf-2', (70, 3)) self.create_platform(5, coords=(74, 4)) self.create_enemy(coords=(74, 5), walk_size=4) #enemy self.create_foreground('other/plant/red-2', (76, 5)) self.create_arrow('right', (81, 7)) self.create_platform(1, coords=(81, 6)) self.create_ground(10, coords=(75, 1), end='sharp') self.create_enemy(coords=(76, 2), walk_size=7) #enemy self.create_foreground('other/plant/red-1', (77, 2)) self.create_foreground('other/plant/red-1', (80, 2)) self.create_background('other/plant/top-read', (81, 4)) self.create_background('other/plant/leaf-1', (81, 3)) self.create_background('other/plant/bottom-2', (81, 2)) self.create_object('other/spikes/spikes-high', (82, 2), sprite_list=self.spikes) #spike self.create_foreground('other/plant/red-6', (83, 2)) self.create_foreground('other/plant/red-2', (86, 7)) self.create_platform(1, coords=(86, 6)) self.create_enemy(2, direction='y', coords=(89, 3), walk_size=6) #enemy self.create_arrow('top-right', (91, 4)) self.create_platform(1, coords=(91, 3)) self.create_object('other/items/yellowCrystal', (96, 6), sprite_list=self.coins) #coin self.create_platform(3, coords=(95, 5)) #self.create_arrow('right', (103, 9)) #self.create_tower(9, 4, coords=(102, 0)) self.create_foreground('other/plant/red-6', (101, 8)) self.create_object('other/items/discGreen', (102, 8), sprite_list=self.lifes) #life self.create_ground(3, coords=(100, 7), end='round') self.create_block('grey', (100, 5)) self.create_object('other/spikes/spikes-high', (99, 2), sprite_list=self.spikes) #spike self.create_foreground('other/plant/red-6', (100, 2)) self.create_ground(5, coords=(98, 1)) # Tiles self.create_foreground('tile/brown/e2', (42, 1)) self.create_foreground('tile/brown/e2', (44, 1)) self.create_foreground('tile/brown/e2', (46, 0)) self.create_foreground('tile/brown/e3', (49, 1)) self.create_foreground('tile/brown/e3', (51, 1)) self.create_foreground('tile/brown/e3', (54, 0)) self.create_foreground('tile/brown/e2', (58, 1)) self.create_foreground('tile/brown/e2', (60, 1)) self.create_foreground('tile/brown/e3', (61, 2)) self.create_foreground('tile/brown/e2', (62, 3)) self.create_foreground('tile/brown/e3', (63, 2)) self.create_foreground('tile/brown/e3', (63, 1)) """ Gabrie's fase Part 3 """ self.world_theme = 'blue' self.create_arrow('sign', (105, 7)) self.create_foreground('other/plant/dark-2', (107, 7)) self.create_tower(7, 4, coords=(105, 0)) self.create_fence('middle', (109, 5)) self.create_fence('right', (110, 5)) self.create_foreground('other/plant/dark-6', (111, 5)) self.create_foreground('other/plant/top-yellow', (112, 6)) self.create_foreground('other/plant/bottom-2', (112, 5)) self.create_tower(5, 5, coords=(108, 0)) self.create_object('other/spikes/spikes-high', (113, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (114, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (115, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (116, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (117, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (118, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (119, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (120, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (121, 0), sprite_list=self.spikes) #spike self.create_object('other/spikes/spikes-high', (122, 0), sprite_list=self.spikes) #spike self.create_enemy(coords=(114, 4), walk_size=4) #enemy self.create_foreground('other/plant/blue-6', (115, 4)) self.create_ground(4, coords=(114, 3), end='round') self.create_block('grey', (116, 9)) self.create_enemy(2, direction='y', coords=(118, 8), walk_size=4) #enemy self.create_block('grey', (120, 11)) self.create_foreground('other/plant/blue-1', (120, 4)) self.create_ground(2, coords=(120, 3), end='sharp') self.create_foreground('other/plant/blue-4', (124, 6)) self.create_tower(6, 3, coords=(123, 0)) self.create_foreground('other/plant/blue-5', (128, 7)) self.create_tower(7, 3, coords=(127, 0)) self.create_foreground('other/plant/blue-2', (132, 8)) self.create_tower(8, 3, coords=(131, 0)) self.create_arrow('top-right', (136, 10)) self.create_object('other/items/yellowCrystal', (137, 10), sprite_list=self.coins) #coin self.create_platform(2, coords=(136, 9)) self.create_enemy(coords=(140, 11), walk_size=2) #enemy self.create_platform(2, coords=(140, 10)) self.create_object('other/items/yellowCrystal', (145, 11), sprite_list=self.coins) #coin self.create_platform(2, coords=(144, 10)) self.create_enemy(2, direction='y', coords=(147, 8), walk_size=5) #enemy self.create_ground(2, coords=(137, 6), end='sharp') self.create_foreground('other/plant/blue-6', (141, 5)) self.create_ground(3, coords=(140, 4), end='round') self.create_ground(2, coords=(144, 2), end='sharp') self.create_block('grey', (150, 8)) self.create_block('grey', (154, 6)) self.create_background('other/plant/top-read', (150, 4)) self.create_background('other/plant/bottom-2', (150, 3)) self.create_background('other/plant/stem-vertical', (150, 2)) self.create_background('other/plant/leaf-1', (150, 1)) self.create_foreground('other/plant/blue-5', (151, 1)) self.create_object('other/spikes/spikes-low', (153, 1), sprite_list=self.spikes) #spike self.create_ground(7, coords=(149, 0)) # Tiles self.create_foreground('tile/blue/e2', (106, 5)) self.create_foreground('tile/blue/e2', (106, 1)) self.create_foreground('tile/blue/e2', (106, 2)) self.create_foreground('tile/blue/e2', (107, 1)) self.create_foreground('tile/blue/e3', (110, 3)) self.create_foreground('tile/blue/e3', (111, 3)) self.create_foreground('tile/blue/e3', (111, 2)) self.create_foreground('tile/blue/e2', (124, 4)) self.create_foreground('tile/blue/e2', (124, 2)) self.create_foreground('tile/blue/e2', (128, 5)) self.create_foreground('tile/blue/e2', (128, 2)) self.create_foreground('tile/blue/e2', (128, 3)) self.create_foreground('tile/blue/e2', (132, 6)) self.create_foreground('tile/blue/e2', (132, 2)) self.create_foreground('tile/blue/e2', (132, 3)) self.create_foreground('tile/blue/e2', (132, 4)) def create_enemy(self, enemy_type=1, direction='x', coords=(0, 0), walk_size=4): """ Creates enemies in the world. Enemy type 1: Walking. Enemy type 2: Flying. """ enemy = arcade.AnimatedWalkingSprite() enemy_name = 'enemyFlying_' if enemy_type == 2 else 'enemyWalking_' enemy_path = 'fgarcade/data/themes/abstract/enemy/' x, y = coords bound1_x, bound1_y = x - 1, y bound2_x, bound2_y = x + walk_size, y border_path = '../../../../../fgarcade/gaguita/src/img/' texture_range = (2, 3, 2, 1) if enemy_type == 2 else (2, 1, 2, 1) speed_x = 1.3 speed_y = 0 if direction == 'y': bound1_x, bound1_y = x, y - 1 bound2_x, bound2_y = x, y + walk_size speed_x = 0 speed_y = 1.0 # First enemy boundary self.create_object(border_path + 'transparent', coords=(bound1_x, bound1_y), role=Role.BACKGROUND, sprite_list=self.enemy_limits) # Second enemy boundary self.create_object(border_path + 'transparent', coords=(bound2_x, bound2_y), role=Role.BACKGROUND, sprite_list=self.enemy_limits) enemy.stand_left_textures = [] enemy.stand_right_textures = [] enemy.walk_left_textures = [] enemy.walk_right_textures = [] enemy.stand_left_textures.append( arcade.load_texture(enemy_path + enemy_name + "1.png", scale=self.scaling, mirrored=True)) enemy.stand_right_textures.append( arcade.load_texture(enemy_path + enemy_name + "1.png", scale=self.scaling)) for i in texture_range: enemy.walk_left_textures.append( arcade.load_texture(enemy_path + enemy_name + str(i) + ".png", scale=self.scaling, mirrored=True)) for i in texture_range: enemy.walk_right_textures.append( arcade.load_texture(enemy_path + enemy_name + str(i) + ".png", scale=self.scaling)) x = int(64 * x + 32) y = int((64 * y) + (44 / 2)) enemy.change_x = speed_x enemy.change_y = speed_y enemy.texture_change_distance = 20 enemy.left = x enemy.bottom = y self.enemies.append(enemy) return enemy def init_enemies(self): self.enemies = SpriteList() self.enemy_limits = SpriteList() def init_items(self): self.coins = SpriteList() self.lifes = SpriteList() self.spikes = SpriteList() def init(self): self.init_items() self.init_enemies() self.init_world() def collision_with_coins(self): self.coins.update() coins_hit_list = arcade.check_for_collision_with_list( self.player, self.coins) for coin in coins_hit_list: coin.remove_from_sprite_lists() self.player_score += 1 arcade.play_sound(self.coin_sound) def collision_with_lifes(self): self.lifes.update() lifes_hit_list = arcade.check_for_collision_with_list( self.player, self.lifes) for life in lifes_hit_list: life.remove_from_sprite_lists() self.player_life += 1 arcade.play_sound(self.life_sound) def collision_with_spikes(self): self.spikes.update() spikes_hit_list = arcade.check_for_collision_with_list( self.player, self.spikes) if len(spikes_hit_list) > 0: if not self.spike_collision: self.player_life -= 1 arcade.play_sound(self.life_lost_sound) self.spike_collision = True else: self.spike_collision = False def collision_with_enemies(self): self.enemies.update() enemies_hit_list = arcade.check_for_collision_with_list( self.player, self.enemies) for enemy in self.enemies: for border in self.enemy_limits: if arcade.check_for_collision(enemy, border): enemy.change_x *= -1 enemy.change_y *= -1 if len(enemies_hit_list) > 0: for enemy in enemies_hit_list: if self.player.change_y < -0.5 and not self.enemy_collision: enemy.remove_from_sprite_lists() self.player_score += 3 arcade.play_sound(self.enemy_killed_sound) else: if not self.enemy_collision: self.player_life -= 1 arcade.play_sound(self.life_lost_sound) self.enemy_collision = True else: self.enemy_collision = False def player_info(self): text_x = (self.viewport_horizontal_start + self.width) - (self.width * 0.15) text_y = (self.viewport_vertical_start + self.height) - (self.height * 0.1) score_text = f"SCORE: {self.player_score}" arcade.draw_text( score_text, text_x, text_y, arcade.csscolor.GRAY, 45, font_name=('fgarcade/data/fonts/monogram_extended.ttf')) life_text = f"LIFE: {self.player_life}" arcade.draw_text( life_text, text_x, text_y - 35, arcade.csscolor.GREY, 45, font_name=('fgarcade/data/fonts/monogram_extended.ttf')) def on_update(self, dt): super().on_update(dt) self.enemies.update() self.enemies.update_animation() self.collision_with_coins() self.collision_with_lifes() self.collision_with_spikes() self.collision_with_enemies() if self.player.change_y > 0: if not self.jumping: arcade.play_sound(self.jump_sound) self.jumping = True else: self.jumping = False if self.player_life <= 0: self.game_over() if self.player.center_x > self.width: #self.next_level() pass if self.player.center_y < 10: self.game_over() if self.player.change_x == 0: self.count_frames += 1 if self.count_frames >= 50: self.count_frames = 0 self.game_over() def draw_elements(self): super().draw_elements() self.coins.draw() self.lifes.draw() self.spikes.draw() self.enemies.draw() self.enemy_limits.draw() self.player_info() def game_over(self): arcade.pause(1) arcade.close_window()
class Game(ge.Platformer): """ Simple game my_level """ final = 90 SCORE = 2 viewport_margin_horizontal = 400 viewport_margin_vertical = 300 LIMIT = 3 cal = False # SOUNDS coin_sound = arcade.load_sound('examples/sounds/coin.wav') jump_sound = arcade.load_sound('examples/sounds/jump.wav') disc_sound = arcade.load_sound('examples/sounds/disc.wav') def init_world(self): # Inicio e chão self.create_tower(10, 2, coords=(0, 1)) self.create_ground(self.final, coords=(0, 0), smooth_ends=True) # Plataforma para fazer a camera acompanhar o jogador em qualquer altura self.create_platform(1, coords=(20, 90)) # Cenário self.moving_platform_list = SpriteList() platform = self.create_object('tile/blue/gl', (34, 3), at=self.moving_platform_list, role=Role.OBJECT) platform = self.create_object('tile/blue/g', (35, 3), at=self.moving_platform_list, role=Role.OBJECT) platform = self.create_object('tile/blue/gr', (36, 3), at=self.moving_platform_list, role=Role.OBJECT) def create_spike(tam, x, y): for i in range(tam): spike = self.create_object('other/spikes/spikes-high', (x, y), at=self.spikes) x += 1 self.discs = SpriteList() def create_disc(x, y): disc = self.create_object('other/items/discGreen', (x, y), at=self.discs) def create_door_key(x, y): doorkey = self.create_object('other/door/doorRed_lock', (x, y), at=self.doorkey) def create_door_top(x, y): doortop = self.create_object('other/door/doorRed_top', (x, y), at=self.doortop) for pt in [(3, (6, 3)), (3, (9, 6)), (3, (12, 9)), (3, (20, 9)), (1, (20, 3)), (3, (62, 5)), (3, (67, 3)), (3, (30, 6))]: s, l = pt self.create_platform(s, l) for pt in [(2, 3, (12, 1)), (4, 3, (14, 1)), (2, 3, (24, 1)), (4, 3, (26, 1)), (2, 3, (52, 1)), (2, 3, (56, 1)), (5, 3, (54, 1)), (2, 3, (75, 1)), (5, 3, (73, 1)), (7, 3, (87, 1))]: x, y, w = pt self.create_tower(x, y, w) # Final tower self.create_tower(10, coords=(self.final - 1, 1)) # Spikes self.spikes = SpriteList() create_spike(7, 17, 1) create_spike(23, 29, 1) create_spike(14, 59, 1) # Discs create_disc(63, 11) create_disc(21, 10) create_disc(20, 4) create_disc(40, 4) create_disc(40, 8) # Door key self.doorkey = SpriteList() create_door_key(88, 8) # Door top self.doortop = SpriteList() create_door_top(88, 9) # Foreground self.create_arrow('right', (3, 1)) self.create_fence('left', (52, 3)) self.create_fence('right', (53, 3)) self.create_fence('left', (57, 3)) self.create_fence('left', (58, 3)) self.create_fence('left', (58, 3)) self.create_fence('left', (76, 3)) self.create_fence('right', (77, 3)) # Background self.background_near = SpriteList(use_spatial_hash=False) self.background_fixed = SpriteList(use_spatial_hash=False) self.background_fixed.append(Sprite(get_sprite_path('background/bg1'))) # Limite da Plataforma que anda def limit_of_platforms(self): self.limit_of_platform_moving = SpriteList(is_static=True) limit = self.create_object('other/block/brown', (30, 3), at=self.limit_of_platform_moving) limit = self.create_object('other/block/brown', (50, 3), at=self.limit_of_platform_moving) # Limite do inimigo que anda def limit_of_enemies(self): self.limit_of_enemies_moving_in_x = SpriteList(is_static=True) limit = self.create_object('other/block/brown', (30, 7), at=self.limit_of_enemies_moving_in_x) limit = self.create_object('other/block/brown', (50, 7), at=self.limit_of_enemies_moving_in_x) def limit_enemies(self): self.limit_of_enemies_moving_in_y = SpriteList(is_static=True) limit = self.create_object('other/block/green', (72, 10), at=self.limit_of_enemies_moving_in_y) limit = self.create_object('other/block/green', (72, 2), at=self.limit_of_enemies_moving_in_y) def init_enemies(self): self.enemies = SpriteList(is_static=True) self.moving_enemies_list_in_x = SpriteList(is_static=False) self.moving_enemies_list_in_y = SpriteList(is_static=False) def create_enemy(x, y, condition, direction_x): if condition: if direction_x: enemy = self.create_object( 'enemy/enemySwimming_1', (x, y), at=self.moving_enemies_list_in_x) else: enemy = self.create_object( 'enemy/enemyFlyingAlt_1', (x, y), at=self.moving_enemies_list_in_y) else: enemy = self.create_object('enemy/enemyFloating_1', (x, y), at=self.enemies) # Parâmetro True caso seja um Inimigo que se move create_enemy(35, 7, True, True) create_enemy(35, 10, True, True) create_enemy(35, 8, True, True) create_enemy(35, 9, True, True) #create_enemy(21, 10, False, False) create_enemy(34, 6, True, False) #create_enemy(40, 4, False, False) create_enemy(46, 6, True, False) create_enemy(72, 6, True, False) create_enemy(66, 6, True, False) create_enemy(18, 6, True, False) create_enemy(23, 6, True, False) create_enemy(60, 6, True, False) def init_items(self): self.coins = SpriteList() def create_coin(x, y, *args): if args: for i in range(args[0]): coin = self.create_object('other/items/yellowGem', (x, y), at=self.coins) self.coins.append(coin) x += 1 else: coin = self.create_object('other/items/yellowGem', (x, y), at=self.coins) self.coins.append(coin) #Coins create_coin(6, 4, 3) create_coin(9, 7, 3) create_coin(14, 5, 3) create_coin(12, 10, 3) create_coin(20, 10, 3) create_coin(24, 3, 2) create_coin(26, 5, 3) create_coin(33, 4, 1) create_coin(35, 4, 1) create_coin(39, 4, 1) create_coin(41, 4, 1) create_coin(45, 4, 1) create_coin(47, 4, 1) create_coin(54, 6, 3) create_coin(62, 6, 3) create_coin(67, 4, 3) create_coin(78, 1, 3) create_coin(81, 1, 3) create_coin(84, 1, 3) self.items = SpriteList() def init(self): self.init_world() self.init_items() self.init_enemies() self.limit_of_platforms() self.limit_of_enemies() self.limit_enemies() self.score_coins = 0 self.cont = 0 self.player_life = 4 self.move_platform = 3 self.move_enemie = 5 self.move_enemy = 5 def collide_coins(self, dt): self.coins.update() coins_hit_list = arcade.check_for_collision_with_list( self.player, self.coins) i = 0 for coin in coins_hit_list: coin.remove_from_sprite_lists() i += 1 if i == self.SCORE: self.score_coins += 10 i = 0 arcade.play_sound(self.coin_sound) def collide_spikes(self, dt): self.spikes.update() spikes_hit_list = arcade.check_for_collision_with_list( self.player, self.spikes) for spike in spikes_hit_list: self.cont += 1 self.player_die() def collide_enemies(self, dt): self.enemies.update() enemies_hit_list = arcade.check_for_collision_with_list( self.player, self.enemies) moving_enemies_in_x_hit_list = arcade.check_for_collision_with_list( self.player, self.moving_enemies_list_in_x) moving_enemies_in_y_hit_list = arcade.check_for_collision_with_list( self.player, self.moving_enemies_list_in_y) for enemie in enemies_hit_list: self.cont += 1 self.player_die() for enemie in moving_enemies_in_x_hit_list: self.cont += 1 self.player_die() for enemie in moving_enemies_in_y_hit_list: self.cont += 1 self.player_die() def collide_discs(self, dt): self.discs.update() discs_hit_list = arcade.check_for_collision_with_list( self.player, self.discs) for disc in discs_hit_list: disc.remove_from_sprite_lists() self.player.jump += 50 arcade.play_sound(self.disc_sound) def player_die(self): if self.cont == self.SCORE: sleep(0.5) super().player.player_initial_tile = 4, 1 del self.physics_engine self.init_items() self.init_enemies() self.init_world() self.score_coins = 0 self.player_life -= 1 self.cont = 0 def game_over(self, dt): game.exit() def object_can_move(self, name, collision): check_hit = [] for limit in name: hit = arcade.check_for_collision_with_list(limit, collision) check_hit.append(hit) for hit in check_hit: if hit: return True return False def move_platforms(self, dt): check = self.object_can_move(self.limit_of_platform_moving, self.moving_platform_list) cont = 3 check_player = arcade.check_for_collision_with_list( self.player, self.moving_platform_list) if check_player or self.cal: self.cal = True for platform in self.moving_platform_list: if check and cont == self.LIMIT: self.move_platform *= (-1) cont = 0 platform.center_x += self.move_platform cont = 3 def move_enemies_in_x(self, dt): for enemie in self.moving_enemies_list_in_x: check_in_x = arcade.check_for_collision_with_list( enemie, self.limit_of_enemies_moving_in_x) if check_in_x: self.move_enemie *= (-1) enemie.center_x += self.move_enemie def move_enemies_in_y(self, dt): for enemy in self.moving_enemies_list_in_y: check_in_y = arcade.check_for_collision_with_list( enemy, self.limit_of_enemies_moving_in_y) if check_in_y: self.move_enemy *= (-1) enemy.center_y += self.move_enemy def on_update(self, dt): if self.player_life >= 1: super().on_update(dt) self.collide_coins(dt) self.collide_spikes(dt) self.collide_enemies(dt) self.move_enemies_in_x(dt) self.move_enemies_in_y(dt) self.collide_discs(dt) self.move_platforms(dt) else: self.game_over(dt) # JUMP SOUND if self.player.change_y > 0: if not self.jumping: arcade.play_sound(self.jump_sound) self.jumping = True else: self.jumping = False def draw_elements(self): super().draw_elements() self.enemies.draw() self.coins.draw() self.spikes.draw() self.moving_enemies_list_in_x.draw() self.moving_enemies_list_in_y.draw() self.moving_platform_list.draw() self.discs.draw() self.doorkey.draw() self.doortop.draw() #Placar de Contagem das moedas e vidas output_score = f"Score: {self.score_coins} ||" output_life = f"Life: {self.player_life}" arcade.draw_text(output_score, self.viewport_horizontal_start, self.viewport_vertical_start + 10, arcade.color.BLACK, 25) arcade.draw_text(output_life, self.viewport_horizontal_start + 250, self.viewport_vertical_start + 10, arcade.color.BLACK, 25)
class SpriteManager(object): def __init__(self): self.player_ships = None self.enemy_ships = None self.player_base = None self.enemy_base = None self.explosions_list = None self.player_benefit = 0 self.enemy_benefit = 0 self.player_idle = 0 self.explosion_texture = load_texture(EXPLOSION_PIC) def setup(self): self.player_ships = SpriteList() self.enemy_ships = SpriteList() self.explosions_list = SpriteList() self.player_base = Base(PLAYER_BASE_POSITION_X, PLAYER_BASE_POSITION_Y, PLAYER_BAR_POSITION_X, PLAYER_BAR_POSITION_Y) self.enemy_base = Base(ENEMY_BASE_POSITION_X, ENEMY_BASE_POSITION_Y, ENEMY_BAR_POSITION_X, ENEMY_BAR_POSITION_Y) def draw_sprites(self): self.explosions_list.draw() self.player_ships.draw() self.enemy_ships.draw() self.player_base.draw() self.enemy_base.draw() def add_ship(self, fighter): self.player_idle = 0 self.player_ships.append(fighter) def update(self, delta_time): self.player_idle += delta_time self.explosions_list.update() self.player_ships.update() self.enemy_ships.update() self.player_base.update() self.enemy_base.update() self.check_ships(self.player_ships) self.check_ships(self.enemy_ships) self.check_collisions(self.player_ships, self.enemy_base) self.check_collisions(self.enemy_ships, self.player_base) self.make_fights() def player_fight_benefit(self) -> int: player_benefit = self.player_benefit self.player_benefit = 0 return player_benefit def enemy_fight_benefit(self) -> int: enemy_benefit = self.enemy_benefit self.enemy_benefit = 0 return enemy_benefit def make_fights(self): for player_ship in self.player_ships: enemy_ships = check_for_collision_with_list( player_ship, self.enemy_ships) for enemy_ship in enemy_ships: while player_ship.get_hp() > 0 and enemy_ship.get_hp() > 0: player_ship.get_damage(player_ship.blow_damage + enemy_ship.make_damage()) enemy_ship.get_damage(enemy_ship.blow_damage + player_ship.make_damage()) explosion = Explosion(self.explosion_texture) explosion.center_x = (player_ship.center_x + enemy_ship.center_x) / 2 explosion.center_y = player_ship.center_y explosion.update() self.explosions_list.append(explosion) if player_ship.get_hp() <= 0: player_ship.remove_from_sprite_lists() if enemy_ship.get_hp() <= 0: enemy_ship.remove_from_sprite_lists() if enemy_ship.get_hp() < player_ship.get_hp(): self.player_benefit += (1.5 * MONEY_COEFFICIENT - player_ship.cost) /\ MONEY_COEFFICIENT * enemy_ship.cost else: self.enemy_benefit += (1.5 * MONEY_COEFFICIENT - enemy_ship.cost) /\ MONEY_COEFFICIENT * player_ship.cost def check_collisions(self, ships, base: Sprite): for ship in ships: if check_for_collision(ship, base): base.damage(ship.make_damage()) explosion = Explosion(self.explosion_texture) explosion.center_x = base.center_x explosion.center_y = base.center_y explosion.update() self.explosions_list.append(explosion) ship.remove_from_sprite_lists() def check_ships(self, ships): for ship in ships: if ship.get_hp() <= 0: explosion = Explosion(ship.dying_sprite) explosion.center_x = ship.center_x explosion.center_y = ship.center_y explosion.update() self.explosions_list.append(explosion) ship.remove_from_sprite_lists() def add_enemy_ship(self, ship): ship.side = 'enemy' ship.center_x = ENEMY_LOCATION_X ship.center_y = ENEMY_LOCATION_Y ship.change_x = -FIGHTERS_SPEED self.enemy_ships.append(ship) def game_state(self): if self.player_idle > PLAYER_IDLE: return PLAYER_IDLE_NUMBER diff = self.enemy_base.hp - self.player_base.hp return diff + self.estimate_force( self.enemy_ships) - self.estimate_force(self.player_ships) def estimate_force(self, ships): result = 0 for ship in ships: result += ship.cost / COST_COEFFICIENT + ship.get_hp( ) / HP_COEFFICIENT return result def check_end_game(self): if self.player_base.hp <= 0: return 1 elif self.enemy_base.hp <= 0: return 2 return 0
class MyGame(Window): """ Main application class. """ def __init__(self, width, height, title): """ Initializer """ super().__init__(width, height, title) """ Set up the game and initialize the variables. """ # Sprite lists self.char_list = None self.shoot_list = None self.particule_list = None self.background = None self.sky_list = None self.score_list = None self.life_list = None self.ship = None # Set up other settings self.score = 0 self.time = 0 self.frame = 0 self.fps = 0 self.combo = 0 self.life = 3 self.music = None self.music_timer = 0 def setup(self): self.background = SpriteList() self.sky_list = SpriteList() self.particule_list = SpriteList() self.ship_list = SpriteList() self.score_list = SpriteList() self.life_list = SpriteList() # Set up lane 1 ship_texture = [] for i in range(6): ship_texture.append( load_texture(f"qs../ressources/E_Run_{i+1}.png") ) ship = Sprite("../ressources/E_Run_1.png", center_x=SCREEN_WIDTH//10, center_y=SCREEN_HEIGHT//2, scale= 2) self.ship = ship self.ship_list.append(ship) for tier in range(3): background = Background("../ressources/E_Sky_1.png", SCREEN_WIDTH) background.center_y = ((SCREEN_HEIGHT // 3) * tier + 1) + 100 background.center_x = SCREEN_WIDTH // 2 background.change_x = - 2 self.background.append(background) background = Background("../ressources/E_Sky_1.png", SCREEN_WIDTH) background.center_y = ((SCREEN_HEIGHT // 3) * tier + 1) + 100 background.center_x = SCREEN_WIDTH + SCREEN_WIDTH // 2 background.change_x = - 2 self.background.append(background) for tier in range(3): sky = Background("../ressources/E_Sky_2.png", SCREEN_WIDTH) sky.center_y = ((SCREEN_HEIGHT // 3) * tier + 1) + 100 sky.center_x = SCREEN_WIDTH // 2 sky.change_x = - 6 self.sky_list.append(sky) sky = Background("./ressources/E_Sky_2.png", SCREEN_WIDTH) sky.center_y = ((SCREEN_HEIGHT // 3) * tier + 1) + 100 sky.center_x = SCREEN_WIDTH + SCREEN_WIDTH // 2 sky.change_x = - 6 self.sky_list.append(sky) # Set up life system self.life = 3 life_pos = [SCREEN_WIDTH // 2 + 40, SCREEN_HEIGHT - 30] for life_sprite in range(self.life): self.life_list.append(Sprite("../ressources/Life_Orb.png", center_x=life_pos[0], center_y=life_pos[1])) life_pos[0] += 40 # Set up Combo and Score and difficulty self.score_list.append(Sprite("../ressources/Score_Box.png", center_x=700, center_y=560, scale=1.2)) self.score = 0 self.combo = 0 self.time = 0 self.frame = 0 self.fps = 0 def on_draw(self): """ Function to draw the game (on_draw) """ start_render() # Draw all the sprites (order determine Z axis) self.sky_list.draw(filter=GL_NEAREST) self.background.draw(filter=GL_NEAREST) self.particule_list.draw(filter=GL_NEAREST) self.ship_list.draw(filter=GL_NEAREST) self.score_list.draw(filter=GL_NEAREST) self.life_list.draw(filter=GL_NEAREST) # Put the text on the screen. output = f"{self.score}" draw_text(output, 693, 560, color.DARK_RED, 15) combo = f"{self.combo}" draw_text(combo, 693, 542, color.DARK_RED, 15) # Put the fps on the bottom left fps = f"FPS: {self.fps}" draw_text(fps, 730, 10, color.YELLOW, 14) def on_key_press(self, key, modifiers): """ Called whenever a key is pressed. """ if key == arcade.key.UP: self.ship.change_y += 5 elif key == arcade.key.DOWN: self.ship.change_y -= 5 elif key == arcade.key.LEFT: self.ship.change_x -= 5 elif key == arcade.key.RIGHT: self.ship.change_x += 5 elif key == arcade.key.SPACE: particule = Sprite("../ressources/Life_Orb.png", center_x=self.ship.right, center_y=self.ship.center_y) particule.change_x = 3 self.particule_list.append(particule) def on_key_release(self, key, modifiers): """ Called whenever a key is pressed. """ if key == arcade.key.UP: self.ship.change_y = 0 elif key == arcade.key.DOWN: self.ship.change_y = 0 elif key == arcade.key.LEFT: self.ship.change_x = 0 elif key == arcade.key.RIGHT: self.ship.change_x = 0 def on_update(self, delta_time): """ Movement and game logic """ self.time += delta_time self.frame += 1 if self.time >= 1: self.fps = self.frame self.frame = 0 self.time = 0 # Update Sprite_Lists self.sky_list.update() self.background.update() self.score_list.update() self.ship_list.update() self.particule_list.update() self.life_list.update()
class Game(ge.Platformer): """ Simple platformer example """ title = 'KiJogão' player_initial_tile = 4 , 1 player_class = Player game_over = False score = 0 life = 0 output_timer = 0.0 timer = 0.0 def init_world(self): self.world_color = 'yellow' self.player_initial_position = (5, 1.5) self.create_tower(12, 2, coords=(0, 1)) self.create_ground(10, coords=(0, 0), smooth_ends=False) self.create_platform(3, coords=(12,3)) self.create_platform(2, coords=(17,6)) self.create_platform(5, coords=(20,2)) self.create_platform(2, coords=(25,5)) self.create_platform(3, coords=(28,2)) self.create_platform(2, coords=(32,4)) self.create_ground(33, coords=(38, 0), smooth_ends=False) self.create_ground(2, coords=(42, 1)) #inimigo self.create_ground(2, coords=(52, 1)) self.create_ramp('up', 6, coords=(65, 1)) #self.create_platform(2, coords=(69,9)) self.create_platform(1, coords=(72,5)) self.create_platform(10, coords=(75,2)) self.create_ground(10, coords=(90, 0)) #inimigo self.create_tower(12, coords=(100, 0)) def init_enemies(self): self.enemies_list = SpriteList(is_static=True) def create_enemy(x,y): enemy = self.create_object('other/spikes/spikes-high',(x,y)) self.enemies_list.append(enemy) create_enemy(7,1) create_enemy(45,1) create_enemy(48,1) create_enemy(22,2.9) create_enemy(54,1) create_enemy(57,1) create_enemy(60,1) create_enemy(63,1) create_enemy(77,2.9) create_enemy(80,2.9) create_enemy(83,2.9) for i in range(100): create_enemy(i,-3) def init_flag(self): self.flags_list = SpriteList(is_static=True) def create_flag(x,y): flag = self.create_object('other/flag/flagRed_up',(x,y)) self.flags_list.append(flag) create_flag(94,1) def init_coins(self): self.coins_list = SpriteList() def create_coin(x,y): coin = self.create_object('other/items/yellowJewel',(x,y)) self.coins_list.append(coin) create_coin(7,4) create_coin(20,8) create_coin(12,7) create_coin(23,8) create_coin(35,7) create_coin(46,4) create_coin(49,5) create_coin(42,5) create_coin(50,5) create_coin(55,2) create_coin(57,4) create_coin(60,3) create_coin(63,5) create_coin(75,5) create_coin(77,4) create_coin(80,7) create_coin(81,3) def draw_elements(self): super().draw_elements() self.enemies_list.draw() posicaox = self.viewport_horizontal_start + 615 posicaoy = self.viewport_vertical_start +540 output = f"Pontos: {self.score}" arcade.draw_text(output,posicaox ,posicaoy - 20,arcade.color.BLACK,20) minutes = int(self.timer) // 60 seconds = int(self.timer) % 60 self.output_timer = f"Tempo: {minutes:02d}:{seconds:02d}" arcade.draw_text(self.output_timer,posicaox,posicaoy,arcade.color.BLACK,20) output_life = f"Vidas: {self.life}" arcade.draw_text(output_life,posicaox,posicaoy + 20,arcade.color.BLACK,20) if self.game_over: output_game_over = "Game Over" arcade.draw_text(output_game_over,posicaox - 240,posicaoy -300,arcade.color.BLACK,20) def update_collision(self,dt): if not self.game_over: self.enemies_list.update() if len(check_for_collision_with_list(self.player, self.enemies_list)) > 0: if self.life > 0: self.score = 0 self.life -= 1 super().player.player_initial_tile = 4, 1 super().physics_engine else: self.game_over = True self.timerend = self.output_timer arcade.draw_text(self.timerend, self.viewport_horizontal_start - 240,self.viewport_vertical_start -200 ,arcade.color.BLACK,20) print(self.timerend) if len(check_for_collision_with_list(self.player, self.flags_list)) > 0: self.timerend = self.output_timer output_win = "You Win" arcade.draw_text(output_win, self.viewport_horizontal_start - 240,self.viewport_vertical_start -200 ,arcade.color.BLACK,20) #aparecer timer, com o tempo e as vidas o timer tambem arcade.draw_text(self.timerend, self.viewport_horizontal_start - 240,self.viewport_vertical_start - 200,arcade.color.BLACK,20) print(self.timerend) if self.life == 3 : arcade.draw_text("SS", self.viewport_horizontal_start - 240,self.viewport_vertical_start - 200,arcade.color.BLACK,20) elif self.life == 2: arcade.draw_text("Ms", self.viewport_horizontal_start - 240,self.viewport_vertical_start - 200,arcade.color.BLACK,20) elif self.life <= 1: arcade.draw_text("MM", self.viewport_horizontal_start - 240,self.viewport_vertical_start - 200,arcade.color.BLACK,20) hit_coin = check_for_collision_with_list(self.player, self.coins_list) for coin in hit_coin: coin.remove_from_sprite_lists() self.score += 1 if self.score % 5 == 0: self.life += 1 if self.game_over: self.draw_elements() def update(self, dt): super().update(dt) self.update_collision(dt) self.timer += dt def init(self): self.init_world() self.init_flag() self.init_enemies() self.init_coins()