protected void updatePlayer(Entity e) {
Velocity v = velocityMapper.get(e);
TurnFactor tf = turnFactorMapper.get(e);
Physics physics = physicsMapper.get(e);
Tower tower = towerMapper.get(e);
Ammo ammo = ammoMapper.get(e);
updateTowerRotation(tower, physics);
updateRecoil(tower);
if (shoot && ammo.hasAmmo(10)) {
shoot = false;
recoil = true;
// Create bullets for both barrels.
{
float x = Utils.getRotatedX(physics.getX() + 75, physics.getY() - 10, physics.getX(), physics.getY(), tower.getRotation());
float y = Utils.getRotatedY(physics.getX() + 75, physics.getY() - 10, physics.getX(), physics.getY(), tower.getRotation());
EntityFactory.createBullet(world, x, y, tower.getRotation(), e);
}
{
float x = Utils.getRotatedX(physics.getX() + 75, physics.getY() + 10, physics.getX(), physics.getY(), tower.getRotation());
float y = Utils.getRotatedY(physics.getX() + 75, physics.getY() + 10, physics.getX(), physics.getY(), tower.getRotation());
EntityFactory.createBullet(world, x, y, tower.getRotation(), e);
}
// apply force to moving tank.
float counterRotation = tower.getRotation()+180;
float force = 2000f;
physics.setForce(force*TrigLUT.cosDeg(counterRotation), force*TrigLUT.sinDeg(counterRotation));
// add sound.
EntityFactory.createSound(world, "sounds/shoot.wav");