class SnakeWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) # self.snake_sprite = arcade.Sprite('images/block.png') # we use class Model sprite instead for collect image data. # self.snake_sprite = ModelSprite('images/block.png', # model=self.world.snake) # self.snake_sprite.set_position(300, 300) self.snake_sprite = SnakeSprite(self.world.snake) self.heart_sprite = ModelSprite('images/heart.png', model=self.world.heart) arcade.set_background_color(arcade.color.BLACK) # create update for update in world class. def update(self, delta): self.world.update(delta) # draw sprite def on_draw(self): arcade.start_render() self.snake_sprite.draw() self.heart_sprite.draw() def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers)
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 SpaceGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.PINK) self.world = World(width, height) self.ship_sprite = ModelSprite('images/ship.png', model=self.world.ship) self.gold_sprite = ModelSprite('images/gold.png', model=self.world.gold) self.asteroid_sprites = [] for asteroid in self.world.asteroids: self.asteroid_sprites.append( ModelSprite('images/ship.png', scale=0.5, model=asteroid)) def on_draw(self): arcade.start_render() self.ship_sprite.draw() self.gold_sprite.draw() for sprite in self.asteroid_sprites: sprite.draw() arcade.draw_text(str(self.world.score), self.width - 60, self.height - 60, arcade.color.BLACK, 20) def animate(self, delta): self.world.animate(delta) def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers)
class MazeWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.BLACK) self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT, BLOCK_SIZE) self.pacman_sprite = ModelSprite('images/pacman.png', model=self.world.pacman) self.maze_drawer = MazeDrawer(self.world.maze) def update(self, delta): self.world.update(delta) def on_draw(self): arcade.start_render() self.maze_drawer.draw() self.pacman_sprite.draw() arcade.draw_text(str(self.world.score), self.width - 60, self.height - 30, arcade.color.WHITE, 20) def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers)
class SpaceGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.BLACK) self.world = World(width, height) self.ship_sprite = ModelSprite('images/ship.png', model=self.world.ship) self.gold_sprite = ModelSprite('images/gold.png', model=self.world.gold) def on_draw(self): arcade.start_render() self.gold_sprite.draw() self.ship_sprite.draw() arcade.draw_text(str(self.world.score), self.width - 30, self.height - 30, arcade.color.WHITE, 20) def update(self, delta): self.world.update(delta) #--self.ship_sprite.set_position(self.world.ship.x, self.world.ship.y) def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers)
class WallRunnerGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.AMAZON) self.current_state = GAME_RUNNING self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.man_sprite = ModelSprite('images/man.png', model=self.world.man) self.rip_sprite = ModelSprite('images/rip.png', model=self.world.man) self.heart_sprite = ModelSprite('images/heart.png', model=self.world.heart) self.rock_sprites = [] for rock in self.world.rocks: self.rock_sprites.append(ModelSprite('images/rock.png', model=rock)) def animate(self, delta): self.world.animate(delta) if (self.world.hp <= 0): self.current_state = GAME_OVER def game_over_screen(self): self.rip_sprite.draw() arcade.draw_text("YOU DEAD!", self.width / 2 - 105, self.height / 2 + 100, arcade.color.BLACK, 30) arcade.draw_text("SURVIVE TIME : " + str(int(self.world.time)), self.width / 2 - 170, self.height / 2, arcade.color.BLACK, 30) def on_draw(self): arcade.start_render() if (self.current_state == GAME_RUNNING): self.heart_sprite.draw() for sprite in self.rock_sprites: sprite.draw() self.man_sprite.draw() arcade.draw_text("SURVIVE TIME : " + str(int(self.world.time)), self.width - 260, self.height - 40, arcade.color.BURNT_SIENNA, 20) arcade.draw_text("HP : " + str(self.world.hp), self.width - 570, self.height - 40, arcade.color.BURNT_SIENNA, 20) else: self.game_over_screen() def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers)
class SpaceGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color((55,71,79)) self.world = World(width,height) self.ship_sprite = ModelSprite('assets/images/rocket.png',model=self.world.ship) def on_draw(self): arcade.start_render() self.ship_sprite.draw() def update(self, delta): self.world.update(delta) def on_key_press(self, key, key_modifiers): 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 SpaceGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.LEMON_MERINGUE) self.world = World(width, height) self.sheep_sprite = ModelSprite('images/sheep.png', 0.13, model=self.world.sheep) self.grass_sprite = ModelSprite('images/grass.png', 0.1, model=self.world.grass) self.enemy = [] for i in self.world.enemy: self.enemy.append(ModelSprite('images/wolf.png', 0.13, model=i)) self.bush_sprite = ModelSprite('images/bush.png', 0.4, model=self.world.bush) def on_key_press(self, key, key_modifiers): if self.world.status == 0: self.world.on_key_press(key, key_modifiers) def update(self, delta): if self.world.status == 0: self.world.update(delta) for i in self.world.tmpenemy: self.enemy.append(ModelSprite('images/wolf.png', 0.15, model=i)) self.world.tmpenemy = [] def on_draw(self): arcade.start_render() if self.world.status == 0: self.sheep_sprite.draw() self.grass_sprite.draw() for i in self.enemy: i.draw() self.bush_sprite.draw() arcade.draw_text(str(self.world.score), self.width - 50, self.height - 50, arcade.color.GRAY, 40) arcade.draw_text("<- Hide here! ", 240, 40, arcade.color.GRAY, 30) if self.world.status == 1: arcade.draw_text("GAME OVER", self.width // 2 - 250, self.height // 2 + 20, arcade.color.GRAY, 80) arcade.draw_text("score : {}".format(self.world.score), self.width // 2 - 80, self.height // 2 - 50, arcade.color.GRAY, 40)
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 SpaceGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.BLACK) self.world = World(width, height) self.worldRenderer = WorldRenderer(width, height, self.world) def on_draw(self): arcade.start_render() self.worldRenderer.on_draw() # self.bg.draw() def animate(self, delta): self.world.animate(delta) def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers)
class MazeWindow(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.spot_sprite = ModelSprite('pacman.png', model=self.world.spot) def update(self, delta): self.world.update(delta) def on_draw(self): arcade.start_render() self.spot_sprite.draw() def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers)
class SpaceGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.BLACK) self.world = World(width, height) self.ship_sprite = ModelSprite('images/ship.png', model=self.world.ship) self.gold_sprite = ModelSprite('images/gold.png',model=self.world.gold) def on_draw(self): arcade.start_render() self.gold_sprite.draw() self.ship_sprite.draw() def animate(self, delta): self.world.animate(delta) def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers)
class SnakeWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.BLACK) self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.snake_sprite = SnakeSprite(self.world.snake) self.heart_sprite = ModelSprite('images/heart.png', model=self.world.heart) def update(self, delta): self.world.update(delta) def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers) def on_draw(self): arcade.start_render() self.snake_sprite.draw() self.heart_sprite.draw()
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 MazeWindow(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.pacman_sprite = ModelSprite('images/pacman.png', model=self.world.pacman) self.maze_drawer = MazeDrawer(self.world.maze) def update(self, delta): self.world.update(delta) def on_draw(self): arcade.start_render() # make sure you call this before drawing pacman sprite self.maze_drawer.draw() self.pacman_sprite.draw() def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers)
class SpaceGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.BLACK) self.world = World(width, height) self.ship_sprite = ModelSprite('images/sword.png', model=self.world.ship) self.gold_sprite = ModelSprite('images/monster.png', model=self.world.gold) for i in range(n): circle = Circle(self.world, randint(100, SCREEN_WIDTH - 100), randint(100, SCREEN_HEIGHT - 100), randint(-5, 5), randint(-5, 5), randint(10, 20)) circles.append(circle) def on_draw(self): arcade.start_render() self.gold_sprite.draw() self.ship_sprite.draw() for c in circles: c.move() c.draw() if self.world.ship.is_hit(c): self.world.ship.restart() arcade.draw_text(str(self.world.score), self.width - 30, self.height - 30, arcade.color.WHITE, 20) def update(self, delta): self.world.update(delta) def on_key_press(self, key, key_modifiers): self.world.on_key_press(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 RoomWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height,'Caught in a lie') self.world = World(SCREEN_WIDTH,SCREEN_HEIGHT) self.spy_sprite = SpySprite(self.world.spy) self.security_sprite1 = SecureSprite(self.world.secure) self.security_sprite2 = SecureSprite(self.world.secure2) self.security_sprite3 = SecureSprite(self.world.secure3) self.security_sprite4 = SecureSprite(self.world.secure4) self.background = arcade.load_texture("images/bg.png") self.background2 = arcade.load_texture("images/bg2.png") self.background3 = arcade.load_texture("images/bg3.png") self.bulldog1 = ModelSprite('images/bulldog.png',model = self.world.brain1) self.bulldog2 = ModelSprite('images/bulldog.png',model = self.world.brain2) self.bulldog3 = ModelSprite('images/bulldog.png',model = self.world.brain3) self.bulldog4 = ModelSprite('images/bulldog.png',model = self.world.brain4) self.scoreCheck = False self.gg = arcade.create_text("Game over", arcade.color.BLACK, 50) self.time_elapsed = 3 self.t9 = arcade.create_text("Time to Lie: {:d}".format(self.time_elapsed), arcade.color.BLACK, 25) self.timePerround = 0 self.tt = arcade.create_text("Time per round: {:d}".format(self.timePerround), arcade.color.BLACK, 25) self.tl = arcade.create_text("Life: {:d}".format(self.world.gg), arcade.color.BLACK, 25) def update(self, delta): self.world.update(delta) if self.world.count % 60 == 0: self.time_elapsed -= 1 if self.spy_sprite.sp.state == self.spy_sprite.sp.STATE_RUN: self.time_elapsed = 3 if self.world.tpr % 60 == 0: self.timePerround += 1 if self.spy_sprite.sp.x == 0: self.timePerround = 0 def on_draw(self): arcade.start_render() if self.world.gg > 0: if self.world.mode == 1: arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2,SCREEN_WIDTH, SCREEN_HEIGHT, self.background) elif self.world.mode == 2: arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2,SCREEN_WIDTH, SCREEN_HEIGHT, self.background2) self.spy_sprite.draw() if self.security_sprite1.sc.type == self.security_sprite1.sc.ORDINARY: self.bulldog1 = ModelSprite('images/bulldog.png',model = self.world.brain1) self.bulldog1.draw() else: self.bulldog1 = ModelSprite('images/brain.png',model = self.world.brain1) self.bulldog1.draw() self.security_sprite1.draw() if self.security_sprite2.sc.type == self.security_sprite2.sc.ORDINARY: self.bulldog2 = ModelSprite('images/bulldog.png',model = self.world.brain2) self.bulldog2.draw() else: self.bulldog2 = ModelSprite('images/brain.png',model = self.world.brain2) self.bulldog2.draw() self.security_sprite2.draw() if self.security_sprite3.sc.type == self.security_sprite3.sc.ORDINARY: self.bulldog3 = ModelSprite('images/bulldog.png',model = self.world.brain3) self.bulldog3.draw() else: self.bulldog3 = ModelSprite('images/brain.png',model = self.world.brain3) self.bulldog3.draw() self.security_sprite3.draw() if self.security_sprite4.sc.type == self.security_sprite4.sc.ORDINARY: self.bulldog4 = ModelSprite('images/bulldog.png',model = self.world.brain4) self.bulldog4.draw() else: self.bulldog4 = ModelSprite('images/brain.png',model = self.world.brain4) self.bulldog4.draw() self.security_sprite4.draw() xx = 100 yy = 370 text = "Score : {:d}".format(int(self.spy_sprite.sp.score/2)) self.t8 = arcade.create_text(text, arcade.color.LAVENDER, 18) arcade.render_text(self.t8, xx, yy) text = "Time to Lie: {:d}".format(int(self.time_elapsed)) if text != self.t9.text: self.t9 = arcade.create_text(text, arcade.color.BLACK, 25) arcade.render_text(self.t9, 384, 250) text2 = "Time per round: {:d}".format(int(self.timePerround)) if text2 != self.tt.text: self.tt = arcade.create_text(text2, arcade.color.BLACK, 25) arcade.render_text(self.tt, 84, 300) textt = "Life : {:d}".format(self.world.gg) self.t7 = arcade.create_text(textt, arcade.color.BLACK, 25) arcade.render_text(self.t7, 84, 200) else: arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2,SCREEN_WIDTH, SCREEN_HEIGHT, self.background3) f = open('highscore.log', 'r') highscore = f.readline() if int(self.spy_sprite.sp.score/2) > int(highscore) or self.scoreCheck: self.scoreCheck = True arcade.draw_text('New Highscore!', 500, 200, arcade.color.BLACK, 30) f = open('highscore.log', 'w') f.write(str(int(self.spy_sprite.sp.score/2))) else: arcade.draw_text('Highscore: ' + highscore, 500, 200, arcade.color.BLACK, 30) start_x = 500 start_y = 250 arcade.render_text(self.gg,start_x,start_y) text = "Score : {:d}".format(int(self.spy_sprite.sp.score/2)) self.score = arcade.create_text(text, arcade.color.BLACK, 30) arcade.render_text(self.score, start_x, start_y-100) arcade.set_background_color(arcade.color.CHARCOAL) def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers)
class GameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) self.bgm_sound = arcade.sound.load_sound("sounds/bgm.mp3") arcade.sound.play_sound(self.bgm_sound) self.setup(width, height) def setup(self, width, height): arcade.set_background_color(arcade.color.GREEN) self.world = World(width, height) self.me_sprite = ModelSprite('images/Me.png', model=self.world.me) self.her_sprite = ModelSprite('images/Her.png', model=self.world.her) self.vega_sprite = ModelSprite('images/Orange.png', model=self.world.vega) self.vegb_sprite = ModelSprite('images/Banana.png', model=self.world.vegb) self.vegc_sprite = ModelSprite('images/Grape.png', model=self.world.vegc) self.vegd_sprite = ModelSprite('images/Watermelon.png', model=self.world.vegd) self.vege_sprite = ModelSprite('images/Strawberry.png', model=self.world.vege) self.shovel_sprite = ModelSprite('images/Shovel.png', model=self.world.shovel) self.trash_sprite = ModelSprite('images/Trash.png', model=self.world.trash) self.wateringcan_sprite = ModelSprite('images/WateringCan.png', model=self.world.wateringcan) self.shop_sprite = ModelSprite('images/Shop.png', model=self.world.shop) self.plant1_texture = arcade.load_texture('images/Plant1.png') self.plant2_texture = arcade.load_texture('images/Plant2.png') self.grass_texture = arcade.load_texture('images/Grass.png') self.vega_texture = arcade.load_texture('images/Orange.png') self.vegb_texture = arcade.load_texture('images/Banana.png') self.vegc_texture = arcade.load_texture('images/Grape.png') self.vegd_texture = arcade.load_texture('images/Watermelon.png') self.vege_texture = arcade.load_texture('images/Strawberry.png') self.soil_texture = arcade.load_texture('images/Soil.png') self.shovel_texture = arcade.load_texture('images/Shovel.png') self.wateringcan_texture = arcade.load_texture( 'images/WateringCan.png') self.deadplant_texture = arcade.load_texture('images/DeadPlant.png') self.ground_texture = arcade.load_texture('images/Ground.png') self.ground2_texture = arcade.load_texture('images/Ground2.png') self.ground3_texture = arcade.load_texture('images/Ground3.png') def draw_me_state(self): if self.world.me.STATE == 'a': arcade.draw_texture_rectangle(self.world.me.x, self.world.me.y + 20, 10, 10, self.vega_texture) arcade.draw_texture_rectangle(380, 50, 75, 75, self.vega_texture) if self.world.me.STATE == 'a2': arcade.draw_texture_rectangle(self.world.me.x, self.world.me.y + 20, 30, 30, self.vega_texture) arcade.draw_texture_rectangle(380, 50, 75, 75, self.vega_texture) if self.world.me.STATE == 'b': arcade.draw_texture_rectangle(self.world.me.x, self.world.me.y + 20, 10, 10, self.vegb_texture) arcade.draw_texture_rectangle(380, 50, 75, 75, self.vegb_texture) if self.world.me.STATE == 'b2': arcade.draw_texture_rectangle(self.world.me.x, self.world.me.y + 20, 30, 30, self.vegb_texture) arcade.draw_texture_rectangle(380, 50, 75, 75, self.vegb_texture) if self.world.me.STATE == 'c': arcade.draw_texture_rectangle(self.world.me.x, self.world.me.y + 20, 10, 10, self.vegc_texture) arcade.draw_texture_rectangle(380, 50, 75, 75, self.vegc_texture) if self.world.me.STATE == 'c2': arcade.draw_texture_rectangle(self.world.me.x, self.world.me.y + 20, 30, 30, self.vegc_texture) arcade.draw_texture_rectangle(380, 50, 75, 75, self.vegc_texture) if self.world.me.STATE == 'd': arcade.draw_texture_rectangle(self.world.me.x, self.world.me.y + 20, 10, 10, self.vegd_texture) arcade.draw_texture_rectangle(380, 50, 75, 75, self.vegd_texture) if self.world.me.STATE == 'd2': arcade.draw_texture_rectangle(self.world.me.x, self.world.me.y + 20, 30, 30, self.vegd_texture) arcade.draw_texture_rectangle(380, 50, 75, 75, self.vegd_texture) if self.world.me.STATE == 'e': arcade.draw_texture_rectangle(self.world.me.x, self.world.me.y + 20, 10, 10, self.vege_texture) arcade.draw_texture_rectangle(380, 50, 75, 75, self.vege_texture) if self.world.me.STATE == 'e2': arcade.draw_texture_rectangle(self.world.me.x, self.world.me.y + 20, 30, 30, self.vege_texture) arcade.draw_texture_rectangle(380, 50, 75, 75, self.vege_texture) if self.world.me.STATE == 's': arcade.draw_texture_rectangle(self.world.me.x, self.world.me.y + 20, 20, 20, self.shovel_texture) arcade.draw_texture_rectangle(380, 50, 75, 75, self.shovel_texture) if self.world.me.STATE == 'w': arcade.draw_texture_rectangle(self.world.me.x, self.world.me.y + 20, 20, 20, self.wateringcan_texture) arcade.draw_texture_rectangle(380, 50, 75, 75, self.wateringcan_texture) def draw_soils_state(self): for s in self.world.soils: arcade.draw_texture_rectangle(s.x, s.y, 50, 50, self.soil_texture) if s.plant_dead == True: s.watered = False arcade.draw_texture_rectangle(s.x, s.y, 15, 15, self.deadplant_texture) elif s.STATE == 'a': arcade.draw_texture_rectangle(s.x, s.y, 15, 15, self.plant1_texture) elif s.STATE == 'a2': arcade.draw_texture_rectangle(s.x, s.y, 20, 20, self.plant2_texture) elif s.STATE == 'a3': arcade.draw_texture_rectangle(s.x, s.y, 30, 30, self.vega_texture) elif s.STATE == 'b': arcade.draw_texture_rectangle(s.x, s.y, 15, 15, self.plant1_texture) elif s.STATE == 'b2': arcade.draw_texture_rectangle(s.x, s.y, 20, 20, self.plant2_texture) elif s.STATE == 'b3': arcade.draw_texture_rectangle(s.x, s.y, 30, 30, self.vegb_texture) elif s.STATE == 'c': arcade.draw_texture_rectangle(s.x, s.y, 15, 15, self.plant1_texture) elif s.STATE == 'c2': arcade.draw_texture_rectangle(s.x, s.y, 20, 20, self.plant2_texture) elif s.STATE == 'c3': arcade.draw_texture_rectangle(s.x, s.y, 30, 30, self.vegc_texture) elif s.STATE == 'd': arcade.draw_texture_rectangle(s.x, s.y, 15, 15, self.plant1_texture) elif s.STATE == 'd2': arcade.draw_texture_rectangle(s.x, s.y, 20, 20, self.plant2_texture) elif s.STATE == 'd3': arcade.draw_texture_rectangle(s.x, s.y, 30, 30, self.vegd_texture) elif s.STATE == 'e': arcade.draw_texture_rectangle(s.x, s.y, 15, 15, self.plant1_texture) elif s.STATE == 'e2': arcade.draw_texture_rectangle(s.x, s.y, 20, 20, self.plant2_texture) elif s.STATE == 'e3': arcade.draw_texture_rectangle(s.x, s.y, 30, 30, self.vege_texture) timer = s.timer if s.timer_on == True: seconds2 = int(timer) % 60 output2 = "{:02d}".format(seconds2) arcade.draw_text(output2, s.x - 5, s.y + 25, arcade.color.WHITE, 10) timer2 = s.timer2 if s.timer2_on == True: seconds3 = int(timer2) % 60 output3 = "{:02d}".format(seconds3) arcade.draw_text(output3, s.x - 5, s.y + 25, arcade.color.WHITE, 10) def on_draw(self): arcade.start_render() arcade.draw_texture_rectangle(425, 325, 850, 650, self.grass_texture) arcade.draw_texture_rectangle(275, 575, 550, 50, self.ground3_texture) arcade.draw_texture_rectangle(25, 325, 50, 450, self.ground2_texture) arcade.draw_texture_rectangle(445, 50, 900, 100, self.ground_texture) arcade.draw_texture_rectangle(700, 575, 300, 50, self.ground_texture) self.draw_soils_state() self.shovel_sprite.draw() self.wateringcan_sprite.draw() self.trash_sprite.draw() self.vega_sprite.draw() self.vegb_sprite.draw() self.vegc_sprite.draw() self.vegd_sprite.draw() self.vege_sprite.draw() self.shop_sprite.draw() self.her_sprite.draw() self.me_sprite.draw() self.draw_me_state() minutes = int(self.world.total_time) // 60 seconds = int(self.world.total_time) % 60 money = int(self.world.me.MONEY) strawberry = int(self.world.me.STRAWBERRY_GIVEN) output = "Time: {:02d}:{:02d}".format(minutes, seconds) moneyShow = "Money: {:02d}".format(money) output2 = "Current Equipment :" strawberryshow = "Strawberries Given: {:d}/3".format(strawberry) arcade.draw_text("Cost: 50", 100, 585, arcade.color.WHITE, 10) arcade.draw_text("Cost: 100", 200, 585, arcade.color.WHITE, 10) arcade.draw_text("Cost: 200", 300, 585, arcade.color.WHITE, 10) arcade.draw_text("Cost: 300", 400, 585, arcade.color.WHITE, 10) arcade.draw_text("Cost: 500", 500, 585, arcade.color.WHITE, 10) arcade.draw_text("Sell: 75", 100, 555, arcade.color.WHITE, 10) arcade.draw_text("Sell: 150", 200, 555, arcade.color.WHITE, 10) arcade.draw_text("Sell: 275", 300, 555, arcade.color.WHITE, 10) arcade.draw_text("Sell: 400", 400, 555, arcade.color.WHITE, 10) arcade.draw_text("Sell: 625", 500, 555, arcade.color.WHITE, 10) arcade.draw_text(output, 560, 565, arcade.color.WHITE, 20) arcade.draw_text(moneyShow, 700, 565, arcade.color.WHITE, 20) arcade.draw_text(output2, 75, 40, arcade.color.WHITE, 20) arcade.draw_text(strawberryshow, 525, 40, arcade.color.WHITE, 20) if self.world.END_STATE == 1: arcade.draw_text("Game Over", 250, 450, arcade.color.WHITE, 30) arcade.draw_text("Press Space Bar to Restart", 250, 250, arcade.color.WHITE, 30) Eminutes = int(self.world.end_time) // 60 Eseconds = int(self.world.end_time) % 60 endtime = "Time Spent: {:02d}:{:02d}".format(Eminutes, Eseconds) arcade.draw_text(endtime, 250, 350, arcade.color.WHITE, 30) def animate(self, delta): if self.world.END_STATE == 0: self.world.animate(delta) def on_key_press(self, 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) if self.world.END_STATE == 1 and key == arcade.key.SPACE: self.setup(850, 600)
class AHwindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.BLACK) self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.board = ModelSprite('board.png', model=self.world.board) self.board.set_position(width // 2, height // 2) self.puck = ModelSprite('puck.png', model=self.world.puck) self.puck.set_position(width // 2, height // 2) self.player1 = ModelSprite('player1.png', model=self.world.player1) self.player1.set_position(100, height // 2) self.player2 = ModelSprite('player2.png', model=self.world.player2) self.player2.set_position(width - 100, height // 2) def on_key_press(self, 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 on_draw(self): arcade.start_render() self.board.draw() self.puck.draw() self.player1.draw() self.player2.draw() arcade.render_text(self.world.scoreboard, SCREEN_WIDTH // 2, 83.5 // 2) if self.world.end == True: if self.world.player1_score > self.world.player2_score: arcade.render_text( arcade.create_text("PLAYER 1 WIN!!!!!", arcade.color.RED, 50, align="center", anchor_x="center", anchor_y="center"), SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2) else: arcade.render_text( arcade.create_text("PLAYER 2 WIN!!!!!", arcade.color.BLUE, 50, align="center", anchor_x="center", anchor_y="center"), SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2) arcade.render_text( arcade.create_text("Press \"Enter\" to restart.", arcade.color.CAMOUFLAGE_GREEN, 15, align="center", anchor_x="center", anchor_y="center"), SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 - 50) def update(self, delta): self.world.update(delta)
class Gameplay: def __init__(self): self.world = None self.player_sprite = None self.bullet_sprite = None self.monster_bullet_sprite = None self.game_over_cover = False self.enable_sound = False self.sound = Sound() def set_up(self): self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.player_sprite = self.player() self.bullet_sprite = BulletSprite(self.world.bullet) self.monster_bullet_sprite = BulletSprite(self.world.monster_bullet) def background(self): arcade.draw_texture_rectangle( SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH, SCREEN_HEIGHT, texture=arcade.load_texture('images/background.png')) def player(self): if self.world.player.current_direction == DIR_LEFT: player_sprite = ModelSprite('images/player/player-' + str(self.world.player.element) + '_left.png', model=self.world.player, scale=0.24) else: player_sprite = ModelSprite('images//player/player-' + str(self.world.player.element) + '_right.png', model=self.world.player, scale=0.24) return player_sprite def draw_idle(self): if self.world.player.idle: arcade.draw_triangle_filled(50, 130, 40, 147.3, 60, 147.3, arcade.color.LEMON_GLACIER) arcade.draw_triangle_outline(50, 130, 40, 147.3, 60, 147.3, arcade.color.WHITE, border_width=2) else: pass def draw_melee(self): melee_sprite = ModelSprite('images/melee/melee.png', model=self.world.player, scale=0.24) if 0 <= self.world.player_melee.frame <= MELEE_FRAME_UPDATE: if self.world.player.current_direction == DIR_LEFT: direction = 'left' else: direction = 'right' melee_sprite = ModelSprite('images/melee/'+ direction +'/melee-'+\ str(self.world.player.element) + str(self.world.player_melee.melee_update)+'.png', model=self.world.player,scale=0.24) return melee_sprite def player_sprite_hit(self): if self.world.player.current_direction == DIR_LEFT: direction = 'left' else: direction = 'right' return ModelSprite('images/player/player-hit_' + direction + '.png', model=self.world.player, scale=0.24) def draw_platforms(self, platforms): for p in platforms: arcade.draw_xywh_rectangle_textured( p.x, p.y - PLATFORM_DRAW_Y_OFFSET, p.width, PLATFORM_DRAW_THICKNESS, texture=arcade.load_texture('images/platform.png')) def monster_sprite(self, m): if m.current_direction == DIR_LEFT: monster_sprite = ModelSprite('images/monster/monster-' + str(m.element) + '_left.png', model=m, scale=0.35) else: monster_sprite = ModelSprite('images/monster/monster-' + str(m.element) + '_right.png', model=m, scale=0.35) return monster_sprite def monster_sprite_hit(self, m): if m.current_direction == DIR_LEFT: direction = 'left' else: direction = 'right' return ModelSprite('images/monster/monster-hit_' + direction + '.png', model=m, scale=0.35) if self.world.player.shield: arcade.draw_xywh_rectangle_filled(20, SCREEN_HEIGHT - 50, 50, 50, arcade.color.GREEN) else: arcade.draw_xywh_rectangle_filled(20, SCREEN_HEIGHT - 50, 50, 50, arcade.color.YELLOW) def hp_bar(self): color = arcade.color.PANSY_PURPLE if self.world.player.element == 0: color = arcade.color.FIRE_ENGINE_RED elif self.world.player.element == 1: color = arcade.color.OCEAN_BOAT_BLUE elif self.world.player.element == 2: color = arcade.color.WINDSOR_TAN elif self.world.player.element == 3: color = arcade.color.SHEEN_GREEN if self.world.player.health >= (1000 / 11): arcade.draw_polygon_filled( [[75, SCREEN_HEIGHT - 25], [75 + (self.world.player.health) * 2.75, SCREEN_HEIGHT - 25], [ 75 + (self.world.player.health) * 2.75, SCREEN_HEIGHT - (25 + (275 - (self.world.player.health) * 2.75)) ], [325, SCREEN_HEIGHT - 50], [75, SCREEN_HEIGHT - 50]], color) self.draw_number(f'{self.world.player.health:.0f}' + '/100', 90, SCREEN_HEIGHT - 45) elif 0 < self.world.player.health < (1000 / 11): arcade.draw_polygon_filled( [[75, SCREEN_HEIGHT - 25], [75 + (self.world.player.health) * 2.75, SCREEN_HEIGHT - 25], [75 + (self.world.player.health) * 2.75, SCREEN_HEIGHT - 50], [75, SCREEN_HEIGHT - 50]], color) self.draw_number(f'{self.world.player.health:.0f}' + '/100', 90, SCREEN_HEIGHT - 45) else: self.draw_number('0/100', 90, SCREEN_HEIGHT - 45) def power_bar(self): color = arcade.color.BLUE if self.world.player.power == 100 or self.world.player.shield: color = arcade.color.PUMPKIN else: color = arcade.color.LEMON if self.world.player.power >= (4700 / 49): arcade.draw_polygon_filled( [[75, SCREEN_HEIGHT - 55], [75 + (self.world.player.power) * 2.45, SCREEN_HEIGHT - 55], [ 75 + (self.world.player.power) * 2.45, SCREEN_HEIGHT - (55 + (245 - (self.world.player.power) * 2.45)) ], [310, SCREEN_HEIGHT - 65], [75, SCREEN_HEIGHT - 65]], color) elif 0 < self.world.player.power < (4700 / 49): arcade.draw_polygon_filled( [[75, SCREEN_HEIGHT - 55], [75 + (self.world.player.power) * 2.45, SCREEN_HEIGHT - 55], [75 + (self.world.player.power) * 2.45, SCREEN_HEIGHT - 65], [75, SCREEN_HEIGHT - 65]], color) else: pass def bar_outline(self): arcade.draw_polygon_outline( [[75, SCREEN_HEIGHT - 25], [350, SCREEN_HEIGHT - 25], [325, SCREEN_HEIGHT - 50], [75, SCREEN_HEIGHT - 50]], arcade.color.BLACK, line_width=2) arcade.draw_polygon_outline( [[75, SCREEN_HEIGHT - 55], [320, SCREEN_HEIGHT - 55], [310, SCREEN_HEIGHT - 65], [75, SCREEN_HEIGHT - 65]], arcade.color.BLACK, line_width=2) # arcade.draw_circle_filled(50,SCREEN_HEIGHT-50,35,arcade.color.WHITE) # arcade.draw_circle_outline(50,SCREEN_HEIGHT-50,35,arcade.color.BLACK,border_width=2) def draw_number(self, string, x, y, size=16, color='white'): x0 = x for s in string: if s == '/': arcade.draw_xywh_rectangle_textured( x0, y, size / 2, size, arcade.load_texture('images/char/' + str(color) + '/slash.png')) else: arcade.draw_xywh_rectangle_textured( x0, y, size / 2, size, arcade.load_texture('images/char/' + str(color) + '/' + str(s) + '.png')) x0 += size / 2 def floor(self, x, y, size): arcade.draw_xywh_rectangle_textured( x, y, size * 3, size, arcade.load_texture('images/char/floor.png')) self.draw_number(str(self.world.floor), x + size * 3.1, y, size) def score(self, x, y, size): arcade.draw_xywh_rectangle_textured( x, y, size * 3, size, arcade.load_texture('images/char/score.png')) self.draw_number(str(self.world.score), x + size * 3.1, y, size) def gui(self): self.hp_bar() self.power_bar() self.bar_outline() self.floor(SCREEN_WIDTH - 135, SCREEN_HEIGHT - 45, 20) self.score(SCREEN_WIDTH - 135, SCREEN_HEIGHT - 70, 20) def game_over(self): if self.world.player.is_dead: arcade.draw_xywh_rectangle_textured( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, arcade.load_texture("images/game_over/game_over.png")) self.floor(200, SCREEN_HEIGHT // 2 - 50, 40) self.score(SCREEN_WIDTH // 2 + 30, SCREEN_HEIGHT // 2 - 50, 40) def draw_gameplay(self): self.draw_melee().draw() self.draw_platforms(self.world.platforms) self.draw_idle() if not self.world.player.is_dead: self.bullet_sprite.draw() self.player_sprite.draw() if self.world.player.is_hit: self.player_sprite_hit().draw() self.monster_bullet_sprite.draw() for m in self.world.monster: self.monster_sprite(m).draw() if m.is_hit: self.monster_sprite_hit(m).draw() def draw_gameplay_update(self): self.player_sprite = self.player() def sound_fx(self): if self.world.player.health <= 30 and not self.world.player.is_dead: self.sound.play_low_hp() else: self.sound.reset_health_play() if not self.world.monster: self.sound.play_next_floor() else: self.sound.reset_floor_play() if self.world.player.power == 100: self.sound.play_pw_full() elif self.world.player.shield: self.sound.play_pw_proc() else: self.sound.reset_power_play() def sound_on_key_press(self, key, key_modifiers): if key == arcade.key.J: self.sound.play_melee() if key == arcade.key.K: self.sound.play_range() def on_draw(self): self.background() self.draw_gameplay() self.gui() self.game_over() def update(self, delta): self.draw_gameplay_update() if self.enable_sound: self.sound_fx() self.world.update(delta) def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers) if self.enable_sound: self.sound_on_key_press(key, key_modifiers) def on_key_release(self, key, key_modifiers): self.world.on_key_release(key, key_modifiers)
class BabyBeeGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) self.w = width self.h = height self.set_up(self.w, self.h) def set_up(self, width, height): arcade.set_background_color(arcade.color.BLACK) self.main_menu = { 'over': arcade.load_texture("images/over.png"), 'start': arcade.load_texture("images/start.png") } self.world = World(width, height) self.bullet_list = arcade.SpriteList() self.bee_list = arcade.SpriteList() self.coin_list = arcade.SpriteList() self.monster_list = arcade.SpriteList() self.bee_sprite = ModelSprite('images/bee.png', model=self.world.bee) self.laser_sound = arcade.sound.load_sound("sounds/laser.wav") self.bee_list.append(self.bee_sprite) self.game_stop = False self.game_start = False self.background = arcade.load_texture("images/background.jpg") def on_draw(self): print(len(self.monster_list)) arcade.start_render() arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH, SCREEN_HEIGHT, self.background) self.bullet_list.draw() self.bee_sprite.draw() self.monster_list.draw() self.coin_list.draw() self.bee_list.draw() arcade.draw_text("Score : " + str(self.world.score), self.width - 120, self.height - 30, arcade.color.GRAY_BLUE, 20) if (self.game_stop): arcade.draw_texture_rectangle(self.width // 2, self.height // 2 + 70, 200, 100, self.main_menu['over'], 0, 255) if (self.game_start): arcade.draw_texture_rectangle(self.width // 2, self.height // 2 - 40, 100, 100, self.main_menu['start'], 0, 255) def update(self, delta): self.world.update(delta) self.world.limit_screen(SCREEN_WIDTH) self.bullet_list.update() self.monster_list.update() for bullet in self.bullet_list: hit_list = hit(bullet, self.monster_list) if len(hit_list) > 0: self.coin_sprite = ModelSprite('images/coin.png', model=self.world.coin) self.coin_sprite.center_x = hit_list[0].center_x self.coin_sprite.center_y = hit_list[0].center_y self.coin_list.append(self.coin_sprite) self.coin_sprite.change_y = COIN_SPEED bullet.kill() for monster in hit_list: monster.kill() self.coin_list.update() for coin in self.coin_list: hit_list = hit(coin, self.bee_list) if len(hit_list) > 0: self.world.score += 1 coin.kill() for monster in self.monster_list: hit_list = hit(monster, self.bee_list) if len(hit_list) > 0: self.game_stop = True self.game_start = True for bee in hit_list: bee.kill() def on_mouse_press(self, x, y, button, modifiers): menu = self.main_menu['start'] h = SCREEN_HEIGHT // 2 - 100 w = SCREEN_WIDTH // 2 if w - menu.width // 2 <= x <= w + menu.width // 2: if h - menu.height // 2 <= y <= h + menu.height // 2: self.set_up(self.w, self.h) def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers) if key == arcade.key.SPACE: arcade.sound.play_sound(self.laser_sound) self.bullet_sprite = ModelSprite('images/bullet.png', model=self.world.bullet) self.bullet_sprite.change_y = BULLET_SPEED self.bullet_sprite.center_x = self.bee_sprite.center_x self.bullet_sprite.bottom = self.bee_sprite.top self.bullet_list.append(self.bullet_sprite) if key == arcade.key.ENTER: self.monster_sprite = ModelSprite('images/monster.png', model=self.world.monster) self.monster_sprite.change_y = MONSTER_SPEED self.monster_sprite.center_x = random.randint( 30, SCREEN_WIDTH - 30) self.monster_sprite.center_y = SCREEN_HEIGHT self.monster_list.append(self.monster_sprite)
class SpaceGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.BLACK) self.world = World(width, height) self.player_sprite = ModelSprite('images/wolf.png', model=self.world.player) self.end_sprites = [] for end in self.world.ends: self.end_sprites.append(ModelSprite('images/warp.png', model=end)) self.wall_sprites = [] for wall in self.world.wall: self.wall_sprites.append( ModelSprite('images/block.png', model=wall)) self.coin_texture = arcade.load_texture('images/meat.png') self.gameover_texture = arcade.load_texture('images/meat.png') def draw_coins(self, coins, player): for c in coins: if not c.is_collected: arcade.draw_texture_rectangle(c.x, c.y, 40, 40, self.coin_texture) def on_draw(self): arcade.start_render() self.draw_coins(self.world.coins, self.world.player) self.player_sprite.draw() self.enemy_sprites = [] for enemy in self.world.enemies: self.enemy_sprites.append( ModelSprite('images/pig.png', model=enemy)) for sprite in self.enemy_sprites: sprite.draw() for sprite in self.wall_sprites: sprite.draw() for sprite in self.end_sprites: sprite.draw() if (self.world.GAMEOVER == 0): arcade.draw_text(str(self.world.score), 750, 550, arcade.color.WHITE, 20) else: arcade.draw_text(str(0), 750, 550, arcade.color.WHITE, 20) if self.world.GAMEOVER == 1 and self.world.WIN == 0: arcade.draw_text("GAMEOVER", 340, 550, arcade.color.WHITE, 20) elif self.world.WIN == 1 and self.world.GAMEOVER == 0: arcade.draw_text("YOU WIN", 375, 570, arcade.color.WHITE, 15) arcade.draw_text("SCORE " + str(self.world.score), 370, 550, arcade.color.WHITE, 15) def animate(self, delta): self.world.animate(delta) def on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers)
class GunnerWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT, BLOCK_SIZE) self.world.player.turn = 0 self.player_right_sprite = ModelSprite('images/Gunner_right.png', model=self.world.player) self.player_left_sprite = ModelSprite('images/Gunner_left.png', model=self.world.player) self.bullet_sprite = BulletSprite() self.slime_sprite = SlimeSprite() self.kingslime_sprite = KingslimeSprite() self.checkpoint_sprite = CheckpointSprite() ## if self.world.currentmap == 0: ## self.background = arcade.Sprite("images/background1.jpg") ## if self.world.currentmap == 1: ## self.background = arcade.Sprite("images/background2.png") ## if self.world.currentmap == 2: ## self.background = arcade.Sprite("images/background3.jpg") ## if self.world.currentmap == 3: ## self.background = arcade.Sprite("images/background4.png") ## self.stage_drawer = StageDrawer(self.world.stage) def update(self, delta): self.world.update(delta) def on_draw(self): arcade.start_render() self.background = arcade.Sprite("images/forest.png") ## self.background = arcade.Sprite(BG[self.world.currentmap]) self.background.set_position(400, 300) self.background.draw() if self.world.player.turn == 0: self.player_right_sprite.draw() if self.world.player.turn == 1: self.player_left_sprite.draw() self.slime_sprite.draw(self.world.slime) self.kingslime_sprite.draw(self.world.kingslime) self.bullet_sprite.draw(self.world.bullet) self.checkpoint_sprite.draw(self.world.checkpoint) self.stage_drawer.draw() if self.world.time == 1: if self.world.player.life > 0: arcade.draw_text(f"PRESS 'R' TO RESPAWN", 50, 300, arcade.color.WHITE, 60) if self.world.player.life == 0: arcade.draw_text(f"PRESS 'R' TO RESTART", 50, 300, arcade.color.WHITE, 60) arcade.draw_text(f"LIFE: {self.world.player.life}", 25, 550, arcade.color.RED, 30) arcade.draw_text(f"SCORE: {self.world.player.kill}", 600, 550, arcade.color.WHITE, 30) if self.world.time == 2: arcade.draw_text("YOU WON!", 75, 300, arcade.color.GOLD, 120) def on_key_press(self, 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)
class SpaceGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.BLACK) self.world = World(width, height) self.player_sprite = ModelSprite('images/jar1.png', model=self.world.player) self.background = arcade.load_texture("images/background.jpg") self.bullet_sprites = [] self.current_state = GAME_MENU def on_draw(self): arcade.start_render() arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, self.background.width, self.background.height, self.background, 0) if self.world.current_state == GAME_MENU: self.draw_menu() elif self.world.current_state == GAME_RUNNING: self.draw_game() elif self.world.current_state == GAME_PAUSE: self.draw_pause() else: self.draw_game_over() self.setup() def setup(self): # del self.bullet_sprites[:] self.bullet_sprites.clear() def draw_game(self): self.update() # self.player_sprite.draw() self.draw_player() for sprite in self.bullet_sprites: sprite.draw() arcade.draw_text( "time: " + "%.2f" % (GAME_TIME - self.world.current_time), self.width - 155, self.height - 30, arcade.color.WHITE, 20) arcade.draw_text("Jar: " + str(self.world.jar), self.width - 155, self.height - 60, arcade.color.WHITE, 20) def draw_player(self): jar = self.world.score % 4 self.player_sprite = ModelSprite('images/jar' + str(self.world.score % 4) + '.png', model=self.world.player) self.player_sprite.draw() def draw_game_over(self): output = "Game Over" arcade.draw_text(output, 175, 400, arcade.color.WHITE, 36) output = "Space to restart" arcade.draw_text(output, 175, 300, arcade.color.WHITE, 24) output = "Jar: " + str(self.world.jar) arcade.draw_text(output, 175, 200, arcade.color.WHITE, 24) def draw_pause(self): output = "Pause" arcade.draw_text(output, 150, 400, arcade.color.WHITE, 36) def draw_menu(self): output = "water jar game" arcade.draw_text(output, 125, 400, arcade.color.WHITE, 36) def animate(self, delta): self.world.animate(delta) def on_key_press(self, 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): for bullet in self.world.bullets.bulletsList: if bullet.isToxic == False: self.bullet_sprites.append( ModelSprite('images/bullet.png', model=bullet)) elif bullet.isToxic == True: self.bullet_sprites.append( ModelSprite('images/bullet_toxic.png', model=bullet))
class TaLaLapWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height, "TaLaLap") self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.coin_list = self.world.coin_list self.plus_dam = arcade.Sprite("images/DoubleDam.png", scale=0.7) self.double_dam = arcade.Sprite("images/DoubleDamT.png", scale=0.7) self.plus_dam.set_position(SCREEN_WIDTH - 40, SCREEN_HEIGHT - 385) self.double_dam.set_position(SCREEN_WIDTH - 100, SCREEN_HEIGHT - 385) def update(self, delta): self.world.update(delta) self.player = ModelSprite( "images/stand.png" if self.world.player.player_frame == 0 else "images/hit.png", scale=0.4, model=self.world.player) self.monster = ModelSprite( "images/monster/" + str(self.world.monster.monster_folder) + "/" + self.world.monster.monster_frame, scale=0.5, model=self.world.monster) def display_information(self): arcade.draw_text("Coin: " + str(self.world.coin), self.width - 590, self.height - 60, FONT_COLOR, 20) arcade.draw_text("HP: " + str(self.world.monster.hp), self.width - 590, self.height - 30, FONT_COLOR, 20) arcade.draw_text("Damage: " + str(self.world.player.damage), self.width - 590, self.height - 410, FONT_COLOR, 20) arcade.draw_text("Level: " + str(self.world.world_level), self.width - 350, self.height - 20, FONT_COLOR, 20) if self.world.item.item_time > 0: arcade.draw_text("Item_time: " + str(self.world.item.item_time), self.width - 590, self.height - 90, FONT_COLOR, 20) if self.world.world_stage == "Fight": arcade.draw_text("Time: " + str(self.world.stage_time), self.width - 106, self.height - 20, FONT_COLOR, 20) def on_draw(self): arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH, SCREEN_HEIGHT, arcade.load_texture("images/bg2.jpg")) self.display_information() if self.world.on_fight_stage(): self.monster.draw() self.double_dam.draw() self.plus_dam.draw() else: self.coin_list.coin.draw() self.player.draw() def on_key_press(self, 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 on_mouse_press(self, x: float, y: float, button: int, modifiers: int): self.world.on_mouse_press(x, y, button, 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 FieldWindow(arcade.Window): GAME_MODE = 0 H2P = 1 def __init__(self, width, height): super().__init__(width, height, "・2 DotThrough") self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.color_status_text = arcade.color.RED_ORANGE self.color_map_in_stage = arcade.color.ORANGE_RED self.color_map_not_in_stage = arcade.color.LIGHT_GRAY self.star_sprite = self.world.star_list self.exit_gate_sprite = ModelSprite('images/Exit_gate.png', model=self.world.exit_gate, scale=1) self.start_button = arcade.Sprite('images/Start.png', scale=0.35, center_x=SCREEN_WIDTH // 2, center_y=SCREEN_HEIGHT // 4) def on_key_press(self, key, key_modifiers): if key == arcade.key.ENTER and self.GAME_MODE == 1: self.H2P += 1 if self.GAME_MODE == 2: self.world.on_key_press(key, key_modifiers) def on_key_release(self, key, key_modifiers): if self.GAME_MODE == 2: self.world.on_key_release(key, key_modifiers) def on_mouse_press(self, x: float, y: float, button, key_modifiers): if self.GAME_MODE == 0: if button == arcade.MOUSE_BUTTON_LEFT: if self.start_button.center_y - 25 <= y <= self.start_button.center_y + 25\ and self.start_button.center_x - 85 <= x <= self.start_button.center_x + 85: self.GAME_MODE = 1 def update(self, delta): self.world.update(delta) self.character_sprite = ModelSprite( 'images/character.png' if self.world.character.animation == 1 else 'images/character2.png' if self.world.character.animation == 2 else 'images/character3.png' if self.world.character.animation == 3 else 'images/character4.png', model=self.world.character) self.object_cant_touch_stage_sprite = self.world.object_list def on_draw(self): arcade.start_render() if self.GAME_MODE == 0: arcade.draw_texture_rectangle( SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH, SCREEN_HEIGHT, arcade.load_texture("images/Interface.png")) self.start_button.draw() elif self.GAME_MODE == 1: if self.H2P == 1: arcade.draw_texture_rectangle( SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH, SCREEN_HEIGHT, arcade.load_texture("images/ControlG.png")) elif self.H2P == 2: arcade.draw_texture_rectangle( SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH, SCREEN_HEIGHT, arcade.load_texture("images/H2P1.png")) elif self.H2P == 3: arcade.draw_texture_rectangle( SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH, SCREEN_HEIGHT, arcade.load_texture("images/H2P2.png")) elif self.H2P == 4: arcade.draw_texture_rectangle( SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH, SCREEN_HEIGHT, arcade.load_texture("images/H2P3.png")) elif self.H2P == 5: self.H2P = 1 self.GAME_MODE = 2 elif self.GAME_MODE == 2: arcade.set_background_color(arcade.color.BLACK_OLIVE) self.character_sprite.draw() self.object_cant_touch_stage_sprite.draw() self.star_sprite.draw() self.exit_gate_sprite.draw() #define the stage location in map arcade.draw_rectangle_filled( 30, SCREEN_HEIGHT - 30, 15, 15, self.color_map_in_stage if self.world.stage_objects.stage_count == 1 else self.color_map_not_in_stage) arcade.draw_rectangle_filled( 50, SCREEN_HEIGHT - 30, 15, 15, self.color_map_in_stage if self.world.stage_objects.stage_count == 2 else self.color_map_not_in_stage) arcade.draw_rectangle_filled( 70, SCREEN_HEIGHT - 30, 15, 15, self.color_map_in_stage if self.world.stage_objects.stage_count == 3 else self.color_map_not_in_stage) arcade.draw_rectangle_filled( 30, SCREEN_HEIGHT - 50, 15, 15, self.color_map_in_stage if self.world.stage_objects.stage_count == 8 else self.color_map_not_in_stage) arcade.draw_rectangle_filled( 50, SCREEN_HEIGHT - 50, 15, 15, self.color_map_in_stage if self.world.stage_objects.stage_count == 9 else self.color_map_not_in_stage) arcade.draw_rectangle_filled( 70, SCREEN_HEIGHT - 50, 15, 15, self.color_map_in_stage if self.world.stage_objects.stage_count == 4 else self.color_map_not_in_stage) arcade.draw_rectangle_filled( 30, SCREEN_HEIGHT - 70, 15, 15, self.color_map_in_stage if self.world.stage_objects.stage_count == 7 else self.color_map_not_in_stage) arcade.draw_rectangle_filled( 50, SCREEN_HEIGHT - 70, 15, 15, self.color_map_in_stage if self.world.stage_objects.stage_count == 6 else self.color_map_not_in_stage) arcade.draw_rectangle_filled( 70, SCREEN_HEIGHT - 70, 15, 15, self.color_map_in_stage if self.world.stage_objects.stage_count == 5 else self.color_map_not_in_stage) arcade.draw_text(self.world.stage_objects.stage_name, 15, SCREEN_HEIGHT - 105, self.color_map_in_stage, 15, bold=True) #star collects if self.world.stage_objects.stage_count != 0: arcade.draw_rectangle_filled(SCREEN_WIDTH-90, SCREEN_HEIGHT-30, 20, 20, arcade.color.GOLDEN_POPPY if len(self.world.star_list) <= 2 \ and self.world.character.keep_star == True else arcade.color.EERIE_BLACK, tilt_angle = 45) arcade.draw_rectangle_filled(SCREEN_WIDTH - 60, SCREEN_HEIGHT - 30, 20, 20, arcade.color.YELLOW_ORANGE if len(self.world.star_list) <= 1 \ and self.world.character.keep_star == True else arcade.color.EERIE_BLACK, tilt_angle=45) arcade.draw_rectangle_filled(SCREEN_WIDTH - 30, SCREEN_HEIGHT - 30, 20, 20, arcade.color.ORANGE if len(self.world.star_list) == 0 \ and self.world.character.keep_star == True else arcade.color.EERIE_BLACK, tilt_angle=45) if self.world.character.hit == True: self.color_status_text = arcade.color.RED_ORANGE elif self.world.character.exit_hit == True: if self.world.stage_objects.stage_count < self.world.stage_objects.MAX_STAGE: self.color_status_text = arcade.color.GREEN else: self.color_status_text = arcade.color.ORANGE_PEEL arcade.draw_text(self.world.stage_objects.status, SCREEN_WIDTH // 3.25, SCREEN_HEIGHT // 1.25, self.color_status_text, font_size=50, bold=True) arcade.draw_text(self.world.stage_objects.desc_status, SCREEN_WIDTH // 2.8, SCREEN_HEIGHT // 1.35, self.color_status_text, font_size=15, bold=True) arcade.draw_text(self.world.stage_objects.tutorial_text, SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2.15, arcade.color.ORANGE_RED, font_size=30, bold=True)
class DragonGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) self.high_score = 0 self.bgm_sound = arcade.sound.load_sound("sounds/sound2.mp3") arcade.sound.play_sound(self.bgm_sound) self.setup(width, height) def setup(self, width, height): arcade.set_background_color(arcade.color.BLACK) self.world = World(width, height) self.background_texture = arcade.load_texture('images/background.png') self.dragon_sprite = ModelSprite('images/dragon.png', model=self.world.dragon) self.man_texture = arcade.load_texture('images/man.png') self.steak_texture = arcade.load_texture('images/steak.png') self.fire_texture = arcade.load_texture('images/fire.png') def draw_men(self, men): for m in men: if m.state == m.STATE_ALIVE: arcade.draw_texture_rectangle(m.x, m.y, m.width, m.height, self.man_texture) if m.state == m.STATE_STEAK: arcade.draw_texture_rectangle(m.x, m.y, m.width, m.height, self.steak_texture) def draw_fire(self, fire): for f in fire: if not f.is_hit: arcade.draw_texture_rectangle(f.x, f.y, f.width, f.height, self.fire_texture) def on_draw(self): arcade.start_render() arcade.draw_texture_rectangle(640, 360, 1280, 720, self.background_texture) self.draw_men(self.world.men) self.draw_fire(self.world.fire) self.dragon_sprite.draw() minutes = int(self.world.total_time) // 60 seconds = int(self.world.total_time) % 60 output = "Time: {:02d}:{:02d}".format(minutes, seconds) arcade.draw_text(output, 0, 690, arcade.color.WHITE, 20) arcade.draw_text(str("HUNGER: "), self.width - 550, self.height - 30, arcade.color.WHITE, 20) arcade.draw_text(str(self.world.hunger), self.width - 430, self.height - 30, arcade.color.WHITE, 20) arcade.draw_text(str("/100"), self.width - 380, self.height - 30, arcade.color.WHITE, 20) arcade.draw_text(str("SCORE: "), self.width - 300, self.height - 30, arcade.color.WHITE, 20) arcade.draw_text(str(self.world.score), self.width - 200, self.height - 30, arcade.color.WHITE, 20) if self.world.current_state == GAME_OVER: arcade.draw_text("Game Over", 440, 360, arcade.color.WHITE, 70) arcade.draw_text("Click to restart.", 445, 250, arcade.color.WHITE, 50) if self.world.score > self.high_score: self.high_score = self.world.score arcade.draw_text("High Score:", 400, 150, arcade.color.WHITE, 50) arcade.draw_text(str(self.high_score), 750, 150, arcade.color.WHITE, 50) def animate(self, delta_time): if self.world.current_state == GAME_RUNNING: self.world.animate(delta_time) def on_key_press(self, 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 on_mouse_press(self, x, y, button, modifiers): if self.world.current_state == GAME_OVER: self.setup(1280, 720)