Пример #1
0
  public void onCreate() {
    brightness = 150;

    released = true;

    GL.setRender3D(true);

    AL.setMasterVolume(0.1f);

    map = new Map();

    camera = new Camera();
    camera.setMaxPitch(90);
    camera.setMinPitch(-90);
    camera.setCameraMode(Camera.XZ_ONLY);

    player = new Player(2, 2, 2, 1, 1, 1, map);
    player.attachCamera(camera);

    Gun pistol = new Pistol(map);
    pistol.addAmmo(2500);
    pistol.reload(false);

    player.addGun(pistol, true);

    player.move(0, 9, 0);

    font =
        new Font(
            "res/images/font/font.png",
            26,
            4,
            new char[] {
              'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
                  'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
              'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
                  'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_', '-', '+', '=', '~', '`', '!',
                  '@', '#', '$', '%', '^', '&', '*', '(', ')',
              '?', '>', '<', ';', ':', '\'', '"', '{', '}', '[', ']', '\\', '|', ',', '.', '/', ' ',
                  ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
            });

    grass = new Texture("res/images/grass.png");

    GL.initLighting();
    GL.setShadeModel(GL.SMOOTH);

    GL.setAmbientLighti(brightness, brightness, brightness);
    GL.setLightProperties();

    GL.addSpecular(GL.LIGHT0, new Point(0.35f, 0.35f, 0.35f));
    //		GL.addSpecular(GL.LIGHT1, new Point(01.0f, 01.0f, 01.0f));
    //
    //		GL.setShadeModel(GL.SMOOTH);
    //
    //		GL.addLight(new Vector(0, 0, -1), 15);

    //		frameBufferId = GL.genFrameBuffer();

    texture = new Texture(0);

    GL.enablePolygonAntialiasing();
    //		GL.initBasicLights();
  }
Пример #2
0
  public void loop(int dfps) {
    float delta = 60f / Frame.getFps();

    map.update(dfps, delta);

    //		if (dfps == 0)
    //		{
    //			System.out.println(Frame.getFps());
    //		}

    if (MouseInput.isGrabbed()) {
      float dWheel = MouseInput.getDWheel();

      if (dWheel != 0) {
        dWheel /= 112;

        if (player.cameraAttached() && player.getPerspective() == Actor.THIRD) {
          offsetY += -1 / 5f * dWheel;
          offsetZ += -5 / 5f * dWheel;

          if (offsetY > 0 && offsetZ > 0) {
            camera.move(0, -1 / 5f * dWheel, -5 / 5f * dWheel);
          } else {
            offsetY -= -1 / 5f * dWheel;
            offsetZ -= -5 / 5f * dWheel;
          }
        }

        brightness += dWheel * 2;

        brightness = brightness < 0 ? 0 : brightness;

        GL.setAmbientLighti(brightness, brightness, brightness);
        GL.setClearColori(brightness, brightness, brightness, 255);
      }

      float dx = MouseInput.getDX();
      float dy = MouseInput.getDY();

      player.setSprinting(KeyboardInput.isKeyDown(KeyboardInput.KEY_LEFT_SHIFT));

      if (KeyboardInput.isKeyDown(KeyboardInput.KEY_W)) {
        player.move(0, 0, -0.1f * delta);
      }
      if (KeyboardInput.isKeyDown(KeyboardInput.KEY_A)) {
        player.move(-0.1f * delta, 0, 0);
      }
      if (KeyboardInput.isKeyDown(KeyboardInput.KEY_S)) {
        player.move(0, 0, 0.1f * delta);
      }
      if (KeyboardInput.isKeyDown(KeyboardInput.KEY_D)) {
        player.move(0.1f * delta, 0, 0);
      }
      if (KeyboardInput.isKeyDown(KeyboardInput.KEY_SPACE)) {
        player.jump();
      }

      player.yaw(dx * 0.10f);
      player.pitch(-dy * 0.10f);

      if (KeyboardInput.next(KeyboardInput.KEY_C)) {
        if (player.getPerspective() == Player.THIRD) {
          player.setPerspective(Player.FIRST);
        } else if (player.getPerspective() == Player.FIRST) {
          player.setPerspective(Player.THIRD);
        }
      }

      if (KeyboardInput.next(KeyboardInput.KEY_L)) {
        map.render = map.render == GL.POINTS ? GL.TRIANGLES : GL.POINTS;
      }

      if (KeyboardInput.next(KeyboardInput.KEY_O)) {

        GL.setWireFrameMode(!GL.isWireFrame(), GL.isWireFrame(), true);
        //			GL.setShowColors(!GL.isShowingColors());
      }

      if (KeyboardInput.next(KeyboardInput.KEY_R)) {
        if (player.getActiveGun() != null) {
          Gun gun = player.getActiveGun();

          if (gun.getIdleAmmo() > 0) {
            gun.reload();
          }
        }
      }

      if (MouseInput.isButtonDown(MouseInput.LEFT_MOUSE_BUTTON)) {
        if (player.getActiveGun() != null) {
          if (releasedDelay > player.getActiveGun().getShotDelay()
              && (player.getActiveGun().getShotDelay() != -1 || released)) {
            player.useActiveWeapon();

            released = false;
            releasedDelay = 0;
          } else {
            releasedDelay++;
          }
        }
      } else {
        released = true;
      }
    }

    if (MouseInput.isButtonDown(MouseInput.LEFT_MOUSE_BUTTON)) {
      MouseInput.setGrabbed(true);

      released = false;
    }

    if (KeyboardInput.isKeyDown(KeyboardInput.KEY_ESCAPE)) {
      MouseInput.setGrabbed(false);
    }

    //			if (KeyboardInput.isKeyDown(KeyboardInput.KEY_R))
    //			{
    //				if (player.cameraAttached())
    //				{
    //					player.detachCamera();
    //				}
    //				else
    //				{
    //					player.attachCamera(camera);
    //				}
    //			}

    if (KeyboardInput.next(KeyboardInput.KEY_F11)) {
      Frame.setFullscreen(!Frame.isFullscreen());
    }

    //			if (KeyboardInput.isKeyDown(KeyboardInput.KEY_K))
    //			{
    //				player.deta
    //			}

    //		System.out.println(player.getYaw() + ", " + player.getPitch() + ", " + player.getRoll());

    player.update(dfps, delta);
  }