parent
cf4e6e0a6d
commit
7f35d1d316
@ -0,0 +1,33 @@ |
||||
package mightypork.rogue; |
||||
|
||||
|
||||
public class Resources { |
||||
|
||||
public static void load(AppAccess app) |
||||
{ |
||||
|
||||
loadSounds(app); |
||||
|
||||
loadTextures(app); |
||||
|
||||
loadFonts(app); |
||||
} |
||||
|
||||
|
||||
private static void loadFonts(AppAccess app) |
||||
{ |
||||
|
||||
} |
||||
|
||||
|
||||
private static void loadTextures(AppAccess app) |
||||
{ |
||||
|
||||
} |
||||
|
||||
|
||||
private static void loadSounds(AppAccess app) |
||||
{ |
||||
|
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
package mightypork.rogue.display.screens; |
||||
|
||||
|
||||
import mightypork.rogue.AppAccess; |
||||
import mightypork.rogue.bus.Subsystem; |
||||
|
||||
|
||||
public class ScreenRegistry extends Subsystem { |
||||
|
||||
public ScreenRegistry(AppAccess app) { |
||||
super(app); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void deinit() |
||||
{ |
||||
// TODO Auto-generated method stub
|
||||
|
||||
} |
||||
|
||||
} |
@ -1,186 +0,0 @@ |
||||
package mightypork.rogue.display.screens; |
||||
|
||||
|
||||
import java.util.Random; |
||||
|
||||
import mightypork.rogue.AppAccess; |
||||
import mightypork.rogue.bus.events.MouseButtonEvent; |
||||
import mightypork.rogue.display.Screen; |
||||
import mightypork.rogue.input.KeyStroke; |
||||
import mightypork.rogue.textures.Render; |
||||
import mightypork.utils.control.timing.animation.AnimDouble; |
||||
import mightypork.utils.control.timing.animation.AnimDoubleDeg; |
||||
import mightypork.utils.math.Polar; |
||||
import mightypork.utils.math.color.RGB; |
||||
import mightypork.utils.math.coord.Coord; |
||||
import mightypork.utils.math.easing.Easing; |
||||
|
||||
import org.lwjgl.input.Keyboard; |
||||
import org.lwjgl.opengl.Display; |
||||
|
||||
|
||||
public class ScreenTestAnimations extends Screen implements MouseButtonEvent.Listener { |
||||
|
||||
public ScreenTestAnimations(AppAccess app) { |
||||
super(app); |
||||
|
||||
bindKeyStroke(new KeyStroke(Keyboard.KEY_RIGHT), new Runnable() { |
||||
|
||||
@Override |
||||
public void run() |
||||
{ |
||||
for (AnimDouble a : anims) { |
||||
a.animate(0, 1, 1 + rand.nextDouble() * 1); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
bindKeyStroke(new KeyStroke(Keyboard.KEY_LEFT), new Runnable() { |
||||
|
||||
@Override |
||||
public void run() |
||||
{ |
||||
for (AnimDouble a : anims) { |
||||
a.animate(1, 0, 1 + rand.nextDouble() * 1); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private Random rand = new Random(); |
||||
|
||||
private AnimDoubleDeg degAnim = new AnimDoubleDeg(0, Easing.ELASTIC_OUT); |
||||
|
||||
//@formatter:off
|
||||
private AnimDouble[] anims = new AnimDouble[] { |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||
|
||||
// new AnimDouble(0, Easing.NONE),
|
||||
// new AnimDouble(0, Easing.LINEAR),
|
||||
//
|
||||
// new AnimDouble(0, Easing.QUADRATIC_IN),
|
||||
// new AnimDouble(0, Easing.QUADRATIC_OUT),
|
||||
// new AnimDouble(0, Easing.QUADRATIC_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.CUBIC_IN),
|
||||
// new AnimDouble(0, Easing.CUBIC_OUT),
|
||||
// new AnimDouble(0, Easing.CUBIC_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.QUADRATIC_IN),
|
||||
// new AnimDouble(0, Easing.QUADRATIC_OUT),
|
||||
// new AnimDouble(0, Easing.QUADRATIC_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.QUINTIC_IN),
|
||||
// new AnimDouble(0, Easing.QUINTIC_OUT),
|
||||
// new AnimDouble(0, Easing.QUINTIC_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.EXPO_IN),
|
||||
// new AnimDouble(0, Easing.EXPO_OUT),
|
||||
// new AnimDouble(0, Easing.EXPO_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.SINE_IN),
|
||||
// new AnimDouble(0, Easing.SINE_OUT),
|
||||
// new AnimDouble(0, Easing.SINE_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.CIRC_IN),
|
||||
// new AnimDouble(0, Easing.CIRC_OUT),
|
||||
// new AnimDouble(0, Easing.CIRC_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.BOUNCE_IN),
|
||||
// new AnimDouble(0, Easing.BOUNCE_OUT),
|
||||
// new AnimDouble(0, Easing.BOUNCE_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.BACK_IN),
|
||||
// new AnimDouble(0, Easing.BACK_OUT),
|
||||
// new AnimDouble(0, Easing.BACK_IN_OUT),
|
||||
//
|
||||
// new AnimDouble(0, Easing.ELASTIC_IN),
|
||||
// new AnimDouble(0, Easing.ELASTIC_OUT),
|
||||
// new AnimDouble(0, Easing.ELASTIC_IN_OUT),
|
||||
}; |
||||
//@formatter:on
|
||||
|
||||
@Override |
||||
protected void deinitScreen() |
||||
{ |
||||
// no impl
|
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void onScreenEnter() |
||||
{ |
||||
// no impl
|
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void onScreenLeave() |
||||
{ |
||||
// no impl
|
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void updateScreen(double delta) |
||||
{ |
||||
degAnim.update(delta); |
||||
|
||||
for (AnimDouble a : anims) { |
||||
a.update(delta); |
||||
} |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void renderScreen() |
||||
{ |
||||
double screenH = Display.getHeight(); |
||||
double screenW = Display.getWidth(); |
||||
double perBoxH = screenH / anims.length; |
||||
double padding = perBoxH * 0.1; |
||||
double boxSide = perBoxH - padding * 2; |
||||
|
||||
for (int i = 0; i < anims.length; i++) { |
||||
AnimDouble a = anims[i]; |
||||
|
||||
Render.setColor(RGB.GREEN); |
||||
Render.quadSize(padding + a.getCurrentValue() * (screenW - perBoxH), screenH - perBoxH * i - perBoxH + padding, boxSide, boxSide); |
||||
} |
||||
|
||||
Render.setColor(RGB.YELLOW); |
||||
Render.translate(new Coord(Display.getWidth() / 2, Display.getHeight() / 2)); |
||||
Render.rotateZ(degAnim.getCurrentValue()); |
||||
Render.quadSize(-10, -10, 20, 200); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void receive(MouseButtonEvent event) |
||||
{ |
||||
if (event.isDown()) { |
||||
Coord vec = disp().getSize().half().vecTo(event.getPos()); |
||||
|
||||
Polar p = Polar.fromCoord(vec); |
||||
|
||||
degAnim.fadeTo(p.getAngleDeg() - 90, 1.5); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,6 @@ |
||||
package mightypork.rogue.display.screens.screenTextures; |
||||
|
||||
|
||||
public class ScreenTextureTest { |
||||
|
||||
} |
@ -0,0 +1,140 @@ |
||||
package mightypork.rogue.textures; |
||||
|
||||
|
||||
import mightypork.utils.math.coord.Rect; |
||||
|
||||
import org.newdawn.slick.opengl.Texture; |
||||
|
||||
|
||||
public class MultiTexture implements Texture { |
||||
|
||||
private Texture backingTexture; |
||||
private String resourcePath; |
||||
|
||||
|
||||
public MultiTexture(String resourcePath) { |
||||
this.resourcePath = resourcePath; |
||||
} |
||||
|
||||
|
||||
public TxQuad getQuad(Rect rect) |
||||
{ |
||||
return new TxQuad(this, rect); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Attempt to load the texture. |
||||
*/ |
||||
private void load() |
||||
{ |
||||
if (backingTexture == null) { |
||||
backingTexture = Render.loadTexture(resourcePath); |
||||
} |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean hasAlpha() |
||||
{ |
||||
load(); |
||||
return backingTexture.hasAlpha(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getTextureRef() |
||||
{ |
||||
load(); |
||||
return backingTexture.getTextureRef(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void bind() |
||||
{ |
||||
load(); |
||||
backingTexture.bind(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getImageHeight() |
||||
{ |
||||
load(); |
||||
return backingTexture.getImageHeight(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getImageWidth() |
||||
{ |
||||
load(); |
||||
return backingTexture.getImageWidth(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public float getHeight() |
||||
{ |
||||
load(); |
||||
return backingTexture.getHeight(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public float getWidth() |
||||
{ |
||||
load(); |
||||
return backingTexture.getWidth(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getTextureHeight() |
||||
{ |
||||
load(); |
||||
return backingTexture.getTextureHeight(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getTextureWidth() |
||||
{ |
||||
load(); |
||||
return backingTexture.getTextureWidth(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void release() |
||||
{ |
||||
if (backingTexture == null) return; |
||||
backingTexture.release(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getTextureID() |
||||
{ |
||||
load(); |
||||
return backingTexture.getTextureID(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public byte[] getTextureData() |
||||
{ |
||||
load(); |
||||
return backingTexture.getTextureData(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void setTextureFilter(int textureFilter) |
||||
{ |
||||
load(); |
||||
backingTexture.setTextureFilter(textureFilter); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,124 @@ |
||||
package mightypork.rogue.textures; |
||||
|
||||
|
||||
import java.util.HashMap; |
||||
|
||||
import mightypork.rogue.AppAccess; |
||||
import mightypork.rogue.bus.Subsystem; |
||||
import mightypork.utils.control.interf.Destroyable; |
||||
import mightypork.utils.math.coord.Rect; |
||||
|
||||
import org.newdawn.slick.opengl.Texture; |
||||
|
||||
|
||||
/** |
||||
* Texture loader and quad registry |
||||
* |
||||
* @author MightyPork |
||||
*/ |
||||
public class TextureRegistry extends Subsystem implements Destroyable { |
||||
|
||||
public TextureRegistry(AppAccess app) { |
||||
super(app); |
||||
} |
||||
|
||||
private HashMap<String, MultiTexture> textures = new HashMap<String, MultiTexture>(); |
||||
|
||||
private HashMap<String, TxQuad> quads = new HashMap<String, TxQuad>(); |
||||
|
||||
private MultiTexture lastTx; |
||||
|
||||
|
||||
/** |
||||
* Load a {@link Texture} from resource |
||||
* |
||||
* @param key texture key |
||||
* @param resourcePath texture resource path |
||||
*/ |
||||
public void loadTexture(String key, String resourcePath) |
||||
{ |
||||
MultiTexture tx = new MultiTexture(resourcePath); |
||||
textures.put(key, tx); |
||||
lastTx = tx; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Create a {@link TxQuad} in a texture |
||||
* |
||||
* @param quadKey quad key |
||||
* @param textureKey texture key |
||||
* @param quad quad rectangle (absolute pixel coordinates) * |
||||
*/ |
||||
public void makeQuad(String quadKey, String textureKey, Rect quad) |
||||
{ |
||||
MultiTexture tx = textures.get(textureKey); |
||||
if (tx == null) throw new RuntimeException("Texture with key " + textureKey + " not defined!"); |
||||
|
||||
TxQuad txquad = tx.getQuad(quad); |
||||
|
||||
quads.put(quadKey, txquad); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Create a {@link TxQuad} in the last loaded texture |
||||
* |
||||
* @param quadKey quad key |
||||
* @param quad quad rectangle (absolute pixel coordinates) |
||||
*/ |
||||
public void makeQuad(String quadKey, Rect quad) |
||||
{ |
||||
MultiTexture tx = lastTx; |
||||
if (tx == null) throw new RuntimeException("There's no texture loaded yet, can't define quads!"); |
||||
|
||||
TxQuad txquad = tx.getQuad(quad); |
||||
|
||||
quads.put(quadKey, txquad); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get a {@link TxQuad} for key |
||||
* |
||||
* @param key quad key |
||||
* @return the quad |
||||
*/ |
||||
public TxQuad getQuad(String key) |
||||
{ |
||||
TxQuad q = quads.get(key); |
||||
|
||||
if (q == null) throw new RuntimeException("There's no quad called " + key + "!"); |
||||
|
||||
return q; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get a loaded {@link Texture} |
||||
* |
||||
* @param key texture key |
||||
* @return the texture |
||||
*/ |
||||
public Texture getTexture(String key) |
||||
{ |
||||
Texture t = textures.get(key); |
||||
|
||||
if (t == null) throw new RuntimeException("There's no texture called " + key + "!"); |
||||
|
||||
return t; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void deinit() |
||||
{ |
||||
for (Texture tx : textures.values()) { |
||||
tx.release(); |
||||
} |
||||
|
||||
textures.clear(); |
||||
quads.clear(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,16 @@ |
||||
package mightypork.utils.control.bus.events; |
||||
|
||||
|
||||
import mightypork.utils.control.bus.Handleable; |
||||
import mightypork.utils.control.interf.Destroyable; |
||||
|
||||
|
||||
public class DestroyEvent implements Handleable<Destroyable> { |
||||
|
||||
@Override |
||||
public void handleBy(Destroyable handler) |
||||
{ |
||||
handler.destroy(); |
||||
} |
||||
|
||||
} |
@ -1,7 +1,8 @@ |
||||
package mightypork.utils.control.timing; |
||||
package mightypork.utils.control.bus.events; |
||||
|
||||
|
||||
import mightypork.utils.control.bus.Handleable; |
||||
import mightypork.utils.control.interf.Updateable; |
||||
|
||||
|
||||
/** |
@ -1,4 +1,4 @@ |
||||
package mightypork.utils.control; |
||||
package mightypork.utils.control.interf; |
||||
|
||||
|
||||
/** |
@ -1,4 +1,4 @@ |
||||
package mightypork.utils.control.timing; |
||||
package mightypork.utils.control.interf; |
||||
|
||||
|
||||
/** |
@ -1,10 +1,9 @@ |
||||
package mightypork.utils.control.timing.animation; |
||||
package mightypork.utils.math.animation; |
||||
|
||||
|
||||
import mightypork.utils.control.interf.Updateable; |
||||
import mightypork.utils.control.timing.Pauseable; |
||||
import mightypork.utils.control.timing.Updateable; |
||||
import mightypork.utils.math.Calc; |
||||
import mightypork.utils.math.easing.Easing; |
||||
|
||||
|
||||
/** |
@ -1,9 +1,8 @@ |
||||
package mightypork.utils.control.timing.animation; |
||||
package mightypork.utils.math.animation; |
||||
|
||||
|
||||
import mightypork.utils.math.Calc; |
||||
import mightypork.utils.math.Calc.Deg; |
||||
import mightypork.utils.math.easing.Easing; |
||||
|
||||
|
||||
/** |
@ -1,9 +1,8 @@ |
||||
package mightypork.utils.control.timing.animation; |
||||
package mightypork.utils.math.animation; |
||||
|
||||
|
||||
import mightypork.utils.math.Calc; |
||||
import mightypork.utils.math.Calc.Rad; |
||||
import mightypork.utils.math.easing.Easing; |
||||
|
||||
|
||||
/** |
@ -1,4 +1,4 @@ |
||||
package mightypork.utils.math.easing; |
||||
package mightypork.utils.math.animation; |
||||
|
||||
|
||||
/** |
Loading…
Reference in new issue