Esempio n. 1
0
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
Esempio n. 3
0
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]),
    ]
Esempio n. 4
0
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}