@Override
 public void keyPressed(KeyEvent e) {
   GameAction action = getKeyAction(e);
   if (action != null) {
     action.press();
   }
   e.consume();
 }
 @Override
 public void keyReleased(KeyEvent e) {
   GameAction action = getKeyAction(e);
   if (action != null) {
     action.release();
   }
   e.consume();
 }
示例#3
0
 // from the KeyListener interface
 public void keyReleased(KeyEvent e) {
   GameAction gameAction = getKeyAction(e);
   if (gameAction != null) {
     gameAction.release();
   }
   // make sure the key isn't processed for anything else
   e.consume();
 }
 private void mouseHelper(int negative, int positive, int delta) {
   GameAction action;
   if (delta < 0) {
     action = mouseActions[negative];
   } else {
     action = mouseActions[positive];
   }
   if (action != null) {
     action.press(Math.abs(delta));
     action.release();
   }
 }
示例#5
0
 private void mouseHelper(int codeNeg, int codePos, int amount) {
   GameAction gameAction;
   if (amount < 0) {
     gameAction = mouseActions[codeNeg];
   } else {
     gameAction = mouseActions[codePos];
   }
   if (gameAction != null) {
     gameAction.press(Math.abs(amount));
     gameAction.release();
   }
 }
示例#6
0
 public void phase2() {
   System.out.println("Phase 2");
   lblStatus1.setText("SR Phase");
   lblStatus2.setText("Resolving slow actions...");
   lblStatus3.setText("");
   ListIterator iList = listAT.listIterator();
   while (iList.hasNext()) {
     GameAction oAction = (GameAction) iList.next();
     if (oAction.isReady()) {
       oAction.fire();
       iList.remove();
     }
   }
   phase3();
 }
  // reset a game action to nothingness.
  public void clearActions(GameAction action) {
    for (int i = 0; i < keyActions.length; i++) {
      if (keyActions[i] == action) {
        keyActions[i] = null;
      }
    }

    for (int i = 0; i < mouseActions.length; i++) {
      if (mouseActions[i] == action) {
        mouseActions[i] = null;
      }
    }
    action.reset();
  }
示例#8
0
  public void checkGameInput() {

    if (moveLeft.isPressed()) {
      g_RotationSpeed -= 0.001f;
    }

    if (moveRight.isPressed()) {

      g_RotationSpeed += 0.001f;
    }

    if (modTex.isPressed()) {
      if (modo == GL_REPLACE) {
        modo = GL_MODULATE;
      } else {
        modo = GL_REPLACE;
      }
      // Ajusta o modo de aplicação da textura
      glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, modo);
    }
    if (drawMode.isPressed()) {

      if (g_ViewMode == GL_TRIANGLES) { // We our drawing mode is at triangles
        g_ViewMode = GL_LINE_STRIP; // Go to line stips
      } else {
        g_ViewMode = GL_TRIANGLES; // Go to triangles
      }
    }

    if (fullScreen.isPressed()) {
      setFullScreen(!isFullScreen());
    }

    if (debug.isPressed()) {
      g_bDisplayNodes = !g_bDisplayNodes;
    }
  }
 public void mouseReleased(MouseEvent e) {
   GameAction action = getMouseButtonAction(e);
   if (action != null) {
     action.release();
   }
 }
 public void mousePressed(MouseEvent e) {
   GameAction action = getMouseButtonAction(e);
   if (action != null) {
     action.press();
   }
 }
 public void addAction(GameAction GA) {
   logger.trace(
       "Create action id : " + GA.getId() + "action {},args {}", GA.getAction(), GA.getArgs());
   this.getActions().put(GA.getId(), GA);
 }
 public void removeAction(GameAction GA) {
   logger.trace("Delete action id : " + GA.getId());
   this.getActions().remove(GA.getId());
 }
 // Checks which input occurs
 public void checkSystemInput() {
   if (exit.isPressed()) {
     System.exit(0);
   }
 }
示例#14
0
  public void updateWorld(long elapsedTime) {

    float angleVelocity;

    Player player = (Player) gameObjectManager.getPlayer();
    MovingTransform3D playerTransform = player.getTransform();
    Vector3D velocity = playerTransform.getVelocity();

    // playerTransform.stop();
    velocity.x = 0;
    velocity.z = 0;
    float x = -playerTransform.getSinAngleY();
    float z = -playerTransform.getCosAngleY();
    if (goForward.isPressed()) {
      velocity.add(x * PLAYER_SPEED, 0, z * PLAYER_SPEED);
    }
    if (goBackward.isPressed()) {
      velocity.add(-x * PLAYER_SPEED, 0, -z * PLAYER_SPEED);
    }
    if (goLeft.isPressed()) {
      velocity.add(z * PLAYER_SPEED, 0, -x * PLAYER_SPEED);
    }
    if (goRight.isPressed()) {
      velocity.add(-z * PLAYER_SPEED, 0, x * PLAYER_SPEED);
    }
    if (jump.isPressed()) {
      player.setJumping(true);
    }
    if (fire.isPressed()) {
      player.fireProjectile();
    }

    playerTransform.setVelocity(velocity);

    // look up/down (rotate around x)
    angleVelocity = Math.min(tiltUp.getAmount(), 200);
    angleVelocity += Math.max(-tiltDown.getAmount(), -200);
    playerTransform.setAngleVelocityX(angleVelocity * PLAYER_TURN_SPEED / 200);

    // turn (rotate around y)
    angleVelocity = Math.min(turnLeft.getAmount(), 200);
    angleVelocity += Math.max(-turnRight.getAmount(), -200);
    playerTransform.setAngleVelocityY(angleVelocity * PLAYER_TURN_SPEED / 200);

    // update objects
    gameObjectManager.update(elapsedTime);

    // limit look up/down
    float angleX = playerTransform.getAngleX();
    float limit = (float) Math.PI / 2;
    if (angleX < -limit) {
      playerTransform.setAngleX(-limit);
    } else if (angleX > limit) {
      playerTransform.setAngleX(limit);
    }

    // set the camera to be 100 units above the player
    Transform3D camera = polygonRenderer.getCamera();
    camera.setTo(playerTransform);
    camera.getLocation().add(0, CAMERA_HEIGHT, 0);
  }
示例#15
0
  public void checkGameInput() {

    if (drawMode.isPressed()) {
      octree.setRenderMode(!octree.isRenderMode());
      octree.setObjectColliding(false);
      if (octree.isRenderMode()) {
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Render the triangles in fill mode
      } else {
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // Render the triangles in wire frame mode
      }
      octree.createDisplayList(octree, g_World, octree.getDisplayListID());
    }

    if (fullScreen.isPressed()) {
      setFullScreen(!isFullScreen());
    }

    if (enter.isPressed()) {
      Octree.octreeCollisionDetection = !Octree.octreeCollisionDetection;
    }

    if (left.isPressed()) {
      camera.strafe(-SPEED / 10 * elapsedTime);
    }

    if (right.isPressed()) {

      camera.strafe(SPEED / 10 * elapsedTime);
    }

    if (zoomIn.isPressed()) {
      camera.move(+SPEED / 10 * elapsedTime);
    }
    if (zoomOut.isPressed()) {

      camera.move(-SPEED / 10 * elapsedTime);
    }

    if (moveLeft.isPressed()) {
      g_BallEntity.fAngle += (float) AR_DegToRad(g_BallEntity.fTurnRate) * elapsedTime;
    }

    if (moveRight.isPressed()) {

      // Rotate the Ball Angle Counter Clockwise.
      g_BallEntity.fAngle -= (float) AR_DegToRad(g_BallEntity.fTurnRate) * elapsedTime;
    }

    // Clamp values above 2 * PI or 360 Deg's.
    if (g_BallEntity.fAngle >= AR_2PI) g_BallEntity.fAngle = g_BallEntity.fAngle - AR_2PI;

    // Clamp values below 0.
    if (g_BallEntity.fAngle < 0.0f) g_BallEntity.fAngle = AR_2PI + g_BallEntity.fAngle;

    if (debug.isPressed()) {
      g_bDisplayNodes = !g_bDisplayNodes;
    }

    if (moveUp.isPressed()) {
      if (g_BallEntity.fVelX + (g_BallEntity.fAccel * elapsedTime) < g_BallEntity.fMaxVel) {
        g_BallEntity.fVelX += g_BallEntity.fAccel * elapsedTime;
        g_BallEntity.fVelZ += g_BallEntity.fAccel * elapsedTime;
      }
    }
    if (moveDown.isPressed()) {

      // Move the Ball Backwards.
      if (g_BallEntity.fVelX - (g_BallEntity.fAccel * elapsedTime) > g_BallEntity.fMinVel) {
        g_BallEntity.fVelX -= g_BallEntity.fAccel * elapsedTime;
        g_BallEntity.fVelZ -= g_BallEntity.fAccel * elapsedTime;
      }
    }

    // Apply Gravity to this Entity (using time based motion) if he's not colliding with anything.
    if (!octree.isObjectColliding()) g_BallEntity.fVelY += (GRAVITY * elapsedTime);

    // Apply (spherical based) motion.

    g_BallEntity.x +=
        (g_fSinTable[(int) AR_RadToDeg(g_BallEntity.fAngle)] * g_BallEntity.fVelX) * elapsedTime;
    g_BallEntity.y += g_BallEntity.fVelY * elapsedTime;
    g_BallEntity.z +=
        (g_fCosTable[(int) AR_RadToDeg(g_BallEntity.fAngle)] * g_BallEntity.fVelZ) * elapsedTime;

    // Adjust the Forward I-Sectors Endpoint.
    g_vForwardISector[1].x =
        g_fSinTable[(int) AR_RadToDeg(g_BallEntity.fAngle)] * g_BallEntity.fRadius * 0.2f;
    g_vForwardISector[1].y = 0.0f;
    g_vForwardISector[1].z =
        g_fCosTable[(int) AR_RadToDeg(g_BallEntity.fAngle)] * g_BallEntity.fRadius * 0.2f;

    // Slow this guy down (friction).
    if (g_BallEntity.fVelX > g_fFriction * elapsedTime) {
      g_BallEntity.fVelX -= g_fFriction * elapsedTime;
    }

    if (g_BallEntity.fVelZ > g_fFriction * elapsedTime) {
      g_BallEntity.fVelZ -= g_fFriction * elapsedTime;
    }

    if (g_BallEntity.fVelX < g_fFriction * elapsedTime) {
      g_BallEntity.fVelX += g_fFriction * elapsedTime;
    }

    if (g_BallEntity.fVelZ < g_fFriction * elapsedTime) {
      g_BallEntity.fVelZ += g_fFriction * elapsedTime;
    }

    // If this Ball falls outside the world, drop back from the top.
    if (g_BallEntity.y < -30) {
      g_BallEntity.x = g_BallEntity.z = 0.0f;
      g_BallEntity.y = 5.0f;
      g_BallEntity.fVelX = g_BallEntity.fVelY = g_BallEntity.fVelZ = 0.0f;
    }

    Vector3f[] vGroundLine = {new Vector3f(), new Vector3f()};
    Vector3f[] vForwardLine = {new Vector3f(), new Vector3f()};

    // Prepare a Temporary line transformed to the Balls exact world position.
    vGroundLine[0].x = g_BallEntity.x + g_vGroundISector[0].x;
    vGroundLine[0].y = g_BallEntity.y + g_vGroundISector[0].y;
    vGroundLine[0].z = g_BallEntity.z + g_vGroundISector[0].z;

    vGroundLine[1].x = g_BallEntity.x + g_vGroundISector[1].x;
    vGroundLine[1].y = g_BallEntity.y + g_vGroundISector[1].y;
    vGroundLine[1].z = g_BallEntity.z + g_vGroundISector[1].z;

    // Prepare a Temporary line transformed to the Balls exact world position.
    vForwardLine[0].x = g_BallEntity.x + g_vForwardISector[0].x;
    vForwardLine[0].y = g_BallEntity.y + g_vForwardISector[0].y;
    vForwardLine[0].z = g_BallEntity.z + g_vForwardISector[0].z;

    vForwardLine[1].x = g_BallEntity.x + g_vForwardISector[1].x;
    vForwardLine[1].y = g_BallEntity.y + g_vForwardISector[1].y;
    vForwardLine[1].z = g_BallEntity.z + g_vForwardISector[1].z;

    // A temporary Vector holding the Intersection Point of our Intersection Check.
    vIntersectionPt = new Vector3f();

    // Reset the Status of the Object (wheter it is colliding or not).
    octree.setObjectColliding(false);

    // Reset the Nodes collided to zero so we can start with a fresh count.
    Octree.numNodesCollided = 0;

    // Test the line for an intersection with the Octree Geometry.
    if (octree.intersectLineWithOctree(octree, g_World, vGroundLine, vIntersectionPt)) {
      // Move the Ball up from the point at which it collided with the ground. This is what
      // ground clamping is!
      g_BallEntity.x = vIntersectionPt.x;
      // NOTE: Make sure it is above the surface, AND half it's height (so it isn't half
      // underground).
      // This would only apply if you placed entity's by their exact center.
      g_BallEntity.y = vIntersectionPt.y + g_BallEntity.fRadius;
      g_BallEntity.z = vIntersectionPt.z;

      // Stop your up-down velocity.
      g_BallEntity.fVelY = 0.0f;
    }

    // Test the line for an intersection with the Octree Geometry.
    if (octree.intersectLineWithOctree(octree, g_World, vForwardLine, vIntersectionPt)) {
      // Move the Ball up from the point at which it collided with the ground. This is what
      // ground clamping is!
      g_BallEntity.x = vIntersectionPt.x;
      // NOTE: Make sure it is above the surface, AND half it's height (so it isn't half
      // underground).
      // This would only apply if you placed entity's by their exact center.
      g_BallEntity.y = vIntersectionPt.y + g_BallEntity.fRadius;
      g_BallEntity.z = vIntersectionPt.z;

      // Stop your up-down velocity.
      g_BallEntity.fVelY = 0.0f;
    }
  }