package com.palepail.TestGame.Model;
import java.util.Iterator;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.palepail.TestGame.Actions.Action;
import com.palepail.TestGame.Model.Bullet.Bullet;
import com.palepail.TestGame.Model.Bullet.EnemyBasicBullet;
import com.palepail.TestGame.Model.Bullet.EnemySplitBullet;
import com.palepail.TestGame.Model.Bullet.EnemySquiggleBullet;
import com.palepail.TestGame.Utilities.Configuration;
import com.palepail.TestGame.View.World;
public abstract class MovableEntity extends Entity {
protected Vector2 velocity;
protected float SPEED;
protected float rotation;
protected boolean shooting;
protected int clip = -1;
protected float cooldown;
protected float cooldownCounter;
protected float fireRate;
private Vector2 previousPosition;
private boolean MOVE_UP = false;
private boolean MOVE_DOWN = false;
private boolean MOVE_LEFT = false;
private boolean MOVE_RIGHT = false;
private float distance;
protected float bulletScale = 1;
protected Vector2 spawnPoint;
protected float topSpeed;
protected float acceleration = .00006f;
protected Array<Action> sequentialScript = new Array<Action>();
protected Array<Action> tandemScript = new Array<Action>();
protected Iterator<Action> scriptIterator;
protected Action action;
protected int burstSpread = 90;
protected int burstCount = 5;
public MovableEntity(float SPEED, float rotation, float width, float height, Vector2 position) {
super(position, width, height);
this.SPEED = SPEED;
this.rotation = rotation;
velocity = new Vector2(0, 0);
}
/**
* @return the cooldown
*/
public float getCooldown() {
return cooldown;
}
/**
* @param cooldown
* the cooldown to set
*/
public void setCooldown(float cooldown) {
this.cooldown = cooldown;
}
/**
* @return the cooldownCounter
*/
public float getCooldownCounter() {
return cooldownCounter;
}
/**
* @param cooldownCounter
* the cooldownCounter to set
*/
public void setCooldownCounter(float cooldownCounter) {
this.cooldownCounter = cooldownCounter;
}
/**
* @return the topSpeed
*/
public float getTopSpeed() {
return topSpeed;
}
/**
* @param topSpeed
* the topSpeed to set
*/
public void setTopSpeed(float topSpeed) {
this.topSpeed = topSpeed;
}
/**
* @return the spawnPoint
*/
public Vector2 getSpawnPoint() {
return spawnPoint;
}
/**
* @param spawnPoint
* the spawnPoint to set
*/
public void setSpawnPoint(Vector2 spawnPoint) {
this.spawnPoint = spawnPoint;
}
/**
* @return the script
*/
public Array<Action> getScript() {
return sequentialScript;
}
/**
* @param script
* the script to set
*/
public void setScript(Array<Action> script) {
this.sequentialScript = script;
}
/**
* @return the fireRate
*/
public float getFireRate() {
return fireRate;
}
/**
* @param fireRate
* the fireRate to set
*/
public void setFireRate(int fireRate) {
this.fireRate = fireRate;
}
/**
* @return the shooting
*/
public boolean isShooting() {
return shooting;
}
/**
* @param shooting
* the shooting to set
*/
public void setShooting(boolean shooting) {
this.shooting = shooting;
}
public void setShooting(boolean shooting, int shots) {
this.shooting = shooting;
this.clip = shots;
}
public void update(Ship ship) {
bounds.x = position.x;
bounds.y = position.y;
}
/**
* @return the rotation
*/
public float getRotation() {
return rotation;
}
/**
* @param rotation
* the rotation to set
*/
public void setRotation(float rotation) {
this.rotation = rotation;
}
/**
* @return the velocity
*/
public Vector2 getVelocity() {
return velocity;
}
/**
* @param velocity
* the velocity to set
*/
public void setVelocity(Vector2 velocity) {
this.velocity = velocity;
}
/**
* @return the SPEED
*/
public float getSPEED() {
return SPEED;
}
/**
* @param SPEED
* the SPEED to set
*/
public void setSPEED(float SPEED) {
this.SPEED = SPEED;
}
/**
* @return the mOVE_UP
*/
public boolean isMOVE_UP() {
return MOVE_UP;
}
/**
* @param mOVE_UP
* the mOVE_UP to set
*/
public void setMOVE_UP(boolean mOVE_UP) {
MOVE_UP = mOVE_UP;
}
/**
* @return the mOVE_DOWN
*/
public boolean isMOVE_DOWN() {
return MOVE_DOWN;
}
/**
* @param mOVE_DOWN
* the mOVE_DOWN to set
*/
public void setMOVE_DOWN(boolean mOVE_DOWN) {
MOVE_DOWN = mOVE_DOWN;
}
/**
* @return the mOVE_LEFT
*/
public boolean isMOVE_LEFT() {
return MOVE_LEFT;
}
/**
* @param mOVE_LEFT
* the mOVE_LEFT to set
*/
public void setMOVE_LEFT(boolean mOVE_LEFT) {
MOVE_LEFT = mOVE_LEFT;
}
/**
* @return the mOVE_RIGHT
*/
public boolean isMOVE_RIGHT() {
return MOVE_RIGHT;
}
/**
* @param mOVE_RIGHT
* the mOVE_RIGHT to set
*/
public void setMOVE_RIGHT(boolean mOVE_RIGHT) {
MOVE_RIGHT = mOVE_RIGHT;
}
public float getDistance() {
return distance;
}
public void setDistance(float distance) {
this.distance = distance;
}
/**
* @return the acceleration
*/
public float getAcceleration() {
return acceleration;
}
/**
* @param acceleration
* the acceleration to set
*/
public void setAcceleration(float acceleration) {
this.acceleration = acceleration;
}
public void moveUp() {
setMOVE_DOWN(false);
if (velocity.y < 0) {
velocity.y = 0;
}
velocity.y += SPEED * acceleration;
}
public void moveRight() {
setMOVE_LEFT(false);
if (velocity.x < 0) {
velocity.x = 0;
}
velocity.x += SPEED * acceleration;
}
public void moveLeft() {
setMOVE_RIGHT(false);
if (velocity.x > 0) {
velocity.x = 0;
}
velocity.x -= SPEED * acceleration;
}
public void moveDown() {
setMOVE_UP(false);
if (velocity.y > 0) {
velocity.y = 0;
}
velocity.y -= SPEED * acceleration;
}
public void stop() {
if (velocity.y != 0) {
velocity.y = 0;
}
if (velocity.x != 0) {
velocity.x = 0;
}
}
public void setVelocity(float x, float y) {
this.velocity.x = x;
this.velocity.y = y;
}
public void setPosition(float x, float y) {
position.x = x;
position.y = y;
}
public void shoot(World world, Ship ship, float bulletScale) {
world.addEnemyBullet(getBasicBullet(ship, bulletScale));
}
public void shootSquiggle(World world, Ship ship, float bulletScale) {
world.addEnemyBullet(getSquiggleBullet(ship, bulletScale));
}
public void shootSplit(World world, Ship ship, float bulletScale, float splitAngle, float splitTime, boolean hasSplit) {
world.addEnemyBullet(getSplitBullet(ship, bulletScale, splitAngle, splitTime, hasSplit));
}
public void shootBurst(World world, Ship ship, float bulletScale) {
float originalAngle = new Vector2(ship.getPosition().tmp().sub(getPosition()).nor()).angle();
for (float i = originalAngle - (burstSpread / 2); i <= originalAngle + (burstSpread / 2); i += (burstSpread / burstCount)) {
float angle = i;
Bullet bullet = getBasicBullet(ship, bulletScale);
bullet.getVelocity().setAngle(angle);
world.addEnemyBullet(bullet);
}
}
public void shootSplitBurst(World world, Ship ship, float bulletScale) {
float originalAngle = new Vector2(ship.getPosition().tmp().sub(getPosition()).nor()).angle();
for (float i = originalAngle - (burstSpread / 2); i <= originalAngle + (burstSpread / 2); i += (burstSpread / burstCount)) {
float angle = i;
Bullet bullet = getBasicBullet(ship, bulletScale);
bullet.getVelocity().setAngle(angle);
world.addEnemyBullet(bullet);
}
}
public void shootFullSquiggleBurst(World world, Ship ship, float bulletScale) {
for (float i = 0; i <= 360; i += 30) {
float angle = i;
EnemySquiggleBullet bullet = (EnemySquiggleBullet) getSquiggleBullet(ship, bulletScale);
bullet.setOriginalAngle(angle);
world.addEnemyBullet(bullet);
}
}
public void shootFullBurst(World world, Ship ship, float bulletScale) {
for (float i = 0; i <= 360; i += 30) {
EnemyBasicBullet bullet = (EnemyBasicBullet) getBasicBullet(ship, bulletScale);
bullet.getVelocity().setAngle(i);
world.addEnemyBullet(bullet);
}
}
public void shootFullSplitBurst(World world, Ship ship, float bulletScale, float splitAngle, float splitTime, boolean hasSplit) {
for (float i = 0; i <= 360; i += 30) {
EnemySplitBullet bullet = (EnemySplitBullet) getSplitBullet(ship, bulletScale, splitAngle, splitTime, hasSplit);
bullet.getVelocity().setAngle(i);
world.addEnemyBullet(bullet);
}
}
public void shootDouble(World world, Ship ship, float bulletScale) {
Bullet bullet = getBasicBullet(ship, bulletScale);
bullet.getVelocity().setAngle(this.getRotation());
world.addEnemyBullet(bullet);
bullet = getBasicBullet(ship, bulletScale);
bullet.getVelocity().setAngle(-this.getRotation());
world.addEnemyBullet(bullet);
}
private Bullet getBasicBullet(Ship ship, float bulletScale) {
return new EnemyBasicBullet(EnemyBasicBullet.BULLETSPEED, 0, .5f * bulletScale * Configuration.gameScale,
.5f * bulletScale* Configuration.gameScale, new Vector2(getPosition().x + getWidth() / 2, getPosition().y
+ getHeight() / 2), new Vector2(ship.getPosition().tmp().sub(getPosition()).nor()),
this.variation);
}
private Bullet getSquiggleBullet(Ship ship , float bulletScale) {
int amplitude = 45;
float frequency = 5;
return new EnemySquiggleBullet(EnemySquiggleBullet.BULLETSPEED, 0, .5f * bulletScale* Configuration.gameScale,
.5f * bulletScale* Configuration.gameScale, new Vector2(getPosition().x + getWidth() / 2, getPosition().y
+ getHeight() / 2), new Vector2(ship.getPosition().tmp().sub(getPosition()).nor()), amplitude,
frequency, this.variation);
}
private Bullet getSplitBullet(Ship ship, float bulletScale, float splitAngle, float splitTime, boolean hasSplit) {
return new EnemySplitBullet(EnemySquiggleBullet.BULLETSPEED, 0, .5f* bulletScale * Configuration.gameScale,
.5f* bulletScale * Configuration.gameScale, new Vector2(getPosition().x + getWidth() / 2, getPosition().y
+ getHeight() / 2), new Vector2(ship.getPosition().tmp().sub(getPosition()).nor()),
this.variation, splitAngle, splitTime, hasSplit, bulletScale);
}
public Vector2 getPreviousPosition() {
return previousPosition;
}
public void setPreviousPosition(Vector2 previousPosition) {
this.previousPosition = previousPosition;
}
}