class FlappyDotWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.WHITE) self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.dot_sprite = ModelSprite('images/dot.png', model=self.world.player) self.pillar_pair_sprite = PillarPairSprite( model=self.world.pillar_pair) def update(self, delta): self.world.update(delta) def on_draw(self): arcade.start_render() self.pillar_pair_sprite.draw() self.dot_sprite.draw() def on_key_press(self, key, key_modifiers): if not self.world.is_started(): self.world.start() self.world.on_key_press(key, key_modifiers)
class DotRunWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.GRAY) self.start() def start(self): self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.dot_sprite = ModelSprite('images/dot.png', model=self.world.dot) self.coin_texture = arcade.load_texture('images/coin.png') def update(self, delta): self.world.update(delta) if self.world.is_dead(): self.start() def draw_platforms(self, platforms): for p in platforms: arcade.draw_rectangle_filled(p.x + p.width // 2, p.y - p.height // 2, p.width, p.height, arcade.color.WHITE) def draw_coins(self, coins): for c in coins: if not c.is_collected: arcade.draw_texture_rectangle(c.x, c.y, c.width, c.height, self.coin_texture) def on_draw(self): arcade.set_viewport(self.world.dot.x - SCREEN_WIDTH // 2, self.world.dot.x + SCREEN_WIDTH // 2, 0, SCREEN_HEIGHT) arcade.start_render() self.draw_platforms(self.world.platforms) self.draw_coins(self.world.coins) self.dot_sprite.draw() arcade.draw_text(str(self.world.score), self.world.dot.x + (SCREEN_WIDTH // 2) - 60, self.height - 30, arcade.color.WHITE, 20) def on_key_press(self, key, key_modifiers): if not self.world.is_started(): self.world.start() self.world.on_key_press(key, key_modifiers)
class BualoiWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) arcade.set_background_color(arcade.color.WHITE_SMOKE) self.pan = ModelSprite('images/handpan3.png', model=self.world.pan) self.circle = ModelSprite('images/cir.png', model=self.world.circle) self.spoon = ModelSprite('images/spoon.png', model=self.world.spoon) def on_draw(self): arcade.start_render() self.pan.draw() radius = self.world.bowl.radius color = self.world.bowl.color arcade.draw_circle_filled(self.world.bowl.x, self.world.bowl.y, radius, color) self.circle.draw() self.spoon.draw() self.draw_score() def draw_score(self): arcade.draw_text( 'Score : ' + str(self.world.score), self.width - 150, self.height - 30, arcade.color.BLACK, 20, ) def on_key_press(self, key, key_modifiers): if not self.world.is_started(): self.world.start() if key == arcade.key.SPACE: if self.world.count == 1: self.world.on_key_press(key, key_modifiers) self.world.on_key_press(key, key_modifiers) def on_key_release(self, key, key_modifiers): self.world.on_key_release(key, key_modifiers) def update(self, delta): self.world.update(delta)
class FlappyDotWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.WHITE) self.start() def start(self): self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.dot_sprite = ModelSprite('images/1.png', model=self.world.player) self.pillar_pair_sprites = [ PillarPairSprite(model=self.world.pillar_pairs[0]), PillarPairSprite(model=self.world.pillar_pairs[1]) ] def on_key_press(self, key, key_modifiers): if not self.world.is_started(): self.world.start() self.world.on_key_press(key, key_modifiers) def update(self, delta): self.world.update(delta) if self.world.is_dead(): self.start() def on_draw(self): arcade.start_render() self.dot_sprite.draw() for pillar_pair_sprite in self.pillar_pair_sprites: pillar_pair_sprite.draw() arcade.draw_text(str(self.world.score), self.width - 30, self.height - 30, arcade.color.BLACK, 20)
class BurnWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.score = 0 self.wizard_sprite = ModelSprite('images/Wizard.png', model=self.world.player) self.start_game = ModelSprite('images/Start.jpg', model=self.world.start_game) self.end = ModelSprite('images/End.jpg', model=self.world.end) self.help_button = False self.background = ModelSprite('images/RealBack_1.jpg', model=self.world.background) self.heart = ModelSprite('images/heart.png', model=self.world.heart_life) self.another_heart = ModelSprite('images/heart.png', model=self.world.another_heart) self.fire_1 = ModelSprite('images/fire.png', model=self.world.fire_1) self.fire_2 = ModelSprite('images/fire.png', model=self.world.fire_2) self.fire_3 = ModelSprite('images/fire.png', model=self.world.fire_3) self.another_fire = ModelSprite('images/fire.png', model=self.world.another_fire) self.bonus = ModelSprite('images/Bonus.png', model=self.world.bonus) self.bonus_1 = ModelSprite('images/Bonus_1.png', model=self.world.bonus_1) self.bonus_2 = ModelSprite('images/Bonus_2.png', model=self.world.bonus_2) self.zombie = ModelSprite('images/Zombie.png', model=self.world.zombie) self.grim = ModelSprite('images/Ghost_1.png', model=self.world.grim) self.ghost = ModelSprite('images/Ghost_2.png', model=self.world.ghost) self.witch = ModelSprite('images/Witch.png', model=self.world.witch) self.TinkerBell = ModelSprite('images/Tinker_Bell.png', model=self.world.TinkerBell) self.Ariel = ModelSprite('images/Royal_3.png', model=self.world.Ariel) self.help = ModelSprite('images/Help.jpg', model=self.world.help) def update(self, delta): self.world.update(delta) def on_draw(self): arcade.start_render() if self.world.state == 2: self.background.draw() self.heart.draw() arcade.draw_text(str(self.world.life), 300, 550, arcade.color.BLACK, 20) self.wizard_sprite.draw() self.score = f"Level {self.world.level} : {str(self.world.score) } / {str(self.world.score_reach)}" arcade.draw_text(str(self.score), 20, 550, arcade.color.BLACK, 20) if self.world.level >= 3 and self.world.fire_1.stat == [ True, False, False ]: self.world.another_fire.stat = True self.another_fire.draw() if self.world.level >= 7 and self.world.fire_1.stat == [ True, True, False ]: self.world.another_fire.stat = True self.another_fire.draw() if self.world.life >= 9: self.world.another_heart.stat = False else: self.another_heart.draw() if self.world.fire_1.stat[0]: self.fire_1.draw() if self.world.fire_1.stat[1]: self.fire_2.draw() if self.world.fire_1.stat[2]: self.fire_3.draw() if self.world.bonus_stat: self.bonus_2.draw() arcade.draw_text(str(math.ceil(self.world.bonus_time)), 440, 550, arcade.color.BLACK, 20) else: self.bonus_1.draw() self.bonus.draw() self.zombie.draw() self.grim.draw() self.ghost.draw() self.witch.draw() self.TinkerBell.draw() self.Ariel.draw() elif self.world.state == 3: self.end.draw() arcade.draw_text("Your score: " + str(self.world.score), 220, 345, arcade.color.BLACK, 20, align="center", anchor_x="center", anchor_y="center") else: self.start_game.draw() if self.help_button: self.help.draw() def on_key_press(self, key, key_modifiers): if not self.world.is_started() and key == arcade.key.ENTER: self.world.start() if self.help_button is not True and key == arcade.key.F1: self.help_button = True if self.help_button and key == arcade.key.ESCAPE: self.help_button = False self.world.reset_on_key_press(key, key_modifiers) self.world.fire_on_key_press(key, key_modifiers) self.world.player_on_key_press(key, key_modifiers)
class MazeWindow(arcade.Window): def __init__(self, width, height): self.car_list = [] super().__init__(width, height) self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.background = arcade.load_texture("Wallpaper2.jpg") self.spot_sprite = Spot(100, 50, angle=0) self.spot_sprite.add_texture('car_move.png') self.world.add_car(self.spot_sprite) park_car_list = ['parking_car1.png', 'parking_car2.png'] for i in self.world.car_park: self.car_list.append( ModelSprite(random.choice(park_car_list), model=i)) def update(self, delta): self.world.update(delta) def on_draw(self): arcade.start_render() arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH, SCREEN_HEIGHT, self.background) self.world.spot.draw() if self.world.state != self.world.STATE_FROZEN: arcade.draw_text(f"Time: {self.world.start_time:.0f}", 23, 450, arcade.color.RED, 30) if self.world.state == self.world.STATE_FROZEN: arcade.draw_text(f"CAR PARKING GAME", 210, 440, arcade.color.RED, 30) arcade.draw_text(f"Press any key to start", 180, 30, arcade.color.BLACK, 15) for i in self.car_list: i.draw() if self.world.state == self.world.STATE_DEAD: self.background = arcade.load_texture("Wallpaper2END.jpg") if self.world.start_time < 15: ModelSprite('star_score3.png', model=self.world.win).draw() arcade.draw_text(f"You get 3 star!!!!!", 300, 250, arcade.color.BLUE, 25) elif self.world.start_time < 20: ModelSprite('star_score2.png', model=self.world.win).draw() arcade.draw_text(f"You get 2 star!!!!!", 300, 250, arcade.color.BLUE, 25) elif self.world.start_time > 20: ModelSprite('star_score1.png', model=self.world.win).draw() arcade.draw_text(f"You get 1 star!!!!!", 300, 250, arcade.color.BLUE, 25) arcade.draw_text(f"Thank you for playing", 240, 200, arcade.color.BLUE, 30) arcade.draw_text("Press any key to restart.", 235, 150, arcade.color.BLACK, 30) self.world.die() def restart(self): self.car_list = [] self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.background = arcade.load_texture("Wallpaper2.jpg") self.spot_sprite = Spot(100, 50, angle=0) self.spot_sprite.add_texture('car_move.png') self.world.add_car(self.spot_sprite) park_car_list = ['parking_car1.png', 'parking_car2.png'] for i in self.world.car_park: self.car_list.append( ModelSprite(random.choice(park_car_list), model=i)) def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers) if self.world.state == World.STATE_RESTART: self.restart() if not self.world.is_dead(): self.world.start() def on_key_release(self, key, key_modifiers): self.world.on_key_release(key, key_modifiers)
class Window(arcade.Window): show_credit = False def __init__(self, width, height, title): super().__init__(width, height, title) self.start() self.menu = { 'score': arcade.load_texture( ".././images/Back ground/loser-score-board.png"), 'play': arcade.load_texture(".././images/button/replay.png"), 'credit': arcade.load_texture(".././images/button/credit.png"), 'quit': arcade.load_texture(".././images/button/QuitButton.png") } self.credit_background = arcade.load_texture( ".././images/Back ground/credit.jpg") def start(self): self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.offset = 0 self.credit_offset = 0 self.check_credit = False self.arrows = [] self.fires = [] self.numArrow = 5 self.bottomFires = [] self.background = arcade.load_texture( ".././images/Back ground/sky.jpg") for i in range(self.numArrow): self.arrows.append(ArrowSprite(model=self.world.arrow[i])) self.arrow_sprite = self.arrows for n in range(self.world.fireNumbers): self.fires.append(FireSprite(model=self.world.fire[n])) self.fire_sprite = self.fires for i in range(10): self.bottomFires.append(BottomFire(model=self.world.bottomfire[i])) self.bottomfires_sprite = self.bottomFires self.player_sprite = PlayerSprite(model=self.world.player) def on_key_press(self, key, key_modifiers): if not self.world.is_started(): self.world.start() self.world.on_key_press(key, key_modifiers) def draw_background(self): arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 + self.offset, SCREEN_WIDTH, SCREEN_HEIGHT, self.background) arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, (SCREEN_HEIGHT // 2 + self.offset) - SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, self.background) def draw_lp(self): arcade.draw_rectangle_filled( (self.width - 120) + (100 - self.world.player.lp), 30, self.world.player.lp * 2, 20, arcade.color.CHERRY) def draw_credit(self): self.show_credit = True arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 + self.credit_offset, SCREEN_WIDTH, SCREEN_HEIGHT, self.credit_background) arcade.draw_texture_rectangle( SCREEN_WIDTH // 2, (SCREEN_HEIGHT // 2 + self.credit_offset) - SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, self.credit_background) def update(self, delta): self.world.update(delta) if self.world.is_dead(): self.world.freeze() if self.world.is_started(): self.offset -= 1 self.offset %= SCREEN_HEIGHT if (self.world.arrowNumbers != self.numArrow): self.arrows.append(ArrowSprite(model=self.world.arrow[-1])) self.numArrow = self.world.arrowNumbers if self.check_credit: self.credit_offset += 1 self.credit_offset %= SCREEN_HEIGHT def on_draw(self): arcade.start_render() self.draw_background() for arrow in self.arrow_sprite: arrow.draw() for fire in self.fire_sprite: fire.draw() for bf in self.bottomfires_sprite: bf.draw() arcade.draw_text(str(int(self.world.score)), 25, self.height - 40, arcade.color.BLACK, 20) arcade.draw_text("LP", self.width - 35, 45, arcade.color.BLACK, 10) self.player_sprite.draw() self.draw_lp() if self.world.player.lp == -1: self.draw_gui() def draw_gui(self): texture = self.menu['score'] arcade.draw_texture_rectangle(self.width // 2, self.height // 2 + 200, texture.width, texture.height, texture, 0) arcade.draw_text(str(int(self.world.score)), self.width // 2 - 80, 475, arcade.color.WHITE, 100) texture = self.menu['play'] arcade.draw_texture_rectangle(self.width // 2, self.height // 2, texture.width, texture.height, texture, 0) texture = self.menu['credit'] arcade.draw_texture_rectangle(self.width // 2, self.height // 2 - 200, texture.width, texture.height, texture, 0) texture = self.menu['quit'] arcade.draw_texture_rectangle(self.width - 60, self.height - 55, texture.width, texture.height, texture, 0) if self.check_credit: self.show_credit = True self.draw_credit() def replay(self, x, y): if self.world.player.lp == -1: if self.width // 2 - 205 <= x <= self.width // 2 + 205 and self.height // 2 - 70 <= y <= self.height // 2 + 70: self.start() self.world.start() def credit(self, x, y): if ((self.height // 2) - 200) - (95) <= y <= ( (self.height // 2) - 200) + ( 95) and self.width // 2 - 95 <= x <= self.width // 2 + 95: self.check_credit = True def quit_game(self, x, y): if self.world.player.lp == -1: if self.height - 90 <= y <= self.height - 20 and self.width - 108 <= x <= self.width - 10: exit() def draw_gui_again(self, x, y): if y <= self.height and x <= self.width: self.check_credit = False self.show_credit = False def on_mouse_press(self, x, y, button, modifiers): if not self.show_credit: self.replay(x, y) self.credit(x, y) self.quit_game(x, y) else: self.draw_gui_again(x, y)
class Pirate_Panda_Window(arcade.Window): def __init__(self, width, height): super().__init__(width, height) self.background = arcade.load_texture("pic/image1.png") self.setup() def setup(self): self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.coin = arcade.load_texture('pic/coin.png') self.skull = arcade.load_texture('pic/skull-model.png') self.walk = arcade.load_texture('pic/sandHalf.png') self.panda_sprite = self.panda() self.backsprite = self.back() def back(self): ba = arcade.load_texture("pic/image1.png") return ba def panda(self): if self.world.panda.is_jump == False: panda_sprite = ModelSprite('pic/Panda.png', model=self.world.panda) return panda_sprite if self.world.panda.is_jump == True: panda_sprite = ModelSprite('pic/Panda_Jump2.png', model=self.world.panda) return panda_sprite def reset(self): self.background = arcade.load_texture("pic/image1.png") self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.panda_sprite = ModelSprite('pic/Panda.png', model=self.world.panda) def update(self, delta): self.world.update(delta) self.panda_sprite = self.panda() self.backsprite = self.back() if self.world.panda.die(): self.world.freeze() self.panda_sprite = ModelSprite('pic/Panda_Die.png', model=self.world.panda) self.background = arcade.load_texture("pic/game_over.jpg") def draw_platforms(self, platforms): for p in platforms: arcade.draw_texture_rectangle(p.x + p.width // 2, p.y - p.height // 2, p.width, p.height, self.walk) def draw_coins(self, coins): for c in coins: if not c.is_collected: if c.effect == False: arcade.draw_texture_rectangle(c.x, c.y, c.width, c.height, self.coin) def draw_skulls(self, skulls): for i in skulls: if not i.is_collected: if i.effect == False: arcade.draw_texture_rectangle(i.x, i.y, i.width, i.height, self.skull) def on_draw(self): arcade.set_viewport(self.world.panda.x - SCREEN_WIDTH // 2, self.world.panda.x + SCREEN_WIDTH // 2, 0, SCREEN_HEIGHT) arcade.start_render() arcade.draw_texture_rectangle(self.panda_sprite.center_x, SCREEN_HEIGHT // 2, SCREEN_WIDTH + 50, SCREEN_HEIGHT, self.background) self.draw_platforms(self.world.platforms) self.draw_coins(self.world.coins) arcade.draw_text("Space to Start", -100, self.height // 2, arcade.color.RED, 30) self.panda_sprite.draw() arcade.draw_text(str(self.world.score), self.world.panda.x + (SCREEN_WIDTH // 2) - 890, self.height - 30, arcade.color.BLACK, 20) self.draw_skulls(self.world.skulls) def on_key_press(self, key, key_modifiers): if key == arcade.key.SPACE: if not self.world.is_started(): self.world.start() self.world.on_key_press(key, key_modifiers) if key == arcade.key.R: self.reset()
class MyGame(arcade.Window): def __init__(self, width, height): super().__init__(width, height) self.current_route = routes['menu'] self.selecting_choice = 0 self.car_choice = 1 self.background = arcade.load_texture("images/Background.png") self.cartexture = Car[self.car_choice] self.menu_setup() self.car_setup() self.game_setup(width,height) def menu_setup(self): self.choice_list = arcade.SpriteList() self.start = MenuChoiceSprite() self.start.textures.append(arcade.load_texture("images/start.png")) self.start.textures.append(arcade.load_texture("images/start1.png")) self.start.set_texture(0) self.start.texture_change_frames = 10 self.car = MenuChoiceSprite() self.car.textures.append(arcade.load_texture("images/car.png")) self.car.textures.append(arcade.load_texture("images/car1.png")) self.car.set_texture(1) self.car.texture_change_frames = 10 self.exit = MenuChoiceSprite() self.exit.textures.append(arcade.load_texture("images/exit.png")) self.exit.textures.append(arcade.load_texture("images/exit1.png")) self.exit.set_texture(1) self.exit.texture_change_frames = 10 self.start.center_x,self.start.center_y = self.width//2,self.height//2 +50 self.car.center_x,self.car.center_y = self.width//2,self.height//2 -20 self.exit.center_x,self.exit.center_y = self.width//2,self.height//2 -90 self.start.select() self.choice_list.append(self.start) self.choice_list.append(self.car) self.choice_list.append(self.exit) def car_setup(self): self.car_choice_list = arcade.SpriteList() self.car_show = arcade.Sprite(Car[self.car_choice]) self.car_show.set_position(self.width//2,self.height//2 +50) def game_setup(self, width, height): self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.background_sprite = ModelSprite("images/Background.png", model=self.world.background) self.background_sprite2 = ModelSprite("images/Background.png", model=self.world.background2) self.car_sprite = ModelSprite(self.cartexture, model=self.world.car) self.enemylist = [] self.fpscounter = Fpscounter() self.set_update_rate(1/70) def car_sprite_selected(self): self.car_sprite = ModelSprite(self.cartexture, model=self.world.car) def draw_menu(self): self.choice_list.draw() def draw_car_menu(self): self.car_show.draw() def update(self, delta): if self.current_route == routes['menu']: for choice in self.choice_list: if choice.is_select == True: choice.update() choice.update_animation() elif self.current_route == routes['car']: self.draw_car_menu() elif self.current_route == routes['exit']: sys.exit() elif self.current_route == routes['game']: self.creteenemy() self.update_enemylist() self.world.update(delta) def on_draw(self): arcade.start_render() arcade.draw_texture_rectangle(self.width//2 , self.height//2 ,self.width, self.height,self.background) if self.current_route == routes['menu']: self.draw_menu() elif self.current_route == routes['car']: self.car_setup() self.draw_car_menu() elif self.current_route == routes['game']: self.car_sprite_selected() self.background_sprite.draw() self.background_sprite2.draw() self.car_sprite.draw() self.fpscounter.tick() self.check_state() fps = f"fps{self.fpscounter.fps():.2f}" score = f"Score {self.world.score}" arcade.draw_text(score,670,770,arcade.color.DARK_CANDY_APPLE_RED,24) arcade.draw_text(fps,750,560,arcade.color.BLACK) for enemy in self.enemylist: enemy.draw() def update_selected_choice(self): for choice in self.choice_list: choice.unselect() choice.set_texture(1) self.choice_list[self.selecting_choice].select() def on_key_press(self, key, key_modifiers): if self.current_route == routes['menu']: if key == arcade.key.DOWN: if self.selecting_choice < 2: self.selecting_choice += 1 else: self.selecting_choice = 0 self.update_selected_choice() press_sound = arcade.load_sound("soundtrack/pressmusic.wav") arcade.play_sound(press_sound) elif key == arcade.key.UP: if self.selecting_choice > 0 : self.selecting_choice -= 1 else: self.selecting_choice = 2 self.update_selected_choice() press_sound = arcade.load_sound("soundtrack/pressmusic.wav") arcade.play_sound(press_sound) elif key == arcade.key.ENTER: self.current_route = routes[choices[self.selecting_choice]] elif self.current_route == routes['car']: if key == arcade.key.RIGHT: if self.car_choice < 6: self.car_choice += 1 else: self.car_choice = 0 elif key == arcade.key.LEFT: if self.car_choice > 0: self.car_choice -= 1 else: self.car_choice = 4 elif key == arcade.key.ENTER: self.cartexture = Car[self.car_choice] self.current_route = routes['menu'] elif self.current_route == routes['game']: self.world.on_key_press(key, key_modifiers) if not self.world.is_dead(): self.world.start() elif key == arcade.key.R and self.world.state == World.STATE_DEAD: self.game_setup(SCREEN_WIDTH,SCREEN_HEIGHT) elif key == arcade.key.M and self.world.state == World.STATE_DEAD: self.current_route = routes['menu'] self.draw_menu() self.game_setup(SCREEN_WIDTH,SCREEN_HEIGHT) def on_key_release(self, key, key_modifiers): if self.current_route == routes['game']: self.world.on_key_release(key, key_modifiers) def creteenemy(self): for enemy in self.world.enemylist: if enemy in (enemy_sprite.model for enemy_sprite in self.enemylist): pass else: self.enemylist.append(ModelSprite(self.randomsprite(), model=enemy)) def randomsprite(self): enemyspritelist = ['images/EnemyCar2.png','images/Enemycarwhite.png','images/redcar.png','images/pinkcar.png'] randomnum = randint(0,3) return enemyspritelist[randomnum] def update_enemylist(self): for enemy_sprite in [_ for _ in self.enemylist]: if enemy_sprite.model not in self.world.enemylist: self.enemylist.remove(enemy_sprite) def draw_game_over(self): output = f"Score {self.world.score}" arcade.draw_text(output, 285, 500, arcade.color.BALL_BLUE, 54) output = "Game Over" arcade.draw_text(output, 225, 400, arcade.color.BALL_BLUE, 54) output = "Press R to restart" arcade.draw_text(output, 280, 300, arcade.color.BALL_BLUE, 24) output = "Press M to mainmenu" arcade.draw_text(output,250,230,arcade.color.BALL_BLUE, 24) def check_state(self): if self.world.state == World.STATE_DEAD: self.draw_game_over()
class GameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height, title="Throw your knives!") self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.knife_sprite = None self.knife_sprite2 = None self.knife_sprite3 = None self.knife_sprite4 = None self.knife_sprite5 = None self.knife_sprite6 = None self.knife_sprite7 = None self.knife_sprite8 = None self.knife_sprite9 = None self.knife_sprite10 = None self.target_sprite = ModelSprite('images/target.png', model=self.world.target) self.total_time = 0.0 def setup(self): arcade.set_background_color(arcade.color.BLACK) self.total_time = 0.0 self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.knife_sprite = ModelSprite('images/knife.png', model=self.world.knife) self.knife_sprite2 = ModelSprite('images/knife.png', model=self.world.knife2) self.knife_sprite3 = ModelSprite('images/knife.png', model=self.world.knife3) self.knife_sprite4 = ModelSprite('images/knife.png', model=self.world.knife4) self.knife_sprite5 = ModelSprite('images/knife.png', model=self.world.knife5) self.knife_sprite6 = ModelSprite('images/knife.png', model=self.world.knife6) self.knife_sprite7 = ModelSprite('images/knife.png', model=self.world.knife7) self.knife_sprite8 = ModelSprite('images/knife.png', model=self.world.knife8) self.knife_sprite9 = ModelSprite('images/knife.png', model=self.world.knife9) self.knife_sprite10 = ModelSprite('images/knife.png', model=self.world.knife10) self.target_sprite = ModelSprite('images/target.png', model=self.world.target) def update(self, delta): self.world.update(delta) self.total_time += delta def on_draw(self): arcade.start_render() self.target_sprite.draw() if self.world.is_menued(): start = "Press P to start" intruction = "Press Spacebar to throw a knife" caution = "Don't hit other knives on the target" arcade.draw_text("Throw your knives !" + "\n" + start + "\n" + intruction + "\n" + caution, 400, 500, arcade.color.WHITE, 18, align="center", anchor_x="center", anchor_y="center") if self.world.is_started(): minutes = int(self.total_time) // 60 seconds = int(self.total_time) % 60 timer = f"Timer: {minutes:02d}:{seconds:02d}" arcade.draw_text("Press P to pause" + "\n" + "Press R to restart" + "\n" + "Score: " + str(self.world.score) + "\n" + timer, 400, 500, arcade.color.WHITE, 18, align="center", anchor_x="center", anchor_y="center") self.knife_sprite.draw() self.knife_sprite2.draw() self.knife_sprite3.draw() self.knife_sprite4.draw() self.knife_sprite5.draw() self.knife_sprite6.draw() self.knife_sprite7.draw() self.knife_sprite8.draw() self.knife_sprite9.draw() self.knife_sprite10.draw() if self.world.is_frozened(): start = "Press P to play" intruction = "Press Spacebar to throw a knife" caution = "Don't hit other knives on the target" arcade.draw_text("Paused" + "\n" + start + "\n" + intruction + "\n" + caution, 400, 500, arcade.color.WHITE, 18, align="center", anchor_x="center", anchor_y="center") if self.world.is_overed(): minutes = int(self.total_time) // 60 seconds = int(self.total_time) % 60 timer = f"Timer: {minutes:02d}:{seconds:02d}" arcade.draw_text("Game Over" + "\n" + "Press P to play again" + "\n" + "Score: " + str(self.world.score - 1), 400, 500, arcade.color.WHITE, 18, align="center", anchor_x="center", anchor_y="center") if self.world.is_win(): minutes = int(self.total_time) // 60 seconds = int(self.total_time) % 60 timer = f"Timer: {minutes:02d}:{seconds:02d}" arcade.draw_text("You win !!" + "\n" + "Press P to play again" + "\n" + "Score: " + str(self.world.score), 400, 500, arcade.color.WHITE, 18, align="center", anchor_x="center", anchor_y="center") def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers) if key == arcade.key.P: if self.world.state == self.world.STATE_MENU: self.setup() self.world.start() elif self.world.state == self.world.STATE_STARTED: self.world.freeze() elif self.world.state == self.world.STATE_FROZEN: self.world.start() elif self.world.state == self.world.STATE_OVER: self.setup() self.world.start() elif self.world.state == self.world.STATE_WIN: self.setup() self.world.start() if key == arcade.key.R: if self.world.state == self.world.STATE_STARTED: self.setup() self.world.start() def on_mouse_press(self, x, y, button, modifiers): self.world.on_mouse_press(x, y, button, modifiers)