Package com.tankz.components

Examples of com.tankz.components.Physics


  }

  protected void updatePlayer(Entity e) {
    Velocity v = velocityMapper.get(e);
    TurnFactor tf = turnFactorMapper.get(e);
    Physics c = collidableMapper.get(e);
   
    updateMoving(e);
    //updateRotating(e);

    //updateMoving(t, v, world.getDelta());
View Full Code Here


    //wc.getBody().setRotation(t.getRotation());
  }
 

  private void updateMoving(Entity e) {
    Physics physics = collidableMapper.get(e);
   
    if(forward) {
      float ax = (TrigLUT.cosDeg(physics.getRotation()) * world.getDelta());
      float ay = (TrigLUT.sinDeg(physics.getRotation()) * world.getDelta());
     
      velocity += world.getDelta() * 0.005f;
      if(velocity > 1.25f) {
        velocity = 1.25f;
      }
     
      physics.getBody().adjustVelocity(new Vector2f(velocity*ax, velocity*ay));
    } else if(velocity > 0) {
      velocity = 0;
    }
   
    if(reverse) {
      float ax = (TrigLUT.cosDeg(physics.getRotation()) * world.getDelta());
      float ay = (TrigLUT.sinDeg(physics.getRotation()) * world.getDelta());
     
      velocity -= world.getDelta() * 0.0025f;
      if(velocity < -1) {
        velocity = -1;
      }
     
      physics.getBody().adjustVelocity(new Vector2f(velocity*ax, velocity*ay));
    } else if(velocity < 0) {
      velocity += world.getDelta() * 1f;
      if(velocity > 0) {
        velocity = 0;
      }
View Full Code Here

    physicsMapper = world.getMapper(Physics.class);
  }

  @Override
  protected void process(Entity e) {
    Physics physics = physicsMapper.get(e);
   
    if(physics.getX() < boundsStartX)
      physics.setLocation(boundsStartX, physics.getY());//physics.applyForce(world.getDelta() * 300, 0);
    else if(physics.getX() > boundsEndX)
      physics.setLocation(boundsEndX, physics.getY());//physics.applyForce(world.getDelta() * -300, 0);
   
    if(physics.getY() < boundsStartY)
      physics.setLocation(physics.getX(), boundsStartY);//physics.applyForce(0, world.getDelta() * 300);
    else if(physics.getY() > boundsEndY)
      physics.setLocation(physics.getX(), boundsEndY);//physics.applyForce(0, world.getDelta() * -300);

  }
 
View Full Code Here

    tf.setFactor(turnFactor);
  }

 
  private void updateRotating(Entity e) {
    Physics physics = collidableMapper.get(e);
   
    TurnFactor turnFactor = turnFactorMapper.get(e);

    if(turnRight) {
      physics.getBody().adjustRotation(turnFactor.getFactor() * (reverse?-1:1));
    }
    else if(turnLeft) {
      physics.getBody().adjustRotation(turnFactor.getFactor() * (reverse?-1:1));
    }
  }
 
View Full Code Here

  }

  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");

      ammo.reduceBy(10);
View Full Code Here

      g.drawRect(offsetX*scaleX, offsetY*scaleY, scaleX*cameraSystem.getWidth(), scaleY*cameraSystem.getHeight());
     
      ImmutableBag<Entity> entities = world.getManager(GroupManager.class).getEntities("crates");
      for(int i = 0; entities.size() > i; i++) {
        Entity crate = entities.get(i);
        Physics cratePhysics = physicsMapper.get(crate);
        float crateX = cratePhysics.getX()*scaleX;
        float crateY = cratePhysics.getY()*scaleY;
        g.fillRect(crateX-1, crateY-1, 2, 2);
      }
     
      ImmutableBag<Entity> tanks = world.getManager(GroupManager.class).getEntities("tanks");
      for(int i = 0; tanks.size() > i; i++) {
        Entity t = tanks.get(i);
        String tp = world.getManager(PlayerManager.class).getPlayer(t);
        Physics physics = physicsMapper.get(t);
        g.setColor(Color.green);
        float tx = physics.getX()*scaleX;
        float ty = physics.getY()*scaleY;
        g.fillRect(tx-3, ty-3, 6, 6);
      }
     
    }
    g.translate(-container.getWidth()+minimapWidth+20,-20);
View Full Code Here

      input.setOffset(getStartX(), getStartY());
    }
  }

  private void updatePosition() {
    Physics physics = physicsMapper.get(player);
    lookAtX = physics.getX();
    lookAtY = physics.getY();
  }
View Full Code Here

  }

  @Override
  protected void process(Entity e) {
    Health health = healthMapper.get(e);
    Physics physics = physicsMapper.get(e);

    float xo = physics.getX()-25;
    float yo = physics.getY()-30;
    g.translate(xo,yo);
    {
      int healthIterations = Math.round(health.getHealthStatus()*10f);
      int i = 0;

View Full Code Here

    physicsWorld.step();
  }
 
  @Override
  protected void added(Entity e) {
    Physics collidable = e.getComponent(Physics.class);
    Body body = collidable.getBody();
    body.setUserData(e);
    physicsWorld.add(body);
  }
View Full Code Here

    physicsWorld.add(body);
  }

  @Override
  protected void removed(Entity e) {
    Physics collidable = e.getComponent(Physics.class);
    physicsWorld.remove(collidable.getBody());
  }
View Full Code Here

TOP

Related Classes of com.tankz.components.Physics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.