Beispiel #1
0
  public void setUp() {

    BodyDef bodyDef = new BodyDef();
    bodyDef.position.set(x + width / 2, y + height / 2);
    bodyDef.type = BodyDef.BodyType.KinematicBody;

    PolygonShape shape = new PolygonShape();
    shape.setAsBox(width / 2, height / 2);

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;

    body = world.createBody(bodyDef);
    body.createFixture(fixtureDef);
    body.setUserData(Constants.robotNinjaID);

    body.setLinearVelocity(Constants.standardVelocity);

    sprite = new Sprite(texture);
    sprite.setSize(width, height);
    sprite.setOrigin(width / 2, height / 2);
    sprite.flip(false, flipy);
    sprite.setPosition(x, y);

    dead = false;
  }
Beispiel #2
0
 public BillGhost(int side) {
   this.side = side;
   sprite = new Sprite(Assets.getInstance().billDeadRegion);
   if (side == 1) sprite.flip(true, false);
   sprite.setCenterX(BILL_DISTANCE * side);
   sprite.setCenterY(BILL_HEIGHT);
   alpha = 0.75f;
   x = sprite.getX();
   y = sprite.getY();
   ghostTime = 0;
 }
Beispiel #3
0
  /** Internal function to update the current animation frame. */
  protected void calcFrame() {
    int indexY;
    int indexX;
    // Handle sprite sheets
    int widthHelper = _pixels.getRegionWidth();
    int heightHelper = _pixels.getRegionHeight();
    if (!_pixels.rotate) {
      indexX = _curIndex * frameWidth;
      indexY = 0;
    } else {
      indexY = (heightHelper - frameWidth) - (_curIndex * frameWidth);
      indexX = 0;
    }
    if (indexX >= widthHelper) {
      indexY = (int) (indexX / widthHelper) * frameHeight;
      indexX %= widthHelper;
    }
    if (indexY >= heightHelper) {
      indexY = heightHelper - frameHeight;
      indexX = widthHelper - frameWidth;
    }
    // Update display bitmap
    if (!_pixels.rotate)
      framePixels.setRegion(
          indexX + _pixels.getRegionX(), indexY + _pixels.getRegionY(), frameWidth, frameHeight);
    else
      framePixels.setRegion(
          indexX + _pixels.getRegionX(), indexY + _pixels.getRegionY(), frameHeight, frameWidth);

    // handle reversed sprites.
    if (_flipped > 0 && _facing == LEFT && _pixels.rotate) framePixels.flip(false, false);
    else if (_flipped > 0 && _facing == LEFT) framePixels.flip(true, true);
    else framePixels.flip(false, true);

    if (_callback != null)
      _callback.callback(((_curAnim != null) ? (_curAnim.name) : null), _curFrame, _curIndex);
    dirty = false;
  }
Beispiel #4
0
  @Override
  public void render(float delta, SpriteBatch batch) {
    if ((extra & 0x1) == 1) {
      walkDuration += delta;
      if (vX < -15f) {
        sprite.setRegion(walk.getKeyFrame(walkDuration));
        previousXFlip = false;
      } else if (vX > 15f) {
        sprite.setRegion(walk.getKeyFrame(walkDuration));
        sprite.flip(true, false);
        previousXFlip = true;
      } else {
        sprite.setRegion(walk.getKeyFrame(walkDuration));
        sprite.flip(previousXFlip, false);
      }
    } else {
      sprite.setRegion(AssetLoader.instance.getTexture("sprites/green_loader.png"));
    }

    float x = position.x - sprite.getWidth() / 2 + 1f;
    float y = position.y - sprite.getHeight() / 2 + ServerBlob.YOFFSET;
    drawAll(sprite, batch, x, y);
  }
Beispiel #5
0
  /** Resets some important variables for sprite optimization and rendering. */
  protected void resetHelpers() {
    if (framePixels == null) framePixels = new Sprite(_pixels);
    framePixels.setRegion(_pixels, 0, 0, frameWidth, frameHeight);
    framePixels.setSize(frameWidth, frameHeight);
    framePixels.flip(false, true);
    origin.make(frameWidth * 0.5f, frameHeight * 0.5f);
    _curIndex = 0;
    _numFrames = 0;

    int widthHelper = _pixels.rotate ? _pixels.getRegionHeight() : _pixels.getRegionWidth();
    int maxFramesX = FlxU.floor(widthHelper / frameWidth);
    int maxFramesY =
        FlxU.floor(
            (_pixels.rotate ? _pixels.getRegionWidth() : _pixels.getRegionHeight()) / frameHeight);
    _maxFrames = maxFramesX * maxFramesY;

    // rotated texture region.
    if (_pixels.rotate) {
      framePixels.setRegion(_pixels.getRegionX(), _pixels.getRegionY(), frameHeight, frameWidth);
      framePixels.flip(false, true);
      dirty = true;
    }
  }
  @Override
  public void create() {
    Gdx.input.setInputProcessor(
        new InputAdapter() {
          public boolean touchDown(int x, int y, int pointer, int newParam) {
            renderMode = (renderMode + 1) % 4;
            return false;
          }
        });

    spriteBatch = new SpriteBatch();
    spriteBatch.setProjectionMatrix(
        new Matrix4().setToOrtho(0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0, 0, 1));

    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    logoSprite = new Sprite(texture);
    logoSprite.flip(false, true);
    logoSprite.setPosition(0, 320 - 256);
    logoSprite.setColor(1, 1, 1, 0.5f);

    font =
        new BitmapFont(
            Gdx.files.internal("data/verdana39.fnt"),
            Gdx.files.internal("data/verdana39.png"),
            true);

    cache1 = font.newFontCache();
    cache2 = font.newFontCache();
    cache3 = font.newFontCache();
    cache4 = font.newFontCache();
    cache5 = font.newFontCache();
    createCaches("cached", cache1, cache2, cache3, cache4, cache5);

    font.getData().setScale(1.33f);
    cacheScaled1 = font.newFontCache();
    cacheScaled2 = font.newFontCache();
    cacheScaled3 = font.newFontCache();
    cacheScaled4 = font.newFontCache();
    cacheScaled5 = font.newFontCache();
    createCaches(
        "cache scaled", cacheScaled1, cacheScaled2, cacheScaled3, cacheScaled4, cacheScaled5);
  }
  @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();
  }