Package com.palepail.TestGame.Model.Items

Source Code of com.palepail.TestGame.Model.Items.Item

package com.palepail.TestGame.Model.Items;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import com.palepail.TestGame.Enemies.Enemy;
import com.palepail.TestGame.Model.MovableEntity;
import com.palepail.TestGame.Model.Ship;
import com.palepail.TestGame.Utilities.Configuration;

public abstract class Item extends MovableEntity {
  int id;
  public static float SPEED = 9 * Configuration.gameScale;
  float ROTATION_SPEED = 1500;
  final float MAX_FALL_SPEED = (float) -.3;
  float deceleration = (float) 1.1;

  protected String textureName;
  Vector2 motion = new Vector2();

  boolean attracted = false;

  public Item(float SPEED, float rotation, float width, float height, Vector2 position) {
    super(SPEED, rotation, width, height, position);

  }

  public abstract void effect(Ship ship);

  @Override
  public void update(Ship ship) {
    if (!attracted) {
      if (velocity.y > MAX_FALL_SPEED) {
        velocity.y -= deceleration * Gdx.graphics.getDeltaTime();

        if (velocity.y > 0) {
          rotation += Gdx.graphics.getDeltaTime() * ROTATION_SPEED;
          if (rotation > 360) {
            rotation -= 360;
          }
        } else {
          rotation = velocity.angle() + 90;
          velocity.x = 0;
        }

      }
    } else {

      position.lerp(
          new Vector2((ship.getPosition().x + ship.getWidth() / 2) - getWidth() / 2,
              (ship.getPosition().y + ship.getHeight() / 2) - getHeight() / 2), Gdx.graphics
              .getDeltaTime() * 15);

    }
    position.add(velocity.tmp().mul(Gdx.graphics.getDeltaTime() * SPEED));

    super.update(ship);
  }

  /**
   * @return the textureName
   */
  public String getTextureName() {
    return textureName;
  }

  /**
   * @return the deceleration
   */
  public float getDeceleration() {
    return deceleration;
  }

  /**
   * @param deceleration
   *            the deceleration to set
   */
  public void setDeceleration(float deceleration) {
    this.deceleration = deceleration;
  }

  /**
   * @return the renderScaleX
   */
  public float getRenderScaleX() {
    return renderScaleX;
  }

  /**
   * @param renderScaleX
   *            the renderScaleX to set
   */
  public void setRenderScaleX(float renderScaleX) {
    this.renderScaleX = renderScaleX;
  }

  /**
   * @return the renderScaleY
   */
  public float getRenderScaleY() {
    return renderScaleY;
  }

  /**
   * @param renderScaleY
   *            the renderScaleY to set
   */
  public void setRenderScaleY(float renderScaleY) {
    this.renderScaleY = renderScaleY;
  }

  public void setAttracted(boolean b) {
    attracted = b;

  }

  public static Item getPower(Enemy enemy, float value) {
    Power power = new Power(
        Power.SPEED,
        0,
        1f * Configuration.gameScale,
        1f * Configuration.gameScale,
        new Vector2(enemy.getPosition().x + enemy.getWidth() / 2, enemy.getPosition().y + enemy.getHeight() / 2),
        new Vector2(new Vector2(enemy.getPosition().x, 3600 * Configuration.gameScale).sub(enemy.getPosition())
            .nor()), value);
    return power;
  }

  public static Item getPoints(Enemy enemy, int value) {
    Points points = new Points(
        Points.SPEED,
        0,
        1f * Configuration.gameScale,
        1f * Configuration.gameScale,
        new Vector2(enemy.getPosition().x + enemy.getWidth() / 2, enemy.getPosition().y + enemy.getHeight() / 2),
        new Vector2(new Vector2(enemy.getPosition().x, 3600 * Configuration.gameScale).sub(enemy.getPosition())
            .nor()), value);
    return points;
  }

  public static Item getBomb(Enemy enemy) {
    BombItem bomb = new BombItem(
        BombItem.SPEED,
        0,
        1f * Configuration.gameScale,
        1f * Configuration.gameScale,
        new Vector2(enemy.getPosition().x + enemy.getWidth() / 2, enemy.getPosition().y + enemy.getHeight() / 2),
        new Vector2(new Vector2(enemy.getPosition().x, 3600 * Configuration.gameScale).sub(enemy.getPosition())
            .nor()));
    return bomb;
  }
}
TOP

Related Classes of com.palepail.TestGame.Model.Items.Item

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.