Package org.newdawn.fizzy

Examples of org.newdawn.fizzy.Body


  }

  @Override
  public void collided(CollisionEvent event) {
    this.radius = currentPlayer.getCurrentBeaver().getCurrentWeapon().getBlastRadius();
    Body currentBeaverBody = currentPlayer.getCurrentBeaver().getBody();
    Beaver[] p1Team = p1.getTeam();
    Beaver[] p2Team = p2.getTeam();
    if (event.contains(bullet)) {
     
      WorldManifold worldManifold = new WorldManifold();
      event.getContact().jboxContact.getWorldManifold(worldManifold);

      drawCircle = true;
      collisionX = worldManifold.points[0].x;
      collisionY = worldManifold.points[0].y;
     
      float bulletX = bullet.getX();
      float bulletY = bullet.getY();
      //mark the bullet to be killed on the next update cycle
      killBullet = true;
      //mark the turn to be ended
      endTurn = 2000;

      //How much damage to do?
      for(int i = 0;i<Constants.BEAVERS_PER_TEAM;i++){
        double x1 = p1Team[i].getBody().getX();
        double y1 = p1Team[i].getBody().getY();
        double x2 = p2Team[i].getBody().getX();
        double y2 = p2Team[i].getBody().getY();
        double distanceB1 = distance(x1,y1,bulletX,bulletY);
        double distanceB2 = distance(x2,y2,bulletX,bulletY);
        if(distanceB1 < this.radius ){
          int damage = calculateDMG(distanceB1);
          p1Team[i].reduceHP(damage);
        }
        if(distanceB2 < this.radius){
          int damage = calculateDMG(distanceB1);
          p2Team[i].reduceHP(damage);
        }
      }
     
     
    }
    //if a body hits the boundary and it's a bullet, remove it.
    //it a beaver hits it, kill the beaver.
    if (event.contains(boundary)) {
      Body otherBody;
      if (event.getBodyA().equals(boundary)) otherBody = event.getBodyB();
      else otherBody = event.getBodyA();
      for(int i=0;i<Constants.BEAVERS_PER_TEAM;i++){
        if(p1Team[i].getBody()==otherBody){
          p1Team[i].reduceHP(1000);
          endTurn = 2000;
          //break;
        }
        if(p2Team[i].getBody()==otherBody){
          p2Team[i].reduceHP(1000);
          endTurn = 2000;
          //break;
        }
      }
      if (otherBody.equals(bullet)) {
        killBullet = true;
        endTurn = 2000;
     
    }
    //if the current beaver collects a health pack or ammo
View Full Code Here


    return value;
  }
 
  @Override
  public void separated(CollisionEvent event) {
    Body currentBeaverBody = currentPlayer.getCurrentBeaver().getBody();
    if (event.contains(currentBeaverBody)) {
      drawCircle = false;
    }
  }
View Full Code Here

    g.pushTransform();
    g.translate(worldCenterX, worldCenterY);
    g.scale(scale, -scale);

    for (int i = 0; i < world.getBodyCount(); i++) {
      Body body = world.getBody(i);
      if (!body.equals(terrainBody) && !body.equals(boundary)) {
        g.setColor(Color.black);
        drawBody(g, body);
      }
    }
    g.popTransform();
View Full Code Here

    drawStats(g);
 
  }
 
  protected void placeCrosshairs(){
    Body currentBeaverBody = currentPlayer.getCurrentBeaver().getBody();
    world.remove(crosshair);
    float x = (float) (currentBeaverBody.getX() + 100*Math.sin(Math.toRadians(crosshairAngle)));
    float y = (float) (currentBeaverBody.getY() + 100*Math.cos(Math.toRadians(crosshairAngle)));
    crosshair = new StaticBody(new Circle(10),x,y);
    world.add(crosshair);
    crosshair.setActive(false);
  }
View Full Code Here

    world.add(item[0].getBody());
    world.add(item[1].getBody());
    world.addBodyListener(item[0].getBody(), this);
    world.addBodyListener(item[1].getBody(), this);
   
    Body currentBeaverBody = currentPlayer.getCurrentBeaver().getBody();
    crosshairAngle = 45;
    crosshair = new StaticBody(new Rectangle(50f,5f),currentBeaverBody.getX(),currentBeaverBody.getY());
    world.add(crosshair);
    crosshair.setRotation(crosshairAngle);
    crosshairImage = new Image("data/crosshair.png").getScaledCopy(0.5f);
    bulletImage = new Image("data/wood.png").getScaledCopy(0.5f);
    healthImage = new Image("data/health.png").getScaledCopy(0.5f);
View Full Code Here

    endTime = startTime + (countdown * 1000);
  }
 
  private void endTurn(GameContainer gc){
    System.out.println("End the turn");
    Body currentBeaverBody = currentPlayer.getCurrentBeaver().getBody();
    if (currentBeaverBody.isAttached()) currentBeaverBody.setActive(true);
    //Cycle Player
    nextPlayer();
    currentBeaverBody = currentPlayer.getCurrentBeaver().getBody();
    worldCenterX = gc.getWidth()/2 - (currentBeaverBody.getX()*scale);
    worldCenterY = gc.getHeight()/2 - (currentBeaverBody.getY()*-scale);
    timer(Constants.SECONDS_PER_TURN);
  }
 
View Full Code Here

        item[i].getBody().setActive(false);
        world.remove(item[i].getBody());
      }
    }
    //Check win condition
    Body currentBeaverBody = currentPlayer.getCurrentBeaver().getBody();
    Beaver currentBeaver = currentPlayer.getCurrentBeaver();
    this.radius = currentBeaver.getCurrentWeapon().getBlastRadius();
   
    if (powerSeqEngaged) {
      if (power >= 150) power = 0;
      else power+=4;
    }
   
    // Keep the camera centered at all times *GIANNI*
    if(!cameraOnBullet){
      if (currentBeaverBody.isAttached())
        if (!currentBeaverBody.isSleeping()){
        worldCenterX = gc.getWidth()/2 - (currentBeaverBody.getX()*scale);
        worldCenterY = gc.getHeight()/2 - (currentBeaverBody.getY()*-scale);
        }
    }
    else{
      if (bullet.isAttached()){
        worldCenterX = gc.getWidth()/2 - (bullet.getX()*scale);
        worldCenterY = gc.getHeight()/2 - (bullet.getY()*-scale);
      }
    }
   
    for (int i = 0; i < Constants.UPDATES; i++) {

      Input input = gc.getInput();
     
      if (input.isKeyPressed(Input.KEY_C)) {
        worldCenterX = gc.getWidth()/2 - (currentBeaverBody.getX()*scale);
        worldCenterY = gc.getHeight()/2 - (currentBeaverBody.getY()*-scale);
      }
     
      if (input.isKeyDown(Input.KEY_Z)) { 
        if (scale > 0.001f) {
          scale = scale - 0.001f;
          worldCenterX = gc.getWidth()/2 - (currentBeaverBody.getX()*scale);
          worldCenterY = gc.getHeight()/2 - (currentBeaverBody.getY()*-scale);
        }
      }
     
      if (input.isKeyDown(Input.KEY_X)) {
        scale = scale + 0.001f;
        worldCenterX = gc.getWidth()/2 - (currentBeaverBody.getX()*scale);
        worldCenterY = gc.getHeight()/2 - (currentBeaverBody.getY()*-scale);
      }
     
      if (input.isKeyDown(Input.KEY_W)) {
        worldCenterY += 0.2f;// /updates;
      }
     
      if (input.isKeyDown(Input.KEY_S)) {
        worldCenterY -= 0.2f;// /updates;
      }
     
      if(input.isKeyPressed(Input.KEY_R)){
        System.out.println(crosshairAngle);
        crosshairAngle = 45;
      }

      if(input.isKeyPressed(Input.KEY_Q)){
        currentPlayer.getCurrentBeaver().cycleWeapon();
      }

      if (input.isKeyDown(Input.KEY_A)) {
        worldCenterX += 0.2f;// /updates;
      }
     
      if (input.isKeyPressed(Input.KEY_O)) {
        endTurn(gc);
      }
     
      if (input.isKeyDown(Input.KEY_D)) {
        worldCenterX -= 0.2f;// /updates;
      }
     
      if (input.isKeyDown(Input.KEY_RIGHT)) {
        if(endTurn>0){
          continue;
        }

        if (crosshairAngle > 180) crosshairAngle = 180-(crosshairAngle-180);
        team1MovingR.update(delta*100);
        team2MovingR.update(delta*100);
        currentPlayer.getCurrentBeaver().setFacingR(true);
        if (currentBeaverBody.getAngularVelocity() > -1.5)
          currentBeaverBody.setAngularVelocity(currentBeaverBody
              .getAngularVelocity() - 0.05f);
        currentBeaverBody.setAngularVelocity(-1.5f);
      }
     
      if (input.isKeyDown(Input.KEY_LEFT)) {
        if(endTurn>0){
          continue;
        }
        if (crosshairAngle < 180) crosshairAngle = 180+(180-crosshairAngle);
        team1Moving.update(delta*100);
        team2Moving.update(delta*100);
        currentPlayer.getCurrentBeaver().setFacingR(false);
        if (currentBeaverBody.getAngularVelocity() < 1.5)
          currentBeaverBody.setAngularVelocity(currentBeaverBody.getAngularVelocity() + 0.05f);
        currentBeaverBody.setAngularVelocity(1.5f);
      }
     
      if (input.isKeyDown(Input.KEY_UP)){
        if(endTurn>0){
          continue;
        }
        if (crosshairAngle < 180 && crosshairAngle > 0) crosshairAngle -= 0.1f;
        else if (crosshairAngle > 180 && crosshairAngle < 360) crosshairAngle += 0.1f;
      }
     
      if (input.isKeyDown(Input.KEY_DOWN)){
        if(endTurn>0){
          continue;
        }
        if (crosshairAngle < 180 && crosshairAngle > 0) crosshairAngle += 0.1f;
        else if (crosshairAngle > 180 && crosshairAngle < 360) crosshairAngle -= 0.1f;
      }
     
      if (input.isKeyPressed(Input.KEY_ENTER)) {
        if(endTurn>0){
          continue;
        }
        if(currentPlayer.getCurrentBeaver().getCurrentWeapon().getAmmo()>0){
          currentPlayer.getCurrentBeaver().useWeapon();
          if (!powerSeqEngaged) {
            power = 1;
            powerSeqEngaged = true;
          }
          else {
            powerSeqEngaged = false;
            currentBeaverBody.setActive(false);
            bullet = new DynamicBody(new Circle(5),currentBeaverBody.getX(),currentBeaverBody.getY());
            bullet.setBullet(true);
            bullet.setRestitution(0);
            float x = (float) (Math.sin(Math.toRadians(crosshairAngle)));
            float y = (float) (Math.cos(Math.toRadians(crosshairAngle)));
            float xForce = (power/50)*(x)*10000000f;
            float yForce = (power/50)*(y)*10000000f;
            //System.out.println("x is "+x+", y is "+y+", angle at"+crosshairAngle);
            world.add(bullet);
            world.addBodyListener(bullet, this);
            bullet.applyForce(xForce, yForce);
            //Shot is fired, turn is over
            cameraOnBullet = true;
          }
        }

      }
     
      if (input.isKeyPressed(Input.KEY_SPACE)) {
        if (currentBeaverBody.getYVelocity() < 0.7 && currentBeaver.getFacingR()) {
          currentBeaverBody.applyForce(0, 1500000f);// /updates);
        }
        if (currentBeaverBody.getYVelocity() > -0.7 && !currentBeaver.getFacingR()) {
          currentBeaverBody.applyForce(0, 1500000f);// /updates);
        }
      }
     
      if (input.isKeyPressed(Input.KEY_ESCAPE)){
        sbg.enterState(BeaversGame.MAINMENUSTATE);
View Full Code Here

    world.add(item[0].getBody());
    world.add(item[1].getBody());
    world.addBodyListener(item[0].getBody(), this);
    world.addBodyListener(item[1].getBody(), this);
   
    Body currentBeaverBody = currentPlayer.getCurrentBeaver().getBody();
    crosshairAngle = 45;
    crosshair = new StaticBody(new Rectangle(50f,5f),currentBeaverBody.getX(),currentBeaverBody.getY());
    world.add(crosshair);
    crosshair.setRotation(crosshairAngle);
    crosshairImage = new Image("data/crosshair.png").getScaledCopy(0.5f);
    bulletImage = new Image("data/wood.png").getScaledCopy(0.5f);
    healthImage = new Image("data/health.png").getScaledCopy(0.5f);
View Full Code Here

        // TODO Auto-generated catch block
        e.printStackTrace();
      }
     
    }
    Body currentBeaverBody = currentPlayer.getCurrentBeaver().getBody();
    if (currentBeaverBody.isAttached()) currentBeaverBody.setActive(true);
    //Cycle Player
    nextPlayer();
    currentBeaverBody = currentPlayer.getCurrentBeaver().getBody();
    worldCenterX = gc.getWidth()/2 - (currentBeaverBody.getX()*scale);
    worldCenterY = gc.getHeight()/2 - (currentBeaverBody.getY()*-scale);
    timer(Constants.SECONDS_PER_TURN);
   
  }
 
View Full Code Here

        item[i].getBody().setActive(false);
        world.remove(item[i].getBody());
      }
    }
    //Check win condition
    Body currentBeaverBody = currentPlayer.getCurrentBeaver().getBody();
    Beaver currentBeaver = currentPlayer.getCurrentBeaver();
    this.radius = currentBeaver.getCurrentWeapon().getBlastRadius();
   
    if (powerSeqEngaged) {
      if (power >= 150) power = 0;
      else power+=4;
    }
   
    // Keep the camera centered at all times *GIANNI*
    if(!cameraOnBullet){
      if (currentBeaverBody.isAttached())
        if (!currentBeaverBody.isSleeping()){
        worldCenterX = gc.getWidth()/2 - (currentBeaverBody.getX()*scale);
        worldCenterY = gc.getHeight()/2 - (currentBeaverBody.getY()*-scale);
        }
    }
    else{
      if (bullet.isAttached()){
        worldCenterX = gc.getWidth()/2 - (bullet.getX()*scale);
        worldCenterY = gc.getHeight()/2 - (bullet.getY()*-scale);
      }
    }

    for (int i = 0; i < Constants.UPDATES; i++) {
      boolean keypress = false;

      Input input = gc.getInput();
      if(currentPlayer == p1){
        if (input.isKeyPressed(Input.KEY_C)) {
          worldCenterX = gc.getWidth()/2 - (currentBeaverBody.getX()*scale);
          worldCenterY = gc.getHeight()/2 - (currentBeaverBody.getY()*-scale);
         
        }

        if (input.isKeyDown(Input.KEY_Z)) { 
          if (scale > 0.001f) scale = scale - 0.001f;// /updates;
        }

        if (input.isKeyDown(Input.KEY_X)) {
          scale = scale + 0.001f;// /updates;
        }

        if (input.isKeyDown(Input.KEY_W)) {
          worldCenterY -= 0.1f;// /updates;
        }

        if (input.isKeyDown(Input.KEY_S)) {
          worldCenterY += 0.1f;// /updates;
        }

        if(input.isKeyPressed(Input.KEY_R)){
          p1Moves.add("r");
          System.out.println(crosshairAngle);
          crosshairAngle = 45;
          keypress = true;
        }

        if(input.isKeyPressed(Input.KEY_Q)){
          p1Moves.add("q");
          currentPlayer.getCurrentBeaver().cycleWeapon();
          keypress = true;
         
        }

        if (input.isKeyDown(Input.KEY_A)) {
          worldCenterX -= 0.1f;// /updates;
         
        }

        if (input.isKeyPressed(Input.KEY_O)) {
          p1Moves.add("o");
          keypress = true;
          endTurn(gc);
        }

        if (input.isKeyDown(Input.KEY_D)) {
          worldCenterX += 0.1f;// /updates;
        }

        if (input.isKeyDown(Input.KEY_RIGHT)) {
          p1Moves.add("right");
          if(endTurn>0){
            continue;
          }

          if (crosshairAngle > 180) crosshairAngle = 180-(crosshairAngle-180);
          team1MovingR.update(delta*100);
          team2MovingR.update(delta*100);
          currentPlayer.getCurrentBeaver().setFacingR(true);
          if (currentBeaverBody.getAngularVelocity() > -1.5)
            currentBeaverBody.setAngularVelocity(currentBeaverBody
                .getAngularVelocity() - 0.05f);
          currentBeaverBody.setAngularVelocity(-1.5f);
          keypress=true;
        }

        if (input.isKeyDown(Input.KEY_LEFT)) {
          p1Moves.add("left");
          if(endTurn>0){
            continue;
          }
          if (crosshairAngle < 180) crosshairAngle = 180+(180-crosshairAngle);
          team1Moving.update(delta*100);
          team2Moving.update(delta*100);
          currentPlayer.getCurrentBeaver().setFacingR(false);
          if (currentBeaverBody.getAngularVelocity() < 1.5)
            currentBeaverBody.setAngularVelocity(currentBeaverBody.getAngularVelocity() + 0.05f);
          currentBeaverBody.setAngularVelocity(1.5f);
          keypress = true;
        }

        if (input.isKeyDown(Input.KEY_UP)){
          p1Moves.add("up");
          if(endTurn>0){
            continue;
          }
          if (crosshairAngle < 180 && crosshairAngle > 0) crosshairAngle -= 0.1f;
          else if (crosshairAngle > 180 && crosshairAngle < 360) crosshairAngle += 0.1f;
          keypress = true;
        }

        if (input.isKeyDown(Input.KEY_DOWN)){
          p1Moves.add("down");
          if(endTurn>0){
            continue;
          }
          if (crosshairAngle < 180 && crosshairAngle > 0) crosshairAngle += 0.1f;
          else if (crosshairAngle > 180 && crosshairAngle < 360) crosshairAngle -= 0.1f;
          keypress = true;
        }

        if (input.isKeyPressed(Input.KEY_ENTER)) {
          p1Moves.add("enter");
          if(endTurn>0){
            continue;
          }
          if(currentPlayer.getCurrentBeaver().getCurrentWeapon().getAmmo()>0){
            currentPlayer.getCurrentBeaver().useWeapon();
            if (!powerSeqEngaged) {
              power = 1;
              powerSeqEngaged = true;
            }
            else {
              powerSeqEngaged = false;
              currentBeaverBody.setActive(false);
              bullet = new DynamicBody(new Circle(5),currentBeaverBody.getX(),currentBeaverBody.getY());
              bullet.setBullet(true);
              bullet.setRestitution(0);
              float x = (float) (Math.sin(Math.toRadians(crosshairAngle)));
              float y = (float) (Math.cos(Math.toRadians(crosshairAngle)));
              float xForce = (power/50)*(x)*10000000f;
              float yForce = (power/50)*(y)*10000000f;
              //System.out.println("x is "+x+", y is "+y+", angle at"+crosshairAngle);
              world.add(bullet);
              world.addBodyListener(bullet, this);
              bullet.applyForce(xForce, yForce);
              //Shot is fired, turn is over
              cameraOnBullet = true;
            }
          }
          keypress = true;
        }

        if (input.isKeyPressed(Input.KEY_SPACE)) {
          p1Moves.add("space");
          if (currentBeaverBody.getYVelocity() < 0.7 && currentBeaver.getFacingR()) {
            currentBeaverBody.applyForce(0, 1500000f);// /updates);
          }
          if (currentBeaverBody.getYVelocity() > -0.7 && !currentBeaver.getFacingR()) {
            currentBeaverBody.applyForce(0, 1500000f);// /updates);
          }
          keypress = true;
        }

        if (input.isKeyPressed(Input.KEY_ESCAPE)){
View Full Code Here

TOP

Related Classes of org.newdawn.fizzy.Body

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.