entity coordinator integration works
This commit is contained in:
parent
a72bd104f0
commit
cfe5e3592b
@ -13,6 +13,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
|
||||
import zero1hd.rhythmbullet.RhythmBullet;
|
||||
import zero1hd.rhythmbullet.entity.coordinator.Coordinator;
|
||||
|
||||
public class Entity extends Actor implements Poolable {
|
||||
@ -58,6 +59,7 @@ public class Entity extends Actor implements Poolable {
|
||||
}
|
||||
|
||||
public void init(HashMap<String, Float> params) {
|
||||
params.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,13 +90,18 @@ public class Entity extends Actor implements Poolable {
|
||||
* @return if this entity is dead or not.
|
||||
*/
|
||||
public boolean isDead() {
|
||||
if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
if (!nonStnrd) {
|
||||
coordinator.coordinate(delta);
|
||||
if (coordinator != null) {
|
||||
coordinator.coordinate(delta);
|
||||
}
|
||||
|
||||
if (move) {
|
||||
move(delta, true);
|
||||
@ -104,6 +111,9 @@ public class Entity extends Actor implements Poolable {
|
||||
}
|
||||
}
|
||||
|
||||
if (angle >= 360f) {
|
||||
angle -= 360f;
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
@ -150,8 +160,10 @@ public class Entity extends Actor implements Poolable {
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
coordinator.clean();
|
||||
coordinator = null;
|
||||
if (coordinator != null) {
|
||||
coordinator.clean();
|
||||
coordinator = null;
|
||||
}
|
||||
rotRatios.set(0, 0);
|
||||
sprite.setPosition(0, 0);
|
||||
hitbox.set(0, 0, 0, 0);
|
||||
@ -180,5 +192,6 @@ public class Entity extends Actor implements Poolable {
|
||||
|
||||
public void setCoordinator(Coordinator coordinator) {
|
||||
this.coordinator = coordinator;
|
||||
coordinator.setEntity(this);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ public class EntityFrame<T extends Entity> {
|
||||
private EntityManager ec;
|
||||
Class<T> ct;
|
||||
EntityFrame<T> ef;
|
||||
public EntityFrame(EntityManager entityController) {
|
||||
public EntityFrame(EntityManager entityController, Class<T> classType) {
|
||||
this.ct = classType;
|
||||
ef = this;
|
||||
ec = entityController;
|
||||
pool = new Pool<T>() {
|
||||
@ -52,4 +53,9 @@ public class EntityFrame<T extends Entity> {
|
||||
entity.remove();
|
||||
pool.free(ct.cast(entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ct.getSimpleName();
|
||||
}
|
||||
}
|
||||
|
@ -39,12 +39,12 @@ public class EntityManager {
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
voidCircle = new EntityFrame<>(this);
|
||||
pellet = new EntityFrame<>(this);
|
||||
shard = new EntityFrame<>(this);
|
||||
bar = new EntityFrame<>(this);
|
||||
flake = new EntityFrame<>(this);
|
||||
laser = new EntityFrame<>(this);
|
||||
voidCircle = new EntityFrame<>(this, VoidCircle.class);
|
||||
pellet = new EntityFrame<>(this, Pellet.class);
|
||||
shard = new EntityFrame<>(this, Shard.class);
|
||||
bar = new EntityFrame<>(this, Bar.class);
|
||||
flake = new EntityFrame<>(this, Flake.class);
|
||||
laser = new EntityFrame<>(this, Laser.class);
|
||||
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,10 @@ public class Coordinator implements Poolable {
|
||||
cf.recycleCoordinator(this);
|
||||
}
|
||||
|
||||
public void setEntity(Entity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
entity = null;
|
||||
|
@ -9,8 +9,9 @@ public class CoordinatorFrame<T extends Coordinator> {
|
||||
private EntityManager em;
|
||||
CoordinatorFrame<T> cf;
|
||||
Class<T> coordinatorType;
|
||||
public CoordinatorFrame(EntityManager entityManager) {
|
||||
public CoordinatorFrame(EntityManager entityManager, Class<T> classtype) {
|
||||
this.em = entityManager;
|
||||
coordinatorType = classtype;
|
||||
cf = this;
|
||||
pool = new Pool<T>() {
|
||||
@Override
|
||||
@ -35,5 +36,9 @@ public class CoordinatorFrame<T extends Coordinator> {
|
||||
protected void recycleCoordinator(Coordinator coordinator) {
|
||||
pool.free(coordinatorType.cast(coordinator));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return coordinatorType.getSimpleName();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
package zero1hd.rhythmbullet.entity.coordinator;
|
||||
|
||||
public enum CoordinatorIndex {
|
||||
SLOW_RIGHT, SLOW_LEFT;
|
||||
}
|
@ -14,7 +14,7 @@ public class CoordinatorManager {
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
slowLeft = new CoordinatorFrame<>(em);
|
||||
slowRight = new CoordinatorFrame<>(em);
|
||||
slowLeft = new CoordinatorFrame<>(em, SlowLeftCoordinator.class);
|
||||
slowRight = new CoordinatorFrame<>(em, SlowRightCoordinator.class);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package zero1hd.rhythmbullet.entity.coordinator;
|
||||
public class SlowLeftCoordinator extends Coordinator {
|
||||
@Override
|
||||
public void coordinate(float delta) {
|
||||
entity.angle -= 8*delta;
|
||||
entity.angle -= 32*delta;
|
||||
super.coordinate(delta);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package zero1hd.rhythmbullet.entity.coordinator;
|
||||
public class SlowRightCoordinator extends Coordinator {
|
||||
@Override
|
||||
public void coordinate(float delta) {
|
||||
entity.angle += 8*delta;
|
||||
entity.angle += 32*delta;
|
||||
super.coordinate(delta);
|
||||
}
|
||||
}
|
||||
|
@ -39,9 +39,6 @@ public class Bar extends Entity {
|
||||
public void act(float delta) {
|
||||
hitbox.setPosition(getX(), getY());
|
||||
super.act(delta);
|
||||
if (getY() < 0-getHeight()) {
|
||||
dead = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,14 +68,10 @@ public class Flake extends Entity {
|
||||
timer -= delta;
|
||||
}
|
||||
|
||||
move(delta, false);
|
||||
System.out.println("---Start----");
|
||||
System.out.println("Flake: " + center);
|
||||
move(delta, true);
|
||||
for (int i = 0; i < shards.length; i++) {
|
||||
shards[i].setPosition(center.x-shards[i].getWidth()/2f, center.y-shards[i].getWidth()/2f);
|
||||
shards[i].move(delta, true);
|
||||
System.out.println("Shard " + i + ": " + shards[i].getCenter());
|
||||
System.out.println("Sprite Pos: " + shards[i].getHitZone());
|
||||
}
|
||||
|
||||
if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) {
|
||||
|
@ -43,10 +43,6 @@ public class Pellet extends Entity implements Poolable {
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
super.act(delta);
|
||||
|
||||
if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) {
|
||||
dead = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +56,7 @@ public class CreativeHUD extends Stage implements MiniListener {
|
||||
bassUMgraphWindow = new BassUMGraphWindow("Bass/UM Peak Values", core.getDefaultSkin());
|
||||
mGraphWindow = new MGraphWindow("Midrange Peak Values", core.getDefaultSkin());
|
||||
volumeWindow = new VolumeWindow("Volume adjustments", core.getDefaultSkin(), core.getPrefs());
|
||||
spawnerWindow = new SpawnerWindow("Spawn Tool", core.getDefaultSkin(), gpa.em, gpa);
|
||||
spawnerWindow = new SpawnerWindow("Spawn Tool", core.getDefaultSkin(), gpa.em, gpa.cm, gpa);
|
||||
diffWindow = new DifficultyWindow(core.getDefaultSkin());
|
||||
|
||||
//Back button
|
||||
|
@ -1,5 +1,7 @@
|
||||
package zero1hd.rhythmbullet.ui.windows;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
@ -9,10 +11,16 @@ import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
|
||||
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 com.badlogic.gdx.utils.Array;
|
||||
|
||||
import zero1hd.rhythmbullet.entity.EntityManager;
|
||||
import zero1hd.rhythmbullet.entity.Entity;
|
||||
import zero1hd.rhythmbullet.entity.EntityFrame;
|
||||
import zero1hd.rhythmbullet.entity.EntityIndex;
|
||||
import zero1hd.rhythmbullet.entity.EntityManager;
|
||||
import zero1hd.rhythmbullet.entity.ally.Laser;
|
||||
import zero1hd.rhythmbullet.entity.coordinator.Coordinator;
|
||||
import zero1hd.rhythmbullet.entity.coordinator.CoordinatorFrame;
|
||||
import zero1hd.rhythmbullet.entity.coordinator.CoordinatorManager;
|
||||
import zero1hd.rhythmbullet.entity.enemies.Bar;
|
||||
import zero1hd.rhythmbullet.entity.enemies.Flake;
|
||||
import zero1hd.rhythmbullet.entity.enemies.Pellet;
|
||||
@ -23,17 +31,24 @@ public class SpawnerWindow extends Window {
|
||||
private EntityManager ec;
|
||||
private Stage stage;
|
||||
|
||||
private List<EntityIndex> listOfEntities;
|
||||
private ScrollPane scroller;
|
||||
private HashMap<String, Float> params = new HashMap<>();
|
||||
|
||||
private Array<EntityFrame<? extends Entity>> entityFrames = new Array<>();
|
||||
private List<EntityFrame<? extends Entity>> listOfEntities;
|
||||
private ScrollPane entityListScroller;
|
||||
|
||||
private Array<CoordinatorFrame<? extends Coordinator>> coordinatorFrames = new Array<>();
|
||||
private List<CoordinatorFrame<? extends Coordinator>> listOfCoordinators;
|
||||
private ScrollPane coordinatorListScroller;
|
||||
|
||||
private Slider mod1;
|
||||
private Slider mod2;
|
||||
private Slider mod3;
|
||||
private Slider mod4;
|
||||
|
||||
public SpawnerWindow(String title, Skin skin, EntityManager ec, Stage stageForEntities) {
|
||||
public SpawnerWindow(String title, Skin skin, EntityManager em, CoordinatorManager cm, Stage stageForEntities) {
|
||||
super(title, skin, "tinted");
|
||||
this.ec = ec;
|
||||
this.ec = em;
|
||||
stage = stageForEntities;
|
||||
|
||||
mod1 = new Slider(0.1f, 50f, 0.01f, true, skin);
|
||||
@ -42,14 +57,29 @@ public class SpawnerWindow extends Window {
|
||||
mod4 = new Slider(1f, 12f, 0.01f, true, skin);
|
||||
|
||||
listOfEntities = new List<>(skin);
|
||||
listOfEntities.setItems(EntityIndex.values());
|
||||
entityFrames.add(em.bar);
|
||||
entityFrames.add(em.flake);
|
||||
entityFrames.add(em.laser);
|
||||
entityFrames.add(em.pellet);
|
||||
entityFrames.add(em.shard);
|
||||
entityFrames.add(em.voidCircle);
|
||||
|
||||
scroller = new ScrollPane(listOfEntities);
|
||||
add(scroller).expandY().fillY().spaceRight(15f);
|
||||
listOfEntities.setItems(entityFrames);
|
||||
entityListScroller = new ScrollPane(listOfEntities, skin);
|
||||
add(entityListScroller).height(350f).width(200f);
|
||||
|
||||
|
||||
listOfCoordinators = new List<>(skin);
|
||||
coordinatorFrames.add(cm.slowLeft);
|
||||
coordinatorFrames.add(cm.slowRight);
|
||||
|
||||
listOfCoordinators.setItems(coordinatorFrames);
|
||||
coordinatorListScroller = new ScrollPane(listOfCoordinators, skin);
|
||||
add(coordinatorListScroller).height(350f).width(200f);
|
||||
|
||||
add(mod1, mod2, mod3, mod4);
|
||||
|
||||
setSize(300f, 375f);
|
||||
pack();
|
||||
}
|
||||
|
||||
|
||||
@ -65,40 +95,33 @@ public class SpawnerWindow extends Window {
|
||||
coords.set(Gdx.input.getX(), Gdx.input.getY());
|
||||
stage.screenToStageCoordinates(coords);
|
||||
|
||||
|
||||
switch(listOfEntities.getSelected()) {
|
||||
case LASER:
|
||||
Laser laser = ec.laser.buildEntity();
|
||||
laser.init(coords.x, coords.y, mod1.getValue());
|
||||
stage.addActor(laser);
|
||||
break;
|
||||
case PELLET:
|
||||
Pellet pellet = ec.pellet.buildEntity();
|
||||
pellet.init(coords.x, coords.y, mod2.getValue()/mod2.getMaxValue()*360f, mod1.getValue());
|
||||
stage.addActor(pellet);
|
||||
break;
|
||||
case VOID_CIRCLE:
|
||||
VoidCircle voidCircle = ec.voidCircle.buildEntity();
|
||||
voidCircle.init(mod2.getValue(), coords.x, coords.y, mod1.getValue(), mod3.getValue());
|
||||
stage.addActor(voidCircle);
|
||||
break;
|
||||
case SHARD:
|
||||
Shard shard = ec.shard.buildEntity();
|
||||
shard.init(coords.x, coords.y, mod2.getValue()/mod2.getMaxValue()*360f, mod1.getValue(), (int) mod3.getValue());
|
||||
stage.addActor(shard);
|
||||
break;
|
||||
case BAR:
|
||||
Bar bar = ec.bar.buildEntity();
|
||||
bar.init(coords.x, mod1.getValue());
|
||||
stage.addActor(bar);
|
||||
break;
|
||||
case FLAKE:
|
||||
Flake flake = ec.flake.buildEntity();
|
||||
flake.init(coords.x, coords.y, mod1.getValue(), mod3.getValue(), mod2.getValue()/mod2.getMaxValue()*360f, (int) mod4.getValue());
|
||||
stage.addActor(flake);
|
||||
default:
|
||||
break;
|
||||
Entity entity = listOfEntities.getSelected().buildEntity();
|
||||
|
||||
if (Gdx.input.isKeyPressed(Keys.ALT_LEFT)) {
|
||||
entity.setCoordinator(listOfCoordinators.getSelected().buildCoordinator());
|
||||
}
|
||||
|
||||
if (entity.getClass() == Laser.class) {
|
||||
Laser laser = (Laser) entity;
|
||||
laser.init(coords.x, coords.y, mod1.getValue());
|
||||
} else if (entity.getClass() == Pellet.class) {
|
||||
Pellet pellet = (Pellet) entity;
|
||||
pellet.init(coords.x, coords.y, mod2.getValue()/mod2.getMaxValue()*360f, mod1.getValue());
|
||||
} else if (entity.getClass() == VoidCircle.class) {
|
||||
VoidCircle voidCircle = (VoidCircle) entity;
|
||||
voidCircle.init(mod2.getValue(), coords.x, coords.y, mod1.getValue(), mod3.getValue());
|
||||
} else if (entity.getClass() == Shard.class) {
|
||||
Shard shard = (Shard) entity;
|
||||
shard.init(coords.x, coords.y, mod2.getValue()/mod2.getMaxValue()*360f, mod1.getValue(), (int) mod3.getValue());
|
||||
} else if (entity.getClass() == Bar.class) {
|
||||
Bar bar = (Bar) entity;
|
||||
bar.init(coords.x, mod1.getValue());
|
||||
} else if (entity.getClass() == Flake.class) {
|
||||
Flake flake = (Flake) entity;
|
||||
flake.init(coords.x, coords.y, mod1.getValue(), mod3.getValue(), mod2.getValue()/mod2.getMaxValue()*360f, (int) mod4.getValue());
|
||||
}
|
||||
|
||||
stage.addActor(entity);
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user