Esempio n. 1
0
    def test_player_tank_move_up(self):
        """Test player tank move up."""
        Game.current_scene = Scene("../res/levels/level0.txt")
        Game.current_scene.bbox = Rect(
            Vector2(-100000, -100000),
            Vector2(100000, 100000) * Game.current_scene.cellSize)
        event = pygame.event.Event(pygame.USEREVENT,
                                   user_type='MAINMENU',
                                   ui_element=self.app.menu.playButton)
        pygame.event.post(event)
        tmp = PlayerTank(pos=Vector2(0, 0), size=10)
        tmp.update(dt=0.5)

        dt = 10.0
        speed = 2 * tmp.rect.width

        event = pygame.event.Event(pygame.KEYDOWN, key=pygame.K_UP)
        tmp.handleEvent(event)
        self.assertEqual(tmp.pos, Vector2(0, 0),
                         'test_update_player_tank_pos_up')
        self.assertEqual(tmp.direction, Vector2(0, -1),
                         'test_update_player_tank_dir_up')
        self.assertEqual(tmp.vel, Vector2(0, -speed),
                         'test_update_player_tank_vel_up')
        tmp.update(dt=dt)
        self.assertEqual(tmp.pos,
                         Vector2(0, -speed) * dt + Vector2(0, 0),
                         'test_update_player_tank_pos_up_update')
        self.assertEqual(tmp.direction, Vector2(0, -1),
                         'test_update_player_tank_dir_up_update')
        self.assertEqual(tmp.vel, Vector2(0, -speed),
                         'test_update_player_tank_vel_up_update')
Esempio n. 2
0
 def test_player_tank_init(self):
     """Test player tank init."""
     Game.current_scene = Scene("../res/levels/level0.txt")
     tmp = PlayerTank(pos=Vector2(5, 5), size=10)
     tmp.update(dt=0.5)
     result = (tmp.pos, tmp.vel)
     response = (Vector2(5, 5), Vector2(0, 0))
     self.assertEqual(result, response, 'player_tank_init')
Esempio n. 3
0
    def test_player_tank_key_reaction(self):
        """Test player tank key reation."""
        Game.current_scene = Scene("../res/levels/level0.txt")
        event = pygame.event.Event(pygame.USEREVENT,
                                   user_type='MAINMENU',
                                   ui_element=self.app.menu.playButton)
        pygame.event.post(event)
        tmp = PlayerTank(pos=Vector2(5, 5), size=10)
        tmp.update(dt=0.5)

        speed = 2 * tmp.rect.width

        event = pygame.event.Event(pygame.KEYDOWN, key=pygame.K_UP)
        tmp.handleEvent(event)
        self.assertEqual(tmp.direction, Vector2(0, -1),
                         'test_update_player_tank_dir_up')
        self.assertEqual(tmp.vel, Vector2(0, -speed),
                         'test_update_player_tank_vel_up')

        event = pygame.event.Event(pygame.KEYDOWN, key=pygame.K_DOWN)
        tmp.handleEvent(event)
        self.assertEqual(tmp.direction, Vector2(0, 1),
                         'test_update_player_tank_dir_down')
        self.assertEqual(tmp.vel, Vector2(0, speed),
                         'test_update_player_tank_vel_down')

        event = pygame.event.Event(pygame.KEYDOWN, key=pygame.K_LEFT)
        tmp.handleEvent(event)
        self.assertEqual(tmp.direction, Vector2(-1, 0),
                         'test_update_player_tank_dir_left')
        self.assertEqual(tmp.vel, Vector2(-speed, 0),
                         'test_update_player_tank_vel_left')

        event = pygame.event.Event(pygame.KEYDOWN, key=pygame.K_RIGHT)
        tmp.handleEvent(event)
        self.assertEqual(tmp.direction, Vector2(1, 0),
                         'test_update_player_tank_dir_right')
        self.assertEqual(tmp.vel, Vector2(speed, 0),
                         'test_update_player_tank_vel_right')