began work on flake entity

This commit is contained in:
Harrison Deng 2017-06-03 23:26:03 -05:00
parent 53ff7109b2
commit b80aca0e29
23 changed files with 149 additions and 16 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 109 B

After

Width:  |  Height:  |  Size: 113 B

BIN
android/assets/1280x720/flake.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 116 B

After

Width:  |  Height:  |  Size: 117 B

BIN
android/assets/1280x800/flake.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 111 B

After

Width:  |  Height:  |  Size: 116 B

BIN
android/assets/1366x768/flake.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 131 B

After

Width:  |  Height:  |  Size: 132 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 135 B

After

Width:  |  Height:  |  Size: 135 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 B

After

Width:  |  Height:  |  Size: 143 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 234 B

After

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 547 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 B

After

Width:  |  Height:  |  Size: 97 B

BIN
android/assets/800x480/flake.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 B

View File

@ -127,6 +127,7 @@ public class Polyjet extends Game {
assetManager.load("pellet.png", Texture.class);
assetManager.load("shard.png", Texture.class);
assetManager.load("bar.png", Texture.class);
assetManager.load("flake.png", Texture.class);
}
public void generateFonts() {
initComplete = true;

View File

@ -1,7 +1,7 @@
package zero1hd.polyjet.entity;
public enum Entities {
POLYJET, BAR, VOID_CIRCLE, SHARD, LASER, PELLET;
POLYJET, BAR, VOID_CIRCLE, SHARD, LASER, PELLET, FLAKE;
public float x;
public float y;

View File

@ -8,6 +8,7 @@ import com.badlogic.gdx.utils.Pool;
import zero1hd.polyjet.entity.ally.Laser;
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;
@ -24,9 +25,11 @@ public class EntityController {
private Pool<Pellet> pelletPool;
private Pool<Shard> shardPool;
private Pool<Bar> barPool;
private Pool<Flake> flakePool;
//Ally pool declaration;
private Pool<Laser> laserPool;
public EntityController(AssetManager assetManager, ShapeRenderer shapeRenderer) {
activeAllies = new Array<Entity>();
activeEnemies = new Array<Entity>();
@ -60,6 +63,12 @@ public class EntityController {
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));
}
};
//Ally pool initialization;
laserPool = new Pool<Laser>() {
@ -93,42 +102,47 @@ public class EntityController {
Bar bar = barPool.obtain();
activeEnemies.add(bar);
return bar;
case FLAKE:
Flake flake = flakePool.obtain();
activeEnemies.add(flake);
return flake;
default:
return null;
}
}
public void free(Entity entity) {
activeEnemies.removeValue(entity, true);
switch (entity.getEntityType()) {
case VOID_CIRCLE:
VoidCircle voidCircle = (VoidCircle) entity;
voidCircle.remove();
activeEnemies.removeValue(entity, true);
voidCirclePool.free(voidCircle);
break;
case LASER:
Laser laser = (Laser) entity;
laser.remove();
activeAllies.removeValue(entity, true);
laserPool.free(laser);
break;
case PELLET:
Pellet pellet = (Pellet) entity;
pellet.remove();
activeEnemies.removeValue(entity, true);
pelletPool.free(pellet);
break;
case SHARD:
Shard shard = (Shard) entity;
shard.remove();
activeEnemies.removeValue(entity, true);
shardPool.free(shard);
break;
case BAR:
Bar bar = (Bar) entity;
bar.remove();
activeEnemies.removeValue(entity, true);
barPool.free(bar);
break;
case FLAKE:
Flake flake = (Flake) entity;
flake.remove();
flakePool.free(flake);
default:
break;
}

View File

@ -0,0 +1,94 @@
package zero1hd.polyjet.entity.enemies;
import com.badlogic.gdx.graphics.Texture;
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;
import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;
public class Flake extends Actor implements Poolable, Entity {
private Texture texture;
private float rate;
private float timer;
private Shard[] shards;
private Rectangle hitbox;
private Vector2 center;
private Vector2 rot;
public Flake(Texture texture) {
this.texture = texture;
hitbox = new Rectangle();
center = new Vector2();
rot = new Vector2();
}
public void init(float x, float y, float rate, float fuse, float angle, Shard... shards) {
this.shards = shards;
setPosition(x, y);
setSize(1f, 1f);
this.rate = rate;
this.timer = fuse;
hitbox.setSize(getWidth(), getHeight());
center.set(getWidth()/2f, getHeight()/2f);
rot.set(MathUtils.sinDeg(angle), MathUtils.cosDeg(angle));
}
@Override
public void act(float delta) {
moveBy(rot.x*delta*rate, rot.y*delta*rate);
if (timer > 0) {
timer -= delta;
}
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);
}
hitbox.setPosition(getX(), getY());
super.act(delta);
}
@Override
public void collided(Entity entity) {
}
@Override
public Rectangle getHitZone() {
return hitbox;
}
@Override
public Entities getEntityType() {
return Entities.FLAKE;
}
@Override
public boolean isDead() {
if (timer <= 0) {
for (int i = 0; i < shards.length; i++) {
shards[i].setRate(40f);
}
return true;
} else {
return false;
}
}
@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);
}
}

View File

@ -40,7 +40,7 @@ public class Shard extends Actor implements Entity, Poolable {
setSize(2f, 2f);
hitbox.setSize(getWidth(), getHeight());
center.set(getWidth()/2f, getHeight()/2f);
setPosition(x-center.x, y-center.y);
setPosition(x, y);
sprite.setOrigin(sprite.getWidth()/2f, sprite.getHeight()/2f);
}
@ -106,5 +106,18 @@ public class Shard extends Actor implements Entity, Poolable {
}
return false;
}
public void setRate(float rate) {
this.rate = rate;
}
@Override
public void setPosition(float x, float y) {
super.setPosition(x-center.x, y-center.y);
}
public Vector2 getCenter() {
return center;
}
}

View File

@ -35,18 +35,15 @@ public VoidCircle(ShapeRenderer shapeRenderer) {
warnTime = warningTime;
this.endRadius = endRadius;
setSize(2f*endRadius, 2f*endRadius);
setX(x - getWidth()/2f);
setY(y - getWidth()/2f);
center.set(getWidth()/2f, getHeight()/2f);
setPosition(x-center.x, y-center.y);
this.growthRate = growthRate;
}
@Override
public void act(float delta) {
toFront();
center.x = getX()+getWidth()/2f;
center.y = getY()+getHeight()/2f;
hitBox.setCenter(center.x, center.y);
hitBox.setCenter(getX()+center.x, getY()+center.y);
if (timer > 0) {
timer -= delta;
@ -74,11 +71,11 @@ public VoidCircle(ShapeRenderer shapeRenderer) {
if (begin) {
shapeRenderer.set(ShapeType.Filled);
shapeRenderer.setColor(Color.BLACK);
shapeRenderer.circle(center.x, center.y, currentRadius, 48);
shapeRenderer.circle(getX()+center.x, getY()+center.y, currentRadius, 48);
} else {
shapeRenderer.set(ShapeType.Line);
shapeRenderer.setColor(1 - timer/warnTime, 1 - timer/warnTime, 1 - timer/warnTime, 1f);
shapeRenderer.circle(center.x, center.y, endRadius, 48);
shapeRenderer.circle(getX()+center.x, getY()+center.y, endRadius, 48);
}
shapeRenderer.end();
batch.begin();

View File

@ -15,6 +15,7 @@ import zero1hd.polyjet.entity.Entity;
import zero1hd.polyjet.entity.EntityController;
import zero1hd.polyjet.entity.ally.Laser;
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;
@ -29,6 +30,8 @@ public class SpawnerWindow extends Window {
private Slider mod1;
private Slider mod2;
private Slider mod3;
private Slider mod4;
public SpawnerWindow(String title, Skin skin, EntityController ec, Stage stageForEntities) {
super(title, skin);
this.ec = ec;
@ -37,13 +40,15 @@ public class SpawnerWindow extends Window {
mod1 = new Slider(0.1f, 50f, 0.01f, true, skin);
mod2 = new Slider(0f, 15f, 0.01f, true, skin);
mod3 = new Slider(0.1f, 15f, 0.01f, true, skin);
mod4 = new Slider(1f, 8f, 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);
add(mod1, mod2, mod3, mod4);
setSize(300f, 375f);
}
@ -89,6 +94,15 @@ public class SpawnerWindow extends Window {
bar.init(coords.x, mod1.getValue());
stage.addActor(bar);
break;
case FLAKE:
Shard[] shards = new Shard[(int) mod4.getValue()];
for (int i = 0; i < shards.length; i++) {
shards[i].init(coords.x, coords.y, 360f/shards.length*i, 0f, (int) mod3.getValue());
stage.addActor(shards[i]);
}
Flake flake = (Flake) entity;
flake.init(coords.x, coords.y, mod1.getValue(), mod3.getValue(), mod2.getValue()/mod2.getMaxValue()*360f, shards);
default:
break;
}