began working on game screen; changing entity system; clean up assets

This commit is contained in:
2018-02-04 21:16:36 -06:00
parent 1fbdefaecd
commit 7f51ca2c55
43 changed files with 102 additions and 78 deletions

View File

@@ -38,11 +38,13 @@ import zero1hd.rhythmbullet.util.AdvancedResizeScreen;
public class RhythmBullet extends Game {
public static final int WORLD_WIDTH = 64;
public static final int WORLD_HEIGHT = 48;
public static final int SPAWN_CIRCLE_RADIUS = 4;
public static float pixels_per_unit;
private boolean initComplete = false;
private boolean resizing;
private int screenWidth, screenHeight;
public static final int GAME_AREA_WIDTH = 64;
public static final int GAME_AREA_HEIGHT = 48;
public static final String VERSION = "(0.1)R1-PreAlpha";
private AssetManager assetManager = new AssetManager();
@@ -165,6 +167,9 @@ public class RhythmBullet extends Game {
if (width != screenWidth || height != screenHeight) {
screenWidth = Gdx.graphics.getWidth();
screenHeight = Gdx.graphics.getHeight();
pixels_per_unit = screenHeight/WORLD_HEIGHT;
if (initComplete) {
Gdx.app.debug("Resize", "Pre-transition is happening. Using resolution " + width + "x" + height);
rRHandler.setResolution(width, height);
@@ -238,7 +243,7 @@ public class RhythmBullet extends Game {
assetManager.load("beateffect.p", ParticleEffect.class);
assetManager.load("tpSelector.png", Texture.class);
assetManager.load("magic1.png", Texture.class);
assetManager.load("RhythmBulletBG.png", Texture.class);
assetManager.load("backgrounds/mainBG.png", Texture.class);
}
public void generateFonts(final int height) {

View File

@@ -4,8 +4,6 @@ import java.security.InvalidParameterException;
import com.badlogic.gdx.utils.FloatArray;
import zero1hd.rhythmbullet.util.MusicManager;
public class AudioDataPackage {
private FloatArray bassPeaks;
private FloatArray mPeaks;

View File

@@ -1,5 +1,5 @@
package zero1hd.rhythmbullet.util;
package zero1hd.rhythmbullet.audio;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Music.OnCompletionListener;

View File

@@ -5,7 +5,7 @@ import java.util.concurrent.Executors;
import com.badlogic.gdx.utils.Disposable;
import zero1hd.rhythmbullet.util.MusicManager;
import zero1hd.rhythmbullet.audio.MusicManager;
public class AudioAnalyzer implements Disposable {
private ExecutorService exec;

View File

@@ -4,7 +4,7 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.FloatArray;
import zero1hd.rhythmbullet.audio.AudioDataPackage;
import zero1hd.rhythmbullet.util.MusicManager;
import zero1hd.rhythmbullet.audio.MusicManager;
public class PeakDetectionRunnable implements Runnable {
boolean work = true, done;

View File

@@ -3,7 +3,7 @@ package zero1hd.rhythmbullet.audio.analyzer;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.FloatArray;
import zero1hd.rhythmbullet.util.MusicManager;
import zero1hd.rhythmbullet.audio.MusicManager;
public class PruneFluxRunnable implements Runnable {
boolean work = true;

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.FloatArray;
import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D;
import zero1hd.rhythmbullet.util.MusicManager;
import zero1hd.rhythmbullet.audio.MusicManager;
public class SpectralFluxAnalysisRunnable implements Runnable {
boolean work = true;

View File

@@ -3,7 +3,7 @@ package zero1hd.rhythmbullet.audio.analyzer;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.FloatArray;
import zero1hd.rhythmbullet.util.MusicManager;
import zero1hd.rhythmbullet.audio.MusicManager;
public class ThresholdCalcRunnable implements Runnable {
boolean work = true;

View File

@@ -11,7 +11,7 @@ import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import zero1hd.rhythmbullet.util.MusicManager;
import zero1hd.rhythmbullet.audio.MusicManager;
public class BasicVisualizer extends VisualizerCore {
private Pixmap pixmap;

View File

@@ -6,7 +6,7 @@ import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.utils.Disposable;
import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D;
import zero1hd.rhythmbullet.util.MusicManager;
import zero1hd.rhythmbullet.audio.MusicManager;
public class VisualizerCore implements Disposable {
protected MusicManager mm;

View File

@@ -1,5 +1,7 @@
package zero1hd.rhythmbullet.entity;
import java.security.InvalidParameterException;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Color;
@@ -22,7 +24,6 @@ public class Entity implements Poolable {
protected EntityManager ec;
protected boolean enemy;
protected boolean nonStnrd = false;
protected boolean move = true;
protected boolean dead;
@@ -62,7 +63,14 @@ public class Entity implements Poolable {
}
public void init(float deg, float speed, int hp) {
rotRatios.set(MathUtils.cosDeg(angle), MathUtils.sinDeg(angle));
sprite.setSize(sprite.getTexture().getWidth()/RhythmBullet.pixels_per_unit, sprite.getTexture().getHeight()/RhythmBullet.pixels_per_unit);
float r = RhythmBullet.SPAWN_CIRCLE_RADIUS - sprite.getWidth();
if (r < RhythmBullet.SPAWN_CIRCLE_RADIUS -1) {
throw new InvalidParameterException("Entity is too big! Calculated final distance from center: " + r);
}
sprite.setPosition(r*rotRatios.x, r*rotRatios.y);
updatePosition();
}
/**
@@ -85,21 +93,19 @@ public class Entity implements Poolable {
}
public void calculate(float delta) {
if (!nonStnrd) {
if (coordinator != null) {
coordinator.coordinate(delta);
}
if (dead) {
ef.recycleEntity(this);
}
if (coordinator != null) {
coordinator.coordinate(delta);
}
if (dead) {
ef.recycleEntity(this);
}
if (angle >= 360f) {
angle -= 360f;
}
if (sprite.getX() > RhythmBullet.GAME_AREA_WIDTH || sprite.getY() > RhythmBullet.GAME_AREA_HEIGHT || sprite.getX() < 0-sprite.getWidth() || sprite.getX() < 0-sprite.getWidth()) {
if (sprite.getX() > RhythmBullet.WORLD_WIDTH || sprite.getY() > RhythmBullet.WORLD_HEIGHT || sprite.getX() < 0-sprite.getWidth() || sprite.getX() < 0-sprite.getWidth()) {
dead = true;
}
@@ -107,18 +113,16 @@ public class Entity implements Poolable {
}
public void draw(Batch batch) {
if (!nonStnrd) {
sprite.draw(batch);
}
sprite.draw(batch);
batch.setColor(Color.WHITE);
}
public void moveBy(float x, float y) {
rotRatios.set(MathUtils.cosDeg(angle), MathUtils.sinDeg(angle));
sprite.setCenter(x, y);
sprite.setCenter(sprite.getX() + x, sprite.getY() + y);
}
public void updatePosition() {
rotRatios.set(MathUtils.cosDeg(angle), MathUtils.sinDeg(angle));
sprite.setOriginCenter();
sprite.setRotation(angle);
hitbox.setCenter(sprite.getOriginX(), sprite.getOriginY());

View File

@@ -28,7 +28,7 @@ public class Laser extends Entity {
@Override
public void calculate(float delta) {
if (getY() > RhythmBullet.GAME_AREA_HEIGHT) {
if (getY() > RhythmBullet.WORLD_HEIGHT) {
dead = true;
}
super.calculate(delta);

View File

@@ -19,12 +19,11 @@ public class PolyjetEntity extends Entity {
private float rate;
private int maxH;
public PolyjetEntity(AssetManager assets, float speed, float accel,int maxHealth, String jet) {
nonStnrd = true;
health = 100;
this.speed = speed;
this.accel = accel;
setSize(1.5f, 1.5f);
setPosition(RhythmBullet.GAME_AREA_WIDTH/2 - getWidth()/2, -4f);
setPosition(RhythmBullet.WORLD_WIDTH/2 - getWidth()/2, -4f);
maxH = maxHealth;
hitbox = new Rectangle(getX(), getY(), getWidth(), getHeight());
polyjet = assets.get("polyjet-" + jet + ".png", Texture.class);

View File

@@ -0,0 +1,28 @@
package zero1hd.rhythmbullet.game;
import java.util.HashMap;
import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityFrame;
import zero1hd.rhythmbullet.entity.coordinator.Coordinator;
import zero1hd.rhythmbullet.entity.coordinator.CoordinatorFrame;
public class EntitySpawnInfo {
private EntityFrame<? extends Entity> entityToSpawn;
private CoordinatorFrame<? extends Coordinator> entityCoordinator;
public HashMap<String, Float> parameters;
public EntitySpawnInfo(EntityFrame<? extends Entity> entityToSpawn, CoordinatorFrame<? extends Coordinator> coordinator) {
this.entityToSpawn = entityToSpawn;
parameters = new HashMap<>();
}
public EntityFrame<? extends Entity> getEntityToSpawn() {
return entityToSpawn;
}
public CoordinatorFrame<? extends Coordinator> getEntityCoordinator() {
return entityCoordinator;
}
}

View File

@@ -0,0 +1,149 @@
package zero1hd.rhythmbullet.game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.utils.Disposable;
import zero1hd.rhythmbullet.controls.KeyMap;
import zero1hd.rhythmbullet.entity.CollisionDetector;
import zero1hd.rhythmbullet.entity.EntityManager;
import zero1hd.rhythmbullet.entity.ally.Laser;
import zero1hd.rhythmbullet.entity.ally.PolyjetEntity;
import zero1hd.rhythmbullet.entity.coordinator.CoordinatorManager;
import zero1hd.rhythmbullet.util.ScoreManager;
public class GameController implements Disposable, InputProcessor {
public PolyjetEntity polyjet;
public CoordinatorManager cm;
public EntityManager em;
private CollisionDetector collisionDetector;
public ScoreManager score = new ScoreManager();
public GameController(AssetManager assetManager, Preferences prefs) {
Gdx.app.debug("Game Area", "new area created");
polyjet = new PolyjetEntity(assetManager, 25f, 25f, 100, "standard");
em = new EntityManager(assetManager, prefs);
cm = new CoordinatorManager(em);
collisionDetector = new CollisionDetector(em.activeEnemies, em.activeAllies, assetManager, prefs);
em.activeAllies.add(polyjet);
}
public void draw(Batch batch) {
batch.begin();
for (int i = 0; i < em.activeEnemies.size; i++) {
em.activeEnemies.get(i).draw(batch);
}
for (int i = 0; i < em.activeAllies.size; i++) {
em.activeAllies.get(i).draw(batch);
}
batch.end();
}
public void prepare(float delta) {
for (int i = 0; i < em.activeEnemies.size; i++) {
em.activeEnemies.get(i).updatePosition();
}
for (int i = 0; i < em.activeAllies.size; i++) {
em.activeAllies.get(i).updatePosition();
}
}
@Override
public boolean keyDown(int keycode) {
if (keycode == KeyMap.left) {
polyjet.moveLeft = true;
}
if (keycode == KeyMap.right) {
polyjet.moveRight = true;
}
if (keycode == KeyMap.up) {
polyjet.moveUp = true;
}
if (keycode == KeyMap.down) {
polyjet.moveDown = true;
}
if (keycode == KeyMap.accelerate) {
polyjet.accelerate = true;
}
return false;
}
@Override
public boolean keyUp(int keycode) {
if (keycode == KeyMap.left) {
polyjet.moveLeft = false;
}
if (keycode == KeyMap.right) {
polyjet.moveRight = false;
}
if (keycode == KeyMap.up) {
polyjet.moveUp = false;
}
if (keycode == KeyMap.down) {
polyjet.moveDown = false;
}
if (keycode == KeyMap.accelerate) {
polyjet.accelerate = false;
}
if (keycode == KeyMap.shoot) {
Laser laser = em.laser.buildEntity();
laser.init(polyjet.getX() + polyjet.getWidth()/2f, polyjet.getY() + polyjet.getHeight()+1f, 60f);
}
return false;
}
public PolyjetEntity getPolyjetEntity() {
return polyjet;
}
@Override
public void dispose() {
}
public CollisionDetector getCollisionDetector() {
return collisionDetector;
}
@Override
public boolean keyTyped(char character) {
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
@Override
public boolean scrolled(int amount) {
return false;
}
}

View File

@@ -0,0 +1,106 @@
package zero1hd.rhythmbullet.game;
import zero1hd.rhythmbullet.audio.MusicManager;
import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityFrame;
import zero1hd.rhythmbullet.entity.coordinator.Coordinator;
import zero1hd.rhythmbullet.entity.coordinator.CoordinatorFrame;
public class GamePlayMap {
private MusicManager musicData;
private MapWindowData[] spawnList;
private boolean building;
private int index;
private byte[] hudType;
/**
* GamePlayMap is what the game area will use to generate entities and judge current audio data
* @param audioData audio data
*/
public GamePlayMap(MusicManager audioData, int totalWindows) {
this.musicData = audioData;
spawnList = new MapWindowData[totalWindows];
hudType = new byte[totalWindows];
}
public int setIndex(int index) {
int previousIndex = this.index;
if (index < 0) {
this.index = 0;
} else if (index >= spawnList.length) {
toHead();
} else {
this.index = index;
}
return previousIndex;
}
public void setHUDType(byte data) {
hudType[index] = data;
}
public byte[] getHudType() {
return hudType;
}
public EntitySpawnInfo addEntity(EntityFrame<? extends Entity> entityType, CoordinatorFrame<? extends Coordinator> coordinator) {
if (building) {
if (spawnList[index] == null) {
spawnList[index] = new MapWindowData();
}
EntitySpawnInfo esi = new EntitySpawnInfo(entityType, coordinator);
spawnList[index].addEntity(esi);
return esi;
} else {
throw new IllegalStateException("Stupid, you need to call begin building first first.");
}
}
public void nextWindowData() {
if (building) {
index++;
} else {
throw new IllegalStateException("Stupid, you need to call begin building first first.");
}
}
public void toHead() {
index = spawnList.length-1;
}
public MusicManager getMusicData() {
return musicData;
}
public void beginBuild() {
if (!building) {
index = 0;
building = true;
} else {
throw new IllegalStateException("Excuse me, but your already building...");
}
}
public void endBuild() {
if (building) {
index = 0;
building = false;
} else {
throw new IllegalStateException("Nothings being built...");
}
}
public MapWindowData getCurrentWindowBasedOnIndex() {
if (index != musicData.getPlaybackIndexPosition()) {
index = musicData.getPlaybackIndexPosition();
if (index < spawnList.length) {
return spawnList[index];
}
}
return null;
}
public int getIndex() {
return index;
}
}

View File

@@ -0,0 +1,18 @@
package zero1hd.rhythmbullet.game;
import com.badlogic.gdx.utils.Array;
public class MapWindowData {
Array<EntitySpawnInfo> entityDatas;
public MapWindowData() {
entityDatas = new Array<>(EntitySpawnInfo.class);
}
public void addEntity(EntitySpawnInfo entity) {
entityDatas.add(entity);
}
public EntitySpawnInfo[] getArray() {
return entityDatas.toArray();
}
}