示例#1
0
  public Pawn(World world, Vector2 pos, float angle) {
    super(world, pos, angle);
    hp = 5;
    protection = 0.0f;

    wrapper =
        new TextureWrapper(
            new TextureRegion(
                new Texture(Gdx.files.internal("pawn.png")),
                Constants.ENEMY_WIDTH,
                Constants.ENEMY_HEIGHT),
            pos);

    PolygonShape bodyShape = new PolygonShape();

    float w = Utils.convertToBox(wrapper.getRegion().getRegionWidth() / 2f);
    float h = Utils.convertToBox(wrapper.getRegion().getRegionHeight() / 2f);
    bodyShape.setAsBox(w, h);

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.density = 0.5f;
    fixtureDef.restitution = 0;
    fixtureDef.shape = bodyShape;
    fixtureDef.friction = 10f;

    body.createFixture(fixtureDef);
    body.setTransform(body.getPosition(), angle);
    body.setAngularVelocity(0.2f);
    bodyShape.dispose();
    body.setUserData(this);

    generalType = Entities.ENEMY;
    specificType = Entities.PAWN;

    wrapper.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
  }
示例#2
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();
    }
  }