parent
a8ed021156
commit
9206396c8e
Binary file not shown.
Before Width: | Height: | Size: 206 KiB |
Before Width: | Height: | Size: 84 KiB |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 6.8 KiB |
Binary file not shown.
@ -0,0 +1,44 @@ |
||||
package mightypork.gamecore.gui.events; |
||||
|
||||
|
||||
import mightypork.gamecore.eventbus.BusEvent; |
||||
import mightypork.gamecore.gui.screens.impl.CrossfadeOverlay; |
||||
|
||||
|
||||
/** |
||||
* @author MightyPork |
||||
*/ |
||||
public class CrossfadeRequest extends BusEvent<CrossfadeOverlay> { |
||||
|
||||
private final String screen; |
||||
private final boolean fromDark; |
||||
|
||||
/** |
||||
* @param screen screen key to show. Null = exit the app. |
||||
* @param fromDark true to fade from full black (ie. start of the game) |
||||
*/ |
||||
public CrossfadeRequest(String screen, boolean fromDark) |
||||
{ |
||||
super(); |
||||
this.screen = screen; |
||||
this.fromDark = fromDark; |
||||
} |
||||
|
||||
/** |
||||
* @param screen screen key to show. Null = exit the app. |
||||
*/ |
||||
public CrossfadeRequest(String screen) |
||||
{ |
||||
super(); |
||||
this.screen = screen; |
||||
this.fromDark = false; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void handleBy(CrossfadeOverlay handler) |
||||
{ |
||||
handler.goToScreen(screen, fromDark); |
||||
} |
||||
|
||||
} |
@ -1,158 +0,0 @@ |
||||
package mightypork.gamecore.gui.screens; |
||||
|
||||
|
||||
import mightypork.gamecore.app.AppAccess; |
||||
import mightypork.gamecore.app.AppSubModule; |
||||
import mightypork.gamecore.gui.events.LayoutChangeEvent; |
||||
import mightypork.gamecore.gui.events.LayoutChangeListener; |
||||
import mightypork.gamecore.input.KeyBinder; |
||||
import mightypork.gamecore.input.KeyBindingPool; |
||||
import mightypork.gamecore.input.KeyStroke; |
||||
import mightypork.gamecore.render.Render; |
||||
import mightypork.gamecore.util.annot.DefaultImpl; |
||||
import mightypork.gamecore.util.math.constraints.rect.Rect; |
||||
|
||||
|
||||
/** |
||||
* Screen class. |
||||
* |
||||
* @author MightyPork |
||||
*/ |
||||
public abstract class BaseScreen extends AppSubModule implements Screen, KeyBinder, LayoutChangeListener { |
||||
|
||||
private final KeyBindingPool keybindings = new KeyBindingPool(); |
||||
|
||||
private volatile boolean active; |
||||
private volatile boolean needSetupViewport = false; |
||||
|
||||
|
||||
/** |
||||
* @param app app access |
||||
*/ |
||||
public BaseScreen(AppAccess app) |
||||
{ |
||||
super(app); |
||||
|
||||
// disable events initially
|
||||
setListening(false); |
||||
|
||||
addChildClient(keybindings); |
||||
} |
||||
|
||||
|
||||
private void fireLayoutChangeEvent() |
||||
{ |
||||
getEventBus().sendDirectToChildren(this, new LayoutChangeEvent()); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public final void bindKey(KeyStroke stroke, Runnable task) |
||||
{ |
||||
keybindings.bindKey(stroke, task); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public final void unbindKey(KeyStroke stroke) |
||||
{ |
||||
keybindings.unbindKey(stroke); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Prepare for being shown |
||||
* |
||||
* @param shown true to show, false to hide |
||||
*/ |
||||
@Override |
||||
public final void setActive(boolean shown) |
||||
{ |
||||
if (shown) { |
||||
active = true; |
||||
needSetupViewport = true; |
||||
|
||||
fireLayoutChangeEvent(); |
||||
onScreenEnter(); |
||||
|
||||
// enable events
|
||||
setListening(true); |
||||
|
||||
} else { |
||||
onScreenLeave(); |
||||
|
||||
active = false; |
||||
|
||||
// disable events
|
||||
setListening(false); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* @return true if screen is the current screen |
||||
*/ |
||||
@Override |
||||
public final boolean isActive() |
||||
{ |
||||
return active; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void onLayoutChanged() |
||||
{ |
||||
if (!isActive()) return; |
||||
|
||||
needSetupViewport = true; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public final Rect getRect() |
||||
{ |
||||
return getDisplay().getRect(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void render() |
||||
{ |
||||
if (!isActive()) return; |
||||
|
||||
if (needSetupViewport) { |
||||
Render.setupOrtho(getDisplay().getSize()); |
||||
} |
||||
|
||||
Render.pushState(); |
||||
|
||||
renderScreen(); |
||||
|
||||
Render.popState(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Called when the screen becomes active |
||||
*/ |
||||
@DefaultImpl |
||||
protected void onScreenEnter() |
||||
{ |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Called when the screen is no longer active |
||||
*/ |
||||
@DefaultImpl |
||||
protected void onScreenLeave() |
||||
{ |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Render screen contents (context is ready for 2D rendering) |
||||
*/ |
||||
protected abstract void renderScreen(); |
||||
|
||||
} |
@ -1,36 +0,0 @@ |
||||
package mightypork.gamecore.gui.screens; |
||||
|
||||
|
||||
import mightypork.gamecore.eventbus.BusEvent; |
||||
|
||||
|
||||
/** |
||||
* @author MightyPork |
||||
*/ |
||||
public class CrossfadeRequest extends BusEvent<CrossfadeRequest.Listener> { |
||||
|
||||
private final String screen; |
||||
|
||||
|
||||
/** |
||||
* @param screen screen key to show. Null = exit the app. |
||||
*/ |
||||
public CrossfadeRequest(String screen) |
||||
{ |
||||
super(); |
||||
this.screen = screen; |
||||
} |
||||
|
||||
public interface Listener { |
||||
|
||||
void goToScreen(String screen); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void handleBy(Listener handler) |
||||
{ |
||||
handler.goToScreen(screen); |
||||
} |
||||
|
||||
} |
@ -1,26 +1,30 @@ |
||||
package mightypork.rogue.screens.test_cat_sound; |
||||
package mightypork.gamecore.gui.screens.impl; |
||||
|
||||
|
||||
import mightypork.gamecore.gui.components.painters.QuadPainter; |
||||
import mightypork.gamecore.gui.screens.BaseScreen; |
||||
import mightypork.gamecore.gui.screens.Screen; |
||||
import mightypork.gamecore.gui.screens.ScreenLayer; |
||||
import mightypork.gamecore.util.math.color.Color; |
||||
|
||||
|
||||
public class LayerColor extends ScreenLayer { |
||||
|
||||
public LayerColor(BaseScreen screen, Color color) |
||||
private int zIndex; |
||||
|
||||
|
||||
public LayerColor(Screen screen, Color color, int zIndex) |
||||
{ |
||||
super(screen); |
||||
|
||||
root.add(new QuadPainter(color)); |
||||
this.zIndex = zIndex; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getZIndex() |
||||
{ |
||||
return Integer.MIN_VALUE; |
||||
return this.zIndex; |
||||
} |
||||
|
||||
} |
@ -1,4 +1,4 @@ |
||||
package mightypork.rogue.screens.gamescreen; |
||||
package mightypork.rogue.screens.game; |
||||
|
||||
|
||||
import mightypork.gamecore.gui.AlignX; |
@ -1,4 +1,4 @@ |
||||
package mightypork.rogue.screens.gamescreen; |
||||
package mightypork.rogue.screens.game; |
||||
|
||||
|
||||
import mightypork.gamecore.gui.AlignX; |
@ -1,4 +1,4 @@ |
||||
package mightypork.rogue.screens.gamescreen; |
||||
package mightypork.rogue.screens.game; |
||||
|
||||
|
||||
import mightypork.gamecore.eventbus.events.Updateable; |
@ -1,27 +1,36 @@ |
||||
package mightypork.rogue.screens.gamescreen; |
||||
package mightypork.rogue.screens.game; |
||||
|
||||
|
||||
import java.util.Random; |
||||
|
||||
import mightypork.gamecore.app.AppAccess; |
||||
import mightypork.gamecore.gui.screens.LayeredScreen; |
||||
import mightypork.gamecore.input.KeyStroke; |
||||
import mightypork.gamecore.input.Keys; |
||||
import mightypork.rogue.world.WorldProvider; |
||||
|
||||
|
||||
public class ScreenGame extends LayeredScreen { |
||||
|
||||
|
||||
private Random rand = new Random(); |
||||
|
||||
|
||||
public ScreenGame(AppAccess app) |
||||
{ |
||||
super(app); |
||||
|
||||
addLayer(new HudLayer(this)); |
||||
addLayer(new WorldLayer(this)); |
||||
} |
||||
|
||||
bindKey(new KeyStroke(Keys.N), new Runnable() { |
||||
|
||||
@Override |
||||
public String getName() |
||||
{ |
||||
return "game_screen"; |
||||
@Override |
||||
public void run() |
||||
{ |
||||
WorldProvider.get().createWorld(rand .nextLong()); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
|
@ -1,4 +1,4 @@ |
||||
package mightypork.rogue.screens.gamescreen; |
||||
package mightypork.rogue.screens.game; |
||||
|
||||
|
||||
import mightypork.gamecore.gui.screens.Screen; |
@ -1,108 +0,0 @@ |
||||
package mightypork.rogue.screens.test_cat_sound; |
||||
|
||||
|
||||
import java.util.Random; |
||||
|
||||
import mightypork.gamecore.gui.AlignX; |
||||
import mightypork.gamecore.gui.components.painters.ImagePainter; |
||||
import mightypork.gamecore.gui.components.painters.QuadPainter; |
||||
import mightypork.gamecore.gui.components.painters.TextPainter; |
||||
import mightypork.gamecore.gui.screens.BaseScreen; |
||||
import mightypork.gamecore.gui.screens.ScreenLayer; |
||||
import mightypork.gamecore.input.KeyStroke; |
||||
import mightypork.gamecore.input.Keys; |
||||
import mightypork.gamecore.input.events.MouseButtonEvent; |
||||
import mightypork.gamecore.input.events.MouseButtonListener; |
||||
import mightypork.gamecore.util.math.Easing; |
||||
import mightypork.gamecore.util.math.color.Color; |
||||
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated; |
||||
import mightypork.gamecore.util.math.constraints.rect.Rect; |
||||
import mightypork.gamecore.util.math.constraints.vect.Vect; |
||||
import mightypork.gamecore.util.math.constraints.vect.mutable.VectAnimated; |
||||
import mightypork.rogue.Res; |
||||
|
||||
|
||||
public class LayerFlyingCat extends ScreenLayer implements MouseButtonListener { |
||||
|
||||
private final NumAnimated size = new NumAnimated(300, Easing.SINE_BOTH); |
||||
private final VectAnimated cat_position = VectAnimated.makeVar(Easing.ELASTIC_OUT); |
||||
|
||||
private final Random rand = new Random(); |
||||
|
||||
|
||||
public LayerFlyingCat(BaseScreen screen) |
||||
{ |
||||
super(screen); |
||||
|
||||
// timing
|
||||
updated.add(size); |
||||
updated.add(cat_position); |
||||
size.setTo(root.height().perc(60)); |
||||
|
||||
// cat
|
||||
cat_position.setTo(getDisplay().getCenter()); |
||||
cat_position.setDefaultDuration(3); |
||||
|
||||
final ImagePainter cat = new ImagePainter(Res.getTxQuad("test.kitten2")); |
||||
cat.setRect(Rect.make(size).centerTo(cat_position)); |
||||
cat.enableCaching(false); |
||||
|
||||
// frame around cat
|
||||
final QuadPainter cat_frame = QuadPainter.gradV(Color.YELLOW, Color.RED); |
||||
cat_frame.setRect(cat.grow(cat.height().mul(0.05))); |
||||
cat_frame.enableCaching(false); |
||||
|
||||
// frame shadow
|
||||
final QuadPainter cat_shadow = new QuadPainter(Color.dark(0.4)); |
||||
cat_shadow.setRect(cat_frame.move(Vect.make(cat.height().mul(0.05)))); |
||||
cat_shadow.enableCaching(false); |
||||
|
||||
// add to root layout
|
||||
root.add(cat_shadow); |
||||
root.add(cat_frame); |
||||
root.add(cat); |
||||
|
||||
// Meow
|
||||
final TextPainter tp = new TextPainter(Res.getFont("press_start")); |
||||
tp.setAlign(AlignX.CENTER); |
||||
tp.setColor(Color.YELLOW); |
||||
tp.setText("Meow!"); |
||||
tp.setShadow(Color.dark(0.5), Vect.make(tp.height().div(16))); |
||||
tp.setRect(Rect.make(cat.height().half()).centerTo(mouse)); |
||||
tp.enableCaching(false); |
||||
root.add(tp); |
||||
|
||||
/* |
||||
* Register keys |
||||
*/ |
||||
bindKey(new KeyStroke(Keys.RETURN), new Runnable() { |
||||
|
||||
@Override |
||||
public void run() |
||||
{ |
||||
cat_position.setTo(getDisplay().getCenter()); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void receive(MouseButtonEvent event) |
||||
{ |
||||
if (!event.isDown()) return; |
||||
|
||||
cat_position.animate(event.getPos()); |
||||
|
||||
final double newSize = root.height().perc(10 + rand.nextInt(40)).value(); |
||||
|
||||
size.animate(newSize, 1); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getZIndex() |
||||
{ |
||||
return 10; |
||||
} |
||||
|
||||
} |
@ -1,52 +0,0 @@ |
||||
package mightypork.rogue.screens.test_cat_sound; |
||||
|
||||
|
||||
import mightypork.gamecore.app.AppAccess; |
||||
import mightypork.gamecore.gui.screens.LayeredScreen; |
||||
import mightypork.gamecore.input.KeyStroke; |
||||
import mightypork.gamecore.input.Keys; |
||||
import mightypork.rogue.events.ActionRequest; |
||||
import mightypork.rogue.events.ActionRequest.RequestType; |
||||
|
||||
|
||||
public class ScreenTestCat extends LayeredScreen { |
||||
|
||||
public ScreenTestCat(AppAccess app) |
||||
{ |
||||
super(app); |
||||
|
||||
addLayer(new LayerFlyingCat(this)); |
||||
|
||||
bindKey(new KeyStroke(Keys.ESCAPE), new Runnable() { |
||||
|
||||
@Override |
||||
public void run() |
||||
{ |
||||
getSoundSystem().fadeOutAllLoops(); |
||||
getEventBus().sendDelayed(new ActionRequest(RequestType.SHUTDOWN), 3); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void onScreenEnter() |
||||
{ |
||||
getSoundSystem().fadeOutAllLoops(); |
||||
//Res.getLoop("test.wilderness").fadeIn();
|
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void onScreenLeave() |
||||
{ |
||||
//Res.getLoop("test.wilderness").fadeOut();
|
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getName() |
||||
{ |
||||
return "test.cat"; |
||||
} |
||||
} |
@ -1,41 +0,0 @@ |
||||
package mightypork.rogue.screens.test_render; |
||||
|
||||
|
||||
import mightypork.gamecore.gui.screens.BaseScreen; |
||||
import mightypork.gamecore.gui.screens.ScreenLayer; |
||||
import mightypork.gamecore.render.Render; |
||||
import mightypork.gamecore.util.math.color.Color; |
||||
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound; |
||||
|
||||
|
||||
public class LayerTestGradient extends ScreenLayer { |
||||
|
||||
private final RectBound pos1; |
||||
private final RectBound pos2; |
||||
|
||||
|
||||
public LayerTestGradient(BaseScreen screen) |
||||
{ |
||||
super(screen); |
||||
|
||||
pos1 = root.topEdge().growDown(64); |
||||
pos2 = root.leftEdge().growUp(-64).growRight(64); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void render() |
||||
{ |
||||
Render.quadColor(root, Color.WHITE, Color.BLUE, Color.BLACK, Color.MAGENTA); |
||||
Render.quadGradH(pos1.getRect(), Color.GREEN, Color.RED); |
||||
Render.quadGradV(pos2.getRect(), Color.WHITE, Color.MAGENTA); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public int getZIndex() |
||||
{ |
||||
return 0; |
||||
} |
||||
|
||||
} |
@ -1,24 +0,0 @@ |
||||
package mightypork.rogue.screens.test_render; |
||||
|
||||
|
||||
import mightypork.gamecore.app.AppAccess; |
||||
import mightypork.gamecore.gui.screens.LayeredScreen; |
||||
|
||||
|
||||
public class ScreenTestRender extends LayeredScreen { |
||||
|
||||
public ScreenTestRender(AppAccess app) |
||||
{ |
||||
super(app); |
||||
|
||||
addLayer(new LayerTestGradient(this)); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getName() |
||||
{ |
||||
return "test.render"; |
||||
} |
||||
|
||||
} |
@ -1,32 +1,38 @@ |
||||
package mightypork.rogue.world.gen.themes; |
||||
|
||||
|
||||
import mightypork.rogue.world.gen.Theme; |
||||
import mightypork.rogue.world.gen.MapTheme; |
||||
import mightypork.rogue.world.tile.TileModel; |
||||
import mightypork.rogue.world.tile.Tiles; |
||||
|
||||
|
||||
// basic dungeon theme
|
||||
public class ThemeDungeon implements Theme { |
||||
public class ThemeBrick implements MapTheme { |
||||
|
||||
@Override |
||||
public TileModel wall() |
||||
{ |
||||
return Tiles.WALL_BRICK; |
||||
return Tiles.BRICK_WALL; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public TileModel floor() |
||||
{ |
||||
return Tiles.FLOOR_DARK; |
||||
return Tiles.BRICK_FLOOR; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public TileModel door() |
||||
{ |
||||
return Tiles.DOOR; |
||||
return Tiles.BRICK_DOOR; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public TileModel passage() |
||||
{ |
||||
return Tiles.BRICK_PASSAGE; |
||||
} |
||||
} |
@ -0,0 +1,31 @@ |
||||
package mightypork.rogue.world.tile.tiles; |
||||
|
||||
import mightypork.rogue.world.tile.TileModel; |
||||
import mightypork.rogue.world.tile.TileRenderer; |
||||
import mightypork.rogue.world.tile.TileType; |
||||
|
||||
|
||||
/** |
||||
* Collapsed wall that's walk-through |
||||
* |
||||
* @author MightyPork |
||||
*/ |
||||
public class WallPassageTile extends SolidTile { |
||||
|
||||
public WallPassageTile(TileModel model, TileRenderer renderer) { |
||||
super(model, renderer); |
||||
} |
||||
|
||||
@Override |
||||
public TileType getType() |
||||
{ |
||||
return TileType.PASSAGE; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isWalkable() |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue