示例#1
0
  private void updatePhysics() {
    // Update
    // float deltaTime = Gdx.graphics.getRawDeltaTime();
    float deltaTime = 1 / 60f;
    // System.out.println(deltaTime);
    tweenManager.update(deltaTime); // Setting delta time
    world.step(deltaTime, 10, 10);

    Vector2 planetPos = planetModel.getPosition().sub(planetModelOrigin);
    planetSprite.setPosition(planetPos.x, planetPos.y);
    planetSprite.setOrigin(planetModelOrigin.x, planetModelOrigin.y);
    planetSprite.setRotation(planetModel.getAngle() * MathUtils.radiansToDegrees);

    Vector2 planetCorePos = planetCoreModel.getPosition().sub(planetCoreModelOrigin);
    planetCoreSprite.setPosition(planetCorePos.x, planetCorePos.y);
    planetCoreSprite.setOrigin(planetCoreModelOrigin.x, planetCoreModelOrigin.y);
    planetCoreSprite.setRotation(planetCoreModel.getAngle() * MathUtils.radiansToDegrees);

    for (int i = 0; i < MAX_BALLS; i++) {
      Vector2 ballPos = ballModels[i].getPosition();
      ballSprites[i].setPosition(
          ballPos.x - ballSprites[i].getWidth() / 2, ballPos.y - ballSprites[i].getHeight() / 2);
      ballSprites[i].setRotation(ballModels[i].getAngle() * MathUtils.radiansToDegrees);
    }
  }
示例#2
0
  @Override
  public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();

    camera = new OrthographicCamera(1, h / w);
    batch = new SpriteBatch();

    texture = new Texture(Gdx.files.internal("data/libgdx.png"));
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    texture_nave = new Texture(Gdx.files.internal("data/nave.png"));

    sprite_nave = new Sprite(texture_nave, 128, 64);
    sprite_nave.setPosition(-0.5f, -0.5f);
    sprite_nave.setSize(0.5f, 0.5f);

    TextureRegion region = new TextureRegion(texture, 0, 0, 512, 275);

    sprite = new Sprite(region);
    sprite2 = new Sprite(region);

    sprite.setSize(0.9f, 0.9f * sprite.getHeight() / sprite.getWidth());
    sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);
    sprite.setPosition(-sprite.getWidth() / 2, -sprite.getHeight() / 2);
    sprite.setPosition(0, 0);
    sprite.setRotation(25);
  }
示例#3
0
  @Override
  public void setValues(Sprite sprite, int i, float[] floats) {
    switch (Mode.values()[i]) {
      case SCALE:
        sprite.setScale(floats[0]);
        break;

      case ALPHA:
        Color color = sprite.getColor();
        sprite.setColor(color.r, color.g, color.b, floats[0]);
        break;

      case POSITION:
        sprite.setX(floats[0]);
        sprite.setY(floats[1]);
        break;

      case ROTATION:
        sprite.setRotation(floats[0]);
        break;

      default:
        assert false;
    }
  }
  public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0.2f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // tell the camera to update its matrices.
    camera.update(
        car.body.getPosition().x * PIXELS_PER_METER, car.body.getPosition().y * PIXELS_PER_METER);

    spriteBatch.setProjectionMatrix(camera.getCombined());

    if (Gdx.input.isKeyPressed(Input.Keys.UP) || Gdx.input.isTouched()) {
      car.setAccelerate(Car.ACC_ACCELERATE);
    } else if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
      car.setAccelerate(Car.ACC_BRAKE);
    } else {
      car.setAccelerate(Car.ACC_NONE);
    }

    if (Gdx.input.isKeyPressed(Input.Keys.LEFT) || Gdx.input.getAccelerometerY() < -2.5) {
      car.setSteer(Car.STEER_HARD_LEFT);
    } else if (Gdx.input.getAccelerometerY() < -1) {
      car.setSteer(Car.STEER_LEFT);
    } else if (Gdx.input.isKeyPressed(Input.Keys.RIGHT) || Gdx.input.getAccelerometerY() > 2.5) {
      car.setSteer(Car.STEER_HARD_RIGHT);
    } else if (Gdx.input.getAccelerometerY() > 1) {
      car.setSteer(Car.STEER_RIGHT);
    } else {
      car.setSteer(Car.STEER_NONE);
    }

    car.update(Gdx.app.getGraphics().getDeltaTime());

    /**
     * Have box2d update the positions and velocities (and etc) of all tracked objects. The second
     * and third argument specify the number of iterations of velocity and position tests to perform
     * -- higher is more accurate but is also slower.
     */
    world.step(Gdx.app.getGraphics().getDeltaTime(), 3, 3);

    world.clearForces();

    // draw the sprites
    spriteBatch.begin();

    playerSprite.setPosition(
        PIXELS_PER_METER * car.body.getPosition().x - playerTexture.getRegionWidth() / 2,
        PIXELS_PER_METER * car.body.getPosition().y - playerTexture.getRegionHeight() / 2);
    playerSprite.setRotation((MathUtils.radiansToDegrees * car.body.getAngle()));

    playerSprite.setFlip(false, true);
    playerSprite.setScale(0.3f);

    playerSprite.draw(spriteBatch);

    spriteBatch.end();

    /** Draw this last, so we can see the collision boundaries on top of the sprites and map. */
    debugRenderer.render(
        world, camera.getCombined().scale(PIXELS_PER_METER, PIXELS_PER_METER, PIXELS_PER_METER));
  }
  @Override
  public void render() {
    camera.update();
    // Step the physics simulation forward at a rate of 60hz
    world.step(1f / 60f, 6, 2);

    sprite.setPosition(
        (body.getPosition().x * PIXELS_TO_METERS) - sprite.getWidth() / 2,
        (body.getPosition().y * PIXELS_TO_METERS) - sprite.getHeight() / 2);

    sprite.setRotation((float) Math.toDegrees(body2.getAngle()));
    sprite2.setPosition(
        (body2.getPosition().x * PIXELS_TO_METERS) - sprite2.getWidth() / 2,
        (body2.getPosition().y * PIXELS_TO_METERS) - sprite2.getHeight() / 2);
    sprite2.setRotation((float) Math.toDegrees(body.getAngle()));

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

    batch.setProjectionMatrix(camera.combined);
    batch.begin();

    batch.draw(
        sprite,
        sprite.getX(),
        sprite.getY(),
        sprite.getOriginX(),
        sprite.getOriginY(),
        sprite.getWidth(),
        sprite.getHeight(),
        sprite.getScaleX(),
        sprite.getScaleY(),
        sprite.getRotation());
    batch.draw(
        sprite2,
        sprite2.getX(),
        sprite2.getY(),
        sprite2.getOriginX(),
        sprite2.getOriginY(),
        sprite2.getWidth(),
        sprite2.getHeight(),
        sprite2.getScaleX(),
        sprite2.getScaleY(),
        sprite2.getRotation());
    batch.end();
  }
示例#6
0
  @Override
  public void draw(SpriteBatch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);

    Vector2 worldPos = getPosition();

    sprite.setPosition(worldPos.x - (sprite.getWidth() / 2), worldPos.y - sprite.getHeight() / 2);

    sprite.setRotation(getRotation());

    sprite.draw(batch);
  }
示例#7
0
  @Override
  public void render(SpriteBatch batch) {

    if (!alive) {
      return;
    }

    if (left_throttle) {
      flame.setPosition(x - width / 2, y - height);
      flame.setOrigin(width / 2, height);
      flame.setRotation(rotation);
      flame.draw(batch);
    }
    if (right_throttle) {
      flame.setPosition(x, y - height);
      flame.setOrigin(0, height);
      flame.setRotation(rotation);
      flame.draw(batch);
    }
    sprite.draw(batch);
  }
示例#8
0
  @Override
  public void render() {
    sprite.setRotation(rotacion);
    if (Gdx.input.isTouched()) {
      rotacion++;
    }
    Gdx.gl.glClearColor(0f, 0.5f, 0.75f, 1f);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    sprite.draw(batch);
    sprite.draw(batch);
    sprite2.draw(batch);
    sprite_nave.draw(batch);
    batch.end();
  }
示例#9
0
  public void draw(SpriteBatch batch, float parentAlpha) {
    stateTime += Gdx.graphics.getDeltaTime();

    Sprite toRender = currentAnimation.getKeyFrame(stateTime);

    // -1 to account for the sword below his feet
    toRender.setPosition(getX(), getY() - 1);
    toRender.setOrigin(
        toRender.getX() + toRender.getWidth(), toRender.getY() + toRender.getHeight());
    toRender.setRotation(getRotation());

    setSize(toRender.getWidth(), toRender.getHeight());
    setOrigin(toRender.getOriginX(), toRender.getOriginY());

    toRender.draw(batch);

    if (TheLoveOfRice.DRAW_DEBUG) {
      drawDebug(batch);
    }
  }
示例#10
0
 public void draw(
     Batch batch,
     float x,
     float y,
     float originX,
     float originY,
     float width,
     float height,
     float scaleX,
     float scaleY,
     float rotation) {
   sprite.setOrigin(originX, originY);
   sprite.setRotation(rotation);
   sprite.setScale(scaleX, scaleY);
   sprite.setBounds(x, y, width, height);
   Color color = sprite.getColor();
   sprite.setColor(Color.tmp.set(color).mul(batch.getColor()));
   sprite.draw(batch);
   sprite.setColor(color);
 }
示例#11
0
  @Override
  public void render(float delta) {
    begin1.setColor(color);
    begin2.setColor(rayColor);
    mid1.setColor(color);
    mid2.setColor(rayColor);
    end1.setColor(color);
    end2.setColor(rayColor);

    mid1.setSize(mid1.getWidth(), len);
    mid2.setSize(mid1.getWidth(), len);

    begin1.setPosition(positon.x, positon.y);
    begin2.setPosition(positon.x, positon.y);

    mid1.setPosition(begin1.getX(), begin1.getY() + begin1.getHeight());
    mid2.setPosition(begin1.getX(), begin1.getY() + begin1.getHeight());

    end1.setPosition(begin1.getX(), begin1.getY() + begin1.getHeight() + mid1.getHeight());
    end2.setPosition(begin1.getX(), begin1.getY() + begin1.getHeight() + mid1.getHeight());

    begin1.setOrigin(begin1.getWidth() / 2, 0);
    begin2.setOrigin(begin1.getWidth() / 2, 0);

    mid1.setOrigin(mid1.getWidth() / 2, -begin1.getHeight());
    mid2.setOrigin(mid2.getWidth() / 2, -begin1.getHeight());
    end1.setOrigin(mid1.getWidth() / 2, -begin1.getHeight() - mid1.getHeight());
    end2.setOrigin(mid2.getWidth() / 2, -begin1.getHeight() - mid2.getHeight());

    begin1.setRotation(degrees);
    begin2.setRotation(degrees);
    mid1.setRotation(degrees);
    mid2.setRotation(degrees);
    end1.setRotation(degrees);
    end2.setRotation(degrees);

    Engine.getSpriteBatch().setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE);
    begin1.draw(Engine.getSpriteBatch());
    begin2.draw(Engine.getSpriteBatch());

    mid1.draw(Engine.getSpriteBatch());

    mid2.draw(Engine.getSpriteBatch());

    end1.draw(Engine.getSpriteBatch());
    end2.draw(Engine.getSpriteBatch());
    Engine.getSpriteBatch().setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
  }
示例#12
0
  public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    rotation = (rotation + 0);
    sprite.setSize(screenRectangle.width, screenRectangle.height);
    sprite.setPosition(screenRectangle.x, screenRectangle.y);
    sprite.setOriginCenter();

    if (Gdx.input.isKeyJustPressed(keyRight)) {
      body.setTransform(body.getPosition().x + 5, body.getPosition().y, body.getAngle());
    }

    elapsedTime += Gdx.graphics.getDeltaTime();
    // body.setTransform(body.getPosition(), rotation);
    batch.end();
    batch.begin();

    sprite.setRotation(rotation);
    sprite.draw(batch);

    // batch.draw(animation.getKeyFrame(elapsedTime, true), screenRectangle.x, screenRectangle.y,
    // screenRectangle.width, screenRectangle.height );
    // animation.setFrameDuration(0.09f);

  }
示例#13
0
  @Override
  public void start() {
    OwnedObjectData data = new OwnedObjectData();

    data.drawAfter = true;

    if (bullet.getTicksAlive() < 20) animationPlaying = true;

    createTick = game.getTick();

    bullet.addOwnedObject(this, data);

    final Sprite current = (Sprite) this.ani.getKeyFrame(getTicksAlive());

    Polygon hitbox = bullet.getHitbox();
    Rectangle rect =
        hitbox != null ? hitbox.getBoundingRectangle() : current.getBoundingRectangle();

    final float modifier = 3f;
    float width = rect.getWidth() * modifier;
    float height = rect.getHeight() * modifier;

    final float scaleX = width / current.getWidth();
    final float scaleY = height / current.getHeight();

    current.setScale(scaleX, scaleY);
    current.setRotation(bullet.getRotationDeg());

    current.setOriginCenter();

    Color c = bullet.getDeletionColor().cpy();

    float min = Math.min(c.g, Math.min(c.r, c.b));
    c.r -= min;
    c.g -= min;
    c.b -= min;

    float mul = 0.8f;
    float start = (1f - mul) + 0.3f;

    Color color = new Color(start + (c.r * mul), start + (c.g * mul), start + (c.b * mul), 0f);

    current.setColor(color);
    current.setAlpha(1f);

    final SaveableObject<ScaleAlphaPhaseAnimation> sani =
        new SaveableObject<ScaleAlphaPhaseAnimation>();

    Getter<Sprite> getter =
        new Getter<Sprite>() {
          @Override
          public Sprite get() {
            Sprite current = (Sprite) ani.getKeyFrame(getTicksAlive());

            int over = 5;

            int ticks = (int) ((time.toTicks() - over) - getTicksAlive());

            double mul = 1f - (ticks <= 0 ? -(float) ticks / over : 0f);

            ScaleAlphaPhaseAnimation ani = sani.getObject();

            if (ani == null) return current;

            if (ticks <= 0) {
              animationPlaying = false;
              ani.setAlpha((float) Math.max(0, mul));
            }

            current.setPosition(
                bullet.getX() - current.getWidth() / 2f, bullet.getY() - current.getHeight() / 2f);

            current.setOriginCenter();

            current.setRotation(bullet.getRotationDeg());

            return current;
          }
        };

    final ScaleAlphaPhaseAnimation ani = new ScaleAlphaPhaseAnimation(getter, bullet);

    sani.setObject(ani);

    ani.setTime(time);
    ani.setAddedScale(scaleX * 3f, scaleY * 3f);
    ani.setAlpha(-0.1f);
    ani.start();

    bullet.removeOwnedObject(ani);
    bullet.addOwnedObject(ani, data);
  }
示例#14
0
 public void reset() {
   setOriginPosition(initPos);
   velocity = initVelocity;
   sprite.setRotation(initRotation);
   updateSides();
 }
示例#15
0
 void AdjustToBody(Sprite sprite, Vector2 origin, Body body, float sizeX, float sizeY) {
   sprite.setOrigin(origin.x, origin.y);
   sprite.setPosition(body.getPosition().sub(origin).x, body.getPosition().sub(origin).y);
   sprite.setSize(sizeX, sizeY);
   sprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees);
 }
示例#16
0
 public void rotate(float angle) {
   sprite.setRotation(angle);
 }
示例#17
0
  public static void drawSpriteLine(
      Batch batch,
      Sprite sprite,
      Sprite spriteEnd,
      float overlap,
      float x1,
      float y1,
      float x2,
      float y2) {
    // chk NPE
    if (batch == null || sprite == null || spriteEnd == null) return;

    float angle = 0; // Pi-basiert, x-Achse 0, gegen Uhrzeigersinn
    if (x1 < x2) // 0-)90( Grad; )270(-360 Grad
    if (y1 <= y2) // 0-)90( Grad
      angle = (float) Math.atan((y2 - y1) / (x2 - x1));
      else
        // )270(-)360( Grad
        angle = (float) (2 * Math.PI - (float) Math.atan((y1 - y2) / (x2 - x1)));
    else if (x1 > x2) // )90( - 180 Grad, 180 - )270( Grad
    if (y1 <= y2) // )90( - 180 Grad
      angle = (float) (Math.PI - (float) Math.atan((y2 - y1) / (x1 - x2)));
      else
        // )270(-)360( Grad
        angle = (float) (Math.PI + (float) Math.atan((y1 - y2) / (x1 - x2)));
    else // 90 Grad, 270 Grad
    if (y1 < y2) // 90 Grad
    angle = (float) (0.5 * Math.PI);
    else if (y1 > y2) // 270 Grad
    angle = (float) (1.5 * Math.PI);
    else
      // 0 Grad
      angle = 0;

    float SpriteHalfX = sprite.getWidth() / 2;
    float SpriteHalfY = sprite.getHeight() / 2;

    sprite.setOrigin(SpriteHalfX, SpriteHalfY);
    sprite.setRotation(
        (float) (angle * MathUtils.RAD_DEG)
            - 90); // Grad-basiert, y-Achse 0 Grad, gegen Uhrzeigersinn

    float SpriteEndHalfX = spriteEnd.getWidth() / 2;
    float SpriteEndHalfY = spriteEnd.getHeight() / 2;

    spriteEnd.setOrigin(SpriteEndHalfX, SpriteEndHalfY);
    spriteEnd.setRotation(
        (float) (angle * MathUtils.RAD_DEG)
            - 90); // Grad-basiert, y-Achse 0 Grad, gegen Uhrzeigersinn

    float h = sprite.getHeight() * overlap;

    double sina = Math.sin(angle);
    double cosa = Math.cos(angle);

    int l = (int) (Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
    int n = (int) ((l - h / 2) / h);
    if (n * h < l - h / 2) n += 1;
    for (int i = 0; i < n + 1; i++) {
      float x = (float) ((i * h * cosa) + x1);
      float y = (float) ((i * h * sina) + y1);

      if (i == 0 || i == n) {
        spriteEnd.setPosition(x - SpriteEndHalfX, y - SpriteEndHalfY);
        spriteEnd.draw(batch);
      } else {
        sprite.setPosition(x - SpriteHalfX, y - SpriteHalfY);
        sprite.draw(batch);
      }
    }
  }
  public GameScreen(Game game, Array<Integer> playerList, Array<Integer> cpuList) {
    super(game);
    Gdx.input.setCatchBackKey(true);
    Gdx.input.setInputProcessor(this);

    cam = new OrthographicCamera(width, height);

    cam.position.x = 400;
    cam.position.y = 240;
    cam.update();

    numPlayers = playerList.size;

    if (numPlayers == 1) {
      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width),
                  -((this.height - 480) / 2) + this.height,
                  0));
    } else if (numPlayers == 2) {
      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + this.height,
                  0));
      touchAreaP2 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + this.height,
                  0));
    } else if (numPlayers == 3) {
      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + (this.height / 2),
                  0));
      touchAreaP2 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2), -((this.height - 480) / 2) + (this.height / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + this.height,
                  0));
      touchAreaP3 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + this.height,
                  0));
    } else if (numPlayers == 4) {
      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + (this.height / 2),
                  0));
      touchAreaP2 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2), -((this.height - 480) / 2) + (this.height / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + this.height,
                  0));
      touchAreaP3 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + (this.height / 2),
                  0));
      touchAreaP4 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + (this.height / 2),
                  0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + this.height,
                  0));
    }

    //		camera = new OrthographicCamera(800, 480);
    //		camera.translate(400, 240, 0);

    if (playerList.size + cpuList.size != 3) {
      POSITIONS.add(new Vector2(150, 180));
      POSITIONS.add(new Vector2(450, 180));
      POSITIONS.add(new Vector2(300, 335));
      POSITIONS.add(new Vector2(300, 25));
    } else {
      POSITIONS.add(new Vector2(170, 92));
      POSITIONS.add(new Vector2(432, 100));
      POSITIONS.add(new Vector2(300, 335));
    }

    // Fade
    blackFade = Resources.getInstance().blackFade;
    fadeBatch = new SpriteBatch();
    fadeBatch.getProjectionMatrix().setToOrtho2D(0, 0, 2, 2);

    stouchAreaP1 = Resources.getInstance().touchArea1;
    stouchAreaP2 = Resources.getInstance().touchArea2;
    stouchAreaP3 = Resources.getInstance().touchArea3;
    stouchAreaP4 = Resources.getInstance().touchArea4;

    if (playerList.size > 0 && playerList.get(0) == 1) {
      p1 = Resources.getInstance().factoryP1Small;
    } else if (playerList.size > 0 && playerList.get(0) == 2) {
      p1 = Resources.getInstance().factoryP2Small;
    } else if (playerList.size > 0 && playerList.get(0) == 3) {
      p1 = Resources.getInstance().factoryP3Small;
    } else if (playerList.size > 0 && playerList.get(0) == 4) {
      p1 = Resources.getInstance().factoryP4Small;
    }

    if (playerList.size > 1 && playerList.get(1) == 1) {
      p2 = Resources.getInstance().factoryP1Small;
    } else if (playerList.size > 1 && playerList.get(1) == 2) {
      p2 = Resources.getInstance().factoryP2Small;
    } else if (playerList.size > 1 && playerList.get(1) == 3) {
      p2 = Resources.getInstance().factoryP3Small;
    } else if (playerList.size > 1 && playerList.get(1) == 4) {
      p2 = Resources.getInstance().factoryP4Small;
    }

    if (playerList.size > 2 && playerList.get(2) == 1) {
      p3 = Resources.getInstance().factoryP1Small;
    } else if (playerList.size > 2 && playerList.get(2) == 2) {
      p3 = Resources.getInstance().factoryP2Small;
    } else if (playerList.size > 2 && playerList.get(2) == 3) {
      p3 = Resources.getInstance().factoryP3Small;
    } else if (playerList.size > 2 && playerList.get(2) == 4) {
      p3 = Resources.getInstance().factoryP4Small;
    }

    if (playerList.size > 3 && playerList.get(3) == 1) {
      p4 = Resources.getInstance().factoryP1Small;
    } else if (playerList.size > 3 && playerList.get(3) == 2) {
      p4 = Resources.getInstance().factoryP2Small;
    } else if (playerList.size > 3 && playerList.get(3) == 3) {
      p4 = Resources.getInstance().factoryP3Small;
    } else if (playerList.size > 3 && playerList.get(3) == 4) {
      p4 = Resources.getInstance().factoryP4Small;
    }

    if (playerList.size > 0) p1.setScale(.2f);
    if (playerList.size > 1) p2.setScale(.2f);
    if (playerList.size > 2) p3.setScale(.2f);
    if (playerList.size > 3) p4.setScale(.2f);

    if (playerList.size > 0) p1.rotate(-90);
    if (playerList.size > 1) p2.rotate(90);
    if (playerList.size > 2) p3.rotate(-90);
    if (playerList.size > 3) p4.rotate(90);

    stouchAreaP1.setRotation(-90);
    stouchAreaP2.setRotation(90);
    stouchAreaP1.setRotation(-90);
    stouchAreaP2.setRotation(90);

    gameBatch = new SpriteBatch();
    gameBatch.getProjectionMatrix().set(cam.combined);

    // init player positions
    //		Array<Vector2> positons = generatePositions(numPlayers + 1);

    int currentPos = 0;

    for (int i = 0; i < playerList.size; ++i) {
      Vector2 temp1 = new Vector2(POSITIONS.get(currentPos).x, POSITIONS.get(currentPos).y);
      Vector2 temp2 = new Vector2(POSITIONS.get(currentPos).x, POSITIONS.get(currentPos).y);
      Vector2 facing = new Vector2(-temp1.sub(CENTER).y, temp2.sub(CENTER).x).nor();
      playerProduction = new PlayerProduction(playerList.get(i), POSITIONS.get(currentPos), facing);
      GameInstance.getInstance().factorys.add(playerProduction);
      ++currentPos;
    }

    for (int i = 0; i < cpuList.size; ++i) {
      Vector2 temp1 = new Vector2(POSITIONS.get(currentPos).x, POSITIONS.get(currentPos).y);
      Vector2 temp2 = new Vector2(POSITIONS.get(currentPos).x, POSITIONS.get(currentPos).y);
      Vector2 facing = new Vector2(-temp1.sub(CENTER).y, temp2.sub(CENTER).x).nor();
      if (GameInstance.getInstance().difficultyConfig == 0) {
        enemyProduction =
            new EasyEnemyProduction(cpuList.get(i), POSITIONS.get(currentPos), facing);
      } else if (GameInstance.getInstance().difficultyConfig == 1) {
        enemyProduction =
            new MediumEnemyProduction(cpuList.get(i), POSITIONS.get(currentPos), facing);
      } else {
        enemyProduction =
            new HardEnemyProduction(cpuList.get(i), POSITIONS.get(currentPos), facing);
      }
      GameInstance.getInstance().factorys.add(enemyProduction);
      ++currentPos;
    }

    //		// add cpu if only one player plays
    //		if (idP2 == -1) {
    //			temp1 = new Vector2(POSITIONS.get(1).x, POSITIONS.get(1).y);
    //			temp2 = new Vector2(POSITIONS.get(1).x, POSITIONS.get(1).y);
    //			facing = new Vector2(-temp1.sub(CENTER).y, temp2.sub(CENTER).x).nor();
    //			if(GameInstance.getInstance().difficultyConfig == 0) {
    //				enemyProduction = new EasyEnemyProduction((idP1+1)%4, POSITIONS.get(1), facing);
    //			} else if(GameInstance.getInstance().difficultyConfig == 1) {
    //				enemyProduction = new MediumEnemyProduction((idP1+1)%4, POSITIONS.get(1), facing);
    //			} else {
    //				enemyProduction = new HardEnemyProduction((idP1+1)%4, POSITIONS.get(1), facing);
    //			}
    //			GameInstance.getInstance().factorys.add(enemyProduction);
    //			touchedP2 = true;
    //			touchFadeP2 = 0;
    //
    //			temp1 = new Vector2(POSITIONS.get(2).x, POSITIONS.get(2).y);
    //			temp2 = new Vector2(POSITIONS.get(2).x, POSITIONS.get(2).y);
    //			facing = new Vector2(-temp1.sub(CENTER).y, temp2.sub(CENTER).x).nor();
    //			if(GameInstance.getInstance().difficultyConfig == 0) {
    //				enemyProduction = new EasyEnemyProduction((idP1+2)%4, POSITIONS.get(2), facing);
    //			} else if(GameInstance.getInstance().difficultyConfig == 1) {
    //				enemyProduction = new MediumEnemyProduction((idP1+2)%4, POSITIONS.get(2), facing);
    //			} else {
    //				enemyProduction = new HardEnemyProduction((idP1+2)%4, POSITIONS.get(2), facing);
    //			}
    //			GameInstance.getInstance().factorys.add(enemyProduction);
    //			touchedP2 = true;
    //			touchFadeP2 = 0;
    //
    //			temp1 = new Vector2(POSITIONS.get(3).x, POSITIONS.get(3).y);
    //			temp2 = new Vector2(POSITIONS.get(3).x, POSITIONS.get(3).y);
    //			facing = new Vector2(-temp1.sub(CENTER).y, temp2.sub(CENTER).x).nor();
    //			if(GameInstance.getInstance().difficultyConfig == 0) {
    //				enemyProduction = new EasyEnemyProduction((idP1+3)%4, POSITIONS.get(3), facing);
    //			} else if(GameInstance.getInstance().difficultyConfig == 1) {
    //				enemyProduction = new MediumEnemyProduction((idP1+3)%4, POSITIONS.get(3), facing);
    //			} else {
    //				enemyProduction = new HardEnemyProduction((idP1+3)%4, POSITIONS.get(3), facing);
    //			}
    //			GameInstance.getInstance().factorys.add(enemyProduction);
    //			touchedP2 = true;
    //			touchFadeP2 = 0;
    //		} else {
    //			temp1 = new Vector2(POSITIONS.get(1).x, POSITIONS.get(1).y);
    //			temp2 = new Vector2(POSITIONS.get(1).x, POSITIONS.get(1).y);
    //			facing = new Vector2(-temp1.sub(CENTER).y, temp2.sub(CENTER).x).nor();
    //			playerProduction = new PlayerProduction(idP2, POSITIONS.get(1), facing);
    //			GameInstance.getInstance().factorys.add(playerProduction);
    //		}

    Gdx.gl.glDisable(GL20.GL_CULL_FACE);
    Gdx.gl.glDisable(GL20.GL_DEPTH_TEST);
  }
  @Override
  public void resize(int width, int height) {
    this.width = width;
    this.height = height;
    if (width == 480 && height == 320) {
      cam = new OrthographicCamera(700, 466);
      this.width = 700;
      this.height = 466;
    } else if (width == 320 && height == 240) {
      cam = new OrthographicCamera(700, 525);
      this.width = 700;
      this.height = 525;
    } else if (width == 400 && height == 240) {
      cam = new OrthographicCamera(800, 480);
      this.width = 800;
      this.height = 480;
    } else if (width == 432 && height == 240) {
      cam = new OrthographicCamera(700, 389);
      this.width = 700;
      this.height = 389;
    } else if (width == 960 && height == 640) {
      cam = new OrthographicCamera(800, 533);
      this.width = 800;
      this.height = 533;
    } else if (width == 1366 && height == 768) {
      cam = new OrthographicCamera(1280, 720);
      this.width = 1280;
      this.height = 720;
    } else if (width == 1366 && height == 720) {
      cam = new OrthographicCamera(1280, 675);
      this.width = 1280;
      this.height = 675;
    } else if (width == 1536 && height == 1152) {
      cam = new OrthographicCamera(1366, 1024);
      this.width = 1366;
      this.height = 1024;
    } else if (width == 1920 && height == 1152) {
      cam = new OrthographicCamera(1366, 854);
      this.width = 1366;
      this.height = 854;
    } else if (width == 1920 && height == 1200) {
      cam = new OrthographicCamera(1366, 800);
      this.width = 1280;
      this.height = 800;
    } else if (width > 1280) {
      cam = new OrthographicCamera(1280, 768);
      this.width = 1280;
      this.height = 768;
    } else if (width < 800) {
      cam = new OrthographicCamera(800, 480);
      this.width = 800;
      this.height = 480;
    } else {
      cam = new OrthographicCamera(width, height);
    }
    cam.position.x = 400;
    cam.position.y = 240;
    cam.update();
    backgroundFX.resize(width, height);
    gameBatch.getProjectionMatrix().set(cam.combined);

    if (numPlayers == 1) {
      p1.setRotation(-90);

      stouchAreaP1.setRotation(-90);

      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width),
                  -((this.height - 480) / 2) + this.height,
                  0));

      stouchAreaP1.setPosition(touchAreaP1.min.x, touchAreaP1.getCenter().y - 40);
      p1.setPosition(touchAreaP1.min.x + 10, touchAreaP1.getCenter().y - 105);
    } else if (numPlayers == 2) {
      p1.setRotation(-90);
      p2.setRotation(90);

      stouchAreaP1.setRotation(-90);
      stouchAreaP2.setRotation(90);

      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + this.height,
                  0));
      touchAreaP2 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + this.height,
                  0));

      stouchAreaP1.setPosition(touchAreaP1.min.x, touchAreaP1.getCenter().y - 40);
      p1.setPosition(touchAreaP1.min.tmp().x + 10, touchAreaP1.getCenter().y - 105);
      stouchAreaP2.setPosition(touchAreaP2.max.x - 170, touchAreaP2.getCenter().y - 40);
      p2.setPosition(touchAreaP2.max.x - 190, touchAreaP2.getCenter().y - 15);
    } else if (numPlayers == 3) {
      p1.setRotation(-90);
      p2.setRotation(-90);
      p3.setRotation(90);

      stouchAreaP1.setRotation(-90);
      stouchAreaP2.setRotation(-90);
      stouchAreaP3.setRotation(90);

      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + (this.height / 2),
                  0));
      touchAreaP2 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2), -((this.height - 480) / 2) + (this.height / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + this.height,
                  0));
      touchAreaP3 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + this.height,
                  0));

      stouchAreaP1.setPosition(touchAreaP1.min.x, touchAreaP1.getCenter().y - 40);
      p1.setPosition(touchAreaP1.min.tmp().x + 10, touchAreaP1.getCenter().y - 105);
      stouchAreaP2.setPosition(touchAreaP2.min.x, touchAreaP2.getCenter().y - 40);
      p2.setPosition(touchAreaP2.min.x + 10, touchAreaP2.getCenter().y - 105);
      stouchAreaP3.setPosition(touchAreaP3.max.x - 170, touchAreaP3.getCenter().y - 40);
      p3.setPosition(touchAreaP3.max.x - 190, touchAreaP3.getCenter().y - 15);
    } else if (numPlayers == 4) {
      p1.setRotation(-90);
      p2.setRotation(-90);
      p3.setRotation(90);
      p4.setRotation(90);

      stouchAreaP1.setRotation(-90);
      stouchAreaP2.setRotation(-90);
      stouchAreaP3.setRotation(90);
      stouchAreaP4.setRotation(90);

      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + (this.height / 2),
                  0));
      touchAreaP2 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2), -((this.height - 480) / 2) + (this.height / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + this.height,
                  0));
      touchAreaP3 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + (this.height / 2),
                  0));
      touchAreaP4 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + (this.height / 2),
                  0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + this.height,
                  0));

      stouchAreaP1.setPosition(touchAreaP1.min.x, touchAreaP1.getCenter().y - 40);
      p1.setPosition(touchAreaP1.min.tmp().x + 10, touchAreaP1.getCenter().y - 105);
      stouchAreaP2.setPosition(touchAreaP2.min.x, touchAreaP2.getCenter().y - 40);
      p2.setPosition(touchAreaP2.min.x + 10, touchAreaP2.getCenter().y - 105);
      stouchAreaP3.setPosition(touchAreaP3.max.x - 170, touchAreaP3.getCenter().y - 40);
      p3.setPosition(touchAreaP3.max.x - 190, touchAreaP3.getCenter().y - 15);
      stouchAreaP4.setPosition(touchAreaP4.max.x - 170, touchAreaP4.getCenter().y - 40);
      p4.setPosition(touchAreaP4.max.x - 190, touchAreaP4.getCenter().y - 15);
    }
  }
示例#20
0
  /** Called by game loop, updates then blits or renders current frame of animation to the screen */
  @Override
  public void draw() {
    if (_flicker) return;

    if (dirty) // rarely
    calcFrame();

    if (_newTextureData != null) // even more rarely
    {
      _pixels.getTexture().load(_newTextureData);
      _newTextureData = null;
    }

    FlxCamera camera = FlxG._activeCamera;

    if (cameras == null) cameras = FlxG.cameras;

    if (!cameras.contains(camera, true)) return;

    if (!onScreen(camera)) return;
    _point.x = x - (camera.scroll.x * scrollFactor.x) - offset.x;
    _point.y = y - (camera.scroll.y * scrollFactor.y) - offset.y;
    _point.x += (_point.x > 0) ? 0.0000001f : -0.0000001f;
    _point.y += (_point.y > 0) ? 0.0000001f : -0.0000001f;

    // tinting
    int tintColor = FlxU.multiplyColors(_color, camera.getColor());
    framePixels.setColor(
        ((tintColor >> 16) & 0xFF) * 0.00392f,
        ((tintColor >> 8) & 0xFF) * 0.00392f,
        (tintColor & 0xFF) * 0.00392f,
        _alpha);

    // rotate
    if (_pixels.rotate) framePixels.rotate90(false);

    if (isSimpleRender()) { // Simple render
      framePixels.setPosition(_point.x, _point.y);
      renderSprite();
    } else { // Advanced render
      framePixels.setOrigin(origin.x, origin.y);
      framePixels.setScale(scale.x, scale.y);
      if ((angle != 0) && (_bakedRotation <= 0)) framePixels.setRotation(angle);
      framePixels.setPosition(_point.x, _point.y);
      if (blend != null && currentBlend != blend) {
        currentBlend = blend;
        int[] blendFunc = BlendMode.getOpenGLBlendMode(blend);
        FlxG.batch.setBlendFunction(blendFunc[0], blendFunc[1]);
      } else if (FlxG.batchShader == null || ignoreBatchShader) {
        // OpenGL ES 2.0 shader render
        renderShader();
        // OpenGL ES 2.0 blend mode render
        renderBlend();
      }
      renderSprite();
    }

    // re-rotate
    if (_pixels.rotate) framePixels.rotate90(true);

    _VISIBLECOUNT++;
    if (FlxG.visualDebug && !ignoreDrawDebug) drawDebug(camera);
  }
示例#21
0
  @Override
  public void render(float delta) {
    super.render();

    totalGameTimer += delta;
    // if ((totalGameTimer >= 5) && (levelStarted == false)) {
    // startLevel("theme1.txt");
    // levelStarted = true;
    // return;
    // }

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

    batch.begin();
    {
      // batch.draw(rightFootprintTexture, WIDTH / 2 + footSpacing - 50,
      // 0);
      // batch.draw(leftFootprintTexture, WIDTH / 2 - footSpacing - 50,
      // 0);
      // batch.draw(rightWall, 0, 0, WIDTH, HEIGHT);
      // batch.draw(leftWall, 0, 0, WIDTH, HEIGHT);
      // batch.draw(perspectiveTexture, 0, 0, WIDTH, HEIGHT);

    }
    batch.end();

    batch.begin();
    // sprite.draw(batch);
    elapsedTime += Gdx.graphics.getDeltaTime();
    // batch.draw(), x, y, originX, originY, width, height, scaleX, scaleY,
    // rotation);
    batch.draw(smokeTexture, 0, 0, WIDTH, HEIGHT);

    // System.out.println(level.getSkipped());
    int damage = (level.getSkipped() + level.getMisses()) / 3;

    // System.out.println(damage);

    if (damage == 5) {
      leftWallAnimation = new Animation(1 / 45f, leftWallTextureAtlas.getRegions());
      rightWallAnimation = new Animation(1 / 45f, rightWallTextureAtlas.getRegions());
    }

    if (damage >= 6) {
      deathCounter++;
      ScreenManager.getInstance().show(ScreenManager.Screens.TITLE);
      endingLevel = true;
      music.stop();
      music.dispose();
    } else {
      batch.draw(
          pentagramAtlas.findRegion("000" + Integer.toString((damage % 7) + 1)),
          WIDTH / 2 - (72 / 2),
          HEIGHT - 72,
          72,
          72);
    }
    // batch.draw(stairTexture, 0, (float) -(level.getCurrPos() * 10),
    // WIDTH, HEIGHT);
    batch.draw(
        stairsAnimation.getKeyFrame(level.getFootstepsBetween(-level.getCurrPos(), 0).size(), true),
        (float) 0,
        0,
        WIDTH,
        HEIGHT / 2);
    batch.draw(leftWallAnimation.getKeyFrame(elapsedTime, true), 0, 0, 225, HEIGHT);
    batch.draw(rightWallAnimation.getKeyFrame(elapsedTime, true), WIDTH - 225, 0, 225, HEIGHT);
    batch.end();

    // Advance in level
    // level.addCurrPos(delta);
    // TODO:
    level.syncWithMusic(music);

    // // Announce next footstep, if one has been passed
    // if (level.getFootsteps().get(nextFootstep).getTime() <
    // level.getCurrPos()) {
    // // "Next" footstep is in the past
    // nextFootstep++;
    //
    // // Announce
    // System.out.println("Next footstep is now: " +
    // level.getFootsteps().get(nextFootstep).toString());
    // }

    // TODO: Look for input
    boolean leftPressed = Gdx.input.isKeyJustPressed(Input.Keys.SHIFT_LEFT);
    boolean rightPressed = Gdx.input.isKeyJustPressed(Input.Keys.SHIFT_RIGHT);
    if (leftPressed || rightPressed) {
      // TODO: If pressed BEFORE a footstep, miss the next footstep

      // If pressed DURING a footstep, mark footstep as hit if it is left.
      // Otherwise miss.
      for (Footstep f : level.getActiveFootsteps(HIT_THRESHOLD)) {
        if (f != null) {
          Footstep active = f;
          if ((!active.isDidHit()) && (!active.isDidMiss())) {
            if (((active.getType() == FootstepType.LEFT) && leftPressed)
                || ((active.getType() == FootstepType.RIGHT) && rightPressed)) {
              // HIT!
              active.setDidHit(true);
              // System.out.println("HIT FOOTSTEP: " +
              // active.toString());
            } else {
              // Miss.
              active.setDidMiss(true);
              // System.out.println("MISSED FOOTSTEP: " +
              // active.toString());
            }
          }
        }
      }
    }

    // Render visible footsteps
    batch.begin();
    {
      double startTime = -2;
      double farthestTime = 5.0f;
      for (Footstep f : level.getFootstepsBetween(startTime, farthestTime)) {
        float distanceOnRoad =
            (float) ((f.getTime() - level.getCurrPos()) / (farthestTime - startTime));
        distanceOnRoad -= 1;
        distanceOnRoad = -(-Math.abs(distanceOnRoad * distanceOnRoad * distanceOnRoad) - 1);
        distanceOnRoad = 2 - (distanceOnRoad);
        Sprite sprite = new Sprite(rightFootprintTexture);
        // Flip for left foot
        sprite.flip(f.getType() == FootstepType.LEFT, false);
        // Add alpha
        if (distanceOnRoad > 0) {
          sprite.setAlpha((1f - distanceOnRoad) * 0.9f + 0.1f);
        }
        // Add scaling
        sprite.setScale((1f - distanceOnRoad) * 0.6f);
        // Light footsteps that are "active"
        double distanceTo = f.getTime() - level.getCurrPos();
        if (Math.abs(distanceTo) < LIT_THRESHOLD) {
          sprite.setColor(Color.BLUE);
        }
        if (-distanceTo > LIT_THRESHOLD && (!(f.isDidHit() || f.isDidMiss()))) {
          sprite.setRotation((int) (level.getCurrPos() * 2000));
          sprite.setColor(Color.FIREBRICK);
        }

        // Mark hits or misses
        if (f.isDidHit()) {
          sprite.setColor(Color.GREEN);
        } else if (f.isDidMiss()) {
          sprite.setColor(Color.RED);
        }

        float leftFactor = 1;
        if (f.getType() == FootstepType.LEFT) {
          leftFactor = -1;
        }
        float x = WIDTH / 2 + (leftFactor * (WIDTH / 11) * (1 - distanceOnRoad));
        float y = (distanceOnRoad * (HEIGHT / 2 + 50 - FOOTSTEP_LINE)) + FOOTSTEP_LINE;

        // Celebrate hits!
        if (f.isDidHit()) {
          y += -distanceTo * 100;
        }

        sprite.setCenter(x, y);
        sprite.draw(batch);
      }
    }
    batch.end();
  }
示例#22
0
 public void Draw(Batch batch) {
   sprite.setRotation(rotation);
   sprite.setPosition(X, Y);
   sprite.draw(batch);
 }