def test_agent_move_east(self): world = World(5, 10) agent = Agent(0) agent.direction = Direction.EAST agent.move = True world.agents[(0, 0)] = agent self.assertEqual(world.agents[(0, 0)], agent, '(0) world incorrectly set agent position') world.update() self.assertTrue((0, 0) not in world.agents, 'agent not moved from previous location') self.assertEqual(world.agents[(1, 0)], agent, '(1) world incorrectly updated to move agent East') world.update() self.assertEqual(world.agents[(2, 0)], agent, '(2) world incorrectly updated to move agent East') world.update() self.assertEqual(world.agents[(3, 0)], agent, '(3) world incorrectly updated to move agent East') world.update() self.assertEqual(world.agents[(4, 0)], agent, '(4) world incorrectly updated to move agent East') world.update() self.assertEqual( world.agents[(0, 0)], agent, '(5) world incorrectly updated to move agent East (wrap)') self.assertEqual(len(world.agents), 1, 'World has incorrect number of agents')
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 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 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)
def test_agent_move_south(self): world = World(10, 5) agent = Agent(0) agent.direction = Direction.SOUTH agent.move = True world.agents[(0, 4)] = agent self.assertEqual(world.agents[(0, 4)], agent, '(0) world incorrectly set agent position') world.update() self.assertTrue((0, 4) not in world.agents, 'agent not moved from previous location') self.assertEqual(world.agents[(0, 3)], agent, '(1) world incorrectly updated to move agent South') world.update() self.assertEqual(world.agents[(0, 2)], agent, '(2) world incorrectly updated to move agent South') world.update() self.assertEqual(world.agents[(0, 1)], agent, '(3) world incorrectly updated to move agent South') world.update() self.assertEqual(world.agents[(0, 0)], agent, '(4) world incorrectly updated to move agent South') world.update() self.assertEqual( world.agents[(0, 4)], agent, '(5) world incorrectly updated to move agent South (wrap)') self.assertEqual(len(world.agents), 1, 'World has incorrect number of agents')
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 SpaceGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.PINK) #self.ship_sprite = arcade.Sprite('./ship.png') 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.gold_sprite.draw() self.ship_sprite.draw() for sprite in self.asteroid_sprites: sprite.draw() arcade.draw_text(str(self.world.score), self.width - 60, 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 SpaceGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.BLACK) self.all_sprites_list = arcade.SpriteList() self.score = 0 self.world = World(width, height) #self.rocketsp = arcade.Sprite('images/Rocket2.png') self.rocketsp = ModelSprite('images/Rocket2.png', model=self.world.rocket) #self.aliensp = arcade.Sprite('images/Alien.png') self.aliensp = ModelSprite('images/Alien.png', model=self.world.alien) self.all_sprites_list.append(self.rocketsp) self.all_sprites_list.append(self.aliensp) #self.alien_list = arcade.SpriteList() #self.alien_list.append(self.aliensp) self.score = 0 def start_new_game(self): for i in range(50): aliensp = self.world.alien #self.aliensp = arcade.Sprite('images/Alien.png') #self.aliensp.set_position(self.world.alien.x, self.world.alien.y) aliensp.x = random.randrange(SCREEN_WIDTH) aliensp.y = SCREEN_HEIGHT def update(self, delta): self.world.update(delta) #self.rocketsp.set_position(self.world.rocket.x, self.world.rocket.y) def on_draw(self): arcade.start_render() #self.all_sprites_list.draw() self.rocketsp.draw() self.aliensp.draw() #self.rocketsp.set_position(self.world.rocket.x, self.world.rocket.y) #self.aliensp.set_position(self.world.alien.x, self.world.alien.y) output = "Score: {}".format(self.score) arcade.draw_text(output, 10, 600, arcade.color.WHITE, 12) def on_key_press(self, key, modifiers): if key == arcade.key.LEFT: self.world.rocket.delta_x = -MOVEMENT_SPEED elif key == arcade.key.RIGHT: self.world.rocket.delta_x = MOVEMENT_SPEED def on_key_release(self, key, modifiers): if key == arcade.key.LEFT or key == arcade.key.RIGHT: self.world.rocket.delta_x = 0
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)
def main(): # Initialize world world = World(5, 5) world.agents[(0,0)] = Agent() world.agents[(0,0)].move = True world.agents[(0,0)].direction = Direction.EAST world.agents[(3,3)] = Agent() world.agents[(3,3)].move = True print('0', world) # Run simulation for t in range(1,10): world.update() print(t, world)
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 DotRunWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.GRAY) self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.dot_sprite = ModelSprite('images/dot.png', model=self.world.dot) def update(self, delta): self.world.update(delta) def on_draw(self): arcade.start_render() self.dot_sprite.draw()
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)
def test_agent_gridlock_wrap(self): world = World(3, 3) # agent moving north agentN = Agent(0) agentN.direction = Direction.NORTH agentN.move = True # agent moving south agentS = Agent(1) agentS.direction = Direction.SOUTH agentS.move = True # agent moving east agentE = Agent(2) agentE.direction = Direction.EAST agentE.move = True # agent moving west agentW = Agent(3) agentW.direction = Direction.WEST agentW.move = True # setup world.agents[(1, 2)] = agentN world.agents[(1, 0)] = agentS world.agents[(2, 1)] = agentE world.agents[(0, 1)] = agentW # update & test world.update() self.assertEqual(world.agents[(1, 2)], agentN, '(1) world incorrectly updated north agent') self.assertEqual(world.agents[(1, 0)], agentS, '(1) world incorrectly updated south agent') self.assertEqual(world.agents[(2, 1)], agentE, '(1) world incorrectly updated east agent') self.assertEqual(world.agents[(0, 1)], agentW, '(1) world incorrectly updated west agent') world.update() self.assertEqual(world.agents[(1, 2)], agentN, '(2) world incorrectly updated north agent') self.assertEqual(world.agents[(1, 0)], agentS, '(2) world incorrectly updated south agent') self.assertEqual(world.agents[(2, 1)], agentE, '(2) world incorrectly updated east agent') self.assertEqual(world.agents[(0, 1)], agentW, '(2) world incorrectly updated west agent') self.assertEqual(len(world.agents), 4, 'World has incorrect number of agents')
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)
def main(): """The entry point for simulation.""" frame = 1 # Read dynamic parameters from the specified file dynamic_params_filename = 'dynamic_params.json' param_reader = DynamicParamReader(dynamic_params_filename) # Initialise the world world = World(dynamic_params_reader=param_reader, output_filename='out.csv') while frame <= MAX_FRAMES: print("Frame #" + str(frame)) world.update(frame) # Speed will depend on the frame interval, which can be set dynamically sleep(param_reader.read_params()[FRAME_INTERVAL[0]]) frame += 1
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 SpaceGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.BLACK) self.world = World(width, height) #new object เป็นobject class World 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 on_key_press(self, key, key_modifiers): self.world.on_key_press(key, key_modifiers) def update(self, delta): self.world.update(delta)
class Window(arcade.Window): def __init__(self, width, height): super().__init__(width, height) self.world = World(width, height) self.background = None # self.ship_sprite = ModelSprite('robin.jpg',model=self.world.robin) def setup(self): self.background = arcade.load_texture( 'Y1T2\\amazing_arrow\\background.png') def on_draw(self): arcade.start_render() arcade.draw_texture_rectangle(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, SCREEN_WIDTH, SCREEN_HEIGHT, self.background) 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)
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 SpaceGameWindow(arcade.Window): def __init__(self, width, height): super().__init__(width, height) self.backgroud = arcade.load_texture('images/Space.jpg') arcade.draw_texture_rectangle(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, SCREEN_WIDTH, SCREEN_HEIGHT, self.backgroud) self.score = 0 self.world = World(width, height) self.alien_list = arcade.SpriteList() self.rocketsp = ModelSprite('images/Rocket2.png', 0.9, model=self.world.rocket) for alien in self.world.alien_list: self.alien_list.append(ModelSprite('images/Alien.png', 0.8, model = alien)) self.hit_list = [] self.counttime = 0 self.target = 50 self.life = 2 def update(self, delta): self.counttime += delta for bullet in self.world.bullet_list: self.hit_list = arcade.check_for_collision_with_list(bullet, self.alien_list) if len(self.hit_list) > 0: bullet.kill() for alien in self.hit_list: alien.kill() self.score+=5 if self.counttime >= TIME: self.world.status = 1 if self.score > self.target: self.world.numAdd += 1 self.target += 50 self.counttime = 0 if (self.score+5)%255 == 0: self.life += 1 self.score += 10 for alien in self.world.tmplist: self.alien_list.append(ModelSprite('images/Alien.png', 0.8, model = alien)) self.world.tmplist = [] for alien in self.alien_list: if alien.model.y <= 0: alien.kill() self.life -= 1 #print(self.life) if self.life < 0: self.life = 0 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+70, self.backgroud) self.rocketsp.draw() for alien in self.alien_list: alien.draw() if self.life <= 0: output1 = "Game Over" arcade.draw_text(output1, 100, 320, arcade.color.WHITE, 46) output2 = "Score: {}".format(self.score) arcade.draw_text(output2, 190, 290, arcade.color.WHITE, 20) for bullet in self.world.bullet_list: bullet.draw() output = "life: {}".format(self.life) arcade.draw_text(output, 400, 600, arcade.color.WHITE, 12) output = "Score: {}".format(self.score) arcade.draw_text(output, 10, 600, arcade.color.WHITE, 12) def on_key_press(self, key, modifiers): if key == arcade.key.LEFT: self.world.rocket.delta_x = -MOVEMENT_SPEED elif key == arcade.key.RIGHT: self.world.rocket.delta_x = MOVEMENT_SPEED if key == arcade.key.SPACE: bullet = Bullet(self.world) bullet.x = self.world.rocket.x bullet.y = self.world.rocket.y + 10 self.world.bullet_model.append(bullet) bullet_sprite = ModelSprite("images/bullet.png",0.5, model = bullet) self.world.bullet_list.append(bullet_sprite) def on_key_release(self, key, modifiers): if key == arcade.key.LEFT or key == arcade.key.RIGHT: self.world.rocket.delta_x = 0
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 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 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 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 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 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)