public void lvlChanged(int bouclier) {
   positionEmiter.nor();
   positionEmiter.scl(originalScale);
   positionEmiter.scl(1 + (bouclier * 0.6f));
   speed = 40;
   speed += (bouclier * 0.66f) * speed;
 }
  /////////////////// SERVER
  @Override
  public void onReceivedNewPacket(Packet pack, Entity ent) {
    PhysixBodyComponent phxc = ComponentMappers.physixBody.get(ent);
    try {

      MovementPacket p = (MovementPacket) pack;
      InventoryComponent inventory = ComponentMappers.inventory.get(ent);
      MoveComponent move = ComponentMappers.move.get(ent);

      Vector2 vel = dummyVector.set(p.xPos, p.yPos);

      if ((inventory.getMetalShards() <= inventory.maxMetalShards)
          && (inventory.getMetalShards() > 0)) {
        float invtemp = (float) inventory.getMetalShards() / (float) inventory.maxMetalShards;
        vel.scl(move.speed - move.speed * (invtemp * 0.75f));
      } else {
        vel.scl(move.speed);
      }

      phxc.setLinearVelocity(vel);
      // phxc.setAngle(p.rotation);
      phxc.setAngle(p.rotation * MathUtils.degreesToRadians);
    } catch (ClassCastException e) {
    }
  }
  public void drawArrow(
      Vector2 a,
      Vector2 b,
      float width,
      float feather,
      float headDist,
      float headWidth,
      Color color) {
    // Firstly, draw the body of the arrow. B is the front.
    drawLine(a, b, width, feather, color);

    // Get the direction vector a->b
    dir.set(a);
    dir.sub(b);
    dir.scl(1 / dir.len());

    // Get the point down the line that the arrow head lines get to
    d.set(dir);
    d.scl(headDist);
    d.add(b);

    // Now, move d out to the sides
    amount.set(dir);
    amount.rotate(90);
    amount.scl(headWidth);

    right.set(d).add(amount);
    left.set(d).sub(amount);

    // Draw the arrow heads to not-quite-b to make it prettier
    c.set(b);
    c.sub(dir.scl(-width * 0.2f));
    drawLine(c, left, width, feather, color);
    drawLine(c, right, width, feather, color);
  }
Beispiel #4
0
  private int generate(Array<Vector2> input, int mult) {
    int c = tristrip.size;
    if (endcap <= 0) {
      tristrip.add(input.get(0));
    } else {
      Vector2 p = input.get(0);
      Vector2 p2 = input.get(1);
      perp.set(p).sub(p2).scl(endcap);
      tristrip.add(new Vector2(p.x + perp.x, p.y + perp.y));
    }
    texcoord.add(new Vector2(0f, 0f));

    for (int i = 1; i < input.size - 1; i++) {
      Vector2 p = input.get(i);
      Vector2 p2 = input.get(i + 1);

      // get direction and normalize it
      perp.set(p).sub(p2).nor();

      // get perpendicular
      perp.set(-perp.y, perp.x);

      float thick = thickness * (1f - ((i) / (float) (input.size)));

      // move outward by thickness
      perp.scl(thick / 2f);

      // decide on which side we are using
      perp.scl(mult);

      // add the tip of perpendicular
      tristrip.add(new Vector2(p.x + perp.x, p.y + perp.y));
      // 0.0 -> end, transparent
      texcoord.add(new Vector2(0f, 0f));

      // add the center point
      tristrip.add(new Vector2(p.x, p.y));
      // 1.0 -> center, opaque
      texcoord.add(new Vector2(1f, 0f));
    }

    // final point
    if (endcap <= 0) {
      tristrip.add(input.get(input.size - 1));
    } else {
      Vector2 p = input.get(input.size - 2);
      Vector2 p2 = input.get(input.size - 1);
      perp.set(p2).sub(p).scl(endcap);
      tristrip.add(new Vector2(p2.x + perp.x, p2.y + perp.y));
    }
    // end cap is transparent
    texcoord.add(new Vector2(0f, 0f));
    return tristrip.size - c;
  }
Beispiel #5
0
  public void update(float delta, Array<Block> collisions) {
    // NOTE: figure out why legs go into block, could be order of checking for collisions/updating
    // position
    // position += velocity above collisions before changing the velocity
    acceleration.y = gravity;

    if (velocity.y < 0) onGround = false;

    if (delta
        > .1f) { // make sure time passed isn't great enough to cause clipping issues when window
                 // moved
      delta = .02f;
    }

    acceleration.scl(delta);
    velocity.add(acceleration);

    processCollisions(collisions);

    if (Math.abs(velocity.x) < .05) velocity.x = 0;
    else {
      velocity.x *= friction;
    }

    if (velocity.x > maxVel) velocity.x = maxVel;
    if (velocity.x < -maxVel) velocity.x = -maxVel;

    position.add(velocity.cpy().scl(delta));
    bounds.x = position.x;
    bounds.y = position.y;
    stateTime += delta;

    setPosition(getPosition());
  }
Beispiel #6
0
  private void drawTriangleStrips(ShapeRenderer shapeRenderer, Color color, Color color1) {
    for (int i = 0; i < vertexDataArray.size; i++) {
      StripVertex bb = vertexDataArray.items[i];

      Array<Float> data = bb.insideVertexData;
      for (int j = 0; j < data.size - 3; ) {

        shapeRenderer.setColor(j == 0 ? color : color1);

        tmp.x = data.items[j];
        tmp.y = data.items[j + 1];
        tmp.rotateRad(angleRad);
        tmp.scl(scale);
        tmp.add(position);

        tmp1.x = data.items[j + 3];
        tmp1.y = data.items[j + 4];
        tmp1.rotateRad(angleRad);
        tmp1.scl(scale);
        tmp1.add(position);
        j += 3;

        shapeRenderer.line(tmp, tmp1);
      }
      data = bb.outsideVertexData;
      for (int j = 0; j < data.size - 3; ) {

        shapeRenderer.setColor(j == 0 ? Color.ORANGE : Color.RED);

        tmp.x = data.items[j];
        tmp.y = data.items[j + 1];
        tmp.rotateRad(angleRad);
        tmp.scl(scale);
        tmp.add(position);

        tmp1.x = data.items[j + 3];
        tmp1.y = data.items[j + 4];
        tmp1.rotateRad(angleRad);
        tmp1.scl(scale);
        tmp1.add(position);
        j += 3;

        shapeRenderer.line(tmp, tmp1);
      }
    }
  }
Beispiel #7
0
  private void drawLineFromFirstToLast(ShapeRenderer shapeRenderer, Color color) {
    shapeRenderer.setColor(color);
    for (BoundingBox br : boundingBoxes) {

      tmp.set(vertices.items[br.begin]);
      tmp.rotateRad(angleRad);
      tmp.scl(scale);
      tmp.add(position);

      tmp1.set(vertices.items[(br.begin + br.count) % vertices.size]);
      tmp1.rotateRad(angleRad);
      tmp1.scl(scale);
      tmp1.add(position);

      shapeRenderer.line(tmp, tmp1);
    }
  }
Beispiel #8
0
  @Override
  public Array<Vector2> getVerticesRotatedScaledAndTranslated(
      float rotation, float scale, float transX, float transY) {

    for (int i = 0; i < vertices.size; i++) {
      Vector2 w = verticesRotatedAndTranslated.items[i];
      w.set(vertices.items[i]);
      w.rotateRad(rotation);
      w.scl(scale);
      w.add(transX, transY);
    }
    return verticesRotatedAndTranslated;
  }
Beispiel #9
0
  /**
   * Ray-cast the world in constant steps specified in {@link #setRay(Vector2, Vector2, float)}
   *
   * @see World#rayCast(RayCastCallback, Vector2, Vector2)
   *     <p>Note: this implementation asumes that the raycast will hit.
   */
  public void process() {
    Vector2 step = new Vector2(endPoint);
    step.sub(beginPoint);
    step.nor();
    step.scl(stepLength);

    Vector2 endPoint = new Vector2(beginPoint);
    endPoint.add(step);

    while (!hit) {
      world.rayCast(this, beginPoint, endPoint);
      endPoint.add(step);
    }
  }
Beispiel #10
0
  public void update(float deltaTime) {
    processKeys();

    if (state == FOLLOW) {
      target.set(map.bob.pos);
      if (map.bob.dir == Bob.RIGHT) target.x--;
      if (map.bob.dir == Bob.LEFT) target.x++;
      target.y += 0.2f;

      vel.set(target).sub(pos).scl(Math.min(4, pos.dst(target)) * deltaTime);
      if (vel.len() > MAX_VELOCITY) vel.nor().scl(MAX_VELOCITY);
      tryMove();
    }

    if (state == CONTROLLED) {
      accel.scl(deltaTime);
      vel.add(accel.x, accel.y);
      if (accel.x == 0) vel.x *= DAMP;
      if (accel.y == 0) vel.y *= DAMP;
      if (vel.x > MAX_VELOCITY) vel.x = MAX_VELOCITY;
      if (vel.x < -MAX_VELOCITY) vel.x = -MAX_VELOCITY;
      if (vel.y > MAX_VELOCITY) vel.y = MAX_VELOCITY;
      if (vel.y < -MAX_VELOCITY) vel.y = -MAX_VELOCITY;
      vel.scl(deltaTime);
      tryMove();
      vel.scl(1.0f / deltaTime);
    }

    if (state == FIXED) {
      if (stateTime > 5.0f) {
        stateTime = 0;
        state = FOLLOW;
      }
    }

    stateTime += deltaTime;
  }
Beispiel #11
0
  /**
   * Update position & velocity vectors given acceleration and deltaTime
   *
   * @param deltaTime
   */
  private void updatePosition(float deltaTime) {
    if (accel.len() > 0) {
      accel.scl(deltaTime); // dv = a * dt
      velocity.add(accel.x, accel.y); // vf = vi + dv

      // Limit velocity to max
      if (velocity.len() > MAX_VELOCITY) {
        velocity.nor().scl(MAX_VELOCITY);
      }
    }
    Vector2 deltaPos = new Vector2(velocity.x * deltaTime, velocity.y * deltaTime);

    Vector2 newDelta = Collision.tryMove(this, bounds, deltaPos);
    if (!newDelta.equals(deltaPos)) { // We hit something
      stopMoving();
    }
    position.add(newDelta); // d = d*dt
  }
Beispiel #12
0
  private void init() {
    r = new Random();
    showedUp = false;
    start = new Vector2();
    target = new Vector2();
    setOrbitable(false);
    double x = calculatePosition();
    double alpha = r.nextDouble() * Math.PI * 2;
    target.set((float) (Math.cos(alpha) * x), (float) (Math.sin(alpha) * x));
    radius = RADIUS;
    setlifespan(BACKUPLIFESPAWN);

    AssetLoader loader = AssetLoader.get();
    enterSound = loader.getSound(AssetContainer.SOUND_HEMAN_ENTER);
    getSound = loader.getSound(AssetContainer.SOUND_HEMAN_GET);
    twinkle = loader.getSound(AssetContainer.SOUND_TWINKLE);
    sprite = new Sprite(loader.getTexture(AssetContainer.HEMAN));

    velocity = new Vector2(target);
    if (r.nextBoolean()) velocity.rotate90(1);
    else velocity.rotate90(-1);
    // TODO does this work? do it better with 'nextFloat' ?

    start = new Vector2(velocity);
    start.scl(10);
    start = start.add(target);
    velocity.scl(-1 * VELOCITIYMULTYPLY);

    ParticleEffect effect = new ParticleEffect(ESPGame.getLevel().particleContainer.heman);
    ESPGame.getLevel().addParticleSystem(effect);
    effect.setPosition(this.position.x, this.position.y);
    effect.start();
    particleEffect = effect;

    getEffect = new ParticleEffect(ESPGame.getLevel().particleContainer.hemanGet);

    setPosition(start);
    sprite.setSize(radius * 2, radius * 2);
    sprite.setOriginCenter();
    sprite.setCenter(position.x, position.y);
  }
Beispiel #13
0
  private void initIntro() {
    try {
      Vector2 m = new Vector2(velocity);
      m.scl(SPAWNVELOCITYMULTIPLY);

      ParticleEffect effect =
          new ParticleEffect(ESPGame.getLevel().particleContainer.sternschnuppe);
      ParticleSpawner spawner = new ParticleSpawner(getPosition(), m, effect, STERNSCHNUPPE_DAUER);
      introParticleEffect = effect;
      ESPGame.getLevel().addEntity(spawner);

      paused = true;
      twinkle.play(ESPGame.game.getSoundVolume() * 0.9f);
      // Game.print("I AM SUCCESS!");
    } catch (Exception e) {
      // Game.print("I AM ERROR!");
      e.printStackTrace();
    }
    introplayed = true;
    // TODO remove try catch?
    // Game.print("I AM DONE!");
  }
Beispiel #14
0
  @Override
  public void update() {
    if (!isActive()) return;

    posCpy.set(GameModel.getPlayer().position);
    diffToPlayer.set(posCpy.sub(position));

    float wantedAngle = MathUtils.atan2(diffToPlayer.y, diffToPlayer.x);
    /*
                      ^
            3,14 <--- |----> 0
    */
    if (direction == AbstractMap.N && (wantedAngle > MathUtils.PI || wantedAngle < 0)) return;
    else if (direction == AbstractMap.S && wantedAngle > 0) return;
    else if (direction == AbstractMap.W
        && (!(wantedAngle < MathUtils.PI / 2f && wantedAngle > -MathUtils.PI / 2f))) return;
    else if (direction == AbstractMap.E
        && (!(wantedAngle > MathUtils.PI / 2f || wantedAngle < -MathUtils.PI / 2f))) return;

    body.setTransform(position.x, position.y, wantedAngle);

    if (diffToPlayer.len() < Config.getDimensions().WORLD_WIDTH / 2f)
      if (MathUtils.random()
          < (type == CANNON_TYPE.SINGLE ? Config.BULLET_RATE_LOW : Config.BULLET_RATE_MEDIUM)) {
        float angle = body.getAngle() * MathUtils.radiansToDegrees;

        origin.set(position).add(diffToPlayer.scl(.1f));
        posCpy.set(GameModel.getPlayer().position);

        if (type == CANNON_TYPE.SINGLE) {
          weapon.fire1(origin, posCpy.rotate(MathUtils.random(-1, 1)));
          createGunSmoke(angle);
        } else if (type == CANNON_TYPE.DOUBLE) {
          weapon.fire1(origin, posCpy.rotate(MathUtils.random(-1, 1)));
          weapon.fire2(origin, posCpy.rotate(MathUtils.random(-1, 1)));
        }
      }
  }
Beispiel #15
0
  @Override
  public void update(float deltaTime) {
    // Compute player input direction
    if (cmds.isEmpty() == false) {
      dir.x = 0;
      dir.y = 0;
      if (cmds.contains(Command.MoveUp)) {
        dir.y += 1;
      }
      if (cmds.contains(Command.MoveDown)) {
        dir.y -= 1;
      }
      if (cmds.contains(Command.MoveLeft)) {
        dir.x -= 1;
      }
      if (cmds.contains(Command.MoveRight)) {
        dir.x += 1;
      }
      dir.nor();
      // Set the velocity of the player object to the direction * speed
      // This enables immediate turns
      super.setVelocity(dir.scl(speed));

      super.position.x += velocity.x * deltaTime;
      super.position.y += velocity.y * deltaTime;
      bounds.setCenter(super.position);

      System.out.println(position.toString());
    }

    if (timeLeftOnEmpowered > 0.0f) {
      timeLeftOnEmpowered -= deltaTime;
      if (timeLeftOnEmpowered < 0.0f) {
        timeLeftOnEmpowered = 0.0f;
      }
    }
  }
Beispiel #16
0
 public Vector2 toWorld(Vector2 boxVec) {
   return boxVec.scl(boxToWorld);
 }
 public void grow(float f) {
   positionEmiter.scl(f);
 }
Beispiel #18
0
 public Vector2 toBox(Vector2 worldVec) {
   return worldVec.scl(worldToBox);
 }
Beispiel #19
0
 @Override
 public void scl(float scalar) {
   anchorA.scl(scalar);
   anchorB.scl(scalar);
 }
 private Vector2 getPos(Entity e) {
   BodyComp b = e.getComponent(BodyComp.class);
   Vector2 pos = b.body.getPosition();
   pos.scl(b.invWorldScale);
   return pos;
 }
Beispiel #21
0
 public void pushAway(Vector2 origin, float force) {
   Vector2 v = new Vector2(origin.x - position.x, origin.y - position.y);
   v.scl(force / v.len());
   velocity.add(v);
 }
Beispiel #22
0
 public void setDirection(float x, float y) {
   direction.set(x, y);
   direction.scl(Gdx.graphics.getDeltaTime());
 }