reworked the entity framework (still in progress)
This commit is contained in:
parent
013e3d7d99
commit
66e82c0efe
@ -1,26 +1,25 @@
|
||||
package zero1hd.polyjet.audio.map;
|
||||
|
||||
import zero1hd.polyjet.entity.Entities;
|
||||
import java.util.HashMap;
|
||||
|
||||
import zero1hd.polyjet.entity.EntityIndex;
|
||||
|
||||
public class EntitySpawnInfo {
|
||||
private Entities entityType;
|
||||
private float[] parameters;
|
||||
private EntityIndex entityType;
|
||||
// private float[] parameters;
|
||||
public HashMap<String, Float> parameters;
|
||||
|
||||
public EntitySpawnInfo(Entities entityType, float... parameters) {
|
||||
public EntitySpawnInfo(EntityIndex entityType) {
|
||||
this.entityType = entityType;
|
||||
this.parameters = parameters;
|
||||
parameters = new HashMap<>();
|
||||
}
|
||||
|
||||
public Entities getEntityType() {
|
||||
public EntityIndex getEntityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return entityType.name() + ": " + parameters.length;
|
||||
}
|
||||
|
||||
public float[] getParameters() {
|
||||
return parameters;
|
||||
return entityType.name() + ": " + parameters.size();
|
||||
}
|
||||
}
|
||||
|
@ -4,14 +4,16 @@ import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import zero1hd.polyjet.audio.AudioData;
|
||||
import zero1hd.polyjet.entity.Entities;
|
||||
import zero1hd.polyjet.entity.EntityIndex;
|
||||
|
||||
public class GamePlayMap {
|
||||
|
||||
private AudioData musicData;
|
||||
private float playTime;
|
||||
private Array<MapWindowData> spawnList;
|
||||
private boolean building;
|
||||
private int index;
|
||||
|
||||
/**
|
||||
* GamePlayMap is what the game area will use to generate entities and judge current audio data
|
||||
* @param audioData audio data
|
||||
@ -61,19 +63,17 @@ public class GamePlayMap {
|
||||
|
||||
|
||||
/**
|
||||
* used to add data types for what entity to spawn at that index position
|
||||
* cannot be null.
|
||||
* @param entityType what type of entity to spawn
|
||||
* @param parameters the arguments for the entity. It is important to have the same amount of parameters the entity requires to spawn
|
||||
* adds a new entity to the map for the current window.
|
||||
* @param entityType what type of entity it should be
|
||||
* @return the object.
|
||||
*/
|
||||
|
||||
public void addToMap(Entities entityType, float... parameters) {
|
||||
if (building && entityType != null && parameters != null) {
|
||||
if (spawnList.get(index) == null) {
|
||||
spawnList.set(index, new MapWindowData());
|
||||
}
|
||||
spawnList.get(index).addEntity(new EntitySpawnInfo(entityType, parameters));
|
||||
public EntitySpawnInfo nextEntitySpawnInfo(EntityIndex entityType) {
|
||||
if (spawnList.get(index) == null) {
|
||||
spawnList.set(index, new MapWindowData());
|
||||
}
|
||||
EntitySpawnInfo esi = new EntitySpawnInfo(entityType);
|
||||
spawnList.get(index).addEntity(esi);
|
||||
return esi;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,8 +81,7 @@ public class GamePlayMap {
|
||||
*/
|
||||
public void nextWindow() {
|
||||
if (building) {
|
||||
spawnList.add(new MapWindowData());
|
||||
resetIndex();
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import com.badlogic.gdx.utils.FloatArray;
|
||||
|
||||
import zero1hd.polyjet.Main;
|
||||
import zero1hd.polyjet.audio.AudioAnalyzer;
|
||||
import zero1hd.polyjet.entity.Entities;
|
||||
import zero1hd.polyjet.entity.EntityIndex;
|
||||
import zero1hd.polyjet.util.MiniEvents;
|
||||
import zero1hd.polyjet.util.MiniSender;
|
||||
|
||||
@ -52,6 +52,8 @@ public class RhythmMapAlgorithm implements Runnable {
|
||||
avgBass = analyzer.getBassAvg();
|
||||
}
|
||||
|
||||
|
||||
EntitySpawnInfo esi;
|
||||
@Override
|
||||
public void run() {
|
||||
map.beginBuild();
|
||||
@ -64,13 +66,14 @@ public class RhythmMapAlgorithm implements Runnable {
|
||||
int indexMoved = map.goBack((int) (windowPerSecond*1.5f));
|
||||
float waitTime = indexMoved/windowPerSecond;
|
||||
float endRadius = (bassPeaks.get(index)/bassMax)*(Main.GAME_AREA_HEIGHT/4f);
|
||||
map.addToMap(Entities.VOID_CIRCLE,
|
||||
endRadius,
|
||||
rand.nextFloat()*Main.GAME_AREA_WIDTH,
|
||||
rand.nextFloat()*Main.GAME_AREA_HEIGHT,
|
||||
endRadius/(avgSPB*0.7f),
|
||||
waitTime
|
||||
);
|
||||
|
||||
esi = map.nextEntitySpawnInfo(EntityIndex.VOID_CIRCLE);
|
||||
esi.parameters.put("warningTime", waitTime);
|
||||
esi.parameters.put("endRadius", endRadius);
|
||||
esi.parameters.put("growthRate", endRadius/(avgSPB*0.7f));
|
||||
esi.parameters.put("x", rand.nextFloat()*Main.GAME_AREA_WIDTH);
|
||||
esi.parameters.put("y", rand.nextFloat()*Main.GAME_AREA_HEIGHT);
|
||||
|
||||
map.goForward(indexMoved);
|
||||
}
|
||||
}
|
||||
@ -79,16 +82,20 @@ public class RhythmMapAlgorithm implements Runnable {
|
||||
if (UMPeaks.get(index) >= avgUM) {
|
||||
//If upper midrange peaks are greater than average, the:
|
||||
int spawnLocations = (Main.GAME_AREA_WIDTH-8)/8;
|
||||
map.addToMap(Entities.BAR,
|
||||
MathUtils.round(rand.nextFloat()*spawnLocations)*8,
|
||||
(8f/avgSPB)*speedMod);
|
||||
|
||||
esi = map.nextEntitySpawnInfo(EntityIndex.BAR);
|
||||
esi.parameters.put("x", (float) (MathUtils.round(rand.nextFloat()*spawnLocations)*8));
|
||||
esi.parameters.put("rate", (8f/avgSPB)*speedMod);
|
||||
|
||||
} else {
|
||||
float xSpawnLocation = (rand.nextFloat()*(Main.GAME_AREA_WIDTH-2))+1;
|
||||
map.addToMap(Entities.PELLET,
|
||||
xSpawnLocation,
|
||||
Main.GAME_AREA_HEIGHT-0.25f,
|
||||
140*rand.nextFloat()+110f,
|
||||
(Main.GAME_AREA_HEIGHT/4f)/avgSPB);
|
||||
|
||||
esi = map.nextEntitySpawnInfo(EntityIndex.PELLET);
|
||||
esi.parameters.put("x", xSpawnLocation);
|
||||
esi.parameters.put("y", Main.GAME_AREA_HEIGHT-0.25f);
|
||||
esi.parameters.put("angle", 140*rand.nextFloat()+110f);
|
||||
esi.parameters.put("speed", (Main.GAME_AREA_HEIGHT/4f)/avgSPB);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,29 +0,0 @@
|
||||
package zero1hd.polyjet.entity;
|
||||
|
||||
import zero1hd.polyjet.entity.ally.Laser;
|
||||
import zero1hd.polyjet.entity.ally.PolyJetEntity;
|
||||
import zero1hd.polyjet.entity.enemies.Bar;
|
||||
import zero1hd.polyjet.entity.enemies.Flake;
|
||||
import zero1hd.polyjet.entity.enemies.Pellet;
|
||||
import zero1hd.polyjet.entity.enemies.Shard;
|
||||
import zero1hd.polyjet.entity.enemies.VoidCircle;
|
||||
|
||||
public enum Entities {
|
||||
POLYJET(false, PolyJetEntity.class), BAR(true, Bar.class), VOID_CIRCLE(true, VoidCircle.class), SHARD(true, Shard.class), LASER(false, Laser.class), PELLET(true, Pellet.class), FLAKE(true, Flake.class);
|
||||
|
||||
private final boolean enemy;
|
||||
private final Class<? extends Entity> classType;
|
||||
|
||||
private Entities(boolean enemy, Class<? extends Entity> classType) {
|
||||
this.enemy = enemy;
|
||||
this.classType = classType;
|
||||
}
|
||||
|
||||
public boolean isEnemy() {
|
||||
return enemy;
|
||||
}
|
||||
|
||||
public Class<? extends Entity> getClassType() {
|
||||
return classType;
|
||||
}
|
||||
}
|
@ -1,34 +1,126 @@
|
||||
package zero1hd.polyjet.entity;
|
||||
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import java.util.HashMap;
|
||||
|
||||
public abstract class Entity extends Actor {
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
|
||||
public class Entity extends Actor implements Poolable {
|
||||
private EntityFrame<?> ef;
|
||||
|
||||
protected AssetManager assets;
|
||||
protected Preferences prefs;
|
||||
protected EntityController ec;
|
||||
|
||||
protected boolean enemy;
|
||||
protected boolean simple = true;
|
||||
protected boolean nonStnrd = false;
|
||||
|
||||
protected Rectangle hitbox;
|
||||
protected Sprite sprite;
|
||||
protected Vector2 rotRatios;
|
||||
protected Vector2 center;
|
||||
protected float angle;
|
||||
protected float speed;
|
||||
|
||||
/**
|
||||
* called by the entity frame and only once (when this object is created).
|
||||
* Since your not supposed to actually use the constructor;
|
||||
*/
|
||||
protected void setup(EntityController ec, EntityFrame<?> ef) {
|
||||
this.ec = ec;
|
||||
this.ef = ef;
|
||||
assets = ec.getAssets();
|
||||
prefs = ec.getPrefs();
|
||||
rotRatios = new Vector2();
|
||||
center = new Vector2();
|
||||
hitbox = new Rectangle();
|
||||
sprite = new Sprite();
|
||||
sprite.setOriginCenter();
|
||||
|
||||
preInit();
|
||||
}
|
||||
|
||||
public void preInit() {
|
||||
if (sprite.getTexture() == null) throw new NullPointerException("what, your not going to have a texture for your entity?");
|
||||
}
|
||||
|
||||
public void init(HashMap<String, Float> params) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever a collision is detected
|
||||
* @param entity is the entity that hit this one.
|
||||
*/
|
||||
public abstract void collided(Entity entity);
|
||||
public void collided(Entity entity) {
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the box that represents the hit box to calculate whether there is a collision or not
|
||||
* @return the object that represents the hit box
|
||||
*/
|
||||
public abstract Rectangle getHitZone();
|
||||
public Rectangle getHitZone() {
|
||||
return hitbox;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the type of entity this entity is
|
||||
* @return the entity type
|
||||
*/
|
||||
public abstract Entities getEntityType();
|
||||
public EntityIndex getEntityType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this entity's life span is over, it should be considered dead. Useful for knowing what can be freed in a pool scenario.
|
||||
* @return if this entity is dead or not.
|
||||
*/
|
||||
public abstract boolean isDead();
|
||||
public boolean isDead() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
if (!nonStnrd) {
|
||||
rotRatios.set(MathUtils.cosDeg(angle), MathUtils.sinDeg(angle));
|
||||
center.set(getX() + getWidth()/2f, getY() + getHeight()/2f);
|
||||
moveBy(rotRatios.x*speed*delta, rotRatios.y*speed*delta);
|
||||
if (simple) {
|
||||
sprite.setPosition(getX(), getY());
|
||||
hitbox.setPosition(getX(), getY());
|
||||
sprite.setSize(getWidth(), getHeight());
|
||||
hitbox.setSize(getWidth(), getHeight());
|
||||
} else {
|
||||
sprite.setCenter(center.x, center.y);
|
||||
hitbox.setCenter(center);
|
||||
sprite.setRotation(angle);
|
||||
}
|
||||
|
||||
super.act(delta);
|
||||
|
||||
if (isDead()) {
|
||||
ef.recycleEntity(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
if (!nonStnrd) {
|
||||
sprite.draw(batch);
|
||||
}
|
||||
batch.setColor(Color.WHITE);
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
|
||||
public boolean playCollidePFX() {
|
||||
return true;
|
||||
@ -37,4 +129,33 @@ public abstract class Entity extends Actor {
|
||||
public boolean playCollideSFX() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
rotRatios.set(0, 0);
|
||||
hitbox.set(0, 0, 0, 0);
|
||||
sprite.setBounds(0, 0, 0, 0);
|
||||
sprite.setRotation(0);
|
||||
sprite.setOrigin(0, 0);
|
||||
setPosition(0, 0);
|
||||
center.set(0, 0);
|
||||
angle = 0;
|
||||
speed = 0;
|
||||
}
|
||||
|
||||
public Vector2 getCenter() {
|
||||
return center;
|
||||
}
|
||||
|
||||
public float getAngle() {
|
||||
return angle;
|
||||
}
|
||||
|
||||
public void setSpeed(float speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,13 @@
|
||||
package zero1hd.polyjet.entity;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.audio.Sound;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Pool;
|
||||
|
||||
import zero1hd.polyjet.audio.map.EntitySpawnInfo;
|
||||
import zero1hd.polyjet.entity.ally.Laser;
|
||||
import zero1hd.polyjet.entity.enemies.Bar;
|
||||
import zero1hd.polyjet.entity.enemies.Flake;
|
||||
@ -20,25 +16,23 @@ import zero1hd.polyjet.entity.enemies.Shard;
|
||||
import zero1hd.polyjet.entity.enemies.VoidCircle;
|
||||
|
||||
public class EntityController {
|
||||
AssetManager assets;
|
||||
Preferences prefs;
|
||||
private AssetManager assets;
|
||||
private Preferences prefs;
|
||||
private Stage stage;
|
||||
|
||||
public Array<Entity> activeAllies;
|
||||
public Array<Entity> activeEnemies;
|
||||
|
||||
//Enemy pool declaration;
|
||||
private Pool<VoidCircle> voidCirclePool;
|
||||
private Pool<Pellet> pelletPool;
|
||||
private Pool<Shard> shardPool;
|
||||
private Pool<Bar> barPool;
|
||||
private Pool<Flake> flakePool;
|
||||
public EntityFrame<VoidCircle> voidCircle;
|
||||
public EntityFrame<Pellet> pellet;
|
||||
public EntityFrame<Shard> shard;
|
||||
public EntityFrame<Bar> bar;
|
||||
public EntityFrame<Flake> flake;
|
||||
|
||||
private EntityController ec = this;
|
||||
public EntityFrame<Laser> laser;
|
||||
|
||||
//Ally pool declaration;
|
||||
private Pool<Laser> laserPool;
|
||||
private HashMap<EntityIndex, EntityFrame<? extends Entity>> index = new HashMap<>();
|
||||
|
||||
private Stage stage;
|
||||
public EntityController(AssetManager assetManager, Preferences preferences, Stage stage) {
|
||||
activeAllies = new Array<Entity>();
|
||||
activeEnemies = new Array<Entity>();
|
||||
@ -46,187 +40,32 @@ public class EntityController {
|
||||
this.prefs = preferences;
|
||||
this.stage = stage;
|
||||
|
||||
//Enemy pool initialization;
|
||||
voidCirclePool = new Pool<VoidCircle>() {
|
||||
@Override
|
||||
protected VoidCircle newObject() {
|
||||
return new VoidCircle(assets.get("void_circle.png", Texture.class), assets.get("disintegrate.ogg", Sound.class), prefs);
|
||||
}
|
||||
};
|
||||
|
||||
pelletPool = new Pool<Pellet>() {
|
||||
@Override
|
||||
protected Pellet newObject() {
|
||||
return new Pellet(assets.get("pellet.png", Texture.class));
|
||||
}
|
||||
};
|
||||
|
||||
shardPool = new Pool<Shard>() {
|
||||
@Override
|
||||
protected Shard newObject() {
|
||||
return new Shard(assets.get("shard.png", Texture.class));
|
||||
}
|
||||
};
|
||||
|
||||
barPool = new Pool<Bar>() {
|
||||
@Override
|
||||
protected Bar newObject() {
|
||||
return new Bar(assets.get("bar.png", Texture.class));
|
||||
}
|
||||
};
|
||||
|
||||
flakePool = new Pool<Flake>() {
|
||||
@Override
|
||||
protected Flake newObject() {
|
||||
return new Flake(assets.get("flake.png", Texture.class), ec);
|
||||
}
|
||||
};
|
||||
|
||||
//Ally pool initialization;
|
||||
laserPool = new Pool<Laser>() {
|
||||
@Override
|
||||
protected Laser newObject() {
|
||||
return new Laser(assets.get("laser.png", Texture.class), assets.get("laser.ogg", Sound.class), prefs);
|
||||
}
|
||||
};
|
||||
setup();
|
||||
}
|
||||
|
||||
public Entity retrieveEntity(Entities entity) {
|
||||
switch (entity) {
|
||||
case VOID_CIRCLE:
|
||||
VoidCircle voidCircle = voidCirclePool.obtain();
|
||||
activeEnemies.add(voidCircle);
|
||||
return voidCircle;
|
||||
case LASER:
|
||||
Laser laser = laserPool.obtain();
|
||||
activeAllies.add(laser);
|
||||
return laser;
|
||||
case PELLET:
|
||||
Pellet pellet = pelletPool.obtain();
|
||||
activeEnemies.add(pellet);
|
||||
return pellet;
|
||||
case SHARD:
|
||||
Shard shard = shardPool.obtain();
|
||||
activeEnemies.add(shard);
|
||||
return shard;
|
||||
case BAR:
|
||||
Bar bar = barPool.obtain();
|
||||
activeEnemies.add(bar);
|
||||
return bar;
|
||||
case FLAKE:
|
||||
Flake flake = flakePool.obtain();
|
||||
activeEnemies.add(flake);
|
||||
return flake;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
private void setup() {
|
||||
index.put(EntityIndex.VOID_CIRCLE, new EntityFrame<>(this, VoidCircle.class));
|
||||
index.put(EntityIndex.PELLET, new EntityFrame<>(this, Pellet.class));
|
||||
index.put(EntityIndex.SHARD, new EntityFrame<>(this, Shard.class));
|
||||
index.put(EntityIndex.BAR, new EntityFrame<>(this, Bar.class));
|
||||
index.put(EntityIndex.FLAKE, new EntityFrame<>(this, Flake.class));
|
||||
|
||||
index.put(EntityIndex.LASER, new EntityFrame<>(this, Laser.class));
|
||||
}
|
||||
|
||||
public Entity spawnEntity(Stage stage, EntitySpawnInfo entitySpawnInfo) {
|
||||
if (entitySpawnInfo != null) {
|
||||
float[] param = entitySpawnInfo.getParameters();
|
||||
Gdx.app.debug("Spawning Entity", entitySpawnInfo.toString() + " parameters: " + Arrays.toString(param));
|
||||
switch (entitySpawnInfo.getEntityType()) {
|
||||
case VOID_CIRCLE:
|
||||
VoidCircle voidCircle = voidCirclePool.obtain();
|
||||
voidCircle.init(param[0], param[1], param[2], param[3], param[4]);
|
||||
activeEnemies.add(voidCircle);
|
||||
stage.addActor(voidCircle);
|
||||
return voidCircle;
|
||||
case LASER:
|
||||
Laser laser = laserPool.obtain();
|
||||
laser.init(param[0], param[1], param[2]);
|
||||
activeAllies.add(laser);
|
||||
stage.addActor(laser);
|
||||
return laser;
|
||||
case PELLET:
|
||||
Pellet pellet = pelletPool.obtain();
|
||||
pellet.init(param[0], param[1], param[2], param[3]);
|
||||
activeEnemies.add(pellet);
|
||||
stage.addActor(pellet);
|
||||
return pellet;
|
||||
case SHARD:
|
||||
Shard shard = shardPool.obtain();
|
||||
shard.init(param[0], param[1], param[2], param[3], (int) param[4]);
|
||||
activeEnemies.add(shard);
|
||||
stage.addActor(shard);
|
||||
return shard;
|
||||
case BAR:
|
||||
Bar bar = barPool.obtain();
|
||||
bar.init(param[0], param[1]);
|
||||
activeEnemies.add(bar);
|
||||
stage.addActor(bar);
|
||||
return bar;
|
||||
case FLAKE:
|
||||
Flake flake = flakePool.obtain();
|
||||
flake.init(param[1], param[2], param[3], param[4], param[5], (int) param[0]);
|
||||
activeEnemies.add(flake);
|
||||
stage.addActor(flake);
|
||||
return flake;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void free(Entity entity) {
|
||||
if (entity.getEntityType().isEnemy()) {
|
||||
activeEnemies.removeValue(entity, true);
|
||||
} else {
|
||||
activeAllies.removeValue(entity, true);
|
||||
}
|
||||
switch (entity.getEntityType()) {
|
||||
case VOID_CIRCLE:
|
||||
VoidCircle voidCircle = (VoidCircle) entity;
|
||||
voidCircle.remove();
|
||||
voidCirclePool.free(voidCircle);
|
||||
break;
|
||||
case LASER:
|
||||
Laser laser = (Laser) entity;
|
||||
laser.remove();
|
||||
laserPool.free(laser);
|
||||
break;
|
||||
case PELLET:
|
||||
Pellet pellet = (Pellet) entity;
|
||||
pellet.remove();
|
||||
pelletPool.free(pellet);
|
||||
break;
|
||||
case SHARD:
|
||||
Shard shard = (Shard) entity;
|
||||
shard.remove();
|
||||
shardPool.free(shard);
|
||||
break;
|
||||
case BAR:
|
||||
Bar bar = (Bar) entity;
|
||||
bar.remove();
|
||||
barPool.free(bar);
|
||||
break;
|
||||
case FLAKE:
|
||||
Flake flake = (Flake) entity;
|
||||
flake.remove();
|
||||
flakePool.free(flake);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void deathClean() {
|
||||
for (int i = 0; i < activeAllies.size; i ++) {
|
||||
if (activeAllies.get(i).isDead()) {
|
||||
free(activeAllies.get(i));
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < activeEnemies.size; i++) {
|
||||
if (activeEnemies.get(i).isDead()) {
|
||||
free(activeEnemies.get(i));
|
||||
}
|
||||
}
|
||||
public HashMap<EntityIndex, EntityFrame<? extends Entity>> getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public Stage getStage() {
|
||||
return stage;
|
||||
}
|
||||
|
||||
public AssetManager getAssets() {
|
||||
return assets;
|
||||
}
|
||||
|
||||
public Preferences getPrefs() {
|
||||
return prefs;
|
||||
}
|
||||
}
|
||||
|
56
core/src/zero1hd/polyjet/entity/EntityFrame.java
Executable file
56
core/src/zero1hd/polyjet/entity/EntityFrame.java
Executable file
@ -0,0 +1,56 @@
|
||||
package zero1hd.polyjet.entity;
|
||||
|
||||
import com.badlogic.gdx.utils.Pool;
|
||||
|
||||
public class EntityFrame<T extends Entity> {
|
||||
private Pool<T> pool;
|
||||
private EntityController ec;
|
||||
Class<T> ct;
|
||||
EntityFrame<T> ef;
|
||||
public EntityFrame(EntityController entityController, Class<T> classType) {
|
||||
ct = classType;
|
||||
ef = this;
|
||||
ec = entityController;
|
||||
pool = new Pool<T>() {
|
||||
@Override
|
||||
protected T newObject() {
|
||||
try {
|
||||
T entity = ct.newInstance();
|
||||
entity.setup(ec, ef);
|
||||
|
||||
return entity;
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public T buildEntity() {
|
||||
T entity = pool.obtain();
|
||||
|
||||
if (entity.enemy) {
|
||||
ec.activeEnemies.add(entity);
|
||||
} else {
|
||||
ec.activeAllies.add(entity);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Free the entity if no longer used.
|
||||
* @param entity to be freed.
|
||||
*/
|
||||
public void recycleEntity(Entity entity) {
|
||||
if (entity.enemy) {
|
||||
ec.activeEnemies.removeValue(entity, true);
|
||||
} else {
|
||||
ec.activeAllies.removeValue(entity, true);
|
||||
}
|
||||
entity.remove();
|
||||
pool.free(ct.cast(entity));
|
||||
}
|
||||
}
|
24
core/src/zero1hd/polyjet/entity/EntityIndex.java
Executable file
24
core/src/zero1hd/polyjet/entity/EntityIndex.java
Executable file
@ -0,0 +1,24 @@
|
||||
package zero1hd.polyjet.entity;
|
||||
|
||||
import zero1hd.polyjet.entity.ally.Laser;
|
||||
import zero1hd.polyjet.entity.ally.PolyJetEntity;
|
||||
import zero1hd.polyjet.entity.enemies.Bar;
|
||||
import zero1hd.polyjet.entity.enemies.Flake;
|
||||
import zero1hd.polyjet.entity.enemies.Pellet;
|
||||
import zero1hd.polyjet.entity.enemies.Shard;
|
||||
import zero1hd.polyjet.entity.enemies.VoidCircle;
|
||||
|
||||
public enum EntityIndex {
|
||||
POLYJET(PolyJetEntity.class), BAR(Bar.class), VOID_CIRCLE(VoidCircle.class), SHARD(Shard.class), LASER(Laser.class), PELLET(Pellet.class), FLAKE(Flake.class);
|
||||
|
||||
private final Class<? extends Entity> classType;
|
||||
|
||||
private EntityIndex(Class<? extends Entity> classType) {
|
||||
this.classType = classType;
|
||||
}
|
||||
|
||||
public Class<? extends Entity> getClassType() {
|
||||
return classType;
|
||||
}
|
||||
|
||||
}
|
@ -1,48 +1,51 @@
|
||||
package zero1hd.polyjet.entity.ally;
|
||||
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.badlogic.gdx.audio.Sound;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
|
||||
import zero1hd.polyjet.Main;
|
||||
import zero1hd.polyjet.entity.Entities;
|
||||
import zero1hd.polyjet.entity.EntityIndex;
|
||||
import zero1hd.polyjet.entity.Entity;
|
||||
|
||||
public class Laser extends Entity implements Poolable {
|
||||
private Rectangle hitBox;
|
||||
private float rate;
|
||||
public class Laser extends Entity {
|
||||
boolean dead;
|
||||
Texture laserTexture;
|
||||
Sound sfx;
|
||||
Preferences prefs;
|
||||
|
||||
public Laser(Texture laserTexture, Sound sfx, Preferences prefs) {
|
||||
this.laserTexture = laserTexture;
|
||||
this.sfx = sfx;
|
||||
this.prefs = prefs;
|
||||
@Override
|
||||
public void preInit() {
|
||||
sprite.setTexture(assets.get("laser.png", Texture.class));
|
||||
sfx = assets.get("laser.ogg", Sound.class);
|
||||
setSize(0.25f, 2f);
|
||||
super.preInit();
|
||||
}
|
||||
|
||||
public void init(float x, float y, float rate) {
|
||||
setX(x);
|
||||
setY(y);
|
||||
this.rate = rate;
|
||||
hitBox = new Rectangle();
|
||||
hitBox.setSize(getWidth(), getHeight());
|
||||
setPosition(x-getWidth()/2f, y-getHeight()/2f);
|
||||
speed = rate;
|
||||
sfx.play(prefs.getFloat("fx vol")/100f);
|
||||
toBack();
|
||||
angle = 90f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vars: x, y, rate;
|
||||
*/
|
||||
@Override
|
||||
public void init(HashMap<String, Float> params) {
|
||||
setX(params.get("x") - getWidth()/2f);
|
||||
setY(params.get("y") - getHeight()/2f);
|
||||
speed = params.get("rate");
|
||||
angle = 90f;
|
||||
sfx.play(prefs.getFloat("fx vol")/100f);
|
||||
super.init(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
toBack();
|
||||
moveBy(0, delta*rate);
|
||||
hitBox.setX(getX());
|
||||
hitBox.setY(getY());
|
||||
super.act(delta);
|
||||
|
||||
if (getY() > Main.GAME_AREA_HEIGHT) {
|
||||
@ -52,16 +55,11 @@ public class Laser extends Entity implements Poolable {
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
batch.draw(laserTexture ,getX(), getY(), getWidth(), getHeight());
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
setX(0);
|
||||
setY(0);
|
||||
rate = 0;
|
||||
hitBox.set(0, 0, 0, 0);
|
||||
dead = false;
|
||||
}
|
||||
|
||||
@ -75,13 +73,8 @@ public class Laser extends Entity implements Poolable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle getHitZone() {
|
||||
return hitBox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entities getEntityType() {
|
||||
return Entities.LASER;
|
||||
public EntityIndex getEntityType() {
|
||||
return EntityIndex.LASER;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,7 +8,7 @@ import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||
|
||||
import zero1hd.polyjet.Main;
|
||||
import zero1hd.polyjet.entity.Entities;
|
||||
import zero1hd.polyjet.entity.EntityIndex;
|
||||
import zero1hd.polyjet.entity.Entity;
|
||||
|
||||
public class PolyJetEntity extends Entity {
|
||||
@ -22,6 +22,7 @@ public class PolyJetEntity extends Entity {
|
||||
private float speed, accel;
|
||||
private float rate;
|
||||
public PolyJetEntity(AssetManager assets, float speed, float accel, String jet) {
|
||||
nonStnrd = true;
|
||||
health = 100;
|
||||
this.speed = speed;
|
||||
this.accel = accel;
|
||||
@ -78,14 +79,10 @@ public class PolyJetEntity extends Entity {
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle getHitZone() {
|
||||
return hitbox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entities getEntityType() {
|
||||
return Entities.POLYJET;
|
||||
public EntityIndex getEntityType() {
|
||||
return EntityIndex.POLYJET;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,35 +1,41 @@
|
||||
package zero1hd.polyjet.entity.enemies;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
|
||||
import zero1hd.polyjet.Main;
|
||||
import zero1hd.polyjet.entity.Entities;
|
||||
import zero1hd.polyjet.entity.EntityIndex;
|
||||
import zero1hd.polyjet.entity.Entity;
|
||||
|
||||
public class Bar extends Entity implements Poolable {
|
||||
public class Bar extends Entity {
|
||||
private boolean dead;
|
||||
private Texture texture;
|
||||
private float rate;
|
||||
private Rectangle hitbox;
|
||||
|
||||
public Bar(Texture barTexture) {
|
||||
this.texture = barTexture;
|
||||
hitbox = new Rectangle();
|
||||
@Override
|
||||
public void preInit() {
|
||||
setSize(8f, 0.5f);
|
||||
sprite.setTexture(assets.get("bar.png", Texture.class));
|
||||
enemy = true;
|
||||
super.preInit();
|
||||
}
|
||||
|
||||
public void init(float x, float rate) {
|
||||
setSize(8f, 0.5f);
|
||||
setPosition(x, Main.GAME_AREA_HEIGHT);
|
||||
this.rate = rate;
|
||||
hitbox.set(getX(), getY(), getWidth(), getHeight());
|
||||
speed = rate;
|
||||
angle = 270;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(HashMap<String, Float> params) {
|
||||
setPosition(params.get("x"), Main.GAME_AREA_HEIGHT);
|
||||
speed = params.get("rate");
|
||||
angle = 270;
|
||||
super.init(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
moveBy(0f, -delta*rate);
|
||||
hitbox.setPosition(getX(), getY());
|
||||
super.act(delta);
|
||||
if (getY() < 0-getHeight()) {
|
||||
@ -37,19 +43,9 @@ public class Bar extends Entity implements Poolable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
batch.draw(texture, getX(), getY(), getWidth(), getHeight());
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
hitbox.set(0, 0, 0, 0);
|
||||
setPosition(0, 0);
|
||||
rate = 0;
|
||||
dead = false;
|
||||
setSize(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,8 +65,8 @@ public class Bar extends Entity implements Poolable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entities getEntityType() {
|
||||
return Entities.BAR;
|
||||
public EntityIndex getEntityType() {
|
||||
return EntityIndex.BAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,52 +1,65 @@
|
||||
package zero1hd.polyjet.entity.enemies;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
|
||||
import zero1hd.polyjet.Main;
|
||||
import zero1hd.polyjet.entity.Entities;
|
||||
import zero1hd.polyjet.entity.EntityIndex;
|
||||
import zero1hd.polyjet.entity.Entity;
|
||||
import zero1hd.polyjet.entity.EntityController;
|
||||
|
||||
public class Flake extends Entity implements Poolable {
|
||||
private Texture texture;
|
||||
private float rate;
|
||||
public class Flake extends Entity {
|
||||
private float timer;
|
||||
private float totalTime;
|
||||
private Shard[] shards;
|
||||
private Rectangle hitbox;
|
||||
private Vector2 center;
|
||||
private Vector2 rot;
|
||||
private EntityController ec;
|
||||
|
||||
public Flake(Texture texture, EntityController ec) {
|
||||
this.ec = ec;
|
||||
this.texture = texture;
|
||||
hitbox = new Rectangle();
|
||||
center = new Vector2();
|
||||
rot = new Vector2();
|
||||
@Override
|
||||
public void preInit() {
|
||||
sprite.setTexture(assets.get("flake.png", Texture.class));
|
||||
simple = true;
|
||||
enemy = true;
|
||||
setSize(3f, 3f);
|
||||
super.preInit();
|
||||
}
|
||||
|
||||
public void init(float x, float y, float rate, float fuse, float angle, int shardCount) {
|
||||
this.shards = new Shard[shardCount];
|
||||
for (int i = 0; i < shards.length; i++) {
|
||||
shards[i] = (Shard) ec.retrieveEntity(Entities.SHARD);
|
||||
shards[i] = ec.shard.buildEntity();
|
||||
shards[i].init(x, y, 360/shards.length*i, 0, 2);
|
||||
ec.getStage().addActor(shards[i]);
|
||||
}
|
||||
setSize(3f, 3f);
|
||||
this.rate = rate;
|
||||
this.speed = rate;
|
||||
this.timer = fuse;
|
||||
this.totalTime = fuse;
|
||||
this.angle = angle;
|
||||
hitbox.setSize(getWidth(), getHeight());
|
||||
center.set(getWidth()/2f, getHeight()/2f);
|
||||
setPosition(x-center.x, y-center.y);
|
||||
rot.set(MathUtils.cosDeg(angle), MathUtils.sinDeg(angle));
|
||||
}
|
||||
|
||||
/**
|
||||
* params: shardCount, x, y, rate, fuse, angle;
|
||||
*/
|
||||
@Override
|
||||
public void init(HashMap<String, Float> params) {
|
||||
this.shards = new Shard[params.get("shardCount").intValue()];
|
||||
for (int i = 0; i < shards.length; i++) {
|
||||
shards[i] = ec.shard.buildEntity();
|
||||
shards[i].init(params.get("x"), params.get("y"), 360/shards.length*i, 0, 2);
|
||||
ec.getStage().addActor(shards[i]);
|
||||
}
|
||||
this.speed = params.get("rate");
|
||||
this.timer = params.get("fuse");
|
||||
this.totalTime = timer;
|
||||
this.angle = params.get("angle");
|
||||
hitbox.setSize(getWidth(), getHeight());
|
||||
setPosition(params.get("x")-getWidth()/2f, params.get("y")-getHeight()/2f);
|
||||
super.init(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,13 +67,10 @@ public class Flake extends Entity implements Poolable {
|
||||
if (timer > 0) {
|
||||
timer -= delta;
|
||||
}
|
||||
moveBy(rot.x*delta*rate, rot.y*delta*rate);
|
||||
for (int i = 0; i < shards.length; i++) {
|
||||
shards[i].setPosition(getX()+center.x-shards[i].getCenter().x, getY()+center.y-shards[i].getCenter().y);
|
||||
shards[i].setPosition(center.x-shards[i].getCenter().x, center.y-shards[i].getCenter().y);
|
||||
}
|
||||
|
||||
hitbox.setPosition(getX(), getY());
|
||||
|
||||
if (getX() > Main.GAME_AREA_WIDTH || getY() > Main.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) {
|
||||
timer = 0;
|
||||
}
|
||||
@ -69,9 +79,7 @@ public class Flake extends Entity implements Poolable {
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
batch.setColor(0.1f,0.1f,0.1f,1f - timer/totalTime);
|
||||
batch.draw(texture, getX(), getY(), getWidth(), getHeight());
|
||||
batch.setColor(Color.WHITE);
|
||||
sprite.setColor(0.1f,0.1f,0.1f,1f - timer/totalTime);
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
|
||||
@ -92,15 +100,15 @@ public class Flake extends Entity implements Poolable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entities getEntityType() {
|
||||
return Entities.FLAKE;
|
||||
public EntityIndex getEntityType() {
|
||||
return EntityIndex.FLAKE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDead() {
|
||||
if (timer <= 0) {
|
||||
for (int i = 0; i < shards.length; i++) {
|
||||
shards[i].setRate(45f);
|
||||
shards[i].setSpeed(45f);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
@ -110,14 +118,9 @@ public class Flake extends Entity implements Poolable {
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
rate = 0;
|
||||
timer = 0;
|
||||
shards = null;
|
||||
hitbox.set(0, 0, 0, 0);
|
||||
setPosition(0, 0);
|
||||
setSize(0, 0);
|
||||
center.set(0, 0);
|
||||
rot.set(0, 0);
|
||||
totalTime = 0;
|
||||
}
|
||||
|
||||
|
@ -1,42 +1,45 @@
|
||||
package zero1hd.polyjet.entity.enemies;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
|
||||
import zero1hd.polyjet.Main;
|
||||
import zero1hd.polyjet.entity.Entities;
|
||||
import zero1hd.polyjet.entity.EntityIndex;
|
||||
import zero1hd.polyjet.entity.Entity;
|
||||
|
||||
public class Pellet extends Entity implements Poolable {
|
||||
private boolean dead;
|
||||
private Texture texture;
|
||||
private Rectangle hitBox;
|
||||
private Vector2 direction;
|
||||
private float rate;
|
||||
|
||||
public Pellet(Texture texture) {
|
||||
hitBox = new Rectangle();
|
||||
direction = new Vector2();
|
||||
this.texture = texture;
|
||||
@Override
|
||||
public void preInit() {
|
||||
sprite.setTexture(assets.get("pellet.png", Texture.class));
|
||||
setSize(0.5f, 0.5f);
|
||||
super.preInit();
|
||||
}
|
||||
|
||||
public void init(float x, float y, float angle, float rate) {
|
||||
setPosition(x, y);
|
||||
direction.set(MathUtils.cosDeg(angle), MathUtils.sinDeg(angle));
|
||||
setSize(0.5f, 0.5f);
|
||||
hitBox.setSize(getWidth(), getHeight());
|
||||
this.rate = rate;
|
||||
this.speed = rate;
|
||||
this.angle = angle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Vars: x, y, speed, angle;
|
||||
*/
|
||||
@Override
|
||||
public void init(HashMap<String, Float> params) {
|
||||
setPosition(params.get("x"), params.get("y"));
|
||||
speed = params.get("speed");
|
||||
angle = params.get("angle");
|
||||
|
||||
super.init(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
moveBy(direction.x*delta*rate, direction.y*delta*rate);
|
||||
hitBox.setPosition(getX(), getY());
|
||||
super.act(delta);
|
||||
|
||||
if (getX() > Main.GAME_AREA_WIDTH || getY() > Main.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) {
|
||||
@ -44,14 +47,6 @@ public class Pellet extends Entity implements Poolable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
batch.setColor(getColor().r, getColor().g, getColor().b, getColor().a);
|
||||
batch.draw(texture, getX(), getY(), getWidth(), getHeight());
|
||||
batch.setColor(Color.WHITE);
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collided(Entity entity) {
|
||||
switch (entity.getEntityType()) {
|
||||
@ -62,13 +57,8 @@ public class Pellet extends Entity implements Poolable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle getHitZone() {
|
||||
return hitBox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entities getEntityType() {
|
||||
return Entities.PELLET;
|
||||
public EntityIndex getEntityType() {
|
||||
return EntityIndex.PELLET;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -78,13 +68,7 @@ public class Pellet extends Entity implements Poolable {
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
hitBox.set(0, 0, 0, 0);
|
||||
setSize(0, 0);
|
||||
setPosition(0, 0);
|
||||
direction.set(0,0);
|
||||
rate = 0;
|
||||
dead = false;
|
||||
setColor(1f, 1f, 1f, 1f);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,65 +1,63 @@
|
||||
package zero1hd.polyjet.entity.enemies;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
|
||||
import zero1hd.polyjet.Main;
|
||||
import zero1hd.polyjet.entity.Entities;
|
||||
import zero1hd.polyjet.entity.EntityIndex;
|
||||
import zero1hd.polyjet.entity.Entity;
|
||||
|
||||
public class Shard extends Entity implements Poolable {
|
||||
private Sprite sprite;
|
||||
private Rectangle hitbox;
|
||||
private Vector2 angle;
|
||||
private Vector2 center;
|
||||
public class Shard extends Entity {
|
||||
private int hp;
|
||||
private int maxHp;
|
||||
private float rate;
|
||||
|
||||
public Shard(Texture shardTexture) {
|
||||
hitbox = new Rectangle();
|
||||
angle = new Vector2();
|
||||
sprite = new Sprite(shardTexture);
|
||||
@Override
|
||||
public void preInit() {
|
||||
sprite = new Sprite(assets.get("shard.png", Texture.class));
|
||||
sprite.setSize(2f, 3f);
|
||||
center = new Vector2();
|
||||
simple = false;
|
||||
enemy = true;
|
||||
super.preInit();
|
||||
}
|
||||
|
||||
public void init(float x, float y, float angle, float rate, int hp) {
|
||||
this.rate = rate;
|
||||
speed = rate;
|
||||
this.hp = hp;
|
||||
maxHp = hp;
|
||||
this.angle.set(MathUtils.cosDeg(angle), MathUtils.sinDeg(angle));
|
||||
this.angle = angle;
|
||||
sprite.setRotation(angle+90);
|
||||
setSize(2f, 2f);
|
||||
setPosition(x-(getWidth()/2f), y-(getHeight()/2f));
|
||||
hitbox.setSize(getWidth(), getHeight());
|
||||
center.set(getWidth()/2f, getHeight()/2f);
|
||||
setPosition(x-center.x, y-center.y);
|
||||
sprite.setOrigin(sprite.getWidth()/2f, sprite.getHeight()/2f);
|
||||
sprite.setOriginCenter();
|
||||
}
|
||||
|
||||
/**
|
||||
* x, y, angle, rate, hp;
|
||||
*/
|
||||
@Override
|
||||
public void init(HashMap<String, Float> params) {
|
||||
setX(params.get("x"));
|
||||
setY(params.get("y"));
|
||||
angle = params.get("angle");
|
||||
speed = params.get("rate");
|
||||
hp = params.get("hp").intValue();
|
||||
super.init(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
hp = 0;
|
||||
maxHp = 0;
|
||||
setPosition(0, 0);
|
||||
angle.set(0, 0);
|
||||
center.set(0, 0);
|
||||
setSize(0, 0);
|
||||
hitbox.set(0, 0, 0, 0);
|
||||
setSize(0, 0);
|
||||
sprite.setRotation(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
moveBy(angle.x*delta*rate, angle.y*rate*delta);
|
||||
hitbox.setPosition(getX(), getY());
|
||||
|
||||
if (getX() > Main.GAME_AREA_WIDTH || getY() > Main.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) {
|
||||
hp = 0;
|
||||
@ -69,7 +67,6 @@ public class Shard extends Entity implements Poolable {
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
sprite.setCenter(getX()+center.x, getY()+center.y);
|
||||
sprite.setColor(((float)hp/(float)maxHp), ((float)hp/(float)maxHp), ((float)hp/(float)maxHp), 0.5f);
|
||||
sprite.draw(batch);
|
||||
batch.setColor(Color.WHITE);
|
||||
@ -93,8 +90,8 @@ public class Shard extends Entity implements Poolable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entities getEntityType() {
|
||||
return Entities.SHARD;
|
||||
public EntityIndex getEntityType() {
|
||||
return EntityIndex.SHARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -104,13 +101,4 @@ public class Shard extends Entity implements Poolable {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setRate(float rate) {
|
||||
this.rate = rate;
|
||||
}
|
||||
|
||||
public Vector2 getCenter() {
|
||||
return center;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,39 +1,33 @@
|
||||
package zero1hd.polyjet.entity.enemies;
|
||||
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.badlogic.gdx.audio.Sound;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
|
||||
import zero1hd.polyjet.entity.Entities;
|
||||
import zero1hd.polyjet.entity.EntityIndex;
|
||||
import zero1hd.polyjet.entity.Entity;
|
||||
|
||||
public class VoidCircle extends Entity implements Poolable {
|
||||
private float timer;
|
||||
private float endRadius;
|
||||
private float currentRadius;
|
||||
private Rectangle hitBox;
|
||||
private Sprite voidCircleTexture;
|
||||
private float growthRate;
|
||||
private boolean done;
|
||||
private boolean begin;
|
||||
private Vector2 center;
|
||||
private float maxTime;
|
||||
private Sound sound;
|
||||
private Preferences prefs;
|
||||
|
||||
public VoidCircle(Texture voidTexture, Sound sound, Preferences prefs) {
|
||||
hitBox = new Rectangle();
|
||||
center = new Vector2();
|
||||
this.sound = sound;
|
||||
this.prefs = prefs;
|
||||
|
||||
voidCircleTexture = new Sprite(voidTexture);
|
||||
|
||||
@Override
|
||||
public void preInit() {
|
||||
sprite.setTexture(assets.get("void_circle.png", Texture.class));
|
||||
simple = false;
|
||||
sound = assets.get("disintegrate.ogg", Sound.class);
|
||||
super.preInit();
|
||||
}
|
||||
|
||||
public void init(float endRadius, float x, float y, float growthRate, float warningTime) {
|
||||
@ -41,22 +35,35 @@ public class VoidCircle extends Entity implements Poolable {
|
||||
maxTime = warningTime;
|
||||
this.endRadius = endRadius;
|
||||
setSize(2f*endRadius, 2f*endRadius);
|
||||
center.set(getWidth()/2f, getHeight()/2f);
|
||||
setPosition(x-center.x, y-center.y);
|
||||
setPosition(x-getWidth()/2f, y-getHeight()/2f);
|
||||
this.growthRate = growthRate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* warningTime, endRadius, growthRate, x, y;
|
||||
*/
|
||||
@Override
|
||||
public void init(HashMap<String, Float> params) {
|
||||
timer = params.get("warningTime");
|
||||
maxTime = timer;
|
||||
endRadius = params.get("endRadius");
|
||||
setSize(2f*endRadius, 2f*endRadius);
|
||||
setPosition(params.get("x")-getWidth()/2f, params.get("y")-getHeight()/2f);
|
||||
growthRate = params.get("growthRate");
|
||||
super.init(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
toFront();
|
||||
if (begin) {
|
||||
voidCircleTexture.setSize(2*currentRadius, 2*currentRadius);
|
||||
voidCircleTexture.setColor(0f,0f,0f,1f);
|
||||
sprite.setSize(2*currentRadius, 2*currentRadius);
|
||||
sprite.setColor(0f,0f,0f,1f);
|
||||
} else {
|
||||
voidCircleTexture.setSize(2*endRadius, 2*endRadius);
|
||||
voidCircleTexture.setColor(1f,1f,1f,0.1f*(timer/maxTime));
|
||||
sprite.setSize(2*endRadius, 2*endRadius);
|
||||
sprite.setColor(1f,1f,1f,0.1f*(timer/maxTime));
|
||||
}
|
||||
hitBox.setCenter(getX()+center.x, getY()+center.y);
|
||||
|
||||
if (timer > 0) {
|
||||
timer -= delta;
|
||||
@ -73,21 +80,18 @@ public class VoidCircle extends Entity implements Poolable {
|
||||
}
|
||||
}
|
||||
}
|
||||
voidCircleTexture.setCenter(getX()+center.x, getY()+center.y);
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
voidCircleTexture.draw(batch);
|
||||
batch.setColor(Color.WHITE);
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
hitBox.set(0, 0, 0, 0);
|
||||
currentRadius = 0;
|
||||
growthRate = 0;
|
||||
timer = 0;
|
||||
@ -95,26 +99,18 @@ public class VoidCircle extends Entity implements Poolable {
|
||||
endRadius = 0;
|
||||
done = false;
|
||||
begin = false;
|
||||
center.set(0, 0);
|
||||
voidCircleTexture.setPosition(0, 0);
|
||||
setSize(0, 0);
|
||||
setPosition(0, 0);
|
||||
}
|
||||
|
||||
public void growCurrentRadius(float radius) {
|
||||
currentRadius += radius;
|
||||
float length = (float) Math.sqrt(2*(currentRadius*currentRadius));
|
||||
hitBox.setSize(length, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle getHitZone() {
|
||||
return hitBox;
|
||||
hitbox.setSize(length, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entities getEntityType() {
|
||||
return Entities.VOID_CIRCLE;
|
||||
public EntityIndex getEntityType() {
|
||||
return EntityIndex.VOID_CIRCLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,8 +17,9 @@ import zero1hd.polyjet.audio.map.GamePlayMap;
|
||||
import zero1hd.polyjet.audio.map.MapWindowData;
|
||||
import zero1hd.polyjet.controls.KeyMap;
|
||||
import zero1hd.polyjet.entity.CollisionDetector;
|
||||
import zero1hd.polyjet.entity.Entities;
|
||||
import zero1hd.polyjet.entity.Entity;
|
||||
import zero1hd.polyjet.entity.EntityController;
|
||||
import zero1hd.polyjet.entity.EntityIndex;
|
||||
import zero1hd.polyjet.entity.ally.Laser;
|
||||
import zero1hd.polyjet.entity.ally.PolyJetEntity;
|
||||
|
||||
@ -126,14 +127,15 @@ public class GamePlayArea extends Stage {
|
||||
EntitySpawnInfo[] currentSpawnInfo = mwd.getArray();
|
||||
if (currentSpawnInfo != null) {
|
||||
for (int i = 0; i < currentSpawnInfo.length; i++) {
|
||||
ec.spawnEntity(this, currentSpawnInfo[i]);
|
||||
Entity entity = ec.getIndex().get(currentSpawnInfo[i].getEntityType()).buildEntity();
|
||||
entity.init(currentSpawnInfo[i].parameters);
|
||||
addActor(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
collisionDetector.collisionCheck();
|
||||
ec.deathClean();
|
||||
|
||||
if (polyjet.getX() <= 1) {
|
||||
polyjet.moveLeft = false;
|
||||
@ -208,8 +210,8 @@ public class GamePlayArea extends Stage {
|
||||
}
|
||||
|
||||
if (keycode == KeyMap.shoot) {
|
||||
Laser laser = (Laser) ec.retrieveEntity(Entities.LASER);
|
||||
laser.init(polyjet.getX() + (polyjet.getWidth()-laser.getWidth())/2f, polyjet.getY() + polyjet.getHeight()+0.25f, 60f);
|
||||
Laser laser = (Laser) ec.getIndex().get(EntityIndex.LASER).buildEntity();
|
||||
laser.init(polyjet.getX() + polyjet.getWidth()/2f, polyjet.getY() + polyjet.getHeight()+1f, 60f);
|
||||
addActor(laser);
|
||||
}
|
||||
return false;
|
||||
|
@ -10,7 +10,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
||||
|
||||
import zero1hd.polyjet.entity.Entities;
|
||||
import zero1hd.polyjet.entity.EntityIndex;
|
||||
import zero1hd.polyjet.entity.Entity;
|
||||
import zero1hd.polyjet.entity.EntityController;
|
||||
import zero1hd.polyjet.entity.ally.Laser;
|
||||
@ -24,7 +24,7 @@ public class SpawnerWindow extends Window {
|
||||
private EntityController ec;
|
||||
private Stage stage;
|
||||
|
||||
private List<Entities> listOfEntities;
|
||||
private List<EntityIndex> listOfEntities;
|
||||
private ScrollPane scroller;
|
||||
|
||||
private Slider mod1;
|
||||
@ -43,7 +43,7 @@ public class SpawnerWindow extends Window {
|
||||
mod4 = new Slider(1f, 12f, 0.01f, true, skin);
|
||||
|
||||
listOfEntities = new List<>(skin);
|
||||
listOfEntities.setItems(Entities.values());
|
||||
listOfEntities.setItems(EntityIndex.values());
|
||||
|
||||
scroller = new ScrollPane(listOfEntities);
|
||||
add(scroller).expandY().fillY().spaceRight(15f);
|
||||
@ -67,7 +67,7 @@ public class SpawnerWindow extends Window {
|
||||
stage.screenToStageCoordinates(coords);
|
||||
|
||||
Entity entity;
|
||||
if ((entity = ec.retrieveEntity(listOfEntities.getSelected())) != null) {
|
||||
if ((entity = ec.getIndex().get(listOfEntities.getSelected()).buildEntity()) != null) {
|
||||
switch(entity.getEntityType()) {
|
||||
case LASER:
|
||||
Laser laser = (Laser) entity;
|
||||
@ -96,8 +96,8 @@ public class SpawnerWindow extends Window {
|
||||
break;
|
||||
case FLAKE:
|
||||
Flake flake = (Flake) entity;
|
||||
stage.addActor(flake);
|
||||
flake.init(coords.x, coords.y, mod1.getValue(), mod3.getValue(), mod2.getValue()/mod2.getMaxValue()*360f, (int) mod4.getValue());
|
||||
stage.addActor(flake);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
|
||||
public class WavDecoder {
|
||||
|
Loading…
Reference in New Issue
Block a user