예제 #1
0
 // Metodo que devuelve una textura de un Arraylist cada X tiempo (intervalTime).
 private Texture SwapTextureFromArray(
     ArrayList<Texture> list, int startIndex, long startTime, float intervalTime) {
   Texture img = null;
   if (startIndex < list.size()) {
     Music sound = soundsList.get(startIndex);
     if (TimeUtils.timeSinceMillis(startTime) < intervalTime * 1000) {
       img = list.get(startIndex);
       if (startIndex < titlesList.size()) {
         imageTitle.ChangeFontText(titlesList.get(startIndex));
       }
       if (!soundPlayed) {
         System.out.println("Playing music");
         sound.play();
         soundPlayed = true;
       }
     } else {
       if (!sound.isPlaying()) {
         actualImgIndex++;
         beginTime = TimeUtils.millis();
         img = list.get(startIndex);
         imageTitle.ChangeFontText(titlesList.get(startIndex));
         System.out.println("Music finished");
         soundPlayed = false;
       }
     }
   } else {
     img = list.get(texturesList.size() - 1);
   }
   return img;
 }
예제 #2
0
 public void damage(float i, float x, float y) {
   long now = TimeUtils.nanosToMillis(TimeUtils.nanoTime());
   if (now - lastDamaged > damageInterval) {
     lastDamaged = now;
     hp -= i;
     deltaPos.x += x;
     deltaPos.y += y;
   }
 }
  private void spawnCircle() {
    Circle fallingCircle = new Circle();

    fallingCircle.x =
        MathUtils.random(0, 480 - 50); // 480 is width of screen, 50 is width of circle
    fallingCircle.y = 1200; // top of screen
    fallingCircle.width = 50;
    fallingCircle.height = 50;
    lastDropTime = TimeUtils.nanoTime();

    // Change the probability (i.e. 5) as gameTime increases, and the more power ups we have
    randomNum = MathUtils.random(0, 7);

    if ((randomNum < 1)
        && (game.circlesGathered > 10)) { // introduce bombs after collecting 10+ circles
      fallingCircle.colour = 1; // 1 represents a bomb
    } else if ((randomNum < 2) && (game.circlesGathered > 25)) {
      // randomly generate a power
      // fallingCircle.powerUp.type = power.

    } else {
      fallingCircle.colour = 0; // 0 represents normal circle
    }

    circles.add(fallingCircle);
  }
예제 #4
0
  @Override
  public void act(float delta) {
    super.act(delta);

    if (TimeUtils.nanoTime() - lastCarTime > 3000000000f) spawnCar();

    Iterator<EnemyCar> iter = enemyCars.iterator();
    while (iter.hasNext()) {
      EnemyCar enemyCar = iter.next();
      if (enemyCar.getBounds().x + enemyCar.getWidth() <= 0) {
        iter.remove();
        removeActor(enemyCar);
      }
      if (enemyCar.getBounds().overlaps(playerCar.getBounds())) {
        iter.remove();
        if (enemyCar.getX() > playerCar.getX()) {
          if (enemyCar.getY() > playerCar.getY()) enemyCar.crash(true, true);
          else enemyCar.crash(true, false);
        } else {
          if (enemyCar.getY() > playerCar.getY()) enemyCar.crash(false, true);
          else enemyCar.crash(false, false);
        }
      }
    }
  }
  @Override
  public void create() {
    ShaderProgram.pedantic = false;

    String vs = Gdx.files.internal("signed/vertex.glsl").readString();
    String fs = Gdx.files.internal("signed/fragment.glsl").readString();

    shader = new ShaderProgram(vs, fs);

    if (!shader.isCompiled()) {
      throw new IllegalArgumentException(
          "Error compiling distance field shader: " + shader.getLog());
    }

    mesh =
        new Mesh(true, 4, 6, new VertexAttribute(VertexAttributes.Usage.Position, 3, "a_position"));
    float[] vertices = {1, -1, 0, 1, 1, 0, -1, 1, 0, -1, -1, 0};

    short[] indices = {
      0, 1, 2,
      2, 3, 0
    };
    mesh.setVertices(vertices);
    mesh.setIndices(indices);

    startTime = TimeUtils.millis();
  }
예제 #6
0
  @Override
  public void render(SpriteBatch sb) {
    delta = (TimeUtils.millis() - startTime + 700) / 1000;
    tweenManager.update(delta);
    bgManager.render(sb);

    sb.setProjectionMatrix(camera.combined);
    sb.begin();
    backButton.render(sb);
    randomCardButton.draw(sb);
    rareCardButton.draw(sb);

    Fonts.MFont.draw(
        sb, "Cost: " + randomCardCost, randomCardButton.getX(), randomCardButton.getY() - 40);
    Fonts.MFont.draw(
        sb, "Cost: " + rareCardCost, rareCardButton.getX(), rareCardButton.getY() - 40);

    Fonts.MFont.draw(
        sb,
        currGold,
        MainGame.WIDTH - Fonts.MFont.getBounds(currGold).width - 40,
        MainGame.HEIGHT - 50);

    if (showingCard) {
      sb.draw(alpha, 0, 0, MainGame.WIDTH, MainGame.HEIGHT);
      purchasedCard.render(
          new Vector2(
              MainGame.WIDTH / 2 - (Card.WIDTH / 2 * cardAnimSprite.getScaleX()),
              MainGame.HEIGHT / 2 - (Card.HEIGHT / 2 * cardAnimSprite.getScaleX())),
          cardAnimSprite.getScaleX(),
          sb);
      unlockedText.draw(sb);
    }
    sb.end();
  }
예제 #7
0
  @Override
  public void render() {
    viewport.apply();

    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    renderer.setProjectionMatrix(viewport.getCamera().combined);
    renderer.begin(ShapeType.Filled);

    // Since we're using an extend viewport, the world might be bigger than we expect
    float worldCenterX = viewport.getWorldWidth() / 2;
    float worldCenterY = viewport.getWorldHeight() / 2;

    // TODO: Figure out how long it's been since the animation started using TimeUtils.nanoTime()
    long delta = TimeUtils.nanoTime() - appCreationTime;

    // TODO: Use MathUtils.nanoToSec to figure out how many seconds the animation has been running
    float seconds = delta * MathUtils.nanoToSec;

    // TODO: Figure out how many cycles have elapsed since the animation started running
    float cycles = seconds / CYCLE;

    // TODO: Figure out where in the cycle we are
    float cyclePosition = cycles % 1;

    // TODO: Use MathUtils.sin() to set the x position of the circle

    float x = worldCenterX + MOVEMENT_DISTANCE * MathUtils.sin(MathUtils.PI2 * cyclePosition);
    float y = worldCenterY;
    renderer.circle(x, y, CIRCLE_RADIUS);
    renderer.end();
  }
예제 #8
0
파일: TextField.java 프로젝트: henu/libgdx
 private void blink() {
   long time = TimeUtils.nanoTime();
   if ((time - lastBlink) / 1000000000.0f > blinkTime) {
     cursorOn = !cursorOn;
     lastBlink = time;
   }
 }
예제 #9
0
파일: Drop.java 프로젝트: hecao/testgithub
  @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();
      }
    }
  }
예제 #10
0
 @Override
 public void show() {
   Gdx.input.setInputProcessor(stage);
   beginTime = TimeUtils.millis();
   actualImgIndex = 0;
   stage = new Stage();
   SetupShowStage();
 }
예제 #11
0
 private void moveRight(float delta) {
   if (jumpState == Enums.JumpState.GROUNDED && walkState != Enums.WalkState.WALKING) {
     walkStartTime = TimeUtils.nanoTime();
   }
   walkState = Enums.WalkState.WALKING;
   facing = Direction.RIGHT;
   position.x += delta * Constants.GIGAGAL_MOVE_SPEED;
 }
예제 #12
0
  @Override
  public void create() {
    renderer = new ShapeRenderer();
    viewport = new ExtendViewport(WORLD_SIZE, WORLD_SIZE);

    // TODO: Save current value of TimeUtils.nanoTime()
    appCreationTime = TimeUtils.nanoTime();
  }
예제 #13
0
 @Override
 protected void end() {
   if (TimeUtils.nanoTime() - startTime > 1000000000) /* 1,000,000,000ns == one second */ {
     int size = getEntityIds().size();
     Gdx.app.log(TAG, "fps: " + Gdx.graphics.getFramesPerSecond() + ", entities: " + size);
     startTime = TimeUtils.nanoTime();
     int max = 250000;
     if (size < max) {
       for (int i = 0; i < Math.max(size / 3, 100); i++) {
         if (size + i < max) {
           createSwarmer();
         } else {
           break;
         }
       }
     }
   }
 }
예제 #14
0
  @Override
  public void render() {
    long frameTime = TimeUtils.nanoTime();
    float deltaTime = (frameTime - lastFrameTime) / 1000000000.0f;
    lastFrameTime = frameTime;

    Gdx.app.log(
        "DeltaTimeTest", "delta: " + deltaTime + ", gdx delta: " + Gdx.graphics.getDeltaTime());
  }
 private void spawnRaindrop() {
   Rectangle raindrop = new Rectangle();
   raindrop.x = MathUtils.random(0, 800 - 64);
   raindrop.y = 480;
   raindrop.width = 32;
   raindrop.height = 128;
   raindrops.add(raindrop);
   lastDropTime = TimeUtils.nanoTime();
 }
예제 #16
0
  private void shoot() {
    long now = TimeUtils.nanosToMillis(TimeUtils.nanoTime());
    if (now - lastShootTime > shootInterval) {
      lastShootTime = now;
      float x = position.x;
      float y = position.y;

      // Use random floats and shootDeviation to add a feeling of accuracy to the shoot
      float directionX =
          dirX + (ran.nextFloat() * (shootDeviation + shootDeviation) - shootDeviation);
      float directionY =
          dirY + (ran.nextFloat() * (shootDeviation + shootDeviation) - shootDeviation);

      lastShoot = new Bullet(bulletTex, x, y, directionX, directionY, false, attack);
      lastShoot.xDisplacement = 28 * (size.x / 32);
      lastShoot.yDisplacement = 28 * (size.y / 32);
      lastShoot.updateAABB();
    }
  }
예제 #17
0
  @Override
  public void render() {
    Gdx.graphics.getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT);

    if (mode == 3) {
      Gdx.graphics.getGL10().glDisable(GL10.GL_BLEND);
      Gdx.graphics.getGL10().glEnable(GL10.GL_ALPHA_TEST);
    }

    if (mode == 2) {
      Gdx.graphics.getGL10().glEnable(GL10.GL_BLEND);
      Gdx.graphics.getGL10().glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    }

    if (mode >= 1) {
      Gdx.graphics.getGL10().glEnable(GL10.GL_TEXTURE_2D);
      texture.bind();
    }

    if (mode == 0) {
      Gdx.graphics.getGL10().glDisable(GL10.GL_BLEND);
      Gdx.graphics.getGL10().glDisable(GL10.GL_ALPHA_TEST);
      Gdx.graphics.getGL10().glDisable(GL10.GL_TEXTURE_2D);
    }

    Gdx.graphics.getGL10().glColor4f(1, 1, 1, 0.01f);

    for (int i = 0; i < numFills; i++) mesh.render(GL10.GL_TRIANGLES);

    mean += numFills;
    frames++;

    if (Gdx.graphics.getDeltaTime() < 1 / 60f) numFills++;

    if (TimeUtils.nanoTime() - lastOut >= 1000000000) {
      Gdx.app.log("FillrateTest", "fills: " + mean / frames + ", fps: " + frames + ", mode" + mode);
      mean = 0;
      frames = 0;
      lastOut = TimeUtils.nanoTime();
      if (Gdx.graphics.getFramesPerSecond() < 60) numFills--;
    }
  }
예제 #18
0
 private void blink() {
   if (!Gdx.graphics.isContinuousRendering()) {
     cursorOn = true;
     return;
   }
   long time = TimeUtils.nanoTime();
   if ((time - lastBlink) / 1000000000.0f > blinkTime) {
     cursorOn = !cursorOn;
     lastBlink = time;
   }
 }
예제 #19
0
 public AssetLoadingTask(
     AssetManager manager,
     AssetDescriptor assetDesc,
     AssetLoader loader,
     ExecutorService threadPool) {
   this.manager = manager;
   this.assetDesc = assetDesc;
   this.loader = loader;
   this.threadPool = threadPool;
   startTime = manager.log.getLevel() == Logger.DEBUG ? TimeUtils.nanoTime() : 0;
 }
예제 #20
0
 private void renderCase() {
   printSelected();
   for (int i = 0; i < 4; i++) {
     number[i] = rand.nextInt(9) + 1;
     selected[i] = false;
   }
   int num1 = rand.nextInt(4);
   int num2 = (num1 + rand.nextInt(3) + 1) % 4;
   answer = number[num1] + number[num2];
   caseStartTime = TimeUtils.millis();
 }
예제 #21
0
 private void spawnCar() {
   int lane = MathUtils.random(0, 2);
   float yPos = 0;
   if (lane == 0) yPos = lane0;
   if (lane == 1) yPos = lane1;
   if (lane == 2) yPos = lane2;
   EnemyCar enemyCar = new EnemyCar(getWidth(), yPos);
   enemyCars.add(enemyCar);
   addActor(enemyCar);
   lastCarTime = TimeUtils.nanoTime();
 }
예제 #22
0
파일: enemy.java 프로젝트: hilalh/sandbox
 public enemy() {
   entRect = new Rectangle();
   entRect.x = MathUtils.random(0, 854 - 48);
   entRect.y = 480;
   entRect.width = 48;
   entRect.height = 34;
   lastEnemyTime = TimeUtils.nanoTime();
   if (MathUtils.random(1, 5) == 2) {
     GameScreen.addBullet(getX(), getY());
     GameScreen.enemyFire.play();
   }
 }
예제 #23
0
  public static long spawnRaindrop(Array<Rectangle> raindrops) {

    // create a raindrop and randomly place it at the top of the screen
    Rectangle raindrop = new Rectangle();
    raindrop.x = MathUtils.random(0, 800 - 64);
    raindrop.y = 480;
    raindrop.width = 64;
    raindrop.height = 64;
    raindrops.add(raindrop);

    return TimeUtils.nanoTime();
  }
예제 #24
0
  @Override
  public void combat_action_1() {
    float x = direction * Constants.ENEMY_SPEED;
    float y =
        amplitude
            * Math.round(((Math.sin(half_period * body.getPosition().x) * Constants.ENEMY_SPEED)));
    if (avoidUp
        && body.getPosition().y
            < Utils.convertToBox(Constants.WORLD_HEIGHT - 2 * Constants.ENEMY_HEIGHT)) {
      avoidUp = false;
    } else if (avoidDown
        && body.getPosition().y
            > Utils.convertToBox(
                GameScreen.cannon.getPosition().y
                    + Utils.convertToBox(Constants.ENEMY_HEIGHT) * 7)) {
      avoidDown = false;
    } else if (body.getPosition().y > Utils.convertToBox(Constants.WORLD_HEIGHT) || avoidUp) {
      y = -1f;
      avoidUp = true;
    } else if (body.getPosition().y
            < GameScreen.cannon.getPosition().y + Utils.convertToBox(Constants.ENEMY_HEIGHT) * 10
        || avoidDown) {
      y = 1f;
      avoidDown = true;
    }
    Vector2 velocity = new Vector2(x, y);
    body.setLinearVelocity(velocity);

    if (body.getPosition().x <= Utils.convertToBox(-Constants.ENEMY_WIDTH)) {
      direction = 1;
    }
    if (body.getPosition().x
        >= Utils.convertToBox((Constants.ENEMY_WIDTH) + Constants.WORLD_WIDTH)) {
      direction = -1;
    }
    if (TimeUtils.millis() - lastFiring > (Math.random() + 10) * MAX_CHARGING) {
      fire();
      lastFiring = (double) TimeUtils.millis();
    }
  }
예제 #25
0
  public void update(AlienSpawner as, float dt) {
    // Find the closest alien
    Alien closest = null;
    float closest_dy = -1, closest_dx = -1;

    for (Alien alien : as.aliens) {
      float dy = 480 - alien.getY();
      float dx = alien.getMidX() - getMidX();

      if (Math.abs(dy) <= Math.abs(closest_dy) || closest_dy == -1) {
        closest_dy = dy;

        if (Math.abs(dx) < Math.abs(closest_dx) || closest_dx == -1) {
          closest_dx = dx;
          closest = alien;
        }
      }
      alien.unhighlight();
    }

    if (closest != null) {
      closest.highlight();

      float d = closest_dx;
      float k = 0.05f;
      float f = k * d;
      float mass = 10.0f;
      float accel = f / mass;
      v += accel;

      if (v > 0) {
        v = Math.min(v, max_speed);
      } else {
        v = Math.max(v, -max_speed);
      }

      double time = TimeUtils.millis();
      if (time - last_shot >= shot_cooldown) {
        if (Math.abs(closest_dx) < (getWidth() / 2 - closest.getWidth() / 2)) {
          GameEventEmitter.trigger("fire_defender_weapon");
          last_shot = time;
        }
      }
    }

    v *= 0.8;
    setX(getX() + v);

    // Make sure the defender stays within the screen bounds
    if (getX() < 0) setX(0);
    if (getX() > 800 - getWidth()) setX(800 - getWidth());
  }
예제 #26
0
  public static void accumulateTimeStep() {
    double newTime = TimeUtils.millis() / 1000.0;
    double frameTime = Math.min(newTime - currentTime, 0.25f);
    float deltaTime = (float) frameTime;
    currentTime = newTime;

    accumulator += deltaTime;

    // System.out.println("Accumulator / TimeStep: "+(float) accumulator / Physics.TIMESTEP);
    // interpolation
    // interpolateTimeStep((float) accumulator / Physics.TIMESTEP);

  }
예제 #27
0
  private void updateInit() {
    if (Gdx.input.justTouched()) {
      game.camera.unproject(touchPosition.set(Gdx.input.getX(), Gdx.input.getY(), 0));

      for (int i = 0; i < 4; i++) {
        if (blockBounds[i].contains(touchPosition.x, touchPosition.y)) {
          gameState = GameState.Action;
          selected[i] = true;
        }
      }
      Gdx.app.log(TAG, "updateInit");
      printSelected();
    }
    caseStartTime = TimeUtils.millis();
  }
예제 #28
0
파일: Drop.java 프로젝트: jmmrcp/Libgdx
  @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();
      }
    }
  }
예제 #29
0
  @Override
  protected void initialize() {
    EntityEdit swarm = world.createEntity().edit();
    swarm.create(Swarm.class);
    swarm.create(Bounds.class).setRadius(10);
    swarm.create(Pos.class);
    swarmId = swarm.getEntityId();
    // we can do about 10k in gwt
    createSwarm(100);
    // hmm consume speed/dmg taken based on swarm size && scale?
    // spread out swarm takes less dmg, but eats slowly,
    // compact swarms eats fast, but is vulnerable to dmg

    edibles =
        world.getAspectSubscriptionManager().get(Aspect.all(Pos.class, Edible.class, Bounds.class));
    startTime = TimeUtils.nanoTime();
  }
 @Override
 public void render() {
   Gdx.gl20.glViewport(
       0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight());
   Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
   shader.begin();
   shader.setUniform2fv(
       "u_resolution",
       new float[] {(float) Gdx.graphics.getWidth(), (float) Gdx.graphics.getHeight()},
       0,
       2);
   shader.setUniformf("u_time", TimeUtils.timeSinceMillis(startTime) / 1000f);
   shader.setUniform2fv(
       "u_mousePos",
       new float[] {Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY()},
       0,
       2);
   mesh.render(shader, GL20.GL_TRIANGLES);
   shader.end();
 }