def test_get_long_collision(direction, x, y, w, h): bullet = Bullet(8, 8, direction=direction) rect = bullet.get_long_collision_rect() assert rect.x == x assert rect.y == y assert rect.width == w assert rect.height == h
def test_render_bullets(pygame): game = Game() game.bullets = [ Bullet(32, 32), Bullet(64, 32), ] drawer = Drawer(game) drawer._blit = Mock(spec=drawer._blit) drawer._render_bullets() assert drawer._blit.call_args_list == [ call('BULLET', game.bullets[0]), call('BULLET', game.bullets[1]), ]
def test_messages_get_world_data(): game = Game() player = Player(x=1, y=1, player_id=0) game.alive_players = [player] game.npcs = [NPC(2, 2)] game.bullets = [Bullet(3, 3)] game.walls = [TinyWall(x=4, y=4), Water(x=5, y=5)] game.coins = [Coin(x=4, y=4), Coin(x=5, y=5)] assert messages.get_world_data(player, game) == dict( id=player.id.hex, cords=[ dict(type='player', id=player.id.hex, position={ 'x': 1, 'y': 1 }), dict(type='npc', id=game.npcs[0].id.hex, position={ 'x': 2, 'y': 2 }), dict(type='bullet', id=game.bullets[0].id.hex, position={ 'x': 3, 'y': 3 }), dict(type='tinywall', id=game.walls[0].id.hex, position={ 'x': 4, 'y': 4 }), dict(type='water', id=game.walls[1].id.hex, position={ 'x': 5, 'y': 5 }), dict(type='coin', id=game.coins[0].id.hex, position={ 'x': 4, 'y': 4 }), dict(type='coin', id=game.coins[1].id.hex, position={ 'x': 5, 'y': 5 }), ])
async def test_set_old_position(): game = Game() game.bullets = [Bullet(128, 128)] game.alive_players = [Player(x=128, y=128, player_id=0)] game.npcs = [NPC(128, 128)] for monster in game.get_monsters_chain(): monster.set_position(42, 24) await SetOldPositionLogicPart(game).do_it() for monster in game.bullets + game.alive_players + game.npcs: assert monster.old_position.x == 42 assert monster.old_position.y == 24
async def test_move(): game = Game() # default direction is UP game.bullets = [Bullet(128, 128)] game.alive_players = [Player(x=128, y=128, player_id=0)] # but default direction of NPC is DOWN game.npcs = [NPC(128, 128)] game.alive_players[0].set_speed(2) game.npcs[0].set_speed(2) await MoveLogicPart(game).do_it() assert game.alive_players[0].get_position() == {'x': 128, 'y': 128 - 2} assert game.npcs[0].get_position() == {'x': 128, 'y': 128 + 2} assert game.bullets[0].get_position() == {'x': 128, 'y': 128 - 8}
def test_messages_get_bullet_data(): player = Player(x=1, y=2, player_id=0) bullet = Bullet(x=1, y=2) bullet.set_direction(direction=Direction.UP) bullet.set_parent(player) assert messages.get_monster_serialized_data(bullet, action='socek') == dict( id=bullet.id.hex, type='bullet', status='data', action='socek', is_freeze=False, direction='up', speed=8, parent=player.id.hex, position={'x': 1, 'y': 2}, )
def test_get_log_collision_offset(direction, offset, x, y): bullet = Bullet(8, 8, direction=direction) rect = bullet.get_long_collision_rect(offset=offset) assert rect.x == x assert rect.y == y