def test_play_all(self): self.item = NPC(model="-o-", name="Dancer") self.animation = Animation(animated_object=self.item, refresh_screen=self.redraw, display_time=0.5) self.animation.add_frame("-o-") self.animation.add_frame("\\o-") self.animation.add_frame("\\o\\") self.animation.add_frame("|o|") self.assertTrue(self.animation.play_all()) self.animation.pause() self.assertFalse(self.animation.play_all()) self.animation.stop() self.assertFalse(self.animation.play_all()) self.animation = Animation(animated_object="breaking", refresh_screen=self.redraw, display_time=0.5) with self.assertRaises(Exception) as context: self.animation.play_all() self.assertTrue( "needs to be a sub class of BoardItem" in str(context.exception)) self.animation = Animation(animated_object=self.item, refresh_screen="breaking", display_time=0.5) with self.assertRaises(Exception) as context: self.animation.play_all() self.assertTrue("needs to be a callback function reference" in str( context.exception))
def test_play_all(self): self.item = NPC(model='-o-', name='Dancer') self.animation = Animation(animated_object=self.item, refresh_screen=self.redraw, display_time=0.5) self.animation.add_frame('-o-') self.animation.add_frame('\\o-') self.animation.add_frame('\\o\\') self.animation.add_frame('|o|') self.assertTrue(self.animation.play_all()) self.animation.pause() self.assertFalse(self.animation.play_all()) self.animation.stop() self.assertFalse(self.animation.play_all()) self.animation = Animation(animated_object='breaking', refresh_screen=self.redraw, display_time=0.5) with self.assertRaises(Exception) as context: self.animation.play_all() self.assertTrue( 'needs to be a sub class of BoardItem' in str(context.exception)) self.animation = Animation(animated_object=self.item, refresh_screen='breaking', display_time=0.5) with self.assertRaises(Exception) as context: self.animation.play_all() self.assertTrue('needs to be a callback function reference' in str( context.exception))
def test_stop(self): self.item = NPC(model='-o-', name='Dancer') self.animation = Animation(animated_object=self.item, refresh_screen=self.redraw, display_time=0.5) self.animation.stop() self.assertEqual(self.animation.state, Constants.STOPPED)
def test_pause(self): self.item = NPC(model="-o-", name="Dancer") self.animation = Animation(animated_object=self.item, refresh_screen=self.redraw, display_time=0.5) self.animation.pause() self.assertEqual(self.animation.state, Constants.PAUSED)
def test_stop(self): self.item = NPC(model="-o-", name="Dancer") self.animation = Animation(parent=self.item, refresh_screen=self.redraw, display_time=0.5) self.animation.stop() self.assertEqual(self.animation.state, Constants.STOPPED)
def flood_filler(g, b, r, c): # If we hit anything but a void cell (BoardItemVoid) we have no business here. if not isinstance(b.item(r, c), BoardItemVoid): return # If we do hit a void cell, then we fill it with animated water if isinstance(b.item(r, c), BoardItemVoid): # First we pick a random integer number between 0 and the max index of the # frames array fi = random.randint(0, len(frames) - 1) # Then create a door object (overlappable and restorable) with that frame as # initial model d = Door(model=frames[fi]) # Then create an animation that animate the Door object, with the frames # defined earlier and the random index we just picked. a = Animation(animated_object=d, frames=frames, initial_index=fi) # Set the Door animation to the animation we just built d.animation = a # Finally place the water on the board b.place_item(d, r, c) # Redraw the screen and wait to see the nice animation of the algorithm working. # Otherwise it's instantanous. redraw_screen(g) time.sleep(0.1) # Now make recursive calls to fill the cells around this one. flood_filler(g, b, r + 1, c) flood_filler(g, b, r - 1, c) flood_filler(g, b, r, c + 1) flood_filler(g, b, r, c - 1)
def test_add_frame(self): self.item = NPC(model='-o-', name='Dancer') self.animation = Animation(animated_object=self.item, refresh_screen=self.redraw, display_time=0.5) self.animation.add_frame('\\o-') with self.assertRaises(Exception) as context: self.animation.add_frame(2) self.assertTrue('must be a string' in str(context.exception))
def test_add_frame(self): self.item = NPC(model="-o-", name="Dancer") self.animation = Animation(parent=self.item, refresh_screen=self.redraw, display_time=0.5) self.animation.add_frame("\\o-") with self.assertRaises(Exception) as context: self.animation.add_frame(2) self.assertTrue("must be a string" in str(context.exception))
def test_current_frame(self): self.item = NPC(model="-o-", name="Dancer") self.animation = Animation(animated_object=self.item, refresh_screen=self.redraw, display_time=0.5) self.animation.add_frame("-o-") self.animation.add_frame("\\o-") self.animation.add_frame("\\o\\") self.animation.add_frame("|o|") self.assertEqual(self.animation.current_frame(), "-o-") self.animation.next_frame() self.assertEqual(self.animation.current_frame(), "\\o-")
def test_current_frame(self): self.item = NPC(model='-o-', name='Dancer') self.animation = Animation(animated_object=self.item, refresh_screen=self.redraw, display_time=0.5) self.animation.add_frame('-o-') self.animation.add_frame('\\o-') self.animation.add_frame('\\o\\') self.animation.add_frame('|o|') self.assertEqual(self.animation.current_frame(), '-o-') self.animation.next_frame() self.assertEqual(self.animation.current_frame(), '\\o-')
def test_search_frame(self): self.item = NPC(model="-o-", name="Dancer") self.animation = Animation(animated_object=self.item, refresh_screen=self.redraw, display_time=0.5) self.animation.add_frame("-o-") self.animation.add_frame("\\o-") self.animation.add_frame("\\o-") self.assertEqual(self.animation.search_frame("\\o-"), 1) self.assertNotEqual(self.animation.search_frame("\\o-"), 2) with self.assertRaises(Exception) as context: self.animation.search_frame(2) self.assertTrue("must be a string" in str(context.exception))
def test_next_frame(self): self.item = NPC(model='-o-', name='Dancer') self.animation = Animation(animated_object=self.item, refresh_screen=self.redraw, display_time=0.5) self.animation.add_frame('-o-') self.animation.add_frame('\\o-') self.animation.add_frame('\\o\\') self.animation.add_frame('|o|') self.assertEqual(self.animation.next_frame(), '\\o-') self.animation.pause() self.assertEqual(self.animation.next_frame(), '\\o-') self.animation.stop() self.assertIsNone(self.animation.next_frame()) self.animation.animated_object = 'This is going to break!' with self.assertRaises(Exception) as context: self.animation.next_frame() self.assertTrue( 'needs to be a sub class of BoardItem' in str(context.exception))
def test_next_frame(self): self.item = NPC(model="-o-", name="Dancer") self.animation = Animation(animated_object=self.item, refresh_screen=self.redraw, display_time=0.5) self.animation.add_frame("-o-") self.animation.add_frame("\\o-") self.animation.add_frame("\\o\\") self.animation.add_frame("|o|") self.assertEqual(self.animation.next_frame(), "\\o-") self.animation.pause() self.assertEqual(self.animation.next_frame(), "\\o-") self.animation.stop() self.assertIsNone(self.animation.next_frame()) self.animation.animated_object = "This is going to break!" with self.assertRaises(Exception) as context: self.animation.next_frame() self.assertTrue( "needs to be a sub class of BoardItem" in str(context.exception))
def test_remove_frame(self): self.item = NPC(model='-o-', name='Dancer') self.animation = Animation(animated_object=self.item, refresh_screen=self.redraw, display_time=0.5) self.animation.add_frame('-o-') self.animation.add_frame('\\o-') self.animation.add_frame('\\o\\') self.animation.add_frame('|o|') self.animation.add_frame('/o/') self.animation.add_frame('-o/') with self.assertRaises(Exception) as context: self.animation.remove_frame(999) self.assertTrue('out of range' in str(context.exception)) self.assertEqual(self.animation.remove_frame(0), '-o-') self.animation.next_frame() self.animation.next_frame() self.assertEqual(self.animation.remove_frame(2), '|o|') self.assertEqual(self.animation.current_frame(), '\\o\\') self.assertEqual(self.animation.next_frame(), '/o/')
def test_remove_frame(self): self.item = NPC(model="-o-", name="Dancer") self.animation = Animation(animated_object=self.item, refresh_screen=self.redraw, display_time=0.5) self.animation.add_frame("-o-") self.animation.add_frame("\\o-") self.animation.add_frame("\\o\\") self.animation.add_frame("|o|") self.animation.add_frame("/o/") self.animation.add_frame("-o/") with self.assertRaises(Exception) as context: self.animation.remove_frame(999) self.assertTrue("out of range" in str(context.exception)) self.assertEqual(self.animation.remove_frame(0), "-o-") self.animation.next_frame() self.animation.next_frame() self.assertEqual(self.animation.remove_frame(2), "|o|") self.assertEqual(self.animation.current_frame(), "\\o\\") self.assertEqual(self.animation.next_frame(), "/o/")
pf = PathFinder(game=g, actuated_object=g.player) pf.add_waypoint(dest_row, dest_col) pf.add_waypoint(24, 24) pf.add_waypoint(21, 40) pf.circle_waypoints = True pf.set_destination(dest_row, dest_col) blocker = NPC(model=Sprites.SKULL) g.current_board().place_item(blocker, 20, 1) wall = Wall(model=Sprites.WALL) wall.animation = Animation(animated_object=wall) wall.animation.add_frame(Sprites.BANKNOTE_DOLLARS) wall.animation.add_frame(Sprites.BANKNOTE_EUROS) wall.animation.add_frame(Sprites.BANKNOTE_WINGS) g.current_board().place_item(wall, 5, 25) # 43,28 43,34 39,34 39,40 44,40 44,28 patroller = NPC(model=Sprites.ALIEN, name='patroller') patroller.actuator = PathFinder(game=g, actuated_object=patroller) g.add_npc(1, patroller, 42, 28) patroller.actuator.set_destination(43, 29) patroller.actuator.add_waypoint(43, 29) patroller.actuator.add_waypoint(43, 34) patroller.actuator.add_waypoint(39, 34) patroller.actuator.add_waypoint(39, 40) patroller.actuator.add_waypoint(44, 40)
elif key == "2": viewport = [15, 30] g.partial_display_viewport = viewport elif key == "3": viewport = [20, 20] g.partial_display_viewport = viewport if key == " ": if g.player.mp >= 4: fireball = Projectile( name="fireball", model=Utils.red_bright(black_circle), hit_model=Sprites.EXPLOSION, ) fireball.animation = Animation( auto_replay=True, animated_object=fireball, refresh_screen=None, display_time=0.5, ) fireball.animation.add_frame(Utils.red_bright(black_circle)) fireball.animation.add_frame(Utils.red_bright(circle_jot)) fireball.range = 7 fireball.set_direction(Constants.RIGHT) g.add_projectile(1, fireball, g.player.pos[0], g.player.pos[1] + 1) g.player.mp -= 4 elif key == Utils.key.UP: g.move_player(Constants.UP, 1) elif key == Utils.key.DOWN: g.move_player(Constants.DOWN, 1) elif key == Utils.key.LEFT: g.move_player(Constants.LEFT, 1)
def test_create_animation(self): self.item = NPC(model="-o-", name="Dancer") self.animation = Animation(parent=self.item, refresh_screen=self.redraw, display_time=0.5) self.assertEqual(self.item.name, self.animation.parent.name)
is_aoe=True, aoe_radius=1, ) zap_template = Projectile( model=Utils.yellow_bright("\U00002301\U00002301"), name="zap", range=8, hit_model=Graphics.Sprites.HIGH_VOLTAGE, hit_callback=zap_callback, ) # Left fireball_template.add_directional_model(Constants.LEFT, Utils.red_bright(f"{black_circle}~")) fa = Animation( auto_replay=True, animated_object=fireball_template, refresh_screen=redraw_screen, display_time=0.5, ) fa.add_frame(Utils.red_bright(f"{black_circle}~")) fa.add_frame(Utils.red_bright(f"{circle_jot}~")) fireball_template.add_directional_animation(Constants.RIGHT, fa) # Right fireball_template.add_directional_model(Constants.RIGHT, Utils.red_bright(f"~{black_circle}")) fa = Animation( auto_replay=True, animated_object=fireball_template, refresh_screen=redraw_screen, display_time=0.5, ) fa.add_frame(Utils.red_bright(f"~{black_circle}"))
def test_create_animation(self): self.item = NPC(model='-o-', name='Dancer') self.animation = Animation(animated_object=self.item, refresh_screen=self.redraw, display_time=0.5) self.assertEqual(self.item.name, self.animation.animated_object.name)