Initial commit
This commit is contained in:
11
core/build.gradle
Executable file
11
core/build.gradle
Executable file
@@ -0,0 +1,11 @@
|
||||
apply plugin: "java"
|
||||
|
||||
sourceCompatibility = 1.6
|
||||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
||||
|
||||
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||
|
||||
|
||||
eclipse.project {
|
||||
name = appName + "-core"
|
||||
}
|
234
core/src/zero1hd/polyjet/Polyjet.java
Executable file
234
core/src/zero1hd/polyjet/Polyjet.java
Executable file
@@ -0,0 +1,234 @@
|
||||
package zero1hd.polyjet;
|
||||
|
||||
import com.badlogic.gdx.Application;
|
||||
import com.badlogic.gdx.Game;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.assets.loaders.ParticleEffectLoader;
|
||||
import com.badlogic.gdx.assets.loaders.TextureAtlasLoader;
|
||||
import com.badlogic.gdx.assets.loaders.TextureLoader;
|
||||
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
|
||||
import com.badlogic.gdx.assets.loaders.resolvers.ResolutionFileResolver.Resolution;
|
||||
import com.badlogic.gdx.audio.Sound;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
|
||||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox.CheckBoxStyle;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox.SelectBoxStyle;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Slider.SliderStyle;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Window.WindowStyle;
|
||||
|
||||
import zero1hd.polyjet.screens.GameScreen;
|
||||
import zero1hd.polyjet.screens.MainMenu;
|
||||
import zero1hd.polyjet.screens.PreGameScreen;
|
||||
import zero1hd.polyjet.screens.LoadingScreen;
|
||||
|
||||
public class Polyjet extends Game {
|
||||
private boolean initComplete = false;
|
||||
|
||||
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";
|
||||
|
||||
public AssetManager assetManager = new AssetManager();
|
||||
public Skin defaultSkin = new Skin();
|
||||
public TextureAtlas buttons;
|
||||
public FreeTypeFontGenerator default_fontGenerator;
|
||||
public FreeTypeFontGenerator darktech_ldr_fontGenerator;
|
||||
TextureAtlas skinAtlas;
|
||||
public Preferences prefs;
|
||||
|
||||
//screens
|
||||
public MainMenu mainMenuScreen;
|
||||
public PreGameScreen preGameScreen;
|
||||
public GameScreen gameScreen;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||
prefs = Gdx.app.getPreferences("PolyJet_Preferences");
|
||||
|
||||
if (prefs.getBoolean("fullscreen", true)) {
|
||||
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
|
||||
} else {
|
||||
Gdx.graphics.setWindowedMode(prefs.getInteger("screen-width"), prefs.getInteger("screen-height"));
|
||||
}
|
||||
|
||||
Gdx.app.debug("Prelaunch Debug Info", "\ncurrent window size: "
|
||||
+ Gdx.graphics.getWidth() + "x" + Gdx.graphics.getHeight() +"\n"
|
||||
+ "Pixel density (PPI): " + Gdx.graphics.getDensity());
|
||||
|
||||
setScreen(mainMenuScreen = new MainMenu(this));
|
||||
|
||||
Resolution[] resolution = {
|
||||
new Resolution(800, 480, "800x480"),
|
||||
new Resolution(1280, 720, "1280x720"),
|
||||
new Resolution(1366, 768, "1366x768"),
|
||||
new Resolution(1280, 800, "1280x800"),
|
||||
new Resolution(1920, 1080, "1920x1080"),
|
||||
new Resolution(1920, 1200, "1920x1200"),
|
||||
new Resolution(2560, 1440, "2560x1440"),
|
||||
new Resolution(3840, 2160, "3840x2160"),
|
||||
};
|
||||
|
||||
RoundingResolutionHandler resolver = new RoundingResolutionHandler(new InternalFileHandleResolver(), resolution);
|
||||
|
||||
assetManager.setLoader(TextureAtlas.class, new TextureAtlasLoader(resolver));
|
||||
assetManager.setLoader(Texture.class, new TextureLoader(resolver));
|
||||
assetManager.setLoader(ParticleEffect.class, new ParticleEffectLoader(resolver));
|
||||
|
||||
default_fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/Gasalt-Regular.ttf"));
|
||||
darktech_ldr_fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/darktech_ldr.ttf"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
super.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (skinAtlas != null) {
|
||||
skinAtlas.dispose();
|
||||
defaultSkin.dispose();
|
||||
default_fontGenerator.dispose();
|
||||
darktech_ldr_fontGenerator.dispose();
|
||||
assetManager.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public void queueAssets() {
|
||||
assetManager.load("sounds/metal_clang.ogg", Sound.class);
|
||||
assetManager.load("sounds/MainMenuLoop1.ogg", Sound.class);
|
||||
assetManager.load("uiskin.atlas", TextureAtlas.class);
|
||||
assetManager.load("Tech-Circle1.png", Texture.class);
|
||||
assetManager.load("polyjet-standard.png", Texture.class);
|
||||
assetManager.load("standard_thrust.p", ParticleEffect.class);
|
||||
assetManager.load("keyboard.atlas", TextureAtlas.class);
|
||||
assetManager.load("cybercircle3B.png", Texture.class);
|
||||
assetManager.load("PolyjetTitle.png", Texture.class);
|
||||
assetManager.load("cybercircle1.png", Texture.class);
|
||||
}
|
||||
public void generateFonts() {
|
||||
initComplete = true;
|
||||
defaultSkin = new Skin();
|
||||
Gdx.app.debug("Prelaunch Debug Info", "Generating fonts...");
|
||||
|
||||
skinAtlas = assetManager.get("uiskin.atlas", TextureAtlas.class);
|
||||
defaultSkin.addRegions(skinAtlas);
|
||||
|
||||
defaultSkin.add("small-font", default_fontGenerator.generateFont(new FreeTypeFontParameter() {
|
||||
{
|
||||
size = fontScale(0.04f);
|
||||
}
|
||||
}));
|
||||
|
||||
defaultSkin.add("default-font", default_fontGenerator.generateFont(new FreeTypeFontParameter() {
|
||||
{
|
||||
size = fontScale(0.06f);
|
||||
}
|
||||
}));
|
||||
|
||||
defaultSkin.add("large-font", default_fontGenerator.generateFont(new FreeTypeFontParameter() {
|
||||
{
|
||||
size = fontScale(0.08f);
|
||||
}
|
||||
}));
|
||||
|
||||
defaultSkin.add("special-font", darktech_ldr_fontGenerator.generateFont(new FreeTypeFontParameter() {
|
||||
{
|
||||
size = fontScale(0.08f);
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
public void defineSkinStyles() {
|
||||
defaultSkin.add("default", Color.BLACK);
|
||||
defaultSkin.add("inverse", Color.WHITE);
|
||||
|
||||
TextButtonStyle defaultTextButton = new TextButtonStyle();
|
||||
defaultTextButton.up = defaultSkin.getDrawable("default-round");
|
||||
defaultTextButton.down = defaultSkin.getDrawable("default-round-down");
|
||||
defaultTextButton.font = defaultSkin.getFont("default-font");
|
||||
defaultTextButton.fontColor = defaultSkin.getColor("default");
|
||||
defaultSkin.add("default", defaultTextButton);
|
||||
|
||||
TextButtonStyle smallTextButton = new TextButtonStyle(defaultTextButton);
|
||||
smallTextButton.font = defaultSkin.getFont("small-font");
|
||||
defaultSkin.add("small", smallTextButton);
|
||||
|
||||
TextButtonStyle textButtonLeft = new TextButtonStyle();
|
||||
textButtonLeft.up = defaultSkin.getDrawable("left-button");
|
||||
textButtonLeft.down = defaultSkin.getDrawable("left-button-down");
|
||||
textButtonLeft.font = defaultSkin.getFont("default-font");
|
||||
textButtonLeft.fontColor = defaultSkin.getColor("default");
|
||||
defaultSkin.add("left", textButtonLeft);
|
||||
|
||||
SliderStyle defaultSlider = new SliderStyle(defaultSkin.getDrawable("default-slider"), defaultSkin.getDrawable("default-slider-knob"));
|
||||
defaultSkin.add("default-horizontal", defaultSlider);
|
||||
|
||||
LabelStyle defaultLabel = new LabelStyle();
|
||||
defaultLabel.font = defaultSkin.getFont("default-font");
|
||||
defaultLabel.fontColor = defaultSkin.getColor("default");
|
||||
defaultSkin.add("default", defaultLabel);
|
||||
|
||||
TextFieldStyle defaultTextField = new TextFieldStyle(defaultSkin.getFont("small-font"), defaultSkin.getColor("default"), defaultSkin.getDrawable("cursor"), defaultSkin.getDrawable("selection"), defaultSkin.getDrawable("textfield"));
|
||||
defaultSkin.add("default", defaultTextField);
|
||||
|
||||
WindowStyle defaultWindow = new WindowStyle(defaultSkin.getFont("small-font"), defaultSkin.getColor("default"), defaultSkin.getDrawable("default-window"));
|
||||
defaultSkin.add("default", defaultWindow);
|
||||
|
||||
ListStyle defaultList = new ListStyle(defaultSkin.getFont("small-font"), defaultSkin.getColor("inverse"), defaultSkin.getColor("default"), defaultSkin.getDrawable("selection"));
|
||||
defaultSkin.add("default", defaultList);
|
||||
|
||||
ScrollPaneStyle defaultScrollPane = new ScrollPaneStyle();
|
||||
defaultScrollPane.vScroll = defaultSkin.getDrawable("default-scroll");
|
||||
defaultScrollPane.hScrollKnob = defaultSkin.getDrawable("default-round-large");
|
||||
defaultScrollPane.hScroll = defaultSkin.getDrawable("default-scroll");
|
||||
defaultScrollPane.vScrollKnob = defaultSkin.getDrawable("default-round-large");
|
||||
defaultSkin.add("default", defaultScrollPane);
|
||||
|
||||
CheckBoxStyle defaultCheckBox = new CheckBoxStyle(defaultSkin.getDrawable("check-off"), defaultSkin.getDrawable("check-on"), defaultSkin.getFont("small-font"), defaultSkin.getColor("default"));
|
||||
defaultSkin.add("default", defaultCheckBox);
|
||||
|
||||
SelectBoxStyle defaultSelectBox = new SelectBoxStyle(defaultSkin.getFont("default-font"), defaultSkin.getColor("default"), defaultSkin.getDrawable("default-select"), defaultScrollPane, defaultList);
|
||||
defaultSkin.add("default", defaultSelectBox);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
if (initComplete) {
|
||||
defaultSkin.dispose();
|
||||
gameScreen = null;
|
||||
assetManager.clear();
|
||||
prefs.putInteger("screen-width", width);
|
||||
prefs.putInteger("screen-height", height);
|
||||
prefs.flush();
|
||||
}
|
||||
setScreen(new LoadingScreen(this, getScreen(), true, !initComplete));
|
||||
super.resize(width, height);
|
||||
}
|
||||
|
||||
|
||||
public int fontScale(float fontSize) {
|
||||
Gdx.app.debug("Font pixel size", MathUtils.round(Gdx.graphics.getDensity()*(fontSize*Gdx.graphics.getHeight())) + "px");
|
||||
return MathUtils.round(Gdx.graphics.getDensity()*(fontSize*Gdx.graphics.getHeight()));
|
||||
}
|
||||
}
|
66
core/src/zero1hd/polyjet/RoundingResolutionHandler.java
Executable file
66
core/src/zero1hd/polyjet/RoundingResolutionHandler.java
Executable file
@@ -0,0 +1,66 @@
|
||||
package zero1hd.polyjet;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
|
||||
import com.badlogic.gdx.assets.loaders.resolvers.ResolutionFileResolver.Resolution;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
|
||||
public class RoundingResolutionHandler implements FileHandleResolver {
|
||||
private final Resolution[] descriptors;
|
||||
private final FileHandleResolver resolver;
|
||||
|
||||
public RoundingResolutionHandler(FileHandleResolver fileResolver, Resolution... descriptors) {
|
||||
if (descriptors.length == 0) throw new IllegalArgumentException("At least one Resolution needs to be supplied.");
|
||||
this.descriptors = descriptors;
|
||||
this.resolver = fileResolver;
|
||||
}
|
||||
|
||||
|
||||
public Resolution chooseRounded(Resolution... descriptors) {
|
||||
Resolution best = descriptors[0];
|
||||
|
||||
int leastDifference = -1;
|
||||
|
||||
int w = MathUtils.round(Gdx.graphics.getWidth()*Gdx.graphics.getDensity()), h = MathUtils.round(Gdx.graphics.getHeight()*Gdx.graphics.getDensity());
|
||||
|
||||
if (w < h) {
|
||||
for (int i = 0; i < descriptors.length; i++) {
|
||||
int currentDiff = h - descriptors[i].portraitHeight;
|
||||
|
||||
if (currentDiff < 0) {
|
||||
currentDiff = currentDiff*-1;
|
||||
}
|
||||
|
||||
if (currentDiff < leastDifference || leastDifference == -1) {
|
||||
best = descriptors[i];
|
||||
leastDifference = currentDiff;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < descriptors.length; i++) {
|
||||
int currentDiff = w - descriptors[i].portraitWidth;
|
||||
|
||||
if (currentDiff < 0) {
|
||||
currentDiff = currentDiff*-1;
|
||||
}
|
||||
|
||||
if (currentDiff < leastDifference || leastDifference == -1) {
|
||||
best = descriptors[i];
|
||||
leastDifference = currentDiff;
|
||||
}
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileHandle resolve(String fileName) {
|
||||
Resolution bestRes = chooseRounded(descriptors);
|
||||
FileHandle initialHandle = new FileHandle(fileName);
|
||||
|
||||
FileHandle resSpecificFile = resolver.resolve(bestRes.folder + "/" + initialHandle.name());
|
||||
if (!resSpecificFile.exists()) resSpecificFile = resolver.resolve(fileName);
|
||||
return resSpecificFile;
|
||||
}
|
||||
}
|
5
core/src/zero1hd/polyjet/TransitionAdapter.java
Executable file
5
core/src/zero1hd/polyjet/TransitionAdapter.java
Executable file
@@ -0,0 +1,5 @@
|
||||
package zero1hd.polyjet;
|
||||
|
||||
public interface TransitionAdapter {
|
||||
public void postTransition();
|
||||
}
|
291
core/src/zero1hd/polyjet/audio/AudioAnalyzer.java
Executable file
291
core/src/zero1hd/polyjet/audio/AudioAnalyzer.java
Executable file
@@ -0,0 +1,291 @@
|
||||
package zero1hd.polyjet.audio;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
|
||||
import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D;
|
||||
|
||||
public class AudioAnalyzer {
|
||||
public boolean containsData;
|
||||
|
||||
FloatFFT_1D fft;
|
||||
public AudioData audiofile;
|
||||
|
||||
float[] audioPCM;
|
||||
float[] spectrum;
|
||||
float[] lastSpectrum;
|
||||
float[] fftData;
|
||||
|
||||
Thread analyticalThread;
|
||||
Runnable analysisAlgorithm;
|
||||
int bassBinBegin;
|
||||
int bassBinEnd;
|
||||
private FloatArray bassSpectralFlux = new FloatArray();
|
||||
private FloatArray bassThreshold = new FloatArray();
|
||||
private FloatArray bassPrunned = new FloatArray();
|
||||
private FloatArray bassPeaks = new FloatArray();
|
||||
private float bassMaxValue;
|
||||
|
||||
int UMBinBegin;
|
||||
int UMBinEnd;
|
||||
private FloatArray UMSpectralFlux = new FloatArray();
|
||||
private FloatArray UMThreshold = new FloatArray();
|
||||
private FloatArray UMPrunned = new FloatArray();
|
||||
private FloatArray UMPeaks = new FloatArray();
|
||||
private float UMMaxValue;
|
||||
|
||||
private FloatArray overlappedBeats = new FloatArray();
|
||||
|
||||
float bassThresholdMultiplier;
|
||||
float UMThresholdMultiplier;
|
||||
int UMThresholdCalcRange;
|
||||
int bassThresholdCalcRange;
|
||||
|
||||
public AudioAnalyzer() {
|
||||
analysisAlgorithm = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
bassThresholdMultiplier = 1.5f;
|
||||
UMThresholdMultiplier = 2f;
|
||||
|
||||
bassBinBegin = binCalculator(60);
|
||||
bassBinEnd = binCalculator(800);
|
||||
|
||||
UMBinBegin = binCalculator(1500);
|
||||
UMBinEnd = binCalculator(3000);
|
||||
|
||||
UMThresholdCalcRange = thresholdRangeCalc(0.5f);
|
||||
bassThresholdCalcRange = thresholdRangeCalc(0.7f);
|
||||
|
||||
Gdx.app.debug("Read freq", String.valueOf(audiofile.getFormat().getSampleRate()));
|
||||
Gdx.app.debug("Using following bin ranges", "\nBass freq begin: " + bassBinBegin + "\nBass freq end: " + bassBinEnd + "\nMain freq begin: " + UMBinBegin + "\nMain freq end: " + UMBinEnd);
|
||||
|
||||
|
||||
Gdx.app.debug("Threshold Calc Range UM", String.valueOf(UMThresholdCalcRange));
|
||||
Gdx.app.debug("Threshold Calc Range Bass", String.valueOf(bassThresholdCalcRange));
|
||||
|
||||
|
||||
fft = new FloatFFT_1D(audiofile.getReadWindowSize());
|
||||
while (audiofile.readSamples(audioPCM) > 0) {
|
||||
|
||||
|
||||
fft.realForward(audioPCM);
|
||||
|
||||
System.arraycopy(spectrum, 0, lastSpectrum, 0, spectrum.length);
|
||||
System.arraycopy(audioPCM, 0, spectrum, 0, spectrum.length);
|
||||
|
||||
float fluxVal = 0;
|
||||
//bass detection
|
||||
fluxVal = 0;
|
||||
for (int i = bassBinBegin; i < bassBinEnd; i++) {
|
||||
fluxVal += ((int) (spectrum[i] - lastSpectrum[i])) > 0
|
||||
? (int) (spectrum[i] - lastSpectrum[i]) : 0;
|
||||
}
|
||||
bassSpectralFlux.add(fluxVal);
|
||||
|
||||
//main detection
|
||||
fluxVal = 0;
|
||||
for (int i = UMBinBegin; i < UMBinEnd; i++) {
|
||||
fluxVal += ((int) (spectrum[i] - lastSpectrum[i])) > 0
|
||||
? (int) (spectrum[i] - lastSpectrum[i]) : 0;
|
||||
}
|
||||
UMSpectralFlux.add(fluxVal);
|
||||
}
|
||||
|
||||
Gdx.app.debug("Audio Analyzer", "Done getting spectral flux.");
|
||||
|
||||
//threshold calculation
|
||||
for (int i = 0; i < UMSpectralFlux.size; i++) {
|
||||
int UMStart = Math.max(0, i - UMThresholdCalcRange/2);
|
||||
int UMEnd = Math.min(UMSpectralFlux.size - 1, i + UMThresholdCalcRange/2);
|
||||
|
||||
int bassStart = Math.max(0, i - bassThresholdCalcRange/2);
|
||||
int bassEnd = Math.min(UMSpectralFlux.size - 1, i + bassThresholdCalcRange/2);
|
||||
|
||||
float average = 0;
|
||||
for (int j = bassStart; j <= bassEnd; j++) {
|
||||
average += bassSpectralFlux.get(j);
|
||||
}
|
||||
average /= (bassEnd - bassStart);
|
||||
bassThreshold.add(average * bassThresholdMultiplier);
|
||||
|
||||
average = 0;
|
||||
for (int j = UMStart; j <= UMEnd; j++) {
|
||||
average+= UMSpectralFlux.get(j);
|
||||
}
|
||||
average /= (UMEnd - UMStart);
|
||||
UMThreshold.add(average*UMThresholdMultiplier);
|
||||
}
|
||||
|
||||
Gdx.app.debug("Audio Analyzer", "Threshold calculated.");
|
||||
|
||||
|
||||
//pruning data
|
||||
float prunnedCurrentVal;
|
||||
for (int i = 0; i < UMSpectralFlux.size; i++) {
|
||||
prunnedCurrentVal = bassSpectralFlux.get(i) - bassThreshold.get(i);
|
||||
|
||||
if (prunnedCurrentVal >= 0) {
|
||||
bassPrunned.add(prunnedCurrentVal);
|
||||
} else {
|
||||
bassPrunned.add(0);
|
||||
}
|
||||
|
||||
prunnedCurrentVal = UMSpectralFlux.get(i) - UMThreshold.get(i);
|
||||
|
||||
if (prunnedCurrentVal >= 0 ) {
|
||||
UMPrunned.add(prunnedCurrentVal);
|
||||
} else {
|
||||
UMPrunned.add(0);
|
||||
}
|
||||
}
|
||||
Gdx.app.debug("Audio Analyzer", "Data prunned.");
|
||||
|
||||
//peak detection
|
||||
for (int i = 0; i < UMPrunned.size-1; i++) {
|
||||
bassPeaks.add((bassPrunned.get(i) > bassPrunned.get(i+1) ? bassPrunned.get(i) : 0));
|
||||
if (bassPeaks.get(i) > bassMaxValue) {
|
||||
bassMaxValue = bassPeaks.get(i);
|
||||
}
|
||||
|
||||
UMPeaks.add((UMPrunned.get(i) > UMPrunned.get(i+1) ? UMPrunned.get(i) : 0));
|
||||
if (UMPeaks.get(i) > UMMaxValue) {
|
||||
UMMaxValue = UMPeaks.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
Gdx.app.debug("Audio Analyzer", "Found all peaks.");
|
||||
|
||||
//overlapping beats
|
||||
for (int i = 0; i < UMPeaks.size; i++) {
|
||||
if (bassPeaks.get(i) != 0 && UMPeaks.get(i) != 0) {
|
||||
overlappedBeats.add(bassPeaks.get(i)+UMPeaks.get(i)/2);
|
||||
} else {
|
||||
overlappedBeats.add(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Gdx.app.debug("Audio Analyzer", "overlapped beats checked.");
|
||||
shrinkData();
|
||||
containsData = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void resetVars() {
|
||||
bassSpectralFlux.clear();
|
||||
bassThreshold.clear();
|
||||
bassPrunned.clear();
|
||||
bassPeaks.clear();
|
||||
|
||||
UMSpectralFlux.clear();
|
||||
UMThreshold.clear();
|
||||
UMPrunned.clear();
|
||||
UMPeaks.clear();
|
||||
|
||||
overlappedBeats.clear();
|
||||
|
||||
containsData = false;
|
||||
}
|
||||
|
||||
public void shrinkData() {
|
||||
bassSpectralFlux.shrink();
|
||||
bassThreshold.shrink();
|
||||
bassPrunned.shrink();
|
||||
bassPeaks.shrink();
|
||||
|
||||
UMSpectralFlux.shrink();
|
||||
UMThreshold.shrink();
|
||||
UMPrunned.shrink();
|
||||
UMPeaks.shrink();
|
||||
|
||||
overlappedBeats.shrink();
|
||||
}
|
||||
|
||||
public void startAnalyticalThread(final AudioData audiofile) {
|
||||
|
||||
fftData = new float[audiofile.getReadWindowSize()];
|
||||
spectrum = new float[(audiofile.getReadWindowSize()/2)+1];
|
||||
lastSpectrum = new float[(audiofile.getReadWindowSize()/2)+1];
|
||||
this.audiofile = audiofile;
|
||||
|
||||
analyticalThread = new Thread(analysisAlgorithm);
|
||||
analyticalThread.start();
|
||||
}
|
||||
|
||||
public float[][] splitChannelData(float[] samples, int channelCount) {
|
||||
int byteIndex = 0;
|
||||
float[][] splitSamples = new float[channelCount][samples.length / (channelCount * 2)];
|
||||
for (int currentByte = 0; currentByte < samples.length;) {
|
||||
for (int channel = 0; channel < channelCount; channel++) {
|
||||
int low = (int) samples[currentByte];
|
||||
currentByte++;
|
||||
int high = (int) samples[currentByte];
|
||||
currentByte++;
|
||||
splitSamples[channel][byteIndex] = (high << 8) + (low & 0x00ff);
|
||||
}
|
||||
byteIndex++;
|
||||
}
|
||||
return splitSamples;
|
||||
}
|
||||
|
||||
public float[] convertPCM(float[] leftChannel, float[] rightChannel) {
|
||||
float[] result = new float[leftChannel.length];
|
||||
for (int i = 0; i < leftChannel.length; i++)
|
||||
result[i] = (leftChannel[i] + rightChannel[i]) / 2 / 32768.0f;
|
||||
return result;
|
||||
}
|
||||
|
||||
public float[] byteToFloat(byte[] byteArray) {
|
||||
float[] floatArray = new float[byteArray.length];
|
||||
for (int i = 0; i < byteArray.length; i++) {
|
||||
floatArray[i] = byteArray[i];
|
||||
}
|
||||
return floatArray;
|
||||
}
|
||||
|
||||
public FloatArray getBassPeaks() {
|
||||
return bassPeaks;
|
||||
}
|
||||
public FloatArray getUMPeaks() {
|
||||
return UMPeaks;
|
||||
}
|
||||
|
||||
private int binCalculator(int frequency) {
|
||||
float totalBins = audiofile.getReadWindowSize()/2 +1;
|
||||
float frequencyRange = audiofile.getFormat().getSampleRate()/2;
|
||||
|
||||
//Formula derived from: (22050b/513)+(22050/513/2) = F
|
||||
//let b be the bin
|
||||
//let F be the frequency.
|
||||
return (int) (totalBins*(frequency - (frequencyRange/totalBins*2))/frequencyRange);
|
||||
}
|
||||
|
||||
private int thresholdRangeCalc(float durationOfRange) {
|
||||
float timePerWindow = (float)audiofile.getReadWindowSize()/audiofile.getFormat().getSampleRate();
|
||||
return (int) (durationOfRange/timePerWindow);
|
||||
}
|
||||
|
||||
public float getBassMaxValue() {
|
||||
return bassMaxValue;
|
||||
}
|
||||
|
||||
public float getUMMaxValue() {
|
||||
return UMMaxValue;
|
||||
}
|
||||
|
||||
public int getReadIndex() {
|
||||
if (audiofile.getReadIndex() < UMPeaks.size) {
|
||||
return audiofile.getReadIndex();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsData() {
|
||||
return containsData;
|
||||
}
|
||||
}
|
55
core/src/zero1hd/polyjet/audio/AudioData.java
Executable file
55
core/src/zero1hd/polyjet/audio/AudioData.java
Executable file
@@ -0,0 +1,55 @@
|
||||
package zero1hd.polyjet.audio;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
|
||||
public interface AudioData {
|
||||
/**
|
||||
* sets a integer variable to the current window of audio data the playback is at.
|
||||
* Useful for efficiency because we compute once for that frame then get the values everytime it is required instead of calculating every time we get the index.
|
||||
*/
|
||||
public void readIndexUpdate();
|
||||
|
||||
/**
|
||||
* Gets the current position in seconds
|
||||
* @return the current frame of audio.
|
||||
*/
|
||||
public int getReadIndex();
|
||||
|
||||
/**
|
||||
* Sets the current audio file
|
||||
*/
|
||||
public void setAudioFile(FileHandle setAudio);
|
||||
|
||||
/**
|
||||
* Completely resets the current audio data. Think of pooling, except, only one instance which is reused instead of multiple.
|
||||
*/
|
||||
public void reset();
|
||||
|
||||
/**
|
||||
* returns the read window size.
|
||||
* @return
|
||||
*/
|
||||
public int getReadWindowSize();
|
||||
|
||||
/**
|
||||
* Gets the object to play the music. Contains playback data.
|
||||
* @return
|
||||
*/
|
||||
public Music getPlaybackMusic();
|
||||
|
||||
/**
|
||||
* read in samples and fills the array.
|
||||
* @param samples the array that should contain said samples
|
||||
* @return amount read. Will return 0 if end of stream.
|
||||
*/
|
||||
public int readSamples(float[] samples);
|
||||
|
||||
/**
|
||||
* Returns properly setup AudioFormat object.
|
||||
* @return
|
||||
*/
|
||||
public AudioFormat getFormat();
|
||||
}
|
113
core/src/zero1hd/polyjet/audio/Mp3AudioData.java
Executable file
113
core/src/zero1hd/polyjet/audio/Mp3AudioData.java
Executable file
@@ -0,0 +1,113 @@
|
||||
package zero1hd.polyjet.audio;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
|
||||
import javazoom.jl.decoder.Obuffer;
|
||||
|
||||
public class Mp3AudioData implements AudioData {
|
||||
private int readWindowSize = 1024;
|
||||
|
||||
private AudioInputStream audStream;
|
||||
private AudioInputStream faudStream;
|
||||
|
||||
private AudioFormat audioFormat;
|
||||
private Music playbackMusic;
|
||||
private int readIndex;
|
||||
|
||||
@Override
|
||||
public void readIndexUpdate() {
|
||||
readIndex = (int) (playbackMusic.getPosition() * audioFormat.getSampleRate() / readWindowSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getReadIndex() {
|
||||
return readIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAudioFile(FileHandle setAudio) {
|
||||
reset();
|
||||
try {
|
||||
audStream = AudioSystem.getAudioInputStream(setAudio.file());
|
||||
AudioFormat bFormat = audStream.getFormat();
|
||||
audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, bFormat.getSampleRate(), 16, bFormat.getChannels(), bFormat.getChannels()*2, bFormat.getSampleRate(), false);
|
||||
faudStream = AudioSystem.getAudioInputStream(audioFormat, audStream);
|
||||
} catch (UnsupportedAudioFileException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
playbackMusic = Gdx.audio.newMusic(setAudio);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
if (playbackMusic != null) {
|
||||
playbackMusic.stop();
|
||||
playbackMusic.dispose();
|
||||
playbackMusic = null;
|
||||
}
|
||||
|
||||
if (audStream != null) {
|
||||
try {
|
||||
audStream.close();
|
||||
faudStream.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getReadWindowSize() {
|
||||
return readWindowSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Music getPlaybackMusic() {
|
||||
return playbackMusic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readSamples(float[] samples) {
|
||||
int samplesRead = 0;
|
||||
int sampleAverage = 0;
|
||||
for (int currentSample = 0; currentSample < samples.length; currentSample++) {
|
||||
for (int channel = 0; channel < audioFormat.getChannels(); channel++) {
|
||||
try {
|
||||
sampleAverage += audStream.read();
|
||||
if (sampleAverage == -1) {
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
sampleAverage /= audioFormat.getChannels()*Short.MAX_VALUE+1;
|
||||
samples[currentSample] = sampleAverage;
|
||||
samplesRead++;
|
||||
if (sampleAverage == -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return samplesRead;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AudioFormat getFormat() {
|
||||
return audioFormat;
|
||||
}
|
||||
|
||||
}
|
83
core/src/zero1hd/polyjet/audio/WavAudioData.java
Executable file
83
core/src/zero1hd/polyjet/audio/WavAudioData.java
Executable file
@@ -0,0 +1,83 @@
|
||||
package zero1hd.polyjet.audio;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
|
||||
import zero1hd.wavedecoder.WavDecoder;
|
||||
|
||||
public class WavAudioData implements AudioData {
|
||||
private int readWindowSize = 1024;
|
||||
private InputStream inStream;
|
||||
private InputStream bufferedAudioIn;
|
||||
private AudioFormat format;
|
||||
int readIndex;
|
||||
Music playbackMusic;
|
||||
WavDecoder decoder;
|
||||
|
||||
@Override
|
||||
public void readIndexUpdate() {
|
||||
readIndex = (int) (playbackMusic.getPosition() * decoder.getSampleRate() / readWindowSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getReadIndex() {
|
||||
return readIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAudioFile(FileHandle audioFileHandler) {
|
||||
reset();
|
||||
|
||||
inStream = audioFileHandler.read();
|
||||
bufferedAudioIn = new BufferedInputStream(inStream);
|
||||
decoder.setAudioFile(audioFileHandler.file());
|
||||
playbackMusic = Gdx.audio.newMusic(audioFileHandler);
|
||||
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, (float) decoder.getSampleRate(), 16, decoder.getChannels(), decoder.getChannels()*2, (float)decoder.getSampleRate(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
if (playbackMusic != null) {
|
||||
playbackMusic.stop();
|
||||
playbackMusic.dispose();
|
||||
playbackMusic = null;
|
||||
}
|
||||
|
||||
if (inStream != null) {
|
||||
try {
|
||||
bufferedAudioIn.close();
|
||||
inStream.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getReadWindowSize() {
|
||||
return readWindowSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Music getPlaybackMusic() {
|
||||
return playbackMusic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readSamples(float[] samples) {
|
||||
return decoder.readSamples(samples);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AudioFormat getFormat() {
|
||||
return format;
|
||||
}
|
||||
}
|
44
core/src/zero1hd/polyjet/entity/BarBeat.java
Executable file
44
core/src/zero1hd/polyjet/entity/BarBeat.java
Executable file
@@ -0,0 +1,44 @@
|
||||
package zero1hd.polyjet.entity;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.NinePatch;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
|
||||
public class BarBeat extends Entity {
|
||||
NinePatch texture;
|
||||
float rate;
|
||||
|
||||
public void initiate(float size, float rate, float spawnX, float spawnY, NinePatch texture) {
|
||||
hitpoints = 1;
|
||||
this.rate = rate;
|
||||
setPosition(spawnX, spawnY);
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
if (getY() + getHeight() < Polyjet.GAME_AREA_HEIGHT) {
|
||||
hitpoints = 0;
|
||||
}
|
||||
moveBy(0, -rate*delta);
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
texture.draw(batch, getX(), getY(), getWidth(), getHeight());
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamageDealt() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
texture = null;
|
||||
super.reset();
|
||||
}
|
||||
}
|
71
core/src/zero1hd/polyjet/entity/Entity.java
Executable file
71
core/src/zero1hd/polyjet/entity/Entity.java
Executable file
@@ -0,0 +1,71 @@
|
||||
package zero1hd.polyjet.entity;
|
||||
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
|
||||
public class Entity extends Actor implements Poolable {
|
||||
private Rectangle hitbox;
|
||||
protected int hitpoints;
|
||||
|
||||
public Entity() {
|
||||
hitbox = new Rectangle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize(float width, float height) {
|
||||
hitbox.setSize(width, height);
|
||||
super.setSize(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
hitbox.setPosition(getX(), getY());
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return amount of hp this entity has left.
|
||||
*/
|
||||
public int getHitPoints() {
|
||||
return hitpoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* used as a hitbox.
|
||||
* @return a rectangle used for hit detection
|
||||
*/
|
||||
public Rectangle getHitbox() {
|
||||
return hitbox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 0 if not overridden.
|
||||
* @return the amount of damage dealt.
|
||||
*/
|
||||
public int getDamageDealt() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't do anything if not overridden.
|
||||
* @param damageToDeal the amount of damage to deal to this entity.
|
||||
*/
|
||||
public void dealDamage(int damageToDeal) {
|
||||
}
|
||||
/**
|
||||
* Default value is 0 if not overridden and setup properly.
|
||||
* Note: this method is called whether or not this entity is dead. whenever two entities cross, this will be called.
|
||||
* @return the amount of points this entity is worth
|
||||
*/
|
||||
public int getPoints() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
setPosition(0, 0);
|
||||
setSize(0, 0);
|
||||
hitpoints = 0;
|
||||
}
|
||||
}
|
68
core/src/zero1hd/polyjet/entity/PolyJetEntity.java
Executable file
68
core/src/zero1hd/polyjet/entity/PolyJetEntity.java
Executable file
@@ -0,0 +1,68 @@
|
||||
package zero1hd.polyjet.entity;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
|
||||
public class PolyJetEntity extends Actor {
|
||||
|
||||
private ParticleEffect thrust;
|
||||
private Texture polyjet;
|
||||
private ParticleEffect teleportCloak;
|
||||
|
||||
|
||||
public boolean moveLeft, moveRight, moveUp, moveDown, teleporting;
|
||||
private int rate;
|
||||
public PolyJetEntity(Polyjet core, int rate, String jet) {
|
||||
this.rate = rate;
|
||||
|
||||
setSize(3, 3);
|
||||
|
||||
setPosition(Polyjet.GAME_AREA_WIDTH/2 - getWidth()/2, -4f);
|
||||
|
||||
polyjet = core.assetManager.get("polyjet-" + jet + ".png", Texture.class);
|
||||
thrust = core.assetManager.get("standard_thrust.p", ParticleEffect.class);
|
||||
thrust.start();
|
||||
|
||||
teleportCloak = core.assetManager.get("magicCircle.png", ParticleEffect.class);
|
||||
|
||||
addAction(Actions.moveTo(getX(), 4f, 0.5f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
thrust.setPosition(getX()+(getWidth()-2)/2 - 1f/16f, getY()-0.15f);
|
||||
thrust.update(delta);
|
||||
teleportCloak.setPosition(getX() +(getWidth()-1)/2, getY() + (getHeight()-1)/2);
|
||||
|
||||
super.act(delta);
|
||||
|
||||
//Movement!
|
||||
if (moveLeft && !moveRight) {
|
||||
moveBy(-(rate*delta), 0);
|
||||
}
|
||||
if (moveRight && !moveLeft) {
|
||||
moveBy(rate*delta, 0);
|
||||
}
|
||||
if (moveUp && !moveDown) {
|
||||
moveBy(0, rate*delta);
|
||||
}
|
||||
|
||||
if (moveDown && !moveUp) {
|
||||
moveBy(0, -rate*delta);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
thrust.draw(batch);
|
||||
batch.draw(polyjet, getX(), getY(), getWidth(), getHeight());
|
||||
super.draw(batch, parentAlpha);
|
||||
|
||||
}
|
||||
}
|
75
core/src/zero1hd/polyjet/entity/Projectile.java
Executable file
75
core/src/zero1hd/polyjet/entity/Projectile.java
Executable file
@@ -0,0 +1,75 @@
|
||||
package zero1hd.polyjet.entity;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
|
||||
public class Projectile extends Entity {
|
||||
float rate;
|
||||
int damage;
|
||||
Texture texture;
|
||||
int hp;
|
||||
int storedPoints;
|
||||
|
||||
public Projectile() {
|
||||
super();
|
||||
Gdx.app.debug("Projectile", "A new projectile was created.");
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param spawnX x spawn location
|
||||
* @param spawnY y spawn location
|
||||
* @param rate r/second
|
||||
* @param hp health this projectile should have
|
||||
* @param texture texture this projectile should render.
|
||||
*/
|
||||
public void initiate(float spawnX, float spawnY, float rate, int hp, Texture texture, float width, float height) {
|
||||
this.hp = hp;
|
||||
setX(spawnX);
|
||||
setY(spawnY);
|
||||
this.texture = texture;
|
||||
this.rate = rate;
|
||||
setSize(width, height);
|
||||
damage = 1;
|
||||
}
|
||||
|
||||
public void setDamage(int damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
public void printDebug() {
|
||||
Gdx.app.debug("Projectile", "Coordinates (X,Y): (" + getX() + ", " + getY() + ") Current parent: " + getParent().getName());
|
||||
Gdx.app.debug("Projectile", "Width and height: " + getWidth() + "x" + getHeight());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
moveBy(0, delta*rate);
|
||||
if (getY() > Polyjet.GAME_AREA_HEIGHT) {
|
||||
hp = 0;
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
batch.draw(texture, getX(), getY(), getWidth(), getHeight());
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
texture = null;
|
||||
storedPoints = 0;
|
||||
rate = 0;
|
||||
damage = 0;
|
||||
setDebug(false);
|
||||
}
|
||||
@Override
|
||||
public int getHitPoints() {
|
||||
return hp;
|
||||
}
|
||||
}
|
142
core/src/zero1hd/polyjet/maps/KeyMap.java
Executable file
142
core/src/zero1hd/polyjet/maps/KeyMap.java
Executable file
@@ -0,0 +1,142 @@
|
||||
package zero1hd.polyjet.maps;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
|
||||
public class KeyMap {
|
||||
TextureAtlas keyTextures;
|
||||
private Preferences keyBindPrefs;
|
||||
|
||||
public static final String UP = "up";
|
||||
public static final String DOWN = "down";
|
||||
public static final String LEFT = "left";
|
||||
public static final String RIGHT = "right";
|
||||
|
||||
public static final String SHOOT = "shoot";
|
||||
|
||||
public static final String FIRSTTHIRDTELEPORT = "firstThirdTP";
|
||||
public static final String SECONDTHIRDTELEPORT = "secondThirdTP";
|
||||
public static final String THIRDTHIRDTELEPORT = "thirdThirdTP";
|
||||
|
||||
/**
|
||||
* forward binding.
|
||||
*/
|
||||
public static int up;
|
||||
/**
|
||||
* backward binding.
|
||||
*/
|
||||
public static int down;
|
||||
/**
|
||||
* left binding.
|
||||
*/
|
||||
public static int left;
|
||||
/**
|
||||
* right binding.
|
||||
*/
|
||||
public static int right;
|
||||
/**
|
||||
* shoot binding
|
||||
*/
|
||||
public static int shoot;
|
||||
/**
|
||||
* teleport first third binding
|
||||
*/
|
||||
public static int firstThirdTeleport;
|
||||
/**
|
||||
* teleport second third binding
|
||||
*/
|
||||
public static int secondThirdTeleport;
|
||||
/**
|
||||
* teleport third third binding
|
||||
*/
|
||||
public static int thirdThirdTeleport;
|
||||
|
||||
|
||||
public KeyMap(Polyjet core) {
|
||||
keyTextures = core.assetManager.get("keyboard.atlas", TextureAtlas.class);
|
||||
|
||||
setKeys(Gdx.app.getPreferences("PolyJet_Controls"));
|
||||
updateKeys();
|
||||
}
|
||||
|
||||
public Preferences getKeys() {
|
||||
return keyBindPrefs;
|
||||
}
|
||||
|
||||
public void setKeys(Preferences keys) {
|
||||
this.keyBindPrefs = keys;
|
||||
}
|
||||
|
||||
public TextureRegion getIcon(int keycode) {
|
||||
// Gdx.app.debug("Keycode texture name", Keys.toString(keycode));
|
||||
|
||||
switch (keycode) {
|
||||
case Keys.ALT_LEFT:
|
||||
case Keys.ALT_RIGHT:
|
||||
return keyTextures.findRegion("Keyboard_Black_Alt");
|
||||
case Keys.SHIFT_LEFT:
|
||||
case Keys.SHIFT_RIGHT:
|
||||
return keyTextures.findRegion("Keyboard_Black_Shift");
|
||||
case Keys.LEFT_BRACKET:
|
||||
return keyTextures.findRegion("Keyboard_Black_Bracket_Left");
|
||||
case Keys.RIGHT_BRACKET:
|
||||
return keyTextures.findRegion("Keyboard_Black_Bracket_Right");
|
||||
case Keys.SEMICOLON:
|
||||
return keyTextures.findRegion("Keyboard_Black_Semicolon");
|
||||
case Keys.SLASH:
|
||||
return keyTextures.findRegion("Keyboard_Black_Slash");
|
||||
case Keys.NUM:
|
||||
return keyTextures.findRegion("Keyboard_Black_Num_Lock");
|
||||
default:
|
||||
return keyTextures.findRegion("Keyboard_Black_" + Keys.toString(keycode).replace(' ', '_'));
|
||||
}
|
||||
}
|
||||
|
||||
public void updateKeys() {
|
||||
up = keyBindPrefs.getInteger(KeyMap.UP, Keys.UP);
|
||||
down = keyBindPrefs.getInteger(KeyMap.DOWN, Keys.DOWN);
|
||||
left = keyBindPrefs.getInteger(KeyMap.LEFT, Keys.LEFT);
|
||||
right = keyBindPrefs.getInteger(KeyMap.RIGHT, Keys.RIGHT);
|
||||
|
||||
shoot = keyBindPrefs.getInteger(KeyMap.SHOOT, Keys.SPACE);
|
||||
|
||||
firstThirdTeleport = keyBindPrefs.getInteger(KeyMap.FIRSTTHIRDTELEPORT, Keys.Q);
|
||||
secondThirdTeleport = keyBindPrefs.getInteger(KeyMap.SECONDTHIRDTELEPORT, Keys.W);
|
||||
thirdThirdTeleport = keyBindPrefs.getInteger(KeyMap.THIRDTHIRDTELEPORT, Keys.E);
|
||||
}
|
||||
|
||||
/**
|
||||
* resets all binding to default;
|
||||
*/
|
||||
public void resetAllBinding() {
|
||||
keyBindPrefs.clear();
|
||||
keyBindPrefs.flush();
|
||||
}
|
||||
|
||||
public int stringToID(String control) {
|
||||
if (control == KeyMap.UP) {
|
||||
return KeyMap.up;
|
||||
} else if (control == KeyMap.DOWN) {
|
||||
return KeyMap.down;
|
||||
} else if (control == KeyMap.LEFT) {
|
||||
return KeyMap.left;
|
||||
} else if (control == KeyMap.RIGHT) {
|
||||
return KeyMap.right;
|
||||
} else if (control == KeyMap.SHOOT) {
|
||||
return KeyMap.shoot;
|
||||
} else if (control == KeyMap.FIRSTTHIRDTELEPORT) {
|
||||
return KeyMap.firstThirdTeleport;
|
||||
} else if (control == KeyMap.SECONDTHIRDTELEPORT) {
|
||||
return KeyMap.secondThirdTeleport;
|
||||
} else if (control == KeyMap.THIRDTHIRDTELEPORT) {
|
||||
return KeyMap.thirdThirdTeleport;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
40
core/src/zero1hd/polyjet/maps/RhythmMap.java
Executable file
40
core/src/zero1hd/polyjet/maps/RhythmMap.java
Executable file
@@ -0,0 +1,40 @@
|
||||
package zero1hd.polyjet.maps;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
import zero1hd.polyjet.audio.AudioAnalyzer;
|
||||
|
||||
public class RhythmMap {
|
||||
private boolean done;
|
||||
public Thread generator;
|
||||
public GenerationAlgorithm generationAlgorithm;
|
||||
int window = 0;
|
||||
public AudioAnalyzer analyzer;
|
||||
|
||||
public RhythmMap(AudioAnalyzer analyzer) {
|
||||
this.analyzer = analyzer;
|
||||
generationAlgorithm = new GenerationAlgorithm();
|
||||
}
|
||||
|
||||
public void generateMapData(int difficulty) {
|
||||
generationAlgorithm.setDifficulty(difficulty);
|
||||
generator = new Thread(generationAlgorithm);
|
||||
generator.start();
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
return done;
|
||||
}
|
||||
|
||||
private class GenerationAlgorithm implements Runnable {
|
||||
private int difficulty;
|
||||
@Override
|
||||
public void run() {
|
||||
Gdx.app.debug("Difficulty", String.valueOf(difficulty));
|
||||
}
|
||||
|
||||
public void setDifficulty(int difficulty) {
|
||||
this.difficulty = difficulty;
|
||||
}
|
||||
}
|
||||
}
|
50
core/src/zero1hd/polyjet/screens/CreativeDebugScreen.java
Executable file
50
core/src/zero1hd/polyjet/screens/CreativeDebugScreen.java
Executable file
@@ -0,0 +1,50 @@
|
||||
package zero1hd.polyjet.screens;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.InputMultiplexer;
|
||||
import com.badlogic.gdx.ScreenAdapter;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.ui.stages.CreativeStage;
|
||||
import zero1hd.polyjet.ui.stages.GamePlayArea;
|
||||
|
||||
public class CreativeDebugScreen extends ScreenAdapter {
|
||||
CreativeStage creative;
|
||||
GamePlayArea gamePlayArea;
|
||||
InputMultiplexer inputs;
|
||||
|
||||
|
||||
public CreativeDebugScreen(Polyjet core) {
|
||||
creative = new CreativeStage(core);
|
||||
gamePlayArea = new GamePlayArea(core);
|
||||
inputs = new InputMultiplexer(creative, gamePlayArea);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
Gdx.input.setInputProcessor(inputs);
|
||||
super.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
|
||||
gamePlayArea.getViewport().apply();
|
||||
gamePlayArea.act();
|
||||
gamePlayArea.draw();
|
||||
|
||||
creative.getViewport().apply();
|
||||
creative.act();
|
||||
creative.draw();
|
||||
super.render(delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
// TODO Auto-generated method stub
|
||||
super.resize(width, height);
|
||||
}
|
||||
}
|
260
core/src/zero1hd/polyjet/screens/GameScreen.java
Executable file
260
core/src/zero1hd/polyjet/screens/GameScreen.java
Executable file
@@ -0,0 +1,260 @@
|
||||
package zero1hd.polyjet.screens;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.InputMultiplexer;
|
||||
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.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.audio.AudioData;
|
||||
import zero1hd.polyjet.maps.RhythmMap;
|
||||
import zero1hd.polyjet.ui.stages.GamePlayArea;
|
||||
import zero1hd.polyjet.ui.windows.FPSWindow;
|
||||
|
||||
public class GameScreen extends ScreenAdapter implements InputProcessor {
|
||||
private GamePlayArea gameArea;
|
||||
public InputMultiplexer inputs;
|
||||
|
||||
public boolean paused = false;
|
||||
private boolean debug = false;
|
||||
|
||||
public Polyjet core;
|
||||
public Stage overlay;
|
||||
private Label scoreLabel;
|
||||
Window pauseMenu;
|
||||
FPSWindow FPSDisplay;
|
||||
|
||||
private AudioData music;
|
||||
|
||||
public GameScreen(Polyjet polyJet) {
|
||||
core = polyJet;
|
||||
|
||||
// Overlay stuff
|
||||
overlay = new Stage();
|
||||
scoreLabel = new Label("Score: 0", core.defaultSkin, "default-font", Color.WHITE);
|
||||
scoreLabel.setPosition(25, Gdx.graphics.getHeight() - scoreLabel.getHeight() - 25);
|
||||
|
||||
ImageButton pause = new ImageButton(core.defaultSkin.getDrawable("pause"),
|
||||
core.defaultSkin.getDrawable("pause-down"));
|
||||
pause.setPosition(Gdx.graphics.getWidth() - pause.getWidth() - 25,
|
||||
Gdx.graphics.getHeight() - pause.getHeight() - 25);
|
||||
pause.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
pause();
|
||||
}
|
||||
});
|
||||
|
||||
WidgetGroup healthBar = new WidgetGroup();
|
||||
final Image healthBarTank = new Image(core.defaultSkin.getPatch("bar-empty"));
|
||||
healthBarTank.setHeight(100);
|
||||
healthBar.setSize(healthBarTank.getWidth(), healthBarTank.getHeight());
|
||||
healthBar.setPosition(Gdx.graphics.getWidth() - healthBar.getWidth() - 16,
|
||||
pause.getY() - healthBar.getHeight() - 32);
|
||||
|
||||
Image healthBarFiller = new Image(core.defaultSkin.getPatch("bar-fill")) {
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
setHeight(
|
||||
((float) gameArea.getHealth() / (float) gameArea.getMaxHealth()) * (healthBarTank.getHeight()));
|
||||
super.act(delta);
|
||||
}
|
||||
};
|
||||
healthBar.addActor(healthBarFiller);
|
||||
healthBar.addActor(healthBarTank);
|
||||
overlay.addActor(healthBar);
|
||||
|
||||
FPSDisplay = new FPSWindow("FPS", core.defaultSkin);
|
||||
overlay.addActor(pause);
|
||||
overlay.addActor(scoreLabel);
|
||||
|
||||
// Pause menu
|
||||
pauseMenu = new Window("Paused", core.defaultSkin);
|
||||
pauseMenu.add(new TextButton("resume", core.defaultSkin) {
|
||||
{
|
||||
addListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
recommence();
|
||||
}
|
||||
});
|
||||
}
|
||||
}).space(20f);
|
||||
pauseMenu.setModal(true);
|
||||
pauseMenu.setPosition((Gdx.graphics.getWidth() - pauseMenu.getWidth()) / 2,
|
||||
(Gdx.graphics.getHeight() - pauseMenu.getHeight()) / 2);
|
||||
|
||||
// Continue to add things to input multiplexer
|
||||
gameArea = new GamePlayArea(core);
|
||||
|
||||
inputs = new InputMultiplexer();
|
||||
inputs.addProcessor(this);
|
||||
inputs.addProcessor(overlay);
|
||||
inputs.addProcessor(gameArea);
|
||||
|
||||
if (!paused) {
|
||||
music.getPlaybackMusic().play();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMap (RhythmMap map) {
|
||||
this.music = map.analyzer.audiofile;
|
||||
gameArea.setMap(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
Gdx.input.setInputProcessor(inputs);
|
||||
super.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
gameArea.getViewport().apply();
|
||||
gameArea.draw();
|
||||
|
||||
overlay.getViewport().apply();
|
||||
overlay.draw();
|
||||
if (!paused) {
|
||||
music.readIndexUpdate();
|
||||
gameArea.setAudioIndex(music.getReadIndex());
|
||||
scoreLabel.setText("Score: " + gameArea.getScore());
|
||||
gameArea.act(delta);
|
||||
|
||||
if (gameArea.getHealth() == 0) {
|
||||
end(false);
|
||||
}
|
||||
|
||||
overlay.act(delta);
|
||||
} else {
|
||||
}
|
||||
|
||||
if (!music.getPlaybackMusic().isPlaying()) {
|
||||
end(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void end(boolean trueEnd) {
|
||||
if (trueEnd) {
|
||||
// TODO they didn't die
|
||||
} else {
|
||||
// TODO They done goofed and ended up dying.
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
overlay.dispose();
|
||||
gameArea.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
gameArea.getViewport().update(width, height, true);
|
||||
overlay.getViewport().update(width, height, true);
|
||||
|
||||
super.resize(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
paused = true;
|
||||
overlay.addActor(pauseMenu);
|
||||
music.getPlaybackMusic().pause();
|
||||
super.pause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
super.resume();
|
||||
}
|
||||
|
||||
public void recommence() {
|
||||
paused = false;
|
||||
pauseMenu.remove();
|
||||
music.getPlaybackMusic().play();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyUp(int keycode) {
|
||||
switch (keycode) {
|
||||
case Keys.F3:
|
||||
if (debug) {
|
||||
debug = false;
|
||||
for (int i = 0; i < gameArea.getActors().size; i++) {
|
||||
gameArea.setDebugAll(debug);
|
||||
}
|
||||
FPSDisplay.remove();
|
||||
} else {
|
||||
debug = true;
|
||||
for (int i = 0; i < gameArea.getActors().size; i++) {
|
||||
gameArea.setDebugAll(debug);
|
||||
}
|
||||
overlay.addActor(FPSDisplay);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case Keys.ESCAPE:
|
||||
if (paused) {
|
||||
recommence();
|
||||
} else {
|
||||
pause();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(char character) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseMoved(int screenX, int screenY) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean scrolled(int amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyDown(int keycode) {
|
||||
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;
|
||||
}
|
||||
}
|
77
core/src/zero1hd/polyjet/screens/LoadingScreen.java
Executable file
77
core/src/zero1hd/polyjet/screens/LoadingScreen.java
Executable file
@@ -0,0 +1,77 @@
|
||||
package zero1hd.polyjet.screens;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.ScreenAdapter;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.TransitionAdapter;
|
||||
|
||||
public class LoadingScreen extends ScreenAdapter {
|
||||
private Stage stage;
|
||||
Polyjet core;
|
||||
Image zero1HD;
|
||||
Screen gotoScreen;
|
||||
boolean reInit;
|
||||
|
||||
public LoadingScreen(Polyjet core, Screen gotoScreen, boolean reInit, boolean timer) {
|
||||
this.core = core;
|
||||
this.gotoScreen = gotoScreen;
|
||||
this.reInit = reInit;
|
||||
|
||||
stage = new Stage(new ScreenViewport());
|
||||
core.assetManager.load("splashlogo.png", Texture.class);
|
||||
core.assetManager.finishLoading();
|
||||
zero1HD = new Image(this.core.assetManager.get("splashlogo.png", Texture.class));
|
||||
|
||||
zero1HD.setColor(0f,1f,1f,0f);
|
||||
stage.addActor(zero1HD);
|
||||
|
||||
zero1HD.setPosition(stage.getWidth()/2 - zero1HD.getWidth()/2, stage.getHeight()/2 - zero1HD.getHeight()/2);
|
||||
if (timer) {
|
||||
zero1HD.addAction(Actions.sequence(Actions.color(Color.WHITE, 1f)));
|
||||
}
|
||||
|
||||
core.queueAssets();
|
||||
}
|
||||
|
||||
float count = 0;
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
stage.act(delta);
|
||||
|
||||
if (!zero1HD.hasActions() & core.assetManager.update()) {
|
||||
Gdx.app.debug("Loading Screen", "queue has all been loaded. Action is done playing.");
|
||||
zero1HD.remove();
|
||||
|
||||
core.generateFonts();
|
||||
core.defineSkinStyles();
|
||||
|
||||
if (reInit) {
|
||||
((TransitionAdapter) gotoScreen).postTransition();
|
||||
}
|
||||
|
||||
core.setScreen(gotoScreen);
|
||||
core.assetManager.unload("splashlogo.png");
|
||||
core.assetManager.get("standard_thrust.p", ParticleEffect.class).flipY();
|
||||
}
|
||||
|
||||
stage.draw();
|
||||
super.render(delta);
|
||||
}
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
stage.getViewport().update(width, height, true);
|
||||
super.resize(width, height);
|
||||
}
|
||||
}
|
122
core/src/zero1hd/polyjet/screens/MainMenu.java
Executable file
122
core/src/zero1hd/polyjet/screens/MainMenu.java
Executable file
@@ -0,0 +1,122 @@
|
||||
package zero1hd.polyjet.screens;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.ScreenAdapter;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.TransitionAdapter;
|
||||
import zero1hd.polyjet.ui.CreditsPage;
|
||||
import zero1hd.polyjet.ui.MainPage;
|
||||
import zero1hd.polyjet.ui.MoreOptionsPage;
|
||||
import zero1hd.polyjet.ui.OptionsPage;
|
||||
|
||||
|
||||
|
||||
public class MainMenu extends ScreenAdapter implements TransitionAdapter {
|
||||
public Stage stage;
|
||||
private Vector3 targetPosition;
|
||||
|
||||
private MainPage mainPage;
|
||||
private OptionsPage optionsPage;
|
||||
private CreditsPage creditsPage;
|
||||
private MoreOptionsPage moreOptionsPage;
|
||||
|
||||
Polyjet core;
|
||||
public MainMenu(final Polyjet core) {
|
||||
this.core = core;
|
||||
stage = new Stage(new ScreenViewport());
|
||||
targetPosition = new Vector3(stage.getCamera().position);
|
||||
}
|
||||
|
||||
public void postTransition() {
|
||||
stage.clear();
|
||||
|
||||
mainPage = new MainPage(core, targetPosition);
|
||||
mainPage.setPosition(0, 0);
|
||||
stage.addActor(mainPage);
|
||||
|
||||
//End main menu
|
||||
moreOptionsPage = new MoreOptionsPage(core, targetPosition);
|
||||
|
||||
optionsPage = new OptionsPage(core, targetPosition, moreOptionsPage);
|
||||
optionsPage.setPosition(Gdx.graphics.getWidth(), 0);
|
||||
stage.addActor(optionsPage);
|
||||
|
||||
creditsPage = new CreditsPage(core.defaultSkin);
|
||||
creditsPage.setPosition(0, Gdx.graphics.getHeight());
|
||||
stage.addActor(creditsPage);
|
||||
|
||||
moreOptionsPage.setPosition(1f*Gdx.graphics.getWidth(), -1f*Gdx.graphics.getHeight());
|
||||
stage.addActor(moreOptionsPage);
|
||||
|
||||
stage.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean keyUp(InputEvent event, int keycode) {
|
||||
if (keycode == Keys.ESCAPE) {
|
||||
stage.unfocusAll();
|
||||
if (targetPosition.x != 0.5f*Gdx.graphics.getWidth() || targetPosition.y != 0.5f*Gdx.graphics.getHeight()) {
|
||||
targetPosition.x = 0.5f*Gdx.graphics.getWidth();
|
||||
targetPosition.y = 0.5f*Gdx.graphics.getHeight();
|
||||
}
|
||||
moreOptionsPage.controlUnselect();
|
||||
optionsPage.saveOptions(core.prefs);
|
||||
}
|
||||
return super.keyUp(event, keycode);
|
||||
}
|
||||
});
|
||||
|
||||
stage.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
if (stage.hit(x, y, true) == null) {
|
||||
stage.unfocusAll();
|
||||
moreOptionsPage.controlUnselect();
|
||||
}
|
||||
super.clicked(event, x, y);
|
||||
}
|
||||
});
|
||||
|
||||
Gdx.app.debug("Post Transition", "Beginning screen setup for Mainmenu.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
super.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
stage.act();
|
||||
stage.draw();
|
||||
if (stage.getCamera().position.x != targetPosition.x || stage.getCamera().position.y != targetPosition.y) {
|
||||
stage.getCamera().position.lerp(targetPosition, 0.25f);
|
||||
}
|
||||
|
||||
super.render(delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
stage.getViewport().update(width, height, false);
|
||||
targetPosition.x = width/2;
|
||||
targetPosition.y = height/2;
|
||||
super.resize(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
stage.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
158
core/src/zero1hd/polyjet/screens/PreGameScreen.java
Executable file
158
core/src/zero1hd/polyjet/screens/PreGameScreen.java
Executable file
@@ -0,0 +1,158 @@
|
||||
package zero1hd.polyjet.screens;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.ScreenAdapter;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.TransitionAdapter;
|
||||
import zero1hd.polyjet.audio.AudioAnalyzer;
|
||||
import zero1hd.polyjet.audio.WavAudioData;
|
||||
import zero1hd.polyjet.maps.RhythmMap;
|
||||
|
||||
|
||||
public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
|
||||
byte phase = 0;
|
||||
Polyjet core;
|
||||
Stage stage;
|
||||
Label statusText;
|
||||
|
||||
AudioAnalyzer analyzer;
|
||||
WavAudioData audiofile;
|
||||
RhythmMap rhythmMap;
|
||||
Vector3 cameraTarget;
|
||||
|
||||
Label lastStatement;
|
||||
|
||||
public PreGameScreen(final Polyjet core) {
|
||||
this.core = core;
|
||||
analyzer = new AudioAnalyzer();
|
||||
rhythmMap = new RhythmMap(analyzer);
|
||||
|
||||
stage = new Stage();
|
||||
|
||||
stage.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
if (phase == 4) {
|
||||
if (core.gameScreen != null) {
|
||||
core.setScreen(core.gameScreen);
|
||||
} else {
|
||||
core.setScreen((core.gameScreen = new GameScreen(core)));
|
||||
}
|
||||
}
|
||||
super.clicked(event, x, y);
|
||||
}
|
||||
});
|
||||
|
||||
cameraTarget = new Vector3(stage.getCamera().position);
|
||||
postTransition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postTransition() {
|
||||
stage.clear();
|
||||
//draw music selector
|
||||
|
||||
statusText = new Label(null, core.defaultSkin);
|
||||
statusText.setPosition(1.6f*Gdx.graphics.getWidth(), (Gdx.graphics.getHeight()-statusText.getHeight())/2);
|
||||
Image cyberCircle1 = new Image(core.assetManager.get("cybercircle3B.png", Texture.class));
|
||||
cyberCircle1.setScale(0.7f);
|
||||
cyberCircle1.setOrigin(cyberCircle1.getWidth()/2, cyberCircle1.getHeight()/2);
|
||||
cyberCircle1.setColor(0.8f,0.8f,0.8f,0.7f);
|
||||
cyberCircle1.addAction(Actions.forever(Actions.rotateBy(-360f, 10f)));
|
||||
cyberCircle1.setPosition(Gdx.graphics.getWidth()-cyberCircle1.getWidth()/2-10, -cyberCircle1.getHeight()*2/4f);
|
||||
stage.addActor(cyberCircle1);
|
||||
|
||||
Image cyberCircle2 = new Image(core.assetManager.get("cybercircle1.png", Texture.class));
|
||||
cyberCircle2.setPosition(1.5f*Gdx.graphics.getWidth()-cyberCircle2.getWidth()/2+20, (Gdx.graphics.getHeight()-cyberCircle2.getHeight())/2);
|
||||
cyberCircle2.setColor(0.8f,0.8f,0.8f,0.7f);
|
||||
cyberCircle2.addAction(Actions.alpha(0.7f));
|
||||
stage.addActor(cyberCircle2);
|
||||
stage.addActor(statusText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
stage.getViewport().apply();
|
||||
stage.act();
|
||||
stage.draw();
|
||||
switch (phase) {
|
||||
case 0:
|
||||
|
||||
break;
|
||||
case 1:
|
||||
if (stage.getCamera().position.x != cameraTarget.x) {
|
||||
stage.getCamera().position.lerp(cameraTarget, 0.25f);
|
||||
}
|
||||
if (analyzer.containsData()) {
|
||||
phase++;
|
||||
statusText.setText("Mapping beats");
|
||||
//TODO MAP GENERATION
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
//finish map generation
|
||||
if (true) {
|
||||
statusText.setText("Loading assets");
|
||||
statusText.setPosition(1.5f*Gdx.graphics.getWidth(), (Gdx.graphics.getHeight()-statusText.getHeight())/2);
|
||||
|
||||
//list of assets needed for game screen exclusively
|
||||
Gdx.app.debug("PreGameScreen Phase", String.valueOf(phase));
|
||||
phase++;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
//Resource loading...
|
||||
if (core.assetManager.update()) {
|
||||
Gdx.app.debug("PreGameScreen Phase", String.valueOf(phase));
|
||||
phase++;
|
||||
Gdx.app.debug("PreGameScreen Phase", String.valueOf(phase));
|
||||
cameraTarget.x = 2.5f*Gdx.graphics.getWidth();
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (stage.getCamera().position.x != cameraTarget.x) {
|
||||
stage.getCamera().position.lerp(cameraTarget, 0.25f);
|
||||
}
|
||||
|
||||
if (lastStatement == null) {
|
||||
lastStatement = new Label("Are you ready?", core.defaultSkin);
|
||||
lastStatement.setPosition(2.5f*Gdx.graphics.getWidth()-lastStatement.getWidth()/2, (Gdx.graphics.getHeight()-lastStatement.getHeight())/2);
|
||||
stage.addActor(lastStatement);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
super.render(delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
analyzer.resetVars();
|
||||
super.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
stage.getViewport().update(width, height);
|
||||
super.resize(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
stage.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
26
core/src/zero1hd/polyjet/ui/CreditsPage.java
Executable file
26
core/src/zero1hd/polyjet/ui/CreditsPage.java
Executable file
@@ -0,0 +1,26 @@
|
||||
package zero1hd.polyjet.ui;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
|
||||
public class CreditsPage extends Page {
|
||||
|
||||
public CreditsPage(Skin skin) {
|
||||
Label title = new Label("Credits", skin, "large-font", skin.getColor("default"));
|
||||
title.setPosition(15, getHeight()-title.getHeight()-15);
|
||||
addActor(title);
|
||||
|
||||
Label subtitle = new Label("This game wouldn't be possible without these people.", skin, "small-font", skin.getColor("default"));
|
||||
subtitle.setPosition(title.getX(), title.getY()-subtitle.getHeight());
|
||||
addActor(subtitle);
|
||||
|
||||
Label listOfNames = new Label(
|
||||
"TheClimbingHippo (texture)\n"
|
||||
+ "Crepitus (sound effects)\n"
|
||||
+ "Neoqueto - Darktech LDR (font)\n"
|
||||
+ "Rémi Lagast - Gasalt (font)\n"
|
||||
+ "Timour Jgenti - Iron Maiden (font)", skin, "small-font", skin.getColor("default"));
|
||||
listOfNames.setPosition(subtitle.getX()+16, subtitle.getY()-listOfNames.getHeight()-10);
|
||||
addActor(listOfNames);
|
||||
}
|
||||
}
|
118
core/src/zero1hd/polyjet/ui/MainPage.java
Executable file
118
core/src/zero1hd/polyjet/ui/MainPage.java
Executable file
@@ -0,0 +1,118 @@
|
||||
package zero1hd.polyjet.ui;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.screens.PreGameScreen;
|
||||
|
||||
public class MainPage extends Page {
|
||||
private Image polyjetTitle;
|
||||
private Label polyJetVersion;
|
||||
private TextButton options;
|
||||
private Image cyberCircle;
|
||||
private Label begin;
|
||||
private TextButton quit;
|
||||
private TextButton credits;
|
||||
private WidgetGroup playButton;
|
||||
|
||||
public MainPage(final Polyjet core, final Vector3 targetPosition) {
|
||||
polyjetTitle = new Image(core.assetManager.get("PolyjetTitle.png", Texture.class));
|
||||
polyjetTitle.setPosition(15, getHeight() - polyjetTitle.getHeight()-15);
|
||||
addActor(polyjetTitle);
|
||||
polyJetVersion = new Label("Version: " + Polyjet.VERSION, core.defaultSkin, "small-font",
|
||||
core.defaultSkin.getColor("default"));
|
||||
polyJetVersion.setPosition(3, 3);
|
||||
addActor(polyJetVersion);
|
||||
|
||||
options = new TextButton(" Options ", core.defaultSkin, "left");
|
||||
options.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
// TODO Options screen
|
||||
targetPosition.x = 1.5f * getWidth();
|
||||
}
|
||||
});
|
||||
options.setPosition(-options.getWidth(), polyjetTitle.getY() - options.getHeight() - 30);
|
||||
options.addAction(Actions.sequence(Actions.delay(0.25f), Actions.moveTo(0, options.getY(), 0.5f)));
|
||||
addActor(options);
|
||||
|
||||
credits = new TextButton(" Credits ", core.defaultSkin, "left");
|
||||
credits.addListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
targetPosition.y = 1.5f * getHeight();
|
||||
}
|
||||
});
|
||||
credits.setPosition(-credits.getWidth(), options.getY() - credits.getHeight() - 10);
|
||||
credits.addAction(Actions.sequence(Actions.delay(0.5f), Actions.moveTo(0, credits.getY(), 0.5f)));
|
||||
addActor(credits);
|
||||
|
||||
quit = new TextButton(" Quit ", core.defaultSkin, "left");
|
||||
quit.setPosition(-quit.getWidth(), credits.getY() - credits.getHeight() - 10);
|
||||
quit.addListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
Gdx.app.exit();
|
||||
}
|
||||
|
||||
});
|
||||
quit.addAction(Actions.sequence(Actions.delay(0.75f), Actions.moveTo(0, quit.getY(), 0.5f)));
|
||||
addActor(quit);
|
||||
|
||||
// begin play button
|
||||
playButton = new WidgetGroup();
|
||||
|
||||
cyberCircle = new Image(core.assetManager.get("Tech-Circle1.png", Texture.class));
|
||||
cyberCircle.setOrigin(cyberCircle.getWidth() / 2, cyberCircle.getHeight() / 2);
|
||||
cyberCircle.setColor(0.7f, 0.7f, 0.7f, 0.8f);
|
||||
cyberCircle.addAction(Actions.forever(Actions.rotateBy(-360f, 10f)));
|
||||
playButton.addActor(cyberCircle);
|
||||
playButton.setSize(cyberCircle.getWidth(), cyberCircle.getHeight());
|
||||
|
||||
begin = new Label("Play", core.defaultSkin, "special-font", core.defaultSkin.getColor("default"));
|
||||
begin.setColor(1f, 1f, 1f, 1f);
|
||||
playButton.addActor(begin);
|
||||
begin.setPosition(((playButton.getWidth() - begin.getWidth()) / 2)-10,
|
||||
(playButton.getHeight() - begin.getHeight()) / 2);
|
||||
playButton.setPosition(getWidth() - cyberCircle.getWidth() * 3 / 4, -cyberCircle.getHeight() / 4);
|
||||
|
||||
// begin animation of begin button
|
||||
playButton.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
if (targetPosition.x == 0.5f * getWidth()) {
|
||||
cyberCircle.addAction(
|
||||
Actions.sequence(Actions.parallel(Actions.scaleBy(2f, 2f, 0.25f), Actions.fadeOut(0.25f)),
|
||||
Actions.run(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (core.preGameScreen != null) {
|
||||
core.setScreen(core.preGameScreen);
|
||||
} else {
|
||||
core.setScreen(core.preGameScreen = new PreGameScreen(core));
|
||||
}
|
||||
}
|
||||
}), Actions.parallel(Actions.scaleTo(1, 1), Actions.alpha(0.6f))));
|
||||
}
|
||||
super.clicked(event, x, y);
|
||||
}
|
||||
});
|
||||
addActor(playButton);
|
||||
// end play button
|
||||
}
|
||||
|
||||
}
|
64
core/src/zero1hd/polyjet/ui/MoreOptionsPage.java
Executable file
64
core/src/zero1hd/polyjet/ui/MoreOptionsPage.java
Executable file
@@ -0,0 +1,64 @@
|
||||
package zero1hd.polyjet.ui;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.maps.KeyMap;
|
||||
import zero1hd.polyjet.ui.builders.ArrowButton;
|
||||
import zero1hd.polyjet.ui.builders.GraphicsTable;
|
||||
import zero1hd.polyjet.ui.builders.SetControls;
|
||||
|
||||
public class MoreOptionsPage extends Page {
|
||||
private KeyMap keymap;
|
||||
private ScrollPane keyBinds;
|
||||
private GraphicsTable graphicsSettings;
|
||||
private SetControls controlSetter;
|
||||
|
||||
public MoreOptionsPage(Polyjet core, final Vector3 targetLocation) {
|
||||
keymap = new KeyMap(core);
|
||||
|
||||
controlSetter = new SetControls(core.defaultSkin, keymap);
|
||||
keyBinds = new ScrollPane(controlSetter, core.defaultSkin);
|
||||
keyBinds.setSize(getWidth(), getHeight());
|
||||
addActor(keyBinds);
|
||||
keyBinds.setVisible(false);
|
||||
|
||||
graphicsSettings = new GraphicsTable(core.defaultSkin, core.prefs);
|
||||
graphicsSettings.setSize(getWidth(), getHeight());
|
||||
addActor(graphicsSettings);
|
||||
graphicsSettings.setVisible(false);
|
||||
|
||||
ArrowButton backArrow = new ArrowButton(core.defaultSkin);
|
||||
backArrow.setRotation(90f);
|
||||
backArrow.setPosition(30, getHeight()-backArrow.getHeight()-10);
|
||||
backArrow.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
targetLocation.y = 0.5f*Gdx.graphics.getHeight();
|
||||
super.clicked(event, x, y);
|
||||
}
|
||||
});
|
||||
addActor(backArrow);
|
||||
}
|
||||
|
||||
public void controlUnselect() {
|
||||
controlSetter.unselect();
|
||||
}
|
||||
|
||||
public void setControlType(byte type) {
|
||||
switch (type) {
|
||||
case 0:
|
||||
keyBinds.setVisible(true);
|
||||
graphicsSettings.setVisible(false);
|
||||
break;
|
||||
case 1:
|
||||
keyBinds.setVisible(false);
|
||||
graphicsSettings.setVisible(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
7
core/src/zero1hd/polyjet/ui/MusicSelectionPage.java
Executable file
7
core/src/zero1hd/polyjet/ui/MusicSelectionPage.java
Executable file
@@ -0,0 +1,7 @@
|
||||
package zero1hd.polyjet.ui;
|
||||
|
||||
public class MusicSelectionPage extends Page {
|
||||
public MusicSelectionPage() {
|
||||
|
||||
}
|
||||
}
|
176
core/src/zero1hd/polyjet/ui/OptionsPage.java
Executable file
176
core/src/zero1hd/polyjet/ui/OptionsPage.java
Executable file
@@ -0,0 +1,176 @@
|
||||
package zero1hd.polyjet.ui;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ProgressBar;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.screens.CreativeDebugScreen;
|
||||
import zero1hd.polyjet.ui.builders.ArrowButton;
|
||||
|
||||
public class OptionsPage extends Page {
|
||||
Table optionsTable = new Table();
|
||||
private ProgressBar musicVolSlider;
|
||||
private ProgressBar fxVolSlider;
|
||||
private TextField directoryField;
|
||||
private Polyjet core;
|
||||
|
||||
private byte goToScreen;
|
||||
private ArrowButton backSymbol;
|
||||
public OptionsPage(final Polyjet core, final Vector3 targetPosition, final MoreOptionsPage moreOptionsPage) {
|
||||
this.core = core;
|
||||
optionsTable.defaults().padTop(5f).padBottom(5f);
|
||||
|
||||
Label optionGeneralTitle = new Label("General", core.defaultSkin, "large-font", core.defaultSkin.getColor("default"));
|
||||
optionsTable.add(optionGeneralTitle).left().spaceBottom(10f);
|
||||
|
||||
optionsTable.row();
|
||||
|
||||
Label musicVolSliderLabel = new Label("Music Volume: ", core.defaultSkin);
|
||||
optionsTable.add(musicVolSliderLabel).left();
|
||||
musicVolSlider = new Slider(0, 100, 0.1f, false, core.defaultSkin);
|
||||
musicVolSlider.setValue(core.prefs.getFloat("music vol", 100f));
|
||||
optionsTable.add(musicVolSlider).prefWidth(790);
|
||||
final Label musicVolPercentage = new Label(MathUtils.round(musicVolSlider.getValue()) + "%", core.defaultSkin);
|
||||
musicVolSlider.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
saveOptions(core.prefs);
|
||||
musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%");
|
||||
}
|
||||
});
|
||||
optionsTable.add(musicVolPercentage).spaceLeft(12f).left();
|
||||
|
||||
optionsTable.row();
|
||||
|
||||
Label fxVolSliderLabel = new Label("FX Volume: ", core.defaultSkin);
|
||||
optionsTable.add(fxVolSliderLabel).left();
|
||||
fxVolSlider = new Slider(0, 100, 1, false, core.defaultSkin);
|
||||
fxVolSlider.setValue(core.prefs.getFloat("fx vol", 100f));
|
||||
optionsTable.add(fxVolSlider).prefWidth(790);
|
||||
final Label fxVolPercentage = new Label(MathUtils.round(fxVolSlider.getValue()) + "%", core.defaultSkin);
|
||||
fxVolSlider.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
saveOptions(core.prefs);
|
||||
fxVolPercentage.setText(MathUtils.round(fxVolSlider.getValue()) + "%");
|
||||
}
|
||||
});
|
||||
|
||||
optionsTable.add(fxVolPercentage).spaceLeft(12f).left();
|
||||
|
||||
optionsTable.row();
|
||||
|
||||
Label musicDirectoryLabel = new Label("Music Directory: ", core.defaultSkin);
|
||||
optionsTable.add(musicDirectoryLabel).left();
|
||||
directoryField = new TextField(null, core.defaultSkin);
|
||||
directoryField.setText(core.prefs.getString("music dir", System.getProperty("user.home")+System.getProperty("file.separator")+"Music"));
|
||||
optionsTable.add(directoryField).prefWidth(810).left();
|
||||
|
||||
optionsTable.row();
|
||||
|
||||
Label debugCodeLabel = new Label("Debug Code: ", core.defaultSkin);
|
||||
optionsTable.add(debugCodeLabel).left();
|
||||
final TextField debugCodeField = new TextField(null, core.defaultSkin);
|
||||
debugCodeField.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean keyUp(InputEvent event, int keycode) {
|
||||
if (keycode == Keys.ENTER) {
|
||||
Gdx.app.debug("Debug Field", debugCodeField.getText());
|
||||
if (debugCodeField.getText().equals("creative")) {
|
||||
saveOptions(core.prefs);
|
||||
Gdx.app.debug("Debug Field", "going to creative test room...");
|
||||
goToScreen = 1;
|
||||
}
|
||||
}
|
||||
return super.keyUp(event, keycode);
|
||||
}
|
||||
});
|
||||
optionsTable.add(debugCodeField).prefWidth(810).left();
|
||||
|
||||
optionsTable.top();
|
||||
|
||||
|
||||
//Back button
|
||||
backSymbol = new ArrowButton(core.defaultSkin);
|
||||
backSymbol.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
targetPosition.x = 0.5f*Gdx.graphics.getWidth();
|
||||
super.clicked(event, x, y);
|
||||
}
|
||||
});
|
||||
backSymbol.setRotation(180);
|
||||
backSymbol.setPosition(10, (getHeight()-backSymbol.getHeight())/2);
|
||||
addActor(backSymbol);
|
||||
|
||||
optionsTable.setPosition(backSymbol.getX()+ 20 + backSymbol.getWidth(), 0);
|
||||
optionsTable.setSize(getWidth()-backSymbol.getWidth()-10-20-10, getHeight());
|
||||
addActor(optionsTable);
|
||||
|
||||
|
||||
ArrowButton keybindSettings = new ArrowButton(core.defaultSkin);
|
||||
keybindSettings.setRotation(270f);
|
||||
keybindSettings.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
moreOptionsPage.setControlType((byte) 0);
|
||||
targetPosition.y = -0.5f*Gdx.graphics.getHeight();
|
||||
super.clicked(event, x, y);
|
||||
}
|
||||
});
|
||||
keybindSettings.setPosition(optionsTable.getWidth()/3, optionsTable.getY());
|
||||
addActor(keybindSettings);
|
||||
Label controlsSection = new Label("Controls", core.defaultSkin);
|
||||
controlsSection.setPosition(keybindSettings.getX()+(keybindSettings.getWidth()-controlsSection.getWidth())/2, keybindSettings.getHeight()+keybindSettings.getY());
|
||||
addActor(controlsSection);
|
||||
|
||||
ArrowButton graphicsSettings = new ArrowButton(core.defaultSkin);
|
||||
graphicsSettings.setRotation(270f);
|
||||
graphicsSettings.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
moreOptionsPage.setControlType((byte) 1);
|
||||
targetPosition.y = -0.5f*Gdx.graphics.getHeight();
|
||||
super.clicked(event, x, y);
|
||||
}
|
||||
});
|
||||
graphicsSettings.setPosition(optionsTable.getWidth()*2/3, optionsTable.getY());
|
||||
addActor(graphicsSettings);
|
||||
Label graphicsSection = new Label("Graphics", core.defaultSkin);
|
||||
graphicsSection.setPosition(graphicsSettings.getX()+(graphicsSettings.getWidth()-graphicsSection.getWidth())/2, graphicsSettings.getHeight()+graphicsSettings.getY());
|
||||
addActor(graphicsSection);
|
||||
}
|
||||
|
||||
public void saveOptions(Preferences prefs) {
|
||||
prefs.putFloat("music vol", musicVolSlider.getValue());
|
||||
prefs.putFloat("fx vol", fxVolSlider.getValue());
|
||||
prefs.putString("music dir", directoryField.getText());
|
||||
prefs.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
if (core.assetManager.update() && goToScreen != 0) {
|
||||
switch (goToScreen) {
|
||||
case 1:
|
||||
core.setScreen(new CreativeDebugScreen(core));
|
||||
}
|
||||
goToScreen = 0;
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
}
|
12
core/src/zero1hd/polyjet/ui/Page.java
Executable file
12
core/src/zero1hd/polyjet/ui/Page.java
Executable file
@@ -0,0 +1,12 @@
|
||||
package zero1hd.polyjet.ui;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.scenes.scene2d.Group;
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable;
|
||||
|
||||
public class Page extends Group {
|
||||
public Page() {
|
||||
setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
setTouchable(Touchable.childrenOnly);
|
||||
}
|
||||
}
|
15
core/src/zero1hd/polyjet/ui/builders/ArrowButton.java
Executable file
15
core/src/zero1hd/polyjet/ui/builders/ArrowButton.java
Executable file
@@ -0,0 +1,15 @@
|
||||
package zero1hd.polyjet.ui.builders;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
|
||||
public class ArrowButton extends Image {
|
||||
public ArrowButton(Skin skin) {
|
||||
super(skin.getDrawable("point-arrow"));
|
||||
setOrigin(getWidth()/2, getHeight()/2);
|
||||
setPosition(10, (getHeight()-getHeight())/2);
|
||||
addAction(Actions.forever(Actions.sequence(Actions.alpha(0.5f, 1.5f), Actions.alpha(1f, 1.5f))));
|
||||
|
||||
}
|
||||
}
|
110
core/src/zero1hd/polyjet/ui/builders/AudioGraph.java
Executable file
110
core/src/zero1hd/polyjet/ui/builders/AudioGraph.java
Executable file
@@ -0,0 +1,110 @@
|
||||
package zero1hd.polyjet.ui.builders;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
|
||||
public class AudioGraph extends Actor {
|
||||
Pixmap audioGraph;
|
||||
Texture textureOfGraph;
|
||||
FloatArray mainGraph;
|
||||
FloatArray overlayGraph;
|
||||
int dataIndex;
|
||||
int displayMode;
|
||||
|
||||
public AudioGraph(int graphSizeW, int graphSizeH) {
|
||||
audioGraph = new Pixmap(graphSizeW, graphSizeH, Format.RGBA8888);
|
||||
audioGraph.setColor(0.1f, 0.1f, 0.1f, 0.75f);
|
||||
audioGraph.fill();
|
||||
|
||||
textureOfGraph = new Texture(audioGraph);
|
||||
setWidth(graphSizeW);
|
||||
setHeight(graphSizeH);
|
||||
}
|
||||
|
||||
public void setAudioDataIndex(int audioDataIndex) {
|
||||
this.dataIndex = audioDataIndex;
|
||||
}
|
||||
|
||||
float scale = 0.2f;
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
audioGraph.setColor(0f, 0f, 0f, 0.75f);
|
||||
audioGraph.fill();
|
||||
|
||||
if (Gdx.input.isKeyPressed(Keys.COMMA)) {
|
||||
if (scale > 0.02) {
|
||||
scale -= 0.005f;
|
||||
}
|
||||
} else if (Gdx.input.isKeyPressed(Keys.PERIOD)) {
|
||||
if (scale < 1.5) {
|
||||
scale += 0.005f;
|
||||
}
|
||||
}
|
||||
if (Gdx.input.isKeyJustPressed(Keys.M)) {
|
||||
displayMode++;
|
||||
if (displayMode != 3) {
|
||||
Gdx.app.debug("Graph", "Switching to another graph.");
|
||||
} else {
|
||||
displayMode = 0;
|
||||
}
|
||||
}
|
||||
switch (displayMode) {
|
||||
case 0:
|
||||
audioGraph.setColor(1f, 0f, 0f, 0.75f);
|
||||
for (int x = 0; x < audioGraph.getWidth(); x++) {
|
||||
try {
|
||||
audioGraph.drawLine(x, audioGraph.getHeight(), x, (int) (audioGraph.getHeight()-mainGraph.get(dataIndex+x-audioGraph.getWidth()/2)*scale));
|
||||
} catch (NullPointerException | IndexOutOfBoundsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
case 1:
|
||||
audioGraph.setColor(0f, 0f, 1f, 0.75f);
|
||||
for (int x = 0; x < audioGraph.getWidth() -1; x++) {
|
||||
try {
|
||||
audioGraph.drawLine(x, audioGraph.getHeight(), x, (int) (audioGraph.getHeight()-overlayGraph.get(dataIndex+x-audioGraph.getWidth()/2)*scale));
|
||||
} catch (NullPointerException | IndexOutOfBoundsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
audioGraph.setColor(1f, 0f, 0f, 0.75f);
|
||||
for (int x = 0; x < audioGraph.getWidth(); x++) {
|
||||
try {
|
||||
audioGraph.drawLine(x, audioGraph.getHeight(), x, (int) (audioGraph.getHeight()-mainGraph.get(dataIndex+x-audioGraph.getWidth()/2)*scale));
|
||||
} catch (NullPointerException | IndexOutOfBoundsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
audioGraph.setColor(0f, 1f, 0f, 0.95f);
|
||||
audioGraph.drawLine(audioGraph.getWidth()/2, 0, audioGraph.getWidth()/2, audioGraph.getHeight());
|
||||
|
||||
textureOfGraph.draw(audioGraph, 0, 0);
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
batch.draw(textureOfGraph, getX(), getY(), getWidth(), getHeight());
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
|
||||
public void setGraphingData(FloatArray dataSet1, FloatArray dataSet2) {
|
||||
this.mainGraph = dataSet1;
|
||||
this.overlayGraph = dataSet2;
|
||||
}
|
||||
|
||||
}
|
82
core/src/zero1hd/polyjet/ui/builders/AudioGraphRelation.java
Executable file
82
core/src/zero1hd/polyjet/ui/builders/AudioGraphRelation.java
Executable file
@@ -0,0 +1,82 @@
|
||||
package zero1hd.polyjet.ui.builders;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
|
||||
public class AudioGraphRelation extends Actor {
|
||||
Pixmap audioGraph;
|
||||
Texture textureOfGraph;
|
||||
FloatArray mainGraph;
|
||||
FloatArray overlayGraph;
|
||||
int audioDataIndex;
|
||||
|
||||
public AudioGraphRelation(FloatArray mainGraph, FloatArray overlayGraph, int graphSizeW, int graphSizeH) {
|
||||
audioGraph = new Pixmap(graphSizeW, graphSizeH, Format.RGBA8888);
|
||||
audioGraph.setColor(0.1f, 0.1f, 0.1f, 0.75f);
|
||||
audioGraph.fill();
|
||||
|
||||
textureOfGraph = new Texture(audioGraph);
|
||||
setWidth(Gdx.graphics.getWidth());
|
||||
setHeight(280);
|
||||
this.mainGraph = mainGraph;
|
||||
this.overlayGraph = overlayGraph;
|
||||
}
|
||||
|
||||
public void setAudioDataIndex(int audioDataIndex) {
|
||||
this.audioDataIndex = audioDataIndex;
|
||||
}
|
||||
|
||||
float scale = 0.2f;
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
audioGraph.setColor(0f, 0f, 0f, 0.75f);
|
||||
audioGraph.fill();
|
||||
|
||||
if (Gdx.input.isKeyPressed(Keys.COMMA)) {
|
||||
if (scale > 0.02) {
|
||||
scale -= 0.005f;
|
||||
}
|
||||
} else if (Gdx.input.isKeyPressed(Keys.PERIOD)) {
|
||||
if (scale < 1) {
|
||||
scale += 0.005f;
|
||||
}
|
||||
}
|
||||
|
||||
audioGraph.setColor(0f, 1f, 1f, 0.75f);
|
||||
for (int x = 0; x < audioGraph.getWidth() -1; x++) {
|
||||
try {
|
||||
audioGraph.drawLine(x, (int) (audioGraph.getHeight()-mainGraph.get(audioDataIndex+x-audioGraph.getWidth()/2)*scale), x+1, (int) (audioGraph.getHeight()-mainGraph.get(audioDataIndex+x+1-audioGraph.getWidth()/2)*scale));
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
audioGraph.setColor(0f, 0.25f, 1f, 0.75f);
|
||||
for (int x = 0; x < audioGraph.getWidth() -1; x++) {
|
||||
try {
|
||||
audioGraph.drawLine(x, (int) (audioGraph.getHeight()-overlayGraph.get(audioDataIndex+x-audioGraph.getWidth()/2)*scale), x+1, (int) (audioGraph.getHeight()-overlayGraph.get(audioDataIndex+x+1-audioGraph.getWidth()/2)*scale));
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
audioGraph.setColor(0f, 0f, 1, 0.95f);
|
||||
audioGraph.drawLine(audioGraph.getWidth()/2, 0, audioGraph.getWidth()/2, audioGraph.getHeight());
|
||||
|
||||
textureOfGraph.draw(audioGraph, 0, 0);
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
batch.draw(textureOfGraph, getX(), getY(), getWidth(), getHeight());
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
|
||||
}
|
82
core/src/zero1hd/polyjet/ui/builders/GraphicsTable.java
Executable file
82
core/src/zero1hd/polyjet/ui/builders/GraphicsTable.java
Executable file
@@ -0,0 +1,82 @@
|
||||
package zero1hd.polyjet.ui.builders;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
|
||||
public class GraphicsTable extends Table {
|
||||
private Label explanation;
|
||||
|
||||
private SetResolutionButton
|
||||
_3840x2160,
|
||||
_2560x1440,
|
||||
_1920x1200,
|
||||
_1920x1080,
|
||||
_1280x800,
|
||||
_1280x720,
|
||||
_1366x768,
|
||||
_800x480;
|
||||
|
||||
|
||||
public GraphicsTable(Skin skin, final Preferences pref) {
|
||||
align(Align.top);
|
||||
defaults().space(10f);
|
||||
|
||||
explanation = new Label("This game is freely resizable\n with a minimun size of\n800x480 and maximum of 3840x2160.\nThe following resolutions are the most optimal however.", skin, "small-font", skin.getColor("default"));
|
||||
add(explanation);
|
||||
row().space(15f);
|
||||
|
||||
TextButton fullscreen = new TextButton("Fullscreen", skin);
|
||||
fullscreen.addListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (!Gdx.graphics.isFullscreen()) {
|
||||
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
|
||||
pref.putBoolean("fullscreen", true);
|
||||
pref.flush();
|
||||
}
|
||||
}
|
||||
});
|
||||
add(fullscreen).fillX();
|
||||
row();
|
||||
|
||||
_3840x2160 = new SetResolutionButton(3840, 2160, skin, pref);
|
||||
add(_3840x2160).fillX();
|
||||
row();
|
||||
|
||||
_2560x1440 = new SetResolutionButton(2560, 1440, skin, pref);
|
||||
add(_2560x1440).fillX();
|
||||
row();
|
||||
|
||||
_1920x1200 = new SetResolutionButton(1920, 1200, skin, pref);
|
||||
add(_1920x1200).fillX();
|
||||
row();
|
||||
|
||||
_1920x1080 = new SetResolutionButton(1920, 1080, skin, pref);
|
||||
add(_1920x1080).fillX();
|
||||
row();
|
||||
|
||||
_1280x800 = new SetResolutionButton(1280, 800, skin, pref);
|
||||
add(_1280x800).fillX();
|
||||
row();
|
||||
|
||||
_1280x720 = new SetResolutionButton(1280, 720, skin, pref);
|
||||
add(_1280x720).fillX();
|
||||
row();
|
||||
|
||||
_1366x768 = new SetResolutionButton(1366, 768, skin, pref);
|
||||
add(_1366x768).fillX();
|
||||
row();
|
||||
|
||||
_800x480 = new SetResolutionButton(800, 480, skin, pref);
|
||||
add(_800x480).fillX();
|
||||
row();
|
||||
}
|
||||
}
|
64
core/src/zero1hd/polyjet/ui/builders/KeySetter.java
Executable file
64
core/src/zero1hd/polyjet/ui/builders/KeySetter.java
Executable file
@@ -0,0 +1,64 @@
|
||||
package zero1hd.polyjet.ui.builders;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||
|
||||
import zero1hd.polyjet.maps.KeyMap;
|
||||
|
||||
public class KeySetter extends Actor {
|
||||
TextureRegion keyIcon;
|
||||
KeyMap keyMap;
|
||||
|
||||
public KeySetter(final KeyMap keyMap, final String control) {
|
||||
this.keyMap = keyMap;
|
||||
keyIcon = keyMap.getIcon(keyMap.stringToID(control));
|
||||
setSize(keyIcon.getRegionWidth(), keyIcon.getRegionHeight());
|
||||
|
||||
InputListener keyListener = new InputListener() {
|
||||
@Override
|
||||
public boolean keyUp(InputEvent event, int keycode) {
|
||||
getStage().setKeyboardFocus(null);
|
||||
Gdx.app.debug("KeySetter", "input keycode received: " + keycode);
|
||||
if (keycode != Keys.ESCAPE) {
|
||||
Gdx.app.debug("keySetter", "input has been set to: " + Keys.toString(keycode));
|
||||
if (setKey(keycode, control)) {
|
||||
keyMap.updateKeys();
|
||||
addAction(Actions.sequence(Actions.color(Color.GREEN, 0.2f), Actions.color(Color.WHITE, 0.2f)));
|
||||
} else {
|
||||
addAction(Actions.sequence(Actions.color(Color.RED, 0.2f), Actions.delay(0.1f), Actions.color(Color.WHITE, 0.2f)));
|
||||
}
|
||||
}
|
||||
return super.keyUp(event, keycode);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
addListener(keyListener);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean setKey(int keycode, String control) {
|
||||
if (keyMap.getIcon(keycode) != null) {
|
||||
keyMap.getKeys().putInteger(control, keycode);
|
||||
keyIcon = keyMap.getIcon(keycode);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
batch.setColor(getColor());
|
||||
batch.draw(keyIcon, getX(), getY(), getWidth(), getHeight());
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
}
|
16
core/src/zero1hd/polyjet/ui/builders/MusicSelectable.java
Normal file
16
core/src/zero1hd/polyjet/ui/builders/MusicSelectable.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package zero1hd.polyjet.ui.builders;
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
|
||||
public class MusicSelectable extends Actor {
|
||||
Image imageIcon;
|
||||
FileHandle musicFile;
|
||||
public MusicSelectable(FileHandle musicFile) {
|
||||
this.musicFile = musicFile;
|
||||
imageIcon = new Image(new Texture(musicFile));
|
||||
|
||||
}
|
||||
}
|
102
core/src/zero1hd/polyjet/ui/builders/SetControls.java
Executable file
102
core/src/zero1hd/polyjet/ui/builders/SetControls.java
Executable file
@@ -0,0 +1,102 @@
|
||||
package zero1hd.polyjet.ui.builders;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import zero1hd.polyjet.maps.KeyMap;
|
||||
|
||||
public class SetControls extends Table {
|
||||
public SetControls(Skin skin, KeyMap keyMap) {
|
||||
super(skin);
|
||||
|
||||
Label forwardKeyLabel = new Label("Forward: ",skin);
|
||||
forwardKeyLabel.setName(KeyMap.UP);
|
||||
add(forwardKeyLabel).left();
|
||||
KeySetter forwardKeySetter = new KeySetter(keyMap, KeyMap.UP);
|
||||
add(forwardKeySetter);
|
||||
|
||||
row();
|
||||
|
||||
Label backwardKeyLabel = new Label("Backward: ", skin);
|
||||
backwardKeyLabel.setName(KeyMap.DOWN);
|
||||
add(backwardKeyLabel).left();
|
||||
KeySetter backwardKeySetter = new KeySetter(keyMap, KeyMap.DOWN);
|
||||
add(backwardKeySetter);
|
||||
|
||||
row();
|
||||
|
||||
Label leftKeyLabel = new Label("Left: ", skin);
|
||||
leftKeyLabel.setName(KeyMap.LEFT);
|
||||
add(leftKeyLabel).left();
|
||||
KeySetter leftKeySetter = new KeySetter(keyMap, KeyMap.LEFT);
|
||||
add(leftKeySetter);
|
||||
|
||||
row();
|
||||
|
||||
Label rightKeyLabel = new Label("Right: ", skin);
|
||||
rightKeyLabel.setName(KeyMap.RIGHT);
|
||||
add(rightKeyLabel).left();
|
||||
KeySetter rightKeySetter = new KeySetter(keyMap, KeyMap.RIGHT);
|
||||
add(rightKeySetter);
|
||||
|
||||
row();
|
||||
|
||||
Label shootKeyLabel = new Label("Shoot: ", skin);
|
||||
shootKeyLabel.setName(KeyMap.SHOOT);
|
||||
add(shootKeyLabel).left();
|
||||
KeySetter shootKeySetter = new KeySetter(keyMap, KeyMap.SHOOT);
|
||||
add(shootKeySetter);
|
||||
|
||||
row();
|
||||
|
||||
Label sector1TPKeyLabel = new Label("Left Teleport", skin);
|
||||
sector1TPKeyLabel.setName(KeyMap.FIRSTTHIRDTELEPORT);
|
||||
add(sector1TPKeyLabel).left();
|
||||
KeySetter Sector1TPKeySetter = new KeySetter(keyMap, KeyMap.FIRSTTHIRDTELEPORT);
|
||||
add(Sector1TPKeySetter);
|
||||
|
||||
row();
|
||||
|
||||
Label sector2TPKeyLabel = new Label("Middle Teleport: ", skin);
|
||||
sector2TPKeyLabel.setName(KeyMap.SECONDTHIRDTELEPORT);
|
||||
add(sector2TPKeyLabel).left();
|
||||
KeySetter sector2TPKeySetter = new KeySetter(keyMap, KeyMap.SECONDTHIRDTELEPORT);
|
||||
add(sector2TPKeySetter);
|
||||
|
||||
row();
|
||||
|
||||
Label sector3TPKeyLabel = new Label("Right Teleport: ", skin);
|
||||
sector3TPKeyLabel.setName(KeyMap.THIRDTHIRDTELEPORT);
|
||||
add(sector3TPKeyLabel).left();
|
||||
KeySetter sector3TPKeySetter = new KeySetter(keyMap, KeyMap.THIRDTHIRDTELEPORT);
|
||||
add(sector3TPKeySetter);
|
||||
|
||||
addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
unselect();
|
||||
getStage().setKeyboardFocus(event.getTarget());
|
||||
event.getTarget().setColor(Color.ORANGE);
|
||||
super.clicked(event, x, y);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void unselect() {
|
||||
Array<Actor> keys = getChildren();
|
||||
for (int i = 0; i < keys.size; i++) {
|
||||
keys.get(i).setColor(Color.WHITE);;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
super.act(delta);
|
||||
}
|
||||
}
|
27
core/src/zero1hd/polyjet/ui/builders/SetResolutionButton.java
Executable file
27
core/src/zero1hd/polyjet/ui/builders/SetResolutionButton.java
Executable file
@@ -0,0 +1,27 @@
|
||||
package zero1hd.polyjet.ui.builders;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
|
||||
public class SetResolutionButton extends TextButton {
|
||||
|
||||
public SetResolutionButton(final int width, final int height, Skin skin, final Preferences prefs) {
|
||||
super(width + "x" + height, skin);
|
||||
|
||||
addListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
Gdx.graphics.setWindowedMode(width, height);
|
||||
prefs.putInteger("screen-width", width);
|
||||
prefs.putInteger("screen-height", height);
|
||||
prefs.putBoolean("fullscreen", false);
|
||||
prefs.flush();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
65
core/src/zero1hd/polyjet/ui/stages/AnalysisResults.java
Executable file
65
core/src/zero1hd/polyjet/ui/stages/AnalysisResults.java
Executable file
@@ -0,0 +1,65 @@
|
||||
package zero1hd.polyjet.ui.stages;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.maps.RhythmMap;
|
||||
|
||||
public class AnalysisResults extends Stage {
|
||||
Label DR;
|
||||
Image circle1;
|
||||
Image circle2;
|
||||
Label proceed;
|
||||
RhythmMap rhythmMap;
|
||||
public boolean next;
|
||||
|
||||
public AnalysisResults(Polyjet core, RhythmMap rhythmMap) {
|
||||
this.rhythmMap = rhythmMap;
|
||||
this.DR = new Label("Ready?", core.defaultSkin, "large-font", Color.WHITE);
|
||||
this.DR.setPosition(Gdx.graphics.getWidth()/2 - this.DR.getWidth()/2, Gdx.graphics.getHeight()/2 - this.DR.getHeight()/2);
|
||||
proceed = new Label("Waiting for user input...", core.defaultSkin, "small-font", Color.WHITE);
|
||||
|
||||
proceed.setPosition((Gdx.graphics.getWidth()-proceed.getWidth())/2, Gdx.graphics.getHeight()-proceed.getHeight()-20);
|
||||
proceed.addAction(Actions.forever(Actions.sequence(Actions.alpha(0.25f, 0.75f), Actions.alpha(1f, 0.75f))));
|
||||
|
||||
circle1 = new Image(core.assetManager.get("circle.png", Texture.class));
|
||||
circle1.setPosition(0, 0);
|
||||
circle2 = new Image(core.assetManager.get("circle.png", Texture.class));
|
||||
circle2.setPosition(Gdx.graphics.getWidth()-circle2.getWidth(), Gdx.graphics.getHeight()-circle2.getHeight());
|
||||
addActor(circle1);
|
||||
addActor(circle2);
|
||||
addActor(this.DR);
|
||||
addActor(proceed);
|
||||
|
||||
addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
next = true;
|
||||
super.clicked(event, x, y);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
super.act(delta);
|
||||
|
||||
//TODO set text to data difficulty
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
// TODO Auto-generated method stub
|
||||
super.draw();
|
||||
}
|
||||
}
|
219
core/src/zero1hd/polyjet/ui/stages/CreativeStage.java
Executable file
219
core/src/zero1hd/polyjet/ui/stages/CreativeStage.java
Executable file
@@ -0,0 +1,219 @@
|
||||
package zero1hd.polyjet.ui.stages;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.audio.AudioAnalyzer;
|
||||
import zero1hd.polyjet.audio.WavAudioData;
|
||||
import zero1hd.polyjet.ui.windows.BeatViewer;
|
||||
import zero1hd.polyjet.ui.windows.FPSWindow;
|
||||
import zero1hd.polyjet.ui.windows.GraphWindow;
|
||||
import zero1hd.polyjet.ui.windows.MusicController;
|
||||
import zero1hd.polyjet.ui.windows.MusicSelector;
|
||||
import zero1hd.polyjet.ui.windows.VolumeWindow;
|
||||
|
||||
public class CreativeStage extends Stage {
|
||||
WavAudioData audioWrapper;
|
||||
MusicController musicPlayBackControls;
|
||||
MusicSelector musicSelector;
|
||||
FPSWindow fpsViewer;
|
||||
BeatViewer beatViewer;
|
||||
GraphWindow graphViewer;
|
||||
VolumeWindow volumeWindow;
|
||||
|
||||
AudioAnalyzer analyzer;
|
||||
Window toolbox;
|
||||
Polyjet core;
|
||||
boolean postAnalysisComplete;
|
||||
|
||||
public CreativeStage(final Polyjet core) {
|
||||
this.core = core;
|
||||
analyzer = new AudioAnalyzer();
|
||||
audioWrapper = new WavAudioData();
|
||||
musicPlayBackControls = new MusicController(core.defaultSkin, audioWrapper);
|
||||
musicSelector = new MusicSelector("Select Audio File", core.defaultSkin, core.prefs.getString("music dir"), "default", false);
|
||||
musicSelector.setSize(400, 200);
|
||||
musicSelector.postInit();
|
||||
musicSelector.refresh();
|
||||
fpsViewer = new FPSWindow("FPS", core.defaultSkin);
|
||||
beatViewer = new BeatViewer("Beat", core.defaultSkin, core, analyzer);
|
||||
graphViewer = new GraphWindow("Peak Values", core.defaultSkin);
|
||||
volumeWindow = new VolumeWindow("Volume adjustments", core.defaultSkin, core.prefs);
|
||||
|
||||
//Back button
|
||||
TextButton backButton = new TextButton("Back", core.defaultSkin);
|
||||
backButton.addListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
dispose();
|
||||
core.setScreen(core.mainMenuScreen);
|
||||
}
|
||||
});
|
||||
backButton.setPosition(10, Gdx.graphics.getHeight()-backButton.getHeight()-10);
|
||||
addActor(backButton);
|
||||
|
||||
|
||||
toolbox = new Window("Tools", core.defaultSkin);
|
||||
toolbox.defaults().pad(5f);
|
||||
|
||||
Table toolboxToolSet = new Table(core.defaultSkin);
|
||||
toolboxToolSet.defaults().space(5f);
|
||||
|
||||
final CheckBox musicSelectorCheckbox = new CheckBox(" Music selector", core.defaultSkin);
|
||||
musicSelectorCheckbox.addListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (musicSelectorCheckbox.isChecked()) {
|
||||
addActor(musicSelector);
|
||||
} else {
|
||||
musicSelector.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
toolboxToolSet.add(musicSelectorCheckbox);
|
||||
toolboxToolSet.row();
|
||||
|
||||
final CheckBox musicPlayBackCheckbox = new CheckBox(" Playback controls", core.defaultSkin);
|
||||
musicPlayBackCheckbox.addListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (musicPlayBackCheckbox.isChecked()) {
|
||||
addActor(musicPlayBackControls);
|
||||
} else {
|
||||
musicPlayBackControls.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
toolboxToolSet.add(musicPlayBackCheckbox);
|
||||
toolboxToolSet.row();
|
||||
|
||||
final CheckBox beatViewerCheckbox = new CheckBox(" Beat viewer", core.defaultSkin);
|
||||
beatViewerCheckbox.addListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (beatViewerCheckbox.isChecked()) {
|
||||
addActor(beatViewer);
|
||||
} else {
|
||||
beatViewer.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
toolboxToolSet.add(beatViewerCheckbox);
|
||||
toolboxToolSet.row();
|
||||
|
||||
final CheckBox fpsViewerCheckbox = new CheckBox(" FPS", core.defaultSkin);
|
||||
fpsViewerCheckbox.addListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (fpsViewerCheckbox.isChecked()) {
|
||||
addActor(fpsViewer);
|
||||
} else {
|
||||
fpsViewer.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
toolboxToolSet.add(fpsViewerCheckbox);
|
||||
toolboxToolSet.row();
|
||||
|
||||
final CheckBox peakGraphCheckbox = new CheckBox(" Peak Graph", core.defaultSkin);
|
||||
peakGraphCheckbox.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (peakGraphCheckbox.isChecked()) {
|
||||
addActor(graphViewer);
|
||||
} else {
|
||||
graphViewer.remove();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
toolboxToolSet.add(peakGraphCheckbox);
|
||||
toolboxToolSet.row();
|
||||
|
||||
final CheckBox volumeMixerCheckbox = new CheckBox(" Volume", core.defaultSkin);
|
||||
volumeMixerCheckbox.addListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (volumeMixerCheckbox.isChecked()) {
|
||||
addActor(volumeWindow);
|
||||
} else {
|
||||
volumeWindow.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
toolboxToolSet.add(volumeMixerCheckbox);
|
||||
|
||||
ScrollPane scroller = new ScrollPane(toolboxToolSet, core.defaultSkin);
|
||||
toolbox.add(scroller).prefWidth(205);
|
||||
toolbox.setSize(210, 140);
|
||||
addActor(toolbox);
|
||||
|
||||
addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean keyUp(InputEvent event, int keycode) {
|
||||
if (keycode == Keys.ENTER || keycode == Keys.ESCAPE) {
|
||||
setKeyboardFocus(null);
|
||||
}
|
||||
return super.keyUp(event, keycode);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
if (musicSelector.isConfirmed()) {
|
||||
audioWrapper.setAudioFile(musicSelector.getSelectedMusic());
|
||||
audioWrapper.getPlaybackMusic().setVolume(core.prefs.getFloat("music vol")/100f);
|
||||
analyzer.resetVars();
|
||||
analyzer.startAnalyticalThread(audioWrapper);
|
||||
musicPlayBackControls.setMusicReady(false);
|
||||
beatViewer.setMusicReady(false);
|
||||
graphViewer.setData(analyzer.getBassPeaks(), analyzer.getUMPeaks());
|
||||
postAnalysisComplete = false;
|
||||
}
|
||||
|
||||
if (!postAnalysisComplete && analyzer.containsData) {
|
||||
postAnalysisComplete = true;
|
||||
musicPlayBackControls.setMusicReady(true);
|
||||
beatViewer.setMusicReady(true);
|
||||
|
||||
}
|
||||
|
||||
if (analyzer.audiofile != null) {
|
||||
if (volumeWindow.isUpdateRequired()) {
|
||||
analyzer.audiofile.getPlaybackMusic().setVolume(core.prefs.getFloat("music vol")/100f);
|
||||
}
|
||||
|
||||
analyzer.audiofile.readIndexUpdate();
|
||||
beatViewer.setSongIndex(analyzer.getReadIndex());
|
||||
graphViewer.getGraph().setAudioDataIndex(analyzer.getReadIndex());
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
analyzer.resetVars();
|
||||
analyzer.shrinkData();
|
||||
audioWrapper.reset();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
}
|
210
core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java
Executable file
210
core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java
Executable file
@@ -0,0 +1,210 @@
|
||||
package zero1hd.polyjet.ui.stages;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.scenes.scene2d.Group;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.utils.Pool;
|
||||
import com.badlogic.gdx.utils.Pools;
|
||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.entity.BarBeat;
|
||||
import zero1hd.polyjet.entity.PolyJetEntity;
|
||||
import zero1hd.polyjet.entity.Projectile;
|
||||
import zero1hd.polyjet.maps.KeyMap;
|
||||
import zero1hd.polyjet.maps.RhythmMap;
|
||||
|
||||
|
||||
public class GamePlayArea extends Stage {
|
||||
public PolyJetEntity polyJet;
|
||||
RhythmMap map;
|
||||
|
||||
float timeCounter;
|
||||
|
||||
//Required to know when to spawn entities on screen.
|
||||
int audioIndex;
|
||||
|
||||
private float health = 50;
|
||||
private float maxHealth = 100;
|
||||
private float yTeleport = Polyjet.GAME_AREA_HEIGHT/2;
|
||||
private int score;
|
||||
|
||||
private final Pool<Projectile> projectilePool = Pools.get(Projectile.class, 50);
|
||||
private final Pool<BarBeat> barBeatPool = Pools.get(BarBeat.class);
|
||||
|
||||
Group projectile;
|
||||
|
||||
Group foes;
|
||||
|
||||
Texture basicLaserTexture;
|
||||
public GamePlayArea(Polyjet core) {
|
||||
super(new FitViewport(Polyjet.GAME_AREA_WIDTH, Polyjet.GAME_AREA_HEIGHT));
|
||||
|
||||
Pixmap basicLaser = new Pixmap(2, 32, Format.RGBA8888);
|
||||
basicLaser.setColor(0f, 0.4f, 1f, 1f);
|
||||
basicLaser.fill();
|
||||
|
||||
basicLaserTexture = new Texture(basicLaser);
|
||||
basicLaser.dispose();
|
||||
|
||||
getCamera().far = 32f;
|
||||
getCamera().near = 0f;
|
||||
|
||||
Gdx.app.debug("Camera position (x,y,z)", getCamera().position.x + " " + getCamera().position.y + " " + getCamera().position.z);
|
||||
getCamera().update();
|
||||
|
||||
polyJet = new PolyJetEntity(core, 54, "standard");
|
||||
addActor(polyJet);
|
||||
|
||||
projectile = new Group();
|
||||
projectile.setName("basic Projectiles");
|
||||
addActor(projectile);
|
||||
|
||||
foes = new Group();
|
||||
addActor(foes);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
health = 50;
|
||||
maxHealth = 100;
|
||||
}
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
timeCounter+=delta;
|
||||
|
||||
for (int projectileID = 0; projectileID < projectile.getChildren().size; projectileID++) {
|
||||
Projectile currentProjectile = (Projectile) projectile.getChildren().get(projectileID);
|
||||
if (currentProjectile.getHitPoints() <= 0) {
|
||||
currentProjectile.printDebug();
|
||||
currentProjectile.remove();
|
||||
projectilePool.free(currentProjectile);
|
||||
}
|
||||
}
|
||||
|
||||
for (int barBeatID = 0; barBeatID < foes.getChildren().size; barBeatID++) {
|
||||
BarBeat currentBarBeat = (BarBeat) foes.getChildren().get(barBeatID);
|
||||
if (currentBarBeat.getHitPoints() <= 0) {
|
||||
currentBarBeat.remove();
|
||||
barBeatPool.free(currentBarBeat);
|
||||
}
|
||||
}
|
||||
|
||||
health -= 2*delta;
|
||||
|
||||
if (health <= 0) {
|
||||
health = 0;
|
||||
}
|
||||
|
||||
if (polyJet.getX() <= 1) {
|
||||
polyJet.moveLeft = false;
|
||||
polyJet.setX(1f);
|
||||
}
|
||||
|
||||
if (polyJet.getX() >= Polyjet.GAME_AREA_WIDTH-1-polyJet.getWidth()) {
|
||||
polyJet.moveRight = false;
|
||||
polyJet.setX(Polyjet.GAME_AREA_WIDTH-1f-polyJet.getWidth());
|
||||
}
|
||||
|
||||
if (polyJet.getY() >= Polyjet.GAME_AREA_HEIGHT - 1 - polyJet.getHeight()) {
|
||||
polyJet.moveUp = false;
|
||||
polyJet.setY(Polyjet.GAME_AREA_HEIGHT - 1 - polyJet.getHeight());
|
||||
}
|
||||
|
||||
if (polyJet.getY() <= 1) {
|
||||
polyJet.moveDown = false;
|
||||
polyJet.setY(1f);
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
public void setAudioIndex(int audioIndex) {
|
||||
this.audioIndex = audioIndex;
|
||||
}
|
||||
public void addScore (int score) {
|
||||
this.score += score;
|
||||
health += score;
|
||||
if (health > maxHealth) {
|
||||
health = maxHealth;
|
||||
}
|
||||
}
|
||||
|
||||
public void spawnProjectile(int ID) {
|
||||
switch (ID) {
|
||||
case 0:
|
||||
Projectile currentProjectile = projectilePool.obtain();
|
||||
currentProjectile.initiate(
|
||||
polyJet.getX()+polyJet.getWidth()/2-(0.125f)/2,
|
||||
polyJet.getY()+polyJet.getHeight()+0.5f,
|
||||
100,
|
||||
1,
|
||||
basicLaserTexture, 0.125f, 2f);
|
||||
projectile.addActor(currentProjectile);
|
||||
|
||||
health -= 5;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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;
|
||||
}
|
||||
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.shoot) {
|
||||
spawnProjectile(0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public float getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
public float getMaxHealth() {
|
||||
return maxHealth;
|
||||
}
|
||||
|
||||
public void setMap(RhythmMap map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public float getyTeleport() {
|
||||
return yTeleport;
|
||||
}
|
||||
}
|
112
core/src/zero1hd/polyjet/ui/windows/BeatViewer.java
Executable file
112
core/src/zero1hd/polyjet/ui/windows/BeatViewer.java
Executable file
@@ -0,0 +1,112 @@
|
||||
package zero1hd.polyjet.ui.windows;
|
||||
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.audio.AudioAnalyzer;
|
||||
|
||||
public class BeatViewer extends Window {
|
||||
Pixmap lights;
|
||||
int songIndex;
|
||||
boolean musicReady;
|
||||
Texture lightOn;
|
||||
|
||||
public BeatViewer(String title, Skin skin, Polyjet core, final AudioAnalyzer data) {
|
||||
super(title, skin);
|
||||
defaults().space(5f);
|
||||
setSize(64, 100);
|
||||
|
||||
|
||||
//Draw the 'lights'
|
||||
lights = new Pixmap(16, 16, Format.RGBA8888);
|
||||
lights.setColor(1, 0.2f, 0.2f, 1f);
|
||||
lights.fillCircle(lights.getWidth()/2, lights.getHeight()/2, 7);
|
||||
lightOn = new Texture(lights);
|
||||
|
||||
|
||||
WidgetGroup bassBar = new WidgetGroup();
|
||||
final Image bgBassBar = new Image(core.defaultSkin.getPatch("bar-empty"));
|
||||
bgBassBar.setHeight(50f);
|
||||
bassBar.setSize(bgBassBar.getWidth(), bgBassBar.getHeight());
|
||||
|
||||
final Image bassBarFill = new Image(core.defaultSkin.getPatch("bar-fill")) {
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
if (musicReady && data.getBassPeaks().get(songIndex) >= 1f) {
|
||||
clearActions();
|
||||
addAction(Actions.sequence(Actions.sizeTo(getWidth(), (data.getBassPeaks().get(songIndex)/data.getBassMaxValue())*bgBassBar.getHeight()), Actions.sizeTo(getWidth(), 0, 0.3f)));
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
};
|
||||
bassBarFill.setHeight(0f);
|
||||
bassBar.addActor(bgBassBar);
|
||||
bassBar.addActor(bassBarFill);
|
||||
add(bassBar).minSize(bassBar.getWidth(), bassBar.getHeight());
|
||||
|
||||
WidgetGroup UMBar = new WidgetGroup();
|
||||
final Image bgUMBar = new Image(core.defaultSkin.getPatch("bar-empty"));
|
||||
bgUMBar.setHeight(50f);
|
||||
UMBar.setSize(bgUMBar.getWidth(), bgUMBar.getHeight());
|
||||
Image UMBarFill = new Image(core.defaultSkin.getPatch("bar-fill")) {
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
if (musicReady && data.getUMPeaks().get(songIndex) >= 1f) {
|
||||
clearActions();
|
||||
addAction(Actions.sequence(Actions.sizeTo(getWidth(), (data.getUMPeaks().get(songIndex)/data.getUMMaxValue())*bgUMBar.getHeight()), Actions.sizeTo(getWidth(), 0f, 0.3f)));
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
};
|
||||
UMBarFill.setHeight(0f);
|
||||
UMBar.addActor(bgUMBar);
|
||||
UMBar.addActor(UMBarFill);
|
||||
add(UMBar).minSize(UMBar.getWidth(), UMBar.getHeight());
|
||||
|
||||
|
||||
row();
|
||||
|
||||
Image bassIndicator = new Image(lightOn) {
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
if (musicReady && data.getBassPeaks().get(songIndex) >= 2) {
|
||||
clearActions();
|
||||
addAction(Actions.sequence(Actions.alpha(1f), Actions.fadeOut(0.15f)));
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
};
|
||||
|
||||
bassIndicator.setColor(1f, 1f, 1f, 0f);
|
||||
add(bassIndicator).center();
|
||||
|
||||
|
||||
Image UMIndicator = new Image(lightOn) {
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
if (musicReady && data.getUMPeaks().get(songIndex) >= 1) {
|
||||
clearActions();
|
||||
addAction(Actions.sequence(Actions.alpha(1f), Actions.fadeOut(0.15f)));
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
};
|
||||
UMIndicator.setColor(1f, 1f, 1f, 0f);
|
||||
add(UMIndicator).center();
|
||||
}
|
||||
|
||||
public void setSongIndex(int songIndex) {
|
||||
this.songIndex = songIndex;
|
||||
}
|
||||
|
||||
public void setMusicReady(boolean musicReady) {
|
||||
this.musicReady = musicReady;
|
||||
}
|
||||
}
|
24
core/src/zero1hd/polyjet/ui/windows/FPSWindow.java
Executable file
24
core/src/zero1hd/polyjet/ui/windows/FPSWindow.java
Executable file
@@ -0,0 +1,24 @@
|
||||
package zero1hd.polyjet.ui.windows;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
||||
|
||||
public class FPSWindow extends Window {
|
||||
|
||||
public FPSWindow(String title, Skin skin) {
|
||||
super(title, skin);
|
||||
Label FPS = new Label("FPS: ", skin, "small-font", skin.getColor("default")) {
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
setText("FPS: " + Gdx.graphics.getFramesPerSecond());
|
||||
super.act(delta);
|
||||
}
|
||||
};
|
||||
|
||||
add(FPS).center();
|
||||
setSize(70, 70);
|
||||
}
|
||||
|
||||
}
|
32
core/src/zero1hd/polyjet/ui/windows/GraphWindow.java
Executable file
32
core/src/zero1hd/polyjet/ui/windows/GraphWindow.java
Executable file
@@ -0,0 +1,32 @@
|
||||
package zero1hd.polyjet.ui.windows;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
|
||||
import zero1hd.polyjet.ui.builders.AudioGraph;
|
||||
|
||||
public class GraphWindow extends Window {
|
||||
AudioGraph graph;
|
||||
|
||||
public GraphWindow(String title, Skin skin) {
|
||||
super(title, skin);
|
||||
graph = new AudioGraph(300, 150);
|
||||
add(graph);
|
||||
setSize(305, 155);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
public void setData(FloatArray dataSet1, FloatArray dataSet2) {
|
||||
graph.setGraphingData(dataSet1, dataSet2);
|
||||
}
|
||||
|
||||
public AudioGraph getGraph() {
|
||||
return graph;
|
||||
}
|
||||
|
||||
}
|
136
core/src/zero1hd/polyjet/ui/windows/MusicController.java
Executable file
136
core/src/zero1hd/polyjet/ui/windows/MusicController.java
Executable file
@@ -0,0 +1,136 @@
|
||||
package zero1hd.polyjet.ui.windows;
|
||||
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
|
||||
import zero1hd.polyjet.audio.WavAudioData;
|
||||
|
||||
public class MusicController extends Window {
|
||||
boolean musicReady;
|
||||
Skin skin;
|
||||
private Image togglePlay;
|
||||
private TextField info;
|
||||
private WavAudioData audiofile;
|
||||
|
||||
public MusicController(final Skin skin, final WavAudioData audiofile) {
|
||||
super("Playback Controller", skin);
|
||||
this.audiofile = audiofile;
|
||||
|
||||
defaults().space(5f);
|
||||
|
||||
this.skin = skin;
|
||||
final ImageButton rewind = new ImageButton(skin.getDrawable("left-double-arrow"));
|
||||
rewind.addListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (audiofile.getPlaybackMusic() != null) {
|
||||
audiofile.getPlaybackMusic().setPosition(audiofile.getPlaybackMusic().getPosition() - 2);
|
||||
info.setText(String.valueOf(MathUtils.round(audiofile.getPlaybackMusic().getPosition())) + " sec");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
add(rewind).center();
|
||||
|
||||
togglePlay = new Image(skin.getDrawable("three-quart-circle")) {
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
if (audiofile.getPlaybackMusic() != null) {
|
||||
if (audiofile.getPlaybackMusic().isPlaying()) {
|
||||
setDrawable(skin.getDrawable("pause"));
|
||||
} else if (!audiofile.getPlaybackMusic().isPlaying() && musicReady) {
|
||||
setDrawable(skin.getDrawable("arrow"));
|
||||
}
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
};
|
||||
togglePlay.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
if (audiofile.getPlaybackMusic() != null) {
|
||||
if (audiofile.getPlaybackMusic().isPlaying()) {
|
||||
audiofile.getPlaybackMusic().pause();
|
||||
} else {
|
||||
if (musicReady) {
|
||||
audiofile.getPlaybackMusic().play();
|
||||
}
|
||||
}
|
||||
}
|
||||
super.clicked(event, x, y);
|
||||
}
|
||||
});
|
||||
add(togglePlay).minWidth(togglePlay.getDrawable().getMinWidth()).center();
|
||||
|
||||
final ImageButton fastForward = new ImageButton(skin.getDrawable("right-double-arrow"));
|
||||
fastForward.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (audiofile.getPlaybackMusic() != null) {
|
||||
audiofile.getPlaybackMusic().play();
|
||||
audiofile.getPlaybackMusic().setPosition(audiofile.getPlaybackMusic().getPosition() + 2);
|
||||
info.setText(String.valueOf(MathUtils.round(audiofile.getPlaybackMusic().getPosition())) + " sec");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
add(fastForward);
|
||||
|
||||
info = new TextField(null, skin) {
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
if (audiofile.getPlaybackMusic() != null && audiofile.getPlaybackMusic().isPlaying()) {
|
||||
setText(String.valueOf(MathUtils.round(audiofile.getPlaybackMusic().getPosition())) + " sec");
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
};
|
||||
add(info);
|
||||
|
||||
|
||||
addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean keyUp(InputEvent event, int keycode) {
|
||||
if (keycode == Keys.ENTER) {
|
||||
if (!info.getText().replaceAll("(?![0-9])\\S+", "").trim().isEmpty()) {
|
||||
audiofile.getPlaybackMusic().setPosition(Float.valueOf(info.getText().replaceAll("(?![0-9])\\S+", "").trim()));
|
||||
}
|
||||
}
|
||||
return super.keyUp(event, keycode);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
setSize(260, 75);
|
||||
}
|
||||
|
||||
public void setMusicReady(boolean musicReady) {
|
||||
this.musicReady = musicReady;
|
||||
if (!musicReady) {
|
||||
togglePlay.setDrawable(skin.getDrawable("three-quart-circle"));
|
||||
info.setText("Analyzing...");
|
||||
} else {
|
||||
togglePlay.setDrawable(skin.getDrawable("arrow"));
|
||||
info.setText("Ready.");
|
||||
audiofile.getPlaybackMusic().play();
|
||||
audiofile.getPlaybackMusic().pause();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
// TODO Auto-generated method stub
|
||||
super.act(delta);
|
||||
}
|
||||
}
|
94
core/src/zero1hd/polyjet/ui/windows/MusicSelector.java
Executable file
94
core/src/zero1hd/polyjet/ui/windows/MusicSelector.java
Executable file
@@ -0,0 +1,94 @@
|
||||
package zero1hd.polyjet.ui.windows;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
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.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
public class MusicSelector extends Window {
|
||||
boolean confirmed;
|
||||
boolean back;
|
||||
FileHandle selectedMusic;
|
||||
Array<String> fileNames;
|
||||
private List<String> musicList;
|
||||
private String path;
|
||||
private ScrollPane listScroller;
|
||||
public MusicSelector(String title, Skin skin, final String path, String listStyle, boolean containsBackButton) {
|
||||
super(title, skin);
|
||||
this.path = path;
|
||||
padTop(25f);
|
||||
padLeft(5f);
|
||||
padRight(5f);
|
||||
|
||||
setSize(Gdx.graphics.getWidth()*0.8f, Gdx.graphics.getHeight()*0.9f);
|
||||
|
||||
fileNames = new Array<>();
|
||||
musicList = new List<String>(skin, listStyle);
|
||||
|
||||
if (containsBackButton) {
|
||||
TextButton backButton = new TextButton("back", skin);
|
||||
backButton.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
back = true;
|
||||
}
|
||||
});
|
||||
add(backButton).left();
|
||||
}
|
||||
|
||||
TextButton confirmButton = new TextButton("confirm", skin);
|
||||
confirmButton.addListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
confirmed = true;
|
||||
selectedMusic = Gdx.files.absolute(path+System.getProperty("file.separator")+musicList.getSelected());
|
||||
}
|
||||
});
|
||||
add(confirmButton).right();
|
||||
|
||||
row();
|
||||
|
||||
listScroller = new ScrollPane(musicList, skin);
|
||||
listScroller.setScrollingDisabled(true, false);
|
||||
}
|
||||
|
||||
public void postInit() {
|
||||
add(listScroller).colspan(2).expand().fill().prefWidth(getWidth()-5);
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
fileNames.clear();
|
||||
FileHandle[] musicListArray = Gdx.files.absolute(path).list();
|
||||
for (int i = 0; i < musicListArray.length; i++) {
|
||||
if (musicListArray[i].name().toLowerCase().endsWith(".wav")) {
|
||||
fileNames.add(musicListArray[i].name());
|
||||
}
|
||||
}
|
||||
fileNames.sort();
|
||||
musicList.setItems(fileNames);
|
||||
|
||||
}
|
||||
|
||||
public boolean isConfirmed() {
|
||||
boolean isConfirmed = confirmed;
|
||||
confirmed = false;
|
||||
return isConfirmed;
|
||||
}
|
||||
|
||||
public boolean isBack() {
|
||||
boolean isBack = back;
|
||||
back = false;
|
||||
return isBack;
|
||||
}
|
||||
|
||||
public FileHandle getSelectedMusic() {
|
||||
return selectedMusic;
|
||||
}
|
||||
}
|
21
core/src/zero1hd/polyjet/ui/windows/Spawnables.java
Executable file
21
core/src/zero1hd/polyjet/ui/windows/Spawnables.java
Executable file
@@ -0,0 +1,21 @@
|
||||
package zero1hd.polyjet.ui.windows;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
||||
|
||||
public class Spawnables extends Window {
|
||||
|
||||
public Spawnables(String title, Skin skin) {
|
||||
super(title, skin);
|
||||
|
||||
Table spawnButtons = new Table(skin);
|
||||
|
||||
ScrollPane entityListScroller = new ScrollPane(spawnButtons);
|
||||
entityListScroller.setSize(180, 80);
|
||||
add(entityListScroller);
|
||||
setSize(185, 85);
|
||||
}
|
||||
|
||||
}
|
71
core/src/zero1hd/polyjet/ui/windows/VolumeWindow.java
Executable file
71
core/src/zero1hd/polyjet/ui/windows/VolumeWindow.java
Executable file
@@ -0,0 +1,71 @@
|
||||
package zero1hd.polyjet.ui.windows;
|
||||
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
|
||||
public class VolumeWindow extends Window {
|
||||
|
||||
private Slider fxVolSlider;
|
||||
private Slider musicVolSlider;
|
||||
private Preferences prefs;
|
||||
boolean updateRequired;
|
||||
|
||||
public VolumeWindow(String title, Skin skin, Preferences prefs) {
|
||||
super(title, skin);
|
||||
this.prefs = prefs;
|
||||
setSize(360f, 100f);
|
||||
|
||||
Label musicVolSliderLabel = new Label("Music Volume: ", skin, "small-font", skin.getColor("default"));
|
||||
add(musicVolSliderLabel).left().padLeft(5f);
|
||||
musicVolSlider = new Slider(0, 100, 0.1f, false, skin);
|
||||
musicVolSlider.setValue(prefs.getFloat("music vol", 100f));
|
||||
add(musicVolSlider).width(200f);
|
||||
final Label musicVolPercentage = new Label(MathUtils.round(musicVolSlider.getValue()) + "%", skin, "small-font", skin.getColor("default"));
|
||||
musicVolSlider.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
save();
|
||||
musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%");
|
||||
}
|
||||
});
|
||||
|
||||
add(musicVolPercentage).spaceLeft(10f).expandX().left();
|
||||
|
||||
row();
|
||||
|
||||
Label fxVolSliderLabel = new Label("FX Volume: ", skin, "small-font", skin.getColor("default"));
|
||||
add(fxVolSliderLabel).left().padLeft(5f);
|
||||
fxVolSlider = new Slider(0, 100, 1, false, skin);
|
||||
fxVolSlider.setValue(prefs.getFloat("fx vol", 100f));
|
||||
add(fxVolSlider).width(200f);
|
||||
final Label fxVolPercentage = new Label(MathUtils.round(fxVolSlider.getValue()) + "%", skin, "small-font", skin.getColor("default"));
|
||||
fxVolSlider.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
save();
|
||||
fxVolPercentage.setText(MathUtils.round(fxVolSlider.getValue()) + "%");
|
||||
}
|
||||
});
|
||||
|
||||
add(fxVolPercentage).spaceLeft(10f).expandX().left();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
prefs.putFloat("music vol", musicVolSlider.getValue());
|
||||
prefs.putFloat("fx vol", fxVolSlider.getValue());
|
||||
updateRequired = true;
|
||||
prefs.flush();
|
||||
}
|
||||
|
||||
public boolean isUpdateRequired() {
|
||||
boolean isUpdateRequired = updateRequired;
|
||||
updateRequired = false;
|
||||
return isUpdateRequired;
|
||||
}
|
||||
}
|
115
core/src/zero1hd/wavedecoder/WavDecoder.java
Executable file
115
core/src/zero1hd/wavedecoder/WavDecoder.java
Executable file
@@ -0,0 +1,115 @@
|
||||
package zero1hd.wavedecoder;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
public class WavDecoder {
|
||||
DataInputStream readStream;
|
||||
private int channels;
|
||||
private double sampleRate;
|
||||
private int dataSize;
|
||||
private int byteRate;
|
||||
|
||||
public void setAudioFile(File file) throws InvalidParameterException {
|
||||
try {
|
||||
FileInputStream audioFile = new FileInputStream(file);
|
||||
readStream = new DataInputStream(audioFile);
|
||||
|
||||
if (!readBytesToString(4).equals("RIFF")) {
|
||||
throw new InvalidParameterException("RIFF tag not found in header.");
|
||||
}
|
||||
dataSize = littleEndianIntBytes();
|
||||
|
||||
if (!readBytesToString(4).equals("WAVE")) {
|
||||
throw new InvalidParameterException("WAVE format tag not found.");
|
||||
}
|
||||
|
||||
if (!readBytesToString(4).equals("fmt ")) {
|
||||
throw new InvalidParameterException("fmt header not found.");
|
||||
}
|
||||
|
||||
if (readStream.readByte() != 16) {
|
||||
throw new InvalidParameterException("Data not pcm?");
|
||||
}
|
||||
|
||||
readStream.skipBytes(3);
|
||||
if (readStream.readByte() != 1) {
|
||||
throw new InvalidParameterException("Data not pcm?");
|
||||
}
|
||||
readStream.skipBytes(1);
|
||||
|
||||
channels = readStream.readByte();
|
||||
readStream.skipBytes(1);
|
||||
|
||||
sampleRate = littleEndianIntBytes();
|
||||
|
||||
byteRate = littleEndianIntBytes();
|
||||
|
||||
readStream.skipBytes(38);
|
||||
|
||||
if (!readBytesToString(4).equals("data")) {
|
||||
throw new InvalidParameterException("initial data section tag not found");
|
||||
}
|
||||
readStream.skipBytes(4);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private String readBytesToString(int bytesToRead) throws IOException {
|
||||
byte byteString[] = new byte[bytesToRead];
|
||||
readStream.read(byteString);
|
||||
return new String(byteString);
|
||||
}
|
||||
|
||||
private int littleEndianIntBytes() throws IOException {
|
||||
int data = readStream.readInt();
|
||||
return Integer.reverseBytes(data);
|
||||
}
|
||||
|
||||
private short readLittleEndianShort() throws IOException {
|
||||
short data = readStream.readShort();
|
||||
return Short.reverseBytes(data);
|
||||
}
|
||||
|
||||
public int getChannels() {
|
||||
return channels;
|
||||
}
|
||||
|
||||
public double getSampleRate() {
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
public int getByteRate() {
|
||||
return byteRate;
|
||||
}
|
||||
|
||||
public int getDataSize() {
|
||||
return dataSize;
|
||||
}
|
||||
|
||||
public int readSamples(float[] samples) {
|
||||
int samplesRead = 0;
|
||||
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
try {
|
||||
|
||||
int currentSample = 0;
|
||||
for (int channel = 0; channel < channels; channel++) {
|
||||
currentSample += readLittleEndianShort();
|
||||
}
|
||||
currentSample /= channels*Short.MAX_VALUE+1;
|
||||
samples[i] = currentSample;
|
||||
samplesRead++;
|
||||
} catch (IOException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return samplesRead;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user