コード例 #1
0
ファイル: ShooterCore.java プロジェクト: tmackgit/GameDev
  public void init() {

    // set up the local lights for the model.
    float ambientLightIntensity = .8f;
    List lights = new LinkedList();
    lights.add(new PointLight3D(-100, 100, 100, .5f, -1));
    lights.add(new PointLight3D(100, 100, 0, .5f, -1));

    // load the object model
    ObjectLoader loader = new ObjectLoader();
    loader.setLights(lights, ambientLightIntensity);
    PolygonGroup blastModel = null;
    try {
      blastModel = loader.loadObject("../images/blast.obj");
      botProjectileModel = loader.loadObject("../images/botprojectile.obj");
    } catch (IOException ex) {
      ex.printStackTrace();
    }

    init(modes);

    inputManager.mapToKey(jump, KeyEvent.VK_SPACE);
    inputManager.mapToMouse(fire, InputManager.MOUSE_BUTTON_1);

    ((Player) gameObjectManager.getPlayer()).setBlastModel(blastModel);
  }
コード例 #2
0
ファイル: ShooterCore.java プロジェクト: tmackgit/GameDev
  public void createPolygons() {
    Graphics2D g = screen.getGraphics();
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, screen.getWidth(), screen.getHeight());
    g.setColor(Color.WHITE);
    g.drawString("Loading...", 5, screen.getHeight() - 5);
    screen.update();

    float ambientLightIntensity = .2f;
    List lights = new LinkedList();
    lights.add(new PointLight3D(-100, 100, 100, .3f, -1));
    lights.add(new PointLight3D(100, 100, 0, .3f, -1));

    MapLoader loader = new MapLoader(new BSPTreeBuilderWithPortals());
    loader.setObjectLights(lights, ambientLightIntensity);

    try {
      bspTree = loader.loadMap(mapFile);
    } catch (IOException ex) {
      ex.printStackTrace();
    }

    collisionDetection = new CollisionDetectionWithSliding(bspTree);
    gameObjectManager = new GridGameObjectManager(bspTree.calcBounds(), collisionDetection);
    gameObjectManager.addPlayer(new Player());

    ((BSPRenderer) polygonRenderer).setGameObjectManager(gameObjectManager);

    createGameObjects(loader.getObjectsInMap());
    Transform3D start = loader.getPlayerStartLocation();
    gameObjectManager.getPlayer().getTransform().setTo(start);
  }
コード例 #3
0
ファイル: ShooterCore.java プロジェクト: tmackgit/GameDev
  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);
  }