示例#1
0
  public static boolean isTouchingCannon(Vector3 touchPos) {
    Cannon cannon = GameScreen.cannon;

    Vector2 origin = cannon.getPosition();
    origin.x = Utils.convertToWorld(origin.x);
    origin.y = Utils.convertToWorld(origin.y);
    origin.sub(new Vector2(cannon.wrapper.width / 2, cannon.wrapper.height / 2));
    Vector2 end = new Vector2(cannon.wrapper.width, cannon.wrapper.height);
    Rectangle rect = new Rectangle(origin.x, origin.y, end.x, end.y);
    return rect.contains(touchPos.x, touchPos.y);
  }
示例#2
0
 @Override
 public void fire() {
   Vector2 bullet_position =
       new Vector2(
           Utils.convertToWorld(body.getPosition().x), Utils.convertToWorld(body.getPosition().y));
   bullet_position =
       bullet_position.add(
           new Vector2(0, -Constants.ENEMY_HEIGHT / 2 - Constants.BULLET_HEIGHT / 2));
   Bullet bullet = new IceBullet(bullet_position, GameScreen.world, 0, true);
   float target_angle =
       (float)
           (Math.PI / 2
               + Math.atan2(
                   (double) this.getPosition().y - GameScreen.cannon.getPosition().y,
                   (double) this.getPosition().x - GameScreen.cannon.getPosition().x));
   bullet.body.setLinearVelocity(
       new Vector2(
           (float) ((-4f) * Math.sin(target_angle)), (float) ((2f) * Math.cos(target_angle))));
   GameScreen.bullets.add(bullet);
 }
示例#3
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);
  }
示例#4
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();
    }
  }