began work adding pellet entity

This commit is contained in:
2017-06-01 17:59:05 -05:00
parent 4e818e2752
commit 529031fd07
69 changed files with 105 additions and 10 deletions

View File

@@ -124,6 +124,7 @@ public class Polyjet extends Game {
assetManager.load("pop_open.ogg", Sound.class);
assetManager.load("pop_close.ogg", Sound.class);
assetManager.load("laser.png", Texture.class);
assetManager.load("pellet.png", Texture.class);
}
public void generateFonts() {
initComplete = true;

View File

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

View File

@@ -7,6 +7,7 @@ import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool;
import zero1hd.polyjet.entity.ally.Laser;
import zero1hd.polyjet.entity.enemies.Pellet;
import zero1hd.polyjet.entity.enemies.VoidCircle;
public class EntityController {
@@ -17,6 +18,7 @@ public class EntityController {
public Array<Entity> activeEnemies;
//Enemy pool declaration;
private Pool<VoidCircle> voidCirclePool;
private Pool<Pellet> pelletPool;
//Ally pool declaration;
private Pool<Laser> laserPool;
@@ -35,6 +37,12 @@ public class EntityController {
return new VoidCircle(shapes);
}
};
pelletPool = new Pool<Pellet>() {
@Override
protected Pellet newObject() {
return new Pellet(assets.get("pellet.png", Texture.class));
}
};
//Ally pool initialization;
laserPool = new Pool<Laser>() {
@@ -52,14 +60,14 @@ public class EntityController {
VoidCircle voidCircle = voidCirclePool.obtain();
activeEnemies.add(voidCircle);
return voidCircle;
case BAR_BEAT:
return null;
case SHARDS:
return null;
case LASER:
Laser laser = laserPool.obtain();
activeAllies.add(laser);
return laser;
case PELLET:
Pellet pellet = pelletPool.obtain();
activeEnemies.add(pellet);
return pellet;
default:
return null;
}
@@ -67,10 +75,6 @@ public class EntityController {
public void free(Entity entity) {
switch (entity.getEntityType()) {
case BAR_BEAT:
break;
case SHARDS:
break;
case VOID_CIRCLE:
VoidCircle voidCircle = (VoidCircle) entity;
voidCircle.remove();
@@ -83,6 +87,11 @@ public class EntityController {
activeAllies.removeValue(entity, true);
laserPool.free(laser);
break;
case PELLET:
Pellet pellet = (Pellet) entity;
pellet.remove();
activeEnemies.removeValue(entity, true);
pelletPool.free(pellet);
default:
break;
}

View File

@@ -0,0 +1,81 @@
package zero1hd.polyjet.entity.enemies;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
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.Polyjet;
import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;
public class Pellet extends Actor implements Entity, 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;
}
public void init(float x, float y, float direction, float rate) {
setPosition(x, y);
this.direction.setAngle(direction);
rate = 0;
setSize(0.5f, 0.5f);
}
@Override
public void act(float delta) {
moveBy(direction.x*delta*rate, direction.y*delta*rate);
super.act(delta);
if (getX() > Polyjet.GAME_AREA_WIDTH || getY() > Polyjet.GAME_AREA_HEIGHT || getX()-getWidth() < 0 || getY()-getHeight() < 0) {
dead = true;
}
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(texture, getX(), getY(), getWidth(), getHeight());
super.draw(batch, parentAlpha);
}
@Override
public void collided(Entity entity) {
if (entity.getEntityType() == Entities.VOID_CIRCLE) {
dead = true;
}
}
@Override
public Rectangle getHitZone() {
return hitBox;
}
@Override
public Entities getEntityType() {
return Entities.PELLET;
}
@Override
public boolean isDead() {
return dead;
}
@Override
public void reset() {
hitBox.set(0, 0, 0, 0);
setSize(0, 0);
setPosition(0, 0);
direction.set(0,0);
rate = 0;
}
}

View File

@@ -14,6 +14,7 @@ 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.enemies.Pellet;
import zero1hd.polyjet.entity.enemies.VoidCircle;
public class SpawnerWindow extends Window {
@@ -68,7 +69,10 @@ public class SpawnerWindow extends Window {
laser.init(coords.x, coords.y, mod1.getValue());
stage.addActor(laser);
break;
case SHARDS:
case PELLET:
Pellet pellet = (Pellet) entity;
pellet.init(coords.x, coords.y, mod2.getValue(), mod3.getValue());
stage.addActor(pellet);
break;
case VOID_CIRCLE:
VoidCircle voidCircle = (VoidCircle) entity;