new framework for entities progress and began working on map part

This commit is contained in:
Harrison Deng 2017-07-28 14:11:55 -05:00
parent 66e82c0efe
commit 5ec04f0f27
35 changed files with 98 additions and 70 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 629 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 572 B

After

Width:  |  Height:  |  Size: 535 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 616 KiB

After

Width:  |  Height:  |  Size: 616 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 783 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 696 B

After

Width:  |  Height:  |  Size: 634 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 799 KiB

After

Width:  |  Height:  |  Size: 799 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 735 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 666 B

After

Width:  |  Height:  |  Size: 609 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 754 KiB

After

Width:  |  Height:  |  Size: 754 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 900 B

After

Width:  |  Height:  |  Size: 851 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 300 B

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 383 B

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 366 KiB

After

Width:  |  Height:  |  Size: 366 KiB

View File

@ -68,10 +68,10 @@ public class GamePlayMap {
* @return the object.
*/
public EntitySpawnInfo nextEntitySpawnInfo(EntityIndex entityType) {
EntitySpawnInfo esi = new EntitySpawnInfo(entityType);
if (spawnList.get(index) == null) {
spawnList.set(index, new MapWindowData());
}
EntitySpawnInfo esi = new EntitySpawnInfo(entityType);
spawnList.get(index).addEntity(esi);
return esi;
}
@ -81,7 +81,8 @@ public class GamePlayMap {
*/
public void nextWindow() {
if (building) {
index++;
spawnList.add(new MapWindowData());
resetIndex();
}
}
@ -117,7 +118,7 @@ public class GamePlayMap {
*/
public void addNullToMap() {
if (building) {
spawnList.set(index, null);
spawnList.add(null);
}
}
public MapWindowData nextWindowData() {

View File

@ -13,8 +13,8 @@ import com.badlogic.gdx.utils.Array;
import zero1hd.polyjet.Main;
public class CollisionDetector {
Array<Entity> firstGroup;
Array<Entity> secondGroup;
Array<Entity> enemies;
Array<Entity> allies;
AssetManager assets;
Preferences prefs;
@ -23,9 +23,9 @@ public class CollisionDetector {
Array<PooledEffect> effects = new Array<>();
Sound explosionSFX;
public CollisionDetector(Array<Entity> firstGroup, Array<Entity> secondGroup, AssetManager assetManager, Preferences prefs) {
this.firstGroup = firstGroup;
this.secondGroup = secondGroup;
public CollisionDetector(Array<Entity> enemies, Array<Entity> allies, AssetManager assetManager, Preferences prefs) {
this.enemies = enemies;
this.allies = allies;
assets = assetManager;
this.prefs = prefs;
@ -34,28 +34,28 @@ public class CollisionDetector {
}
public void collisionCheck() {
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 ((enemies.size != 0) && (allies.size != 0)) {
for (int f = 0; f < enemies.size; f++) {
Entity enemy = enemies.get(f);
for (int s = 0; s < allies.size; s++) {
Entity ally = allies.get(s);
if (fe.getHitZone().overlaps(se.getHitZone())) {
Gdx.app.debug("Collision Detector", "Collision between entities: " + fe.getEntityType() + " and " + se.getEntityType());
if (enemy.getHitZone().overlaps(ally.getHitZone())) {
Gdx.app.debug("Collision Detector", "Collision between entities: " + enemy.getEntityType() + " and " + ally.getEntityType());
//Play FX;
if (se.playCollideSFX() && fe.playCollideSFX()) {
explosionSFX.play(prefs.getFloat("fx vol"), 1f, (fe.getX()/Main.GAME_AREA_WIDTH)-0.55f);
if (ally.playCollideSFX() && enemy.playCollideSFX()) {
explosionSFX.play(prefs.getFloat("fx vol"), 1f, (enemy.getX()/Main.GAME_AREA_WIDTH)-0.55f);
}
if (se.playCollidePFX() && fe.playCollidePFX()) {
if (ally.playCollidePFX() && enemy.playCollidePFX()) {
PooledEffect currentPFX;
currentPFX = explosionEffectPool.obtain();
currentPFX.setPosition(fe.getX() + fe.getWidth()/2f, fe.getY() + fe.getHeight()/2f);
currentPFX.setPosition(enemy.getX() + enemy.getWidth()/2f, enemy.getY() + enemy.getHeight()/2f);
effects.add(currentPFX);
}
fe.collided(se);
se.collided(fe);
enemy.collided(ally);
ally.collided(enemy);
break;
}
}

View File

@ -23,6 +23,7 @@ public class Entity extends Actor implements Poolable {
protected boolean enemy;
protected boolean simple = true;
protected boolean nonStnrd = false;
protected boolean move = true;
protected Rectangle hitbox;
protected Sprite sprite;
@ -30,10 +31,11 @@ public class Entity extends Actor implements Poolable {
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;
@ -43,14 +45,12 @@ public class Entity extends Actor implements Poolable {
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?");
sprite.setOriginCenter();
}
public void init(HashMap<String, Float> params) {
@ -90,9 +90,11 @@ public class Entity extends Actor implements Poolable {
@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 (move) {
move(delta, false);
}
if (simple) {
sprite.setPosition(getX(), getY());
hitbox.setPosition(getX(), getY());
@ -101,6 +103,7 @@ public class Entity extends Actor implements Poolable {
} else {
sprite.setCenter(center.x, center.y);
hitbox.setCenter(center);
sprite.setOriginCenter();
sprite.setRotation(angle);
}
@ -110,7 +113,6 @@ public class Entity extends Actor implements Poolable {
ef.recycleEntity(this);
}
}
}
@Override
@ -129,14 +131,32 @@ public class Entity extends Actor implements Poolable {
public boolean playCollideSFX() {
return true;
}
public void move(float delta, boolean update) {
rotRatios.set(MathUtils.cosDeg(angle), MathUtils.sinDeg(angle));
moveBy(rotRatios.x*speed*delta, rotRatios.y*speed*delta);
center.set(getX() + getWidth()/2f, getY() + getHeight()/2f);
if (update) {
if (simple) {
sprite.setPosition(getX(), getY());
hitbox.setPosition(getX(), getY());
} else {
sprite.setCenter(center.x, center.y);
hitbox.setCenter(center);
sprite.setOriginCenter();
sprite.setRotation(angle);
}
}
}
@Override
public void reset() {
rotRatios.set(0, 0);
hitbox.set(0, 0, 0, 0);
sprite.setBounds(0, 0, 0, 0);
sprite.setPosition(0, 0);
sprite.setRotation(0);
sprite.setOrigin(0, 0);
setPosition(0, 0);
center.set(0, 0);
angle = 0;

View File

@ -44,13 +44,13 @@ public class EntityController {
}
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.VOID_CIRCLE, (voidCircle = new EntityFrame<>(this, VoidCircle.class)));
index.put(EntityIndex.PELLET, pellet = new EntityFrame<>(this, Pellet.class));
index.put(EntityIndex.SHARD, shard = new EntityFrame<>(this, Shard.class));
index.put(EntityIndex.BAR, bar = new EntityFrame<>(this, Bar.class));
index.put(EntityIndex.FLAKE, flake = new EntityFrame<>(this, Flake.class));
index.put(EntityIndex.LASER, new EntityFrame<>(this, Laser.class));
index.put(EntityIndex.LASER, laser = new EntityFrame<>(this, Laser.class));
}
public HashMap<EntityIndex, EntityFrame<? extends Entity>> getIndex() {

View File

@ -5,6 +5,7 @@ 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.graphics.g2d.Sprite;
import zero1hd.polyjet.Main;
import zero1hd.polyjet.entity.EntityIndex;
@ -16,7 +17,7 @@ public class Laser extends Entity {
@Override
public void preInit() {
sprite.setTexture(assets.get("laser.png", Texture.class));
sprite = new Sprite(assets.get("laser.png", Texture.class));
sfx = assets.get("laser.ogg", Sound.class);
setSize(0.25f, 2f);
super.preInit();
@ -46,11 +47,10 @@ public class Laser extends Entity {
@Override
public void act(float delta) {
toBack();
super.act(delta);
if (getY() > Main.GAME_AREA_HEIGHT) {
dead = true;
}
super.act(delta);
}
@Override
@ -61,6 +61,7 @@ public class Laser extends Entity {
@Override
public void reset() {
dead = false;
super.reset();
}
@Override

View File

@ -16,7 +16,6 @@ public class PolyJetEntity extends Entity {
private ParticleEffect thrust;
private Texture polyjet;
private ParticleEffect teleportCloak;
private Rectangle hitbox;
public boolean moveLeft, moveRight, moveUp, moveDown, teleporting, accelerate;
private float speed, accel;
@ -97,4 +96,8 @@ public class PolyJetEntity extends Entity {
return false;
}
}
public Rectangle getHitbox() {
return hitbox;
}
}

View File

@ -3,6 +3,7 @@ package zero1hd.polyjet.entity.enemies;
import java.util.HashMap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Rectangle;
import zero1hd.polyjet.Main;
@ -15,7 +16,7 @@ public class Bar extends Entity {
@Override
public void preInit() {
setSize(8f, 0.5f);
sprite.setTexture(assets.get("bar.png", Texture.class));
sprite = new Sprite(assets.get("bar.png", Texture.class));
enemy = true;
super.preInit();
}
@ -46,6 +47,7 @@ public class Bar extends Entity {
@Override
public void reset() {
dead = false;
super.reset();
}
@Override

View File

@ -4,24 +4,24 @@ import java.util.HashMap;
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 zero1hd.polyjet.Main;
import zero1hd.polyjet.entity.EntityIndex;
import zero1hd.polyjet.entity.Entity;
import zero1hd.polyjet.entity.EntityController;
public class Flake extends Entity {
private float timer;
private float totalTime;
private Shard[] shards;
private EntityController ec;
@Override
public void preInit() {
sprite.setTexture(assets.get("flake.png", Texture.class));
sprite = new Sprite(assets.get("flake.png", Texture.class));
simple = true;
enemy = true;
move = false;
setSize(3f, 3f);
super.preInit();
}
@ -33,13 +33,13 @@ public class Flake extends Entity {
shards[i].init(x, y, 360/shards.length*i, 0, 2);
ec.getStage().addActor(shards[i]);
}
setSize(3f, 3f);
this.speed = rate;
this.timer = fuse;
this.totalTime = fuse;
this.angle = angle;
hitbox.setSize(getWidth(), getHeight());
setPosition(x-center.x, y-center.y);
setPosition(x-getWidth()/2f, y-getHeight()/2f);
}
/**
@ -67,19 +67,27 @@ public class Flake extends Entity {
if (timer > 0) {
timer -= delta;
}
move(delta, false);
System.out.println("---Start----");
System.out.println("Flake: " + center);
for (int i = 0; i < shards.length; i++) {
shards[i].setPosition(center.x-shards[i].getCenter().x, center.y-shards[i].getCenter().y);
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() > Main.GAME_AREA_WIDTH || getY() > Main.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) {
timer = 0;
}
super.act(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
sprite.setColor(0.1f,0.1f,0.1f,1f - timer/totalTime);
sprite.setColor(0.1f,0.1f,0.1f, timer/totalTime);
super.draw(batch, parentAlpha);
}
@ -122,6 +130,7 @@ public class Flake extends Entity {
shards = null;
hitbox.set(0, 0, 0, 0);
totalTime = 0;
super.reset();
}
}

View File

@ -3,6 +3,7 @@ package zero1hd.polyjet.entity.enemies;
import java.util.HashMap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.utils.Pool.Poolable;
import zero1hd.polyjet.Main;
@ -14,7 +15,7 @@ public class Pellet extends Entity implements Poolable {
@Override
public void preInit() {
sprite.setTexture(assets.get("pellet.png", Texture.class));
sprite = new Sprite(assets.get("pellet.png", Texture.class));
setSize(0.5f, 0.5f);
super.preInit();
}
@ -54,6 +55,7 @@ public class Pellet extends Entity implements Poolable {
dead = true;
break;
}
super.collided(entity);
}
@Override
@ -69,6 +71,7 @@ public class Pellet extends Entity implements Poolable {
@Override
public void reset() {
dead = false;
super.reset();
}
}

View File

@ -2,7 +2,6 @@ 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;
@ -19,7 +18,8 @@ public class Shard extends Entity {
@Override
public void preInit() {
sprite = new Sprite(assets.get("shard.png", Texture.class));
sprite.setSize(2f, 3f);
setSize(2f, 2f);
sprite.setSize(3f, 2f);
simple = false;
enemy = true;
super.preInit();
@ -30,11 +30,9 @@ public class Shard extends Entity {
this.hp = hp;
maxHp = hp;
this.angle = angle;
sprite.setRotation(angle+90);
setSize(2f, 2f);
setPosition(x-(getWidth()/2f), y-(getHeight()/2f));
hitbox.setSize(getWidth(), getHeight());
sprite.setOriginCenter();
}
/**
@ -58,7 +56,6 @@ public class Shard extends Entity {
@Override
public void act(float delta) {
if (getX() > Main.GAME_AREA_WIDTH || getY() > Main.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) {
hp = 0;
}
@ -68,8 +65,6 @@ public class Shard extends Entity {
@Override
public void draw(Batch batch, float parentAlpha) {
sprite.setColor(((float)hp/(float)maxHp), ((float)hp/(float)maxHp), ((float)hp/(float)maxHp), 0.5f);
sprite.draw(batch);
batch.setColor(Color.WHITE);
super.draw(batch, parentAlpha);
}

View File

@ -3,15 +3,13 @@ package zero1hd.polyjet.entity.enemies;
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.utils.Pool.Poolable;
import com.badlogic.gdx.graphics.g2d.Sprite;
import zero1hd.polyjet.entity.EntityIndex;
import zero1hd.polyjet.entity.Entity;
public class VoidCircle extends Entity implements Poolable {
public class VoidCircle extends Entity {
private float timer;
private float endRadius;
private float currentRadius;
@ -24,8 +22,9 @@ public class VoidCircle extends Entity implements Poolable {
@Override
public void preInit() {
sprite.setTexture(assets.get("void_circle.png", Texture.class));
sprite = new Sprite(assets.get("void_circle.png", Texture.class));
simple = false;
enemy = true;
sound = assets.get("disintegrate.ogg", Sound.class);
super.preInit();
}
@ -84,12 +83,6 @@ public class VoidCircle extends Entity implements Poolable {
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.setColor(Color.WHITE);
super.draw(batch, parentAlpha);
}
@Override
public void reset() {
currentRadius = 0;
@ -100,6 +93,7 @@ public class VoidCircle extends Entity implements Poolable {
done = false;
begin = false;
setSize(0, 0);
super.reset();
}
public void growCurrentRadius(float radius) {

View File

@ -48,7 +48,7 @@ public class GamePlayArea extends Stage {
polyjet = new PolyJetEntity(assetManager, 25f, 25f, "standard");
ec = new EntityController(assetManager, prefs, this);
collisionDetector = new CollisionDetector(ec.activeAllies, ec.activeEnemies, assetManager, prefs);
collisionDetector = new CollisionDetector(ec.activeEnemies, ec.activeAllies, assetManager, prefs);
ec.activeAllies.add(polyjet);
addActor(polyjet);
}