Exemplo n.º 1
0
    @Override
    public boolean mouseMoved(int screenX, int screenY) {

      if (controls == ControlScheme.MOUSE_AIM) {
        Vector3 touchPos = new Vector3();
        touchPos.set(screenX, screenY, 0);
        camera.unproject(touchPos);

        player.accSpeed =
            80; // ;(float)Math.sqrt((touchPos.x-camera.position.x-originX)*(touchPos.x-camera.position.x-originX)+(touchPos.y-camera.position.y-originY)*(touchPos.y-camera.position.y-originY))*SENSITIVITY;//-150;
        player.MAX_SPEED =
            player.accSpeed =
                (float)
                        Math.sqrt(
                            (touchPos.x - camera.position.x - originX)
                                    * (touchPos.x - camera.position.x - originX)
                                + (touchPos.y - camera.position.y - originY)
                                    * (touchPos.y - camera.position.y - originY))
                    * SENSITIVITY;
        if (player.MAX_SPEED > 500) {
          player.MAX_SPEED = 500;
        }
        // player.speed=(float)Math.sqrt((touchPos.x-camera.position.x-originX)*(touchPos.x-camera.position.x-originX)+(touchPos.y-camera.position.y-originY)*(touchPos.y-camera.position.y-originY))*SENSITIVITY;
        player.desAngle =
            MathUtils.atan2(
                (touchPos.y - camera.position.y - originY),
                (touchPos.x - camera.position.x - originX));

        // rotate the player acording to his angle
        player.setRotation(MathUtils.radDeg * player.angle - 90);
      }

      return false;
    }
Exemplo n.º 2
0
  public Vector3[] getNinePoints() {
    Vector3[] nine = new Vector3[8];

    CubeVertex[] vertexes = getVerts();
    for (int i = 0; i < vertexes.length; i++) {
      float[] pos = vertexes[i].getPosition();
      nine[i] = new Vector3(pos[0], pos[1], pos[2]);
    }

    for (int i = 0; i < vertexes.length; i++) {
      Vector3 prev = nine[i];
      Vector3 next = nine[(i + 1) % vertexes.length];
      nine[vertexes.length + i] = next.cpy().sub(prev).mul(0.5f).add(prev);
    }

    //  System.out.println("INIT " + Arrays.toString(nine));
    /*  if (NINE_OFFSET != 0) {
        Vector3 origin = nine[nine.length - 1].cpy();
        for (int i = 0; i < nine.length; i++) {
            nine[i].sub(origin);
            nine[i].mul(1 - NINE_OFFSET);
            nine[i].add(origin);
        }
    }*/

    //  System.out.println("     " + Arrays.toString(nine));
    return nine;
  }
Exemplo n.º 3
0
 /**
  * Handles mouse button input.
  *
  * @param deltaX
  * @param deltaY
  * @param button
  * @return
  */
 protected boolean process(float deltaX, float deltaY, int button) {
   if (button == rotateButton) {
     tmpV1.set(screen.active().direction).crs(screen.active().up).y = 0f;
     screen.active().rotateAround(target, tmpV1.nor(), deltaY * rotateAngle);
     screen.active().rotateAround(target, Vector3.Y, deltaX * -rotateAngle);
   } else if (button == translateButton) {
     screen
         .active()
         .translate(
             tmpV1
                 .set(screen.active().direction)
                 .crs(screen.active().up)
                 .nor()
                 .scl(-deltaX * translateUnits));
     screen.active().translate(tmpV2.set(screen.active().up).scl(-deltaY * translateUnits));
     if (translateTarget) target.add(tmpV1).add(tmpV2);
   } else if (button == interactButton) {
     /**
      * @TODO Make the interact button interact here. No zooming. zoom code.
      * screen.active().translate(tmpV1.set(screen.active().direction).scl(deltaY *
      * translateUnits));
      */
   }
   if (autoUpdate) screen.active().update();
   return true;
 }
Exemplo n.º 4
0
 public Transform lerp(
     final Vector3 targetT, final Quaternion targetR, final Vector3 targetS, final float alpha) {
   translation.lerp(targetT, alpha);
   rotation.slerp(targetR, alpha);
   scale.lerp(targetS, alpha);
   return this;
 }
Exemplo n.º 5
0
  private void setStaticProjectionAndCamera(Graphics graphics, Application app, GL10 gl) {
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    // x=left-right, y=up-down, z=back-forward
    camera.far = 1000000;
    camera.position.set(0, 7f + 0, 9f + 0);
    // camera.direction.set(0, 0, -4f).sub(camera.position).nor();
    camera.fieldOfView = 67;
    float orbitRadius = (new Vector3(0, 0, 0).dst(camera.position));
    camera.position.set(new Vector3(0, 0, 0));

    camera.rotate(Splash.cameraHorizAngle, 0, 1, 0);
    Vector3 orbitReturnVector = new Vector3(0, 0, 0);
    orbitReturnVector.set(camera.direction.tmp().mul(-orbitRadius));
    camera.translate(orbitReturnVector.x, orbitReturnVector.y, orbitReturnVector.z);
    camera.update();
    camera.apply(gl);

    orbitRadius = (new Vector3(0, 0, 0)).dst(camera.position);
    camera.position.set(new Vector3(0, 0, 0));
    camera.rotate(Splash.cameraVertAngle, 1, 0, 0);
    orbitReturnVector = new Vector3(0, 0, 0);
    orbitReturnVector.set(camera.direction.tmp().mul(-orbitRadius));
    camera.translate(orbitReturnVector.x, orbitReturnVector.y, orbitReturnVector.z);
    camera.update();
    camera.apply(gl);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    Splash.cameraHorizAngle = 0;
    Splash.cameraVertAngle = 0;
  }
Exemplo n.º 6
0
 @Override
 public boolean touchDown(int x, int y, int arg2, int arg3) {
   camera.unproject(mousePos.set(x, y, 0));
   if (backButton.contains(mousePos.x, mousePos.y)) {
     goBack();
   }
   ObjectMap.Entries<String, Rectangle> entries = bindingButtons.entries();
   boolean focusedAnOption = false;
   while (entries.hasNext()) {
     ObjectMap.Entry<String, Rectangle> entry = entries.next();
     Rectangle bounds = entry.value;
     camera.unproject(mousePos.set(x, y, 0));
     if (bounds.contains(mousePos.x, mousePos.y)) {
       this.focused = true;
       focusedAnOption = true;
       this.focusedBox.setY(bounds.y);
       this.focusedBox.setX(bounds.x);
       BitmapFont.TextBounds b = font.getBounds(entry.key);
       this.focusedBox.setHeight(b.height);
       this.focusedBox.setWidth(b.width);
       this.focusedAction = entry.key;
     }
   }
   if (!focusedAnOption) {
     this.focused = false;
   }
   return false;
 }
Exemplo n.º 7
0
  @Override
  public void calculateLocalInertia(float mass, Vector3 inertia) {
    // as an approximation, take the inertia of the box that bounds the spheres

    Stack stack = Stack.enter();
    Transform ident = stack.allocTransform();
    ident.setIdentity();

    float radius = getRadius();

    Vector3 halfExtents = stack.allocVector3();
    halfExtents.set(radius, radius, radius);
    VectorUtil.setCoord(halfExtents, getUpAxis(), radius + getHalfHeight());

    float margin = BulletGlobals.CONVEX_DISTANCE_MARGIN;

    float lx = 2f * (halfExtents.x + margin);
    float ly = 2f * (halfExtents.y + margin);
    float lz = 2f * (halfExtents.z + margin);
    float x2 = lx * lx;
    float y2 = ly * ly;
    float z2 = lz * lz;
    float scaledmass = mass * 0.08333333f;

    inertia.x = scaledmass * (y2 + z2);
    inertia.y = scaledmass * (x2 + z2);
    inertia.z = scaledmass * (x2 + y2);
    stack.leave();
  }
Exemplo n.º 8
0
  private int getObject(int screenX, int screenY) {
    Ray ray = cam.getPickRay(screenX, screenY);

    int result = -1;
    float distance = -1;

    for (int i = 0; i < instances.size; ++i) {
      final ObjectInstance instance = (ObjectInstance) instances.get(i);
      if (instance.equals(pitchInstance)) continue;
      instance.transform.getTranslation(position);
      position.add(instance.center);

      final float len =
          ray.direction.dot(
              position.x - ray.origin.x, position.y - ray.origin.y, position.z - ray.origin.z);
      if (len < 0f) continue;

      float dist2 =
          position.dst2(
              ray.origin.x + ray.direction.x * len,
              ray.origin.y + ray.direction.y * len,
              ray.origin.z + ray.direction.z * len);

      if (distance >= 0f && dist2 > distance) continue;
      if (dist2 <= instance.radius * instance.radius) {
        result = i;
        distance = dist2;
      }
    }
    return result;
  }
Exemplo n.º 9
0
  public void computeBoundaries() {
    min.set(Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE);
    max.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE);

    for (CubeVertex vert : verts) {

      // x coord
      if (vert.getPosition()[0] < min.x) {
        min.x = vert.getPosition()[0];
      } else if (vert.getPosition()[0] > max.x) {
        max.x = vert.getPosition()[0];
      }

      // y coord
      if (vert.getPosition()[1] < min.y) {
        min.y = vert.getPosition()[1];
      } else if (vert.getPosition()[1] > max.y) {
        max.y = vert.getPosition()[1];
      }

      // z coord
      if (vert.getPosition()[2] < min.z) {
        min.z = vert.getPosition()[2];
      } else if (vert.getPosition()[2] > max.z) {
        max.z = vert.getPosition()[2];
      }
    }

    mean.set((max.x + min.x) / 2f, (max.y + min.y) / 2f, (max.z + min.z) / 2f);
    center.set(min.x + mean.x, min.y + mean.y, min.z + mean.z);
  }
  @Override
  public void render(float delta) {
    Gdx.gl.glClearColor(1f, 1f, 1f, 0f);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    batch.setProjectionMatrix(camera.combined);
    // menu goes here
    batch.begin();
    batch.setColor(Color.GREEN);
    batch.draw(continueButton, 0, MyGdxGame.hR * 3 / 4, MyGdxGame.wR, MyGdxGame.hR / 4);
    batch.draw(newGameButton, 0, MyGdxGame.hR / 2, MyGdxGame.wR, MyGdxGame.hR / 4);
    batch.draw(optionsButton, 0, MyGdxGame.hR / 4, MyGdxGame.wR, MyGdxGame.hR / 4);
    batch.draw(exitButton, 0, 0, MyGdxGame.wR, MyGdxGame.hR / 4);

    batch.end();

    if (Gdx.input.justTouched()) {
      Vector3 touchPos = new Vector3();
      touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
      //			camera.unproject(touchPos);
      if (touchPos.y < MyGdxGame.hR / 4) {
        game.setScreen(MyGdxGame.gameScreen);
      }
      if (touchPos.y > MyGdxGame.hR / 4 && touchPos.y < MyGdxGame.hR / 2) {
        MyGdxGame.gameScreen = new GameScreen(game, MyGdxGame.getLandscapeGenerator());
        game.setScreen(MyGdxGame.gameScreen);
      }
      if (touchPos.y < MyGdxGame.hR * 3 / 4 && touchPos.y > MyGdxGame.hR / 2) {
        game.setScreen(MyGdxGame.optionsScreen);
      }
      if (touchPos.y > MyGdxGame.hR * 3 / 4) {
        Gdx.app.exit();
      }
    }
  }
Exemplo n.º 11
0
  @Override
  public void render() {
    // clear the screen with a dark blue color. The
    // arguments to glClearColor are the red, green
    // blue and alpha component in the range [0,1]
    // of the color to be used to clear the screen.
    Gdx.gl.glClearColor(0, 0, 0.2f, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    // tell the camera to update its matrices.
    camera.update();

    // tell the SpriteBatch to render in the
    // coordinate system specified by the camera.
    batch.setProjectionMatrix(camera.combined);

    // begin a new batch and draw the bucket and
    // all drops
    batch.begin();
    batch.draw(bucketImage, bucket.x, bucket.y);
    for (Rectangle raindrop : raindrops) {
      batch.draw(dropImage, raindrop.x, raindrop.y);
    }
    batch.end();
    //

    // process user input
    if (Gdx.input.isTouched()) {
      Vector3 touchPos = new Vector3();
      touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
      camera.unproject(touchPos);
      bucket.x = touchPos.x - 48 / 2;
    }
    if (Gdx.input.isKeyPressed(Keys.LEFT)) bucket.x -= 200 * Gdx.graphics.getDeltaTime();
    if (Gdx.input.isKeyPressed(Keys.RIGHT)) bucket.x += 200 * Gdx.graphics.getDeltaTime();

    // make sure the bucket stays within the screen bounds
    if (bucket.x < 0) bucket.x = 0;
    if (bucket.x > 800 - 48) bucket.x = 800 - 48;

    // commit

    // check if we need to create a new raindrop
    if (TimeUtils.nanoTime() - lastDropTime > 1000000000) spawnRaindrop();

    // move the raindrops, remove any that are beneath the bottom edge of
    // the screen or that hit the bucket. In the later case we play back
    // a sound effect as well.
    Iterator<Rectangle> iter = raindrops.iterator();
    while (iter.hasNext()) {
      Rectangle raindrop = iter.next();
      raindrop.y -= 200 * Gdx.graphics.getDeltaTime();
      if (raindrop.y + 48 < 0) iter.remove();
      if (raindrop.overlaps(bucket)) {
        dropSound.play();
        iter.remove();
      }
    }
  }
Exemplo n.º 12
0
  private void cameraUpdate(float delta) {
    Vector3 position = camera.position;
    position.x = player.getPosition().x * PPM;
    position.y = player.getPosition().y * PPM;
    camera.position.set(position);

    camera.update();
  }
Exemplo n.º 13
0
 private static Vector3 calcNor(Vector3 v1, Vector3 v2, Vector3 v3) {
   _A = v2.cpy();
   _A.sub(v1);
   _B = v3.cpy();
   _B.sub(v2);
   _n = _A.crs(_B).nor();
   return _n;
 }
Exemplo n.º 14
0
 @Override
 public boolean touchDragged(int screenX, int screenY, int pointer) {
   mCurrentPos.set(screenX, screenY, 0);
   camera.unproject(mCurrentPos);
   camera.position.sub(mCurrentPos.sub(mCamPos));
   camera.update();
   return true;
 }
Exemplo n.º 15
0
 // ==============================================================================================
 // NOT BOX 2D STUFF JUST COOL THINGS I ADDED TO MAKE THE PROGRAM MORE "FUN"
 public void HandleTouch() {
   float fSprite_Width = sprite.getWidth();
   float fSprite_Height = sprite.getHeight();
   if (Gdx.input.isTouched()) {
     Vector3 touchPos = new Vector3(); // Using vector 3 as a 2-D vector for touch coordinates
     touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
     body.setTransform(touchPos.x - (fSprite_Width / 2), (touchPos.y - (fSprite_Height / 2)), 0);
   }
 }
Exemplo n.º 16
0
 public Zombie(City _city) {
   position = new Vector3();
   direction = new Vector3();
   direction.set(TGame.rand.nextFloat(), 0, TGame.rand.nextFloat());
   do {
     position.set(TGame.rand.nextFloat(), 0, TGame.rand.nextFloat());
   } while (!_city.isRoad(position.x, position.z));
   state = 0;
 }
Exemplo n.º 17
0
 private void updateCamZoom(float newZoom) {
   OrthographicCamera c = cam.camera;
   c.unproject(zTmp1.set(cs.xy.x, cs.xy.y, 0));
   c.zoom = newZoom;
   c.update();
   c.unproject(zTmp2.set(cs.xy.x, cs.xy.y, 0));
   c.translate(zTmp1.sub(zTmp2));
   c.update();
 }
 public boolean contains(Vector3 vec) {
   Vector3 temp = new Vector3(vec);
   Matrix4 tempMat = new Matrix4(modelMatrix);
   tempMat.inv();
   temp.mul(tempMat);
   if (box.contains(temp)) {
     return true;
   }
   return false;
 }
 @Override
 public boolean touchDragged(int x, int y, int pointer) {
   camera.unproject(curr.set(x, y, 0));
   if (!(last.x == -1 && last.y == -1 && last.z == -1)) {
     camera.unproject(delta.set(last.x, last.y, 0));
     delta.sub(curr);
     camera.position.add(delta.x, delta.y, 0);
   }
   last.set(x, y, 0);
   return false;
 }
Exemplo n.º 20
0
  public void spawnOrb(int x, int y) {
    Vector3 touchPos = new Vector3();
    touchPos.set(x, y, 0);
    camera.unproject(touchPos);

    Orb orb =
        new Orb(new Vector2(touchPos.x, touchPos.y), 10f, new Color(0.4f, 0.6f, .09f, 1.0f), this);
    orbs.add(orb);

    Gdx.app.log("LOG", "Orb Spawned at: (" + touchPos.x + ", " + touchPos.y + ")!");
  }
Exemplo n.º 21
0
  public void render() {

    logger.log();

    final float delta = Gdx.graphics.getDeltaTime();
    camController.update(delta);

    timer += delta;
    for (int i = 0; i < lightManager.pointLights.size; i++) {
      final Vector3 v = lightManager.pointLights.get(i).position;
      v.x += MathUtils.sin(timer) * 0.01f;
      v.z += MathUtils.cos(timer) * 0.01f;
      lightManager.pointLights.get(i).color.b = MathUtils.sin(timer) * 0.25f + 0.25f;
    }

    animInstance.time += delta;
    if (Gdx.input.justTouched()) {
      currAnimIdx++;
      if (currAnimIdx == model3.getAnimations().length) currAnimIdx = 0;
      animInstance.animation = model3.getAnimations()[currAnimIdx].name;
      animInstance.time = 0;
    }
    if (animInstance.time > model3.getAnimations()[currAnimIdx].totalDuration) {
      animInstance.time = 0;
    }

    Gdx.gl.glEnable(GL10.GL_CULL_FACE);
    Gdx.gl.glFrontFace(GL10.GL_CCW);
    Gdx.gl.glCullFace(GL10.GL_FRONT);

    Gdx.gl.glEnable(GL10.GL_DEPTH_TEST);
    Gdx.gl.glDepthMask(true);

    Gdx.gl.glClearColor(0, 0.1f, 0.2f, 0);
    Gdx.gl.glClear(
        GL10.GL_COLOR_BUFFER_BIT
            | GL10.GL_DEPTH_BUFFER_BIT
            | (Gdx.graphics.getBufferFormat().coverageSampling
                ? GL20.GL_COVERAGE_BUFFER_BIT_NV
                : 0));

    protoRenderer.begin();

    protoRenderer.draw(model3, animInstance);

    protoRenderer.end();
    Gdx.gl.glCullFace(GL10.GL_BACK);
    protoRenderer.begin();
    protoRenderer.draw(model, instance);
    protoRenderer.draw(model, instance2);
    protoRenderer.draw(model2, instance2);
    protoRenderer.end();
  }
Exemplo n.º 22
0
 private void checkFinish() {
   this.nodeOperator.getNodeData(/*this.nodeOperatorName*/ ).flushScale(helpV);
   if (checkSingleOrth(helpV.x, targetScale.x, scaleSpeed.x)
       || checkSingleOrth(helpV.y, targetScale.y, scaleSpeed.y)
       || checkSingleOrth(helpV.z, targetScale.z, scaleSpeed.z)) {
     helpV.x = targetScale.x / helpV.x;
     helpV.y = targetScale.y / helpV.y;
     helpV.z = targetScale.z / helpV.z;
     this.nodeOperator.scale(helpV);
     finish = true;
   }
 }
Exemplo n.º 23
0
  public void update(float delta) {
    // tmp.set(acceleration);
    // tmp.scl(delta);
    // velocity.add(tmp);
    // velocity = velocity.scl(0.95f);
    tmp.set(velocity);
    tmp.scl(delta);
    position.add(tmp);

    transform.setTranslation(position);
    collisionObject.setWorldTransform(transform);
  }
Exemplo n.º 24
0
    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
      touchDown.set(screenX, screenY, 0);
      cam.unproject(touchDown);
      toolLock = true;

      switch (current_Tool) {
        case SELECT:
          boolean selected = false;
          touchDown.set(screenX, screenY, 0);
          cam.unproject(touchDown);

          for (Selectable n : controller.levelObjects) {
            if (n.contains(touchDown.x, touchDown.y)) {
              if (n == controller.selection) {
                current_Tool = E_TOOL.TRANSLATE;
                selected = true;
              } else {
                controller.setSelection(n);
                selected = true;
              }
            }
          }

          if (selected == false) {
            controller.setSelection(null);
            current_Tool = E_TOOL.PAN;
          } else {
            if (controller.isSelectionShape()) {
              shape_Type = ((Shape) controller.selection).type;
            } else if (controller.isSelectionPoint()) {
              point_Type = ((Point) controller.selection).type;
            }
          }
          break;
        case RECTANGLE:
          controller.createBox(
              shape_Type, snapToGrid(touchDown.x), snapToGrid(touchDown.y), 2, 2, 0, 0);
          break;
        case CIRCLE:
          controller.createCircle(
              shape_Type, snapToGrid(touchDown.x), snapToGrid(touchDown.y), 2, 0, 0);
          break;
        case POINT:
          controller.createPoint(
              point_Type, "default", snapToGrid(touchUp.x), snapToGrid(touchUp.y));
          break;
      }

      return false;
    }
  private void setPosition(Vector3 basePosition, float delta) {
    tempVector.set(cam.direction);

    // Reverse the direction
    tempVector.scl(-1);
    tempVector.scl(zoomScale);

    // Add the base position
    tempVector.add(basePosition);

    // Move up the camera a bit
    tempVector.y += 0.25f;
    cam.position.set(tempVector);
  }
  @Override
  public boolean touchDragged(int x, int y, int pointer) {
    Ray ray = camera.getPickRay(x, y);
    Intersector.intersectRayPlane(ray, plane, curr);

    if (!(last.x == -1 && last.y == -1 && last.z == -1)) {
      ray = camera.getPickRay(last.x, last.y);
      Intersector.intersectRayPlane(ray, plane, delta);
      delta.sub(curr);
      camera.position.add(delta.x, delta.y, delta.z);
    }
    last.set(x, y, 0);
    return false;
  }
Exemplo n.º 27
0
  @Override
  protected void initialize() {
    Vector3 vect3 = new Vector3();

    collisionSystem.relations.connectGroups(CollisionGroups.TEDDY, CollisionGroups.TOYS);

    entityFactory.createTeddy(vect3.set(0.5f, 0f, -0.2f));
    entityFactory.createRoom();

    Entity airplane = entityFactory.createToy("airplane", vect3.set(0.5f, 0f, -6.4f), true);
    Entity alien = entityFactory.createToy("alien", vect3.set(8.5f, 0f, -9.4f), true);
    Entity workbench = entityFactory.createToy("workbench", vect3.set(18.5f, 0f, -5.4f), false);

    // TODO create furniture, obstacles, etc.
  }
Exemplo n.º 28
0
 @Override
 public void doJob(T target, long processTime) {
   long diffTime = processTime - this.lastCheckTime;
   if (diffTime > 20) {
     this.nodeOperator.getNodeData(/*this.nodeOperatorName*/ ).flushScale(helpV);
     helpV.x = 1f + (scaleSpeed.x * diffTime) / helpV.x;
     helpV.y = 1f + (scaleSpeed.y * diffTime) / helpV.y;
     helpV.z = 1f + (scaleSpeed.z * diffTime) / helpV.z;
     this.nodeOperator.scale(helpV);
     this.lastCheckTime += diffTime;
     checkFinish();
     this.nodeOperator.updatePrint();
     this.subject.adjustCurrentPrint();
   }
 }
Exemplo n.º 29
0
  @Override
  public void render() {

    Gdx.gl.glClearColor(0, 0, 0.2f, 1);

    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    camera.update();

    batch.setProjectionMatrix(camera.combined);

    batch.begin();
    batch.draw(bucketImage, bucket.x, bucket.y);

    for (Rectangle raindrop : raindrops) {
      batch.draw(dropImage, raindrop.x, raindrop.y);
    }

    batch.end();

    if (Gdx.input.isTouched()) {
      Vector3 touchPos = new Vector3();
      touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
      camera.unproject(touchPos);
      bucket.x = touchPos.x - 64 / 2;
    }
    if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) bucket.x -= 200 * Gdx.graphics.getDeltaTime();
    if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) bucket.x += 200 * Gdx.graphics.getDeltaTime();

    // make sure the bucket stays within the screen bounds
    if (bucket.x < 0) bucket.x = 0;
    if (bucket.x > 800 - 64) bucket.x = 800 - 64;

    if (TimeUtils.nanoTime() - lastDropTime > 1000000000) {
      spawnRaindrop();
    }

    Iterator<Rectangle> iter = raindrops.iterator();
    while (iter.hasNext()) {
      Rectangle raindrop = iter.next();
      raindrop.y -= 200 * Gdx.graphics.getDeltaTime();
      if (raindrop.y + 64 < 0) iter.remove();
      if (raindrop.overlaps(bucket)) {
        dropSound.play();
        iter.remove();
      }
    }
  }
Exemplo n.º 30
0
    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
      Gdx.app.log("TOUCH", "pointer: " + pointer);
      Vector3 touchPos = new Vector3();
      touchPos.set(screenX, screenY, 0);
      camera.unproject(touchPos);
      if (pointer == 0) { // the first finger is for movement
        if (controls == ControlScheme.TOUCH_JOYSTICK) {

          originX = touchPos.x - camera.position.x;
          originY = touchPos.y - camera.position.y;

          // update control-visuals
          psX = (int) (touchPos.x - camera.position.x);
          peX = psX;
          psY = (int) (touchPos.y - camera.position.y);
          peY = psY;
        } else if (controls == ControlScheme.TOUCH_AIM) {
          //		player.aimX=touchPos.x;
          //	player.aimY=touchPos.y;
        }

      } else { // the second finger makes our ship shoot
        // player.shoot();
        player.isShooting = true;
        // return false;
      }
      if (controls == ControlScheme.MOUSE_AIM && button == 0) {
        player.isShooting = true;
      }

      // we want to be able to shoot while moving
      if (touchPos.y - camera.position.y < -camera.getHeight() / 2 + 64
          && touchPos.x - camera.position.x > camera.getWidth() / 2 - 64) {
        if (avaiableToLandOnThisFrame != null) {
          // game.setScreen(new GameOverScreen(game));

          SpaceGame.screen(Res.shop);
        } else {
          player.switchWeapon();
        }
      }

      if (controls == ControlScheme.ACCELERATION) {
        player.isShooting = true;
      }
      return false;
    }