successfully added debug spawning system and finished void circle enemy

This commit is contained in:
Harrison Deng 2017-05-31 23:55:44 -05:00
parent 70bf120a5f
commit b17cc61839
14 changed files with 152 additions and 113 deletions

View File

@ -154,6 +154,13 @@ default-slider-knob
orig: 9, 18
offset: 0, 0
index: -1
vertical-slider-knob
rotate: false
xy: 27, 1
size: 13, 5
orig: 13, 5
offset: 0, 0
index: -1
default-splitpane
rotate: false
xy: 17, 1

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -194,6 +194,10 @@ public class Polyjet extends Game {
SliderStyle defaultSlider = new SliderStyle(getDefaultSkin().getDrawable("default-slider"), getDefaultSkin().getDrawable("default-slider-knob"));
getDefaultSkin().add("default-horizontal", defaultSlider);
SliderStyle vertSlider = new SliderStyle(defaultSlider);
vertSlider.knob = getDefaultSkin().getDrawable("vertical-slider-knob");
getDefaultSkin().add("default-vertical", vertSlider);
ButtonStyle infoButton = new ButtonStyle();
infoButton.up = getDefaultSkin().getDrawable("holo-pane");
infoButton.down = getDefaultSkin().getDrawable("holo-pane-down");
@ -207,6 +211,10 @@ public class Polyjet extends Game {
TextFieldStyle defaultTextField = new TextFieldStyle(getDefaultSkin().getFont("sub-font"), getDefaultSkin().getColor("default"), getDefaultSkin().getDrawable("cursor"), getDefaultSkin().getDrawable("selection"), getDefaultSkin().getDrawable("textfield"));
getDefaultSkin().add("default", defaultTextField);
TextFieldStyle uiTextField = new TextFieldStyle(defaultTextField);
uiTextField.font = getDefaultSkin().getFont("window-font");
getDefaultSkin().add("ui", uiTextField);
WindowStyle defaultWindow = new WindowStyle(getDefaultSkin().getFont("window-font"), getDefaultSkin().getColor("default"), getDefaultSkin().getDrawable("default-window"));
getDefaultSkin().add("default", defaultWindow);
@ -215,7 +223,7 @@ public class Polyjet extends Game {
tintedWindow.background = getDefaultSkin().getDrawable("tinted-window");
getDefaultSkin().add("tinted", tintedWindow);
ListStyle defaultList = new ListStyle(getDefaultSkin().getFont("sub-font"), getDefaultSkin().getColor("inverse"), getDefaultSkin().getColor("default"), getDefaultSkin().getDrawable("selection"));
ListStyle defaultList = new ListStyle(getDefaultSkin().getFont("window-font"), getDefaultSkin().getColor("inverse"), getDefaultSkin().getColor("default"), getDefaultSkin().getDrawable("selection"));
getDefaultSkin().add("default", defaultList);
ScrollPaneStyle defaultScrollPane = new ScrollPaneStyle();

View File

@ -7,25 +7,24 @@ public class CollisionDetector {
Array<Entity> firstGroup;
Array<Entity> secondGroup;
private boolean debug = true;
public CollisionDetector(Array<Entity> firstGroup, Array<Entity> secondGroup) {
this.firstGroup = firstGroup;
this.secondGroup = secondGroup;
}
public void collisionCheck() {
if (debug) {
Gdx.app.debug("collision check", "First group size: " + firstGroup.size);
Gdx.app.debug("collision check", "Second group size: " + secondGroup.size);
}
if ((firstGroup.size != 0) && (secondGroup.size != 0)) {
for (int f = 0; f < firstGroup.size; f++) {
Entity fe = firstGroup.get(f);
for (int s = 0; s < secondGroup.size; s++) {
Entity se = secondGroup.get(s);
if (fe.getHitZone().overlaps(se.getHitZone())) {
Gdx.app.debug("Collision Detector", "Collision between entities: " + fe.getEntityType() + " and " + se.getEntityType());
for (int firstEID = 0; firstEID < firstGroup.size; firstEID++) {
for (int secondEID = 0; secondEID < secondGroup.size; secondEID++) {
if (firstGroup.get(firstEID).getHitZone().overlaps(secondGroup.get(secondEID).getHitZone())) {
firstGroup.get(firstEID).collided(secondGroup.get(secondEID));
secondGroup.get(secondEID).collided(firstGroup.get(firstEID));
fe.collided(se);
se.collided(fe);
}
}
}
}

View File

@ -14,21 +14,23 @@ public class EntityController {
AssetManager assets;
ShapeRenderer shapes;
public final Array<Entity> ACTIVE_ALLIES;
public final Array<Entity> ACTIVE_ENEMIES;
public Array<Entity> activeAllies;
public Array<Entity> activeEnemies;
//Enemy pool declaration;
private final Pool<VoidCircle> VOID_CIRCLE_POOL;
private Pool<VoidCircle> voidCirclePool;
//Ally pool declaration;
private final Pool<Laser> LASER_POOL;
public EntityController(ShapeRenderer shapeRenderer, AssetManager assetManager) {
ACTIVE_ALLIES = new Array<Entity>();
ACTIVE_ENEMIES = new Array<Entity>();
private Pool<Laser> laserPool;
public EntityController(AssetManager assetManager, ShapeRenderer shapeRenderer) {
activeAllies = new Array<Entity>();
activeEnemies = new Array<Entity>();
this.assets = assetManager;
this.shapes = shapeRenderer;
shapes.setAutoShapeType(true);
//Enemy pool initialization;
VOID_CIRCLE_POOL = new Pool<VoidCircle>() {
voidCirclePool = new Pool<VoidCircle>() {
@Override
protected VoidCircle newObject() {
return new VoidCircle(shapes);
@ -36,7 +38,7 @@ public class EntityController {
};
//Ally pool initialization;
LASER_POOL = new Pool<Laser>() {
laserPool = new Pool<Laser>() {
@Override
protected Laser newObject() {
return new Laser(assets.get("laser.png", Texture.class));
@ -46,19 +48,18 @@ public class EntityController {
}
public Entity retrieveEntity(Entities entity) {
Gdx.app.debug("EntityController", "spawning entity " + entity.name());
switch (entity) {
case VOID_CIRCLE:
VoidCircle voidCircle = VOID_CIRCLE_POOL.obtain();
ACTIVE_ENEMIES.add(voidCircle);
VoidCircle voidCircle = voidCirclePool.obtain();
activeEnemies.add(voidCircle);
return voidCircle;
case BAR_BEAT:
return null;
case SHARDS:
return null;
case LASER:
Laser laser = LASER_POOL.obtain();
ACTIVE_ALLIES.add(laser);
Laser laser = laserPool.obtain();
activeAllies.add(laser);
return laser;
default:
return null;
@ -74,14 +75,14 @@ public class EntityController {
case VOID_CIRCLE:
VoidCircle voidCircle = (VoidCircle) entity;
voidCircle.remove();
ACTIVE_ENEMIES.removeValue(entity, true);
VOID_CIRCLE_POOL.free(voidCircle);
activeEnemies.removeValue(entity, true);
voidCirclePool.free(voidCircle);
break;
case LASER:
Laser laser = (Laser) entity;
laser.remove();
ACTIVE_ALLIES.removeValue(entity, true);
LASER_POOL.free(laser);
activeAllies.removeValue(entity, true);
laserPool.free(laser);
break;
default:
break;

View File

@ -1,5 +1,6 @@
package zero1hd.polyjet.entity.ally;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Rectangle;
@ -18,13 +19,15 @@ public class Laser extends Actor implements Entity, Poolable {
public Laser(Texture laserTexture) {
this.laserTexture = laserTexture;
setSize(0.25f, 1f);
}
public void init(float x, float y, float rate) {
Gdx.app.debug("Laser", "Pos: " + x + "," + y);
setX(x);
setY(y);
this.rate = rate;
setSize(0.25f, 1f);
hitBox = new Rectangle();
hitBox.setSize(getWidth(), getHeight());
}
@ -51,7 +54,6 @@ public class Laser extends Actor implements Entity, Poolable {
public void reset() {
setX(0);
setY(0);
setSize(0, 0);
rate = 0;
hitBox.set(0, 0, 0, 0);
dead = false;

View File

@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
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;
@ -13,6 +14,7 @@ import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;
public class VoidCircle extends Actor implements Entity, Poolable {
private float warnTime;
private float timer;
private float endRadius;
private float currentRadius;
@ -21,24 +23,29 @@ public class VoidCircle extends Actor implements Entity, Poolable {
private float growthRate;
private boolean done;
private boolean begin;
private Vector2 center;
public VoidCircle(ShapeRenderer shapeRenderer) {
hitBox = new Rectangle();
this.shapeRenderer = shapeRenderer;
center = new Vector2();
}
public void init(float endRadius, float x, float y, float growthRate, float warningTime) {
Gdx.app.debug("Void Circle", "Initiated.");
timer = warningTime;
warnTime = warningTime;
this.endRadius = endRadius;
setSize(2*endRadius, 2*endRadius);
setX(x);
setY(y);
setSize(2f*endRadius, 2f*endRadius);
setX(x - getWidth()/2f);
setY(y - getWidth()/2f);
this.growthRate = growthRate;
}
@Override
public void act(float delta) {
hitBox.setPosition(getX(), getY());
center.x = getX()+getWidth()/2f;
center.y = getY()+getHeight()/2f;
hitBox.setCenter(center.x, center.y);
if (timer > 0) {
timer -= delta;
} else {
@ -57,6 +64,7 @@ public VoidCircle(ShapeRenderer shapeRenderer) {
super.act(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.end();
@ -64,11 +72,12 @@ public VoidCircle(ShapeRenderer shapeRenderer) {
if (begin) {
shapeRenderer.set(ShapeType.Filled);
shapeRenderer.setColor(Color.BLACK);
shapeRenderer.circle(getX(), getY(), currentRadius);
}
shapeRenderer.circle(center.x, center.y, currentRadius, 48);
} else {
shapeRenderer.set(ShapeType.Line);
shapeRenderer.setColor(Color.RED);
shapeRenderer.circle(getX(), getY(), endRadius);
shapeRenderer.setColor(1 - timer/warnTime, 1 - timer/warnTime, 1 - timer/warnTime, 1f);
shapeRenderer.circle(center.x, center.y, endRadius, 48);
}
shapeRenderer.end();
batch.begin();
@ -85,18 +94,15 @@ public VoidCircle(ShapeRenderer shapeRenderer) {
endRadius = 0;
done = false;
begin = false;
warnTime = 0;
center.set(0, 0);
setSize(0, 0);
}
public void setCurrentRadius(float currentRadius) {
this.currentRadius = currentRadius;
hitBox.setSize(2*(currentRadius*currentRadius));
hitBox.setCenter(getX(), getY());
}
public void growCurrentRadius(float currentRadius) {
this.currentRadius += currentRadius;
hitBox.setSize(2*(currentRadius*currentRadius));
hitBox.setCenter(getX(), getY());
public void growCurrentRadius(float radius) {
currentRadius += radius;
float length = (float) Math.sqrt(2*(currentRadius*currentRadius));
hitBox.setSize(length, length);
}
@Override

View File

@ -4,7 +4,6 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.ui.stages.CreativeStage;
@ -15,15 +14,10 @@ public class CreativeDebugScreen extends ScreenAdapter {
GamePlayArea gamePlayArea;
InputMultiplexer inputs;
ShapeRenderer shapes;
public CreativeDebugScreen(Polyjet core, MainMenu mainMenu) {
gamePlayArea = new GamePlayArea(core.getAssetManager(), shapes);
gamePlayArea = new GamePlayArea(core.getAssetManager());
creative = new CreativeStage(core, mainMenu, gamePlayArea);
shapes = new ShapeRenderer();
shapes.setAutoShapeType(true);
inputs = new InputMultiplexer(creative, gamePlayArea);
}
@ -37,6 +31,7 @@ public class CreativeDebugScreen extends ScreenAdapter {
public void render(float delta) {
Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glLineWidth(1f);
gamePlayArea.getViewport().apply();
gamePlayArea.act();
@ -55,7 +50,6 @@ public class CreativeDebugScreen extends ScreenAdapter {
@Override
public void dispose() {
shapes.dispose();
super.dispose();
}
}

View File

@ -7,7 +7,6 @@ import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
@ -38,11 +37,8 @@ public class GameScreen extends ScreenAdapter implements InputProcessor {
private AudioData music;
private ShapeRenderer shapeRenderer;
public GameScreen(Polyjet polyJet) {
core = polyJet;
shapeRenderer = new ShapeRenderer();
// Overlay stuff
overlay = new Stage();
@ -101,7 +97,7 @@ public class GameScreen extends ScreenAdapter implements InputProcessor {
(Gdx.graphics.getHeight() - pauseMenu.getHeight()) / 2);
// Continue to add things to input multiplexer
gameArea = new GamePlayArea(polyJet.getAssetManager(), shapeRenderer);
gameArea = new GamePlayArea(polyJet.getAssetManager());
inputs = new InputMultiplexer();
inputs.addProcessor(this);
@ -123,6 +119,7 @@ public class GameScreen extends ScreenAdapter implements InputProcessor {
public void render(float delta) {
Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glLineWidth(1f);
gameArea.getViewport().apply();
gameArea.draw();

View File

@ -56,7 +56,6 @@ public class CreativeStage extends Stage implements MiniListener {
@Override
public void changed(ChangeEvent event, Actor actor) {
dispose();
musicSelector.getSelectedMusic().reset();
core.setScreen(mainMenu);
}
});
@ -200,7 +199,9 @@ public class CreativeStage extends Stage implements MiniListener {
@Override
public void dispose() {
if (musicSelector.getSelectedMusic() != null) {
musicSelector.getSelectedMusic().dispose();
}
super.dispose();
}

View File

@ -10,7 +10,6 @@ import zero1hd.polyjet.Polyjet;
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.ally.Laser;
import zero1hd.polyjet.entity.ally.PolyJetEntity;
@ -19,6 +18,8 @@ import zero1hd.polyjet.entity.ally.PolyJetEntity;
public class GamePlayArea extends Stage {
public PolyJetEntity polyjet;
public ShapeRenderer shapes;
public EntityController entityController;
private CollisionDetector collisionDetector;
@ -27,13 +28,15 @@ public class GamePlayArea extends Stage {
private int score;
Texture basicLaserTexture;
public GamePlayArea(AssetManager assetManager, ShapeRenderer shapeRenderer) {
public GamePlayArea(AssetManager assetManager) {
super(new FitViewport(Polyjet.GAME_AREA_WIDTH, Polyjet.GAME_AREA_HEIGHT));
polyjet = new PolyJetEntity(assetManager, 48f, "standard");
entityController = new EntityController(shapeRenderer, assetManager);
collisionDetector = new CollisionDetector(entityController.ACTIVE_ALLIES, entityController.ACTIVE_ENEMIES);
shapes = new ShapeRenderer();
shapes.setProjectionMatrix(getCamera().combined);
entityController = new EntityController(assetManager, shapes);
collisionDetector = new CollisionDetector(entityController.activeAllies, entityController.activeEnemies);
addActor(polyjet);
}
@ -41,17 +44,15 @@ public class GamePlayArea extends Stage {
public void act(float delta) {
collisionDetector.collisionCheck();
while (entityController.ACTIVE_ALLIES.iterator().hasNext()) {
Entity entity = entityController.ACTIVE_ALLIES.iterator().next();
if (entity.isDead()) {
entityController.free(entity);
for (int i = 0; i < entityController.activeAllies.size; i ++) {
if (entityController.activeAllies.get(i).isDead()) {
entityController.free(entityController.activeAllies.get(i));
}
}
while (entityController.ACTIVE_ENEMIES.iterator().hasNext()) {
Entity entity = entityController.ACTIVE_ENEMIES.iterator().next();
if (entity.isDead()) {
entityController.free(entity);
for (int i = 0; i < entityController.activeEnemies.size; i++) {
if (entityController.activeEnemies.get(i).isDead()) {
entityController.free(entityController.activeEnemies.get(i));
}
}
@ -120,7 +121,7 @@ public class GamePlayArea extends Stage {
}
if (keycode == KeyMap.shoot) {
Laser laser = (Laser) entityController.retrieveEntity(Entities.LASER);
laser.init(polyjet.getX() + (polyjet.getWidth()-laser.getWidth())/2, polyjet.getY() + polyjet.getHeight()+0.25f, 30f);
laser.init(polyjet.getX() + (polyjet.getWidth()-laser.getWidth())/2f, polyjet.getY() + polyjet.getHeight()+0.25f, 30f);
addActor(laser);
}
return false;

View File

@ -80,7 +80,7 @@ public class MusicController extends Window {
add(fastForward);
info = new TextField(null, skin) {
info = new TextField(null, skin, "ui") {
@Override
public void act(float delta) {
if (audiofile != null && audiofile.getPlaybackMusic().isPlaying()) {

View File

@ -87,6 +87,10 @@ public class MusicSelector extends Window {
}
public AudioData getSelectedMusic() {
if (selectedMusic != null) {
return Audio.getAudioData(selectedMusic);
} else {
return null;
}
}
}

View File

@ -1,9 +1,13 @@
package zero1hd.polyjet.ui.windows;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.List;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import zero1hd.polyjet.entity.Entities;
@ -13,52 +17,67 @@ import zero1hd.polyjet.entity.ally.Laser;
import zero1hd.polyjet.entity.enemies.VoidCircle;
public class SpawnerWindow extends Window {
private TextField spawnName;
private TextField modifier;
private EntityController ec;
private Stage stage;
private List<Entities> listOfEntities;
private ScrollPane scroller;
private Slider mod1;
private Slider mod2;
private Slider mod3;
public SpawnerWindow(String title, Skin skin, EntityController ec, Stage stageForEntities) {
super(title, skin);
spawnName = new TextField("", skin);
modifier = new TextField("0;0;0", skin);
add(spawnName, modifier);
this.ec = ec;
stage = stageForEntities;
setWidth(spawnName.getWidth()+modifier.getWidth()+30f);
setHeight(spawnName.getHeight()+35f);
mod1 = new Slider(0.1f, 50f, 0.01f, true, skin);
mod2 = new Slider(0.1f, 15f, 0.01f, true, skin);
mod3 = new Slider(0.1f, 15f, 0.01f, true, skin);
listOfEntities = new List<>(skin);
listOfEntities.setItems(Entities.values());
scroller = new ScrollPane(listOfEntities);
add(scroller).expandY().fillY().spaceRight(15f);
add(mod1, mod2, mod3);
setSize(300f, 375f);
}
@Override
public boolean remove() {
spawnName.setText("");
return super.remove();
}
private Vector2 coords = new Vector2();
@Override
public void act(float delta) {
if (Gdx.input.isTouched() && !spawnName.getText().isEmpty()) {
Entity entity = ec.retrieveEntity(Entities.valueOf(spawnName.getText()));
if (Gdx.input.justTouched() && Gdx.input.isKeyPressed(Keys.SHIFT_LEFT)) {
coords.set(Gdx.input.getX(), Gdx.input.getY());
stage.screenToStageCoordinates(coords);
Entity entity;
if ((entity = ec.retrieveEntity(listOfEntities.getSelected())) != null) {
switch(entity.getEntityType()) {
case BAR_BEAT:
break;
case LASER:
Laser laser = (Laser) entity;
laser.init(Gdx.input.getX(), Gdx.input.getY(), Float.valueOf(modifier.getText().split(";")[0]));
laser.init(coords.x, coords.y, mod1.getValue());
stage.addActor(laser);
break;
case SHARDS:
break;
case VOID_CIRCLE:
VoidCircle voidCircle = (VoidCircle) entity;
voidCircle.init(Float.valueOf(modifier.getText().split(";")[0]), Gdx.input.getX(), Gdx.input.getY(), Float.valueOf(modifier.getText().split(";")[1]), Float.valueOf(modifier.getText().split(";")[2]));
voidCircle.init(mod3.getValue(), coords.x, coords.y, mod1.getValue(), mod2.getValue());
stage.addActor(voidCircle);
break;
default:
break;
}
}
}
super.act(delta);