Adapted to use new gamecore. UGLY. to be done. Also no sounds.

master
Ondřej Hruška 11 years ago
parent f0401d0184
commit 60e76ecfcc
  1. 169
      src/mightypork/rogue/Launcher.java
  2. 157
      src/mightypork/rogue/RogueApp.java
  3. 19
      src/mightypork/rogue/RogueConfig.java
  4. 63
      src/mightypork/rogue/RogueInitConfig.java
  5. 81
      src/mightypork/rogue/RogueInitResources.java
  6. 24
      src/mightypork/rogue/RogueInitWorkdir.java
  7. 46
      src/mightypork/rogue/RogueKeys.java
  8. 14
      src/mightypork/rogue/RogueRoutes.java
  9. 76
      src/mightypork/rogue/world/WorldProvider.java
  10. 39
      src/mightypork/rogue/world/gui/Minimap.java
  11. 84
      src/mightypork/rogue/world/gui/interaction/MIPKeyboard.java

@ -5,7 +5,36 @@ import java.io.File;
import java.util.logging.Level;
import mightypork.gamecore.core.App;
import mightypork.gamecore.core.DeltaMainLoop;
import mightypork.gamecore.core.MainLoop;
import mightypork.gamecore.core.init.InitTaskCrashHandler;
import mightypork.gamecore.core.init.InitTaskCustom;
import mightypork.gamecore.core.init.InitTaskDisplay;
import mightypork.gamecore.core.init.InitTaskIonizables;
import mightypork.gamecore.core.init.InitTaskLog;
import mightypork.gamecore.core.init.InitTaskLogHeader;
import mightypork.gamecore.core.init.InitTaskMainLoop;
import mightypork.gamecore.core.init.InitTaskResourceLoaderAsync;
import mightypork.gamecore.core.init.InitTaskScreens;
import mightypork.gamecore.core.plugins.screenshot.InitTaskPluginScreenshot;
import mightypork.gamecore.core.plugins.screenshot.ScreenshotRequest;
import mightypork.gamecore.graphics.FullscreenToggleRequest;
import mightypork.gamecore.graphics.Renderable;
import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.gamecore.gui.screens.impl.CrossfadeOverlay;
import mightypork.gamecore.input.Trigger;
import mightypork.rogue.screens.FpsOverlay;
import mightypork.rogue.screens.LoadingOverlay;
import mightypork.rogue.screens.game.ScreenGame;
import mightypork.rogue.screens.menu.ScreenMainMenu;
import mightypork.rogue.screens.select_world.ScreenSelectWorld;
import mightypork.rogue.screens.story.ScreenStory;
import mightypork.rogue.world.Inventory;
import mightypork.rogue.world.WorldProvider;
import mightypork.utils.eventbus.BusEvent;
import mightypork.utils.files.OsUtils;
import mightypork.utils.ion.Ion;
import mightypork.utils.logging.Log;
public class Launcher {
@ -78,13 +107,145 @@ public class Launcher {
}
final App app = new RogueApp();
App.bus().detailedLogging = true;
app.getInitOptions().setWorkdir(workdir);
app.getInitOptions().setSigleInstance(true);
app.addInitTask(new RogueInitWorkdir(workdir));
app.addInitTask(new RogueInitConfig());
app.addInitTask(new InitTaskResourceLoaderAsync());
app.addInitTask(new RogueInitResources());
app.getInitOptions().setLogLevel(llFile, llSyso);
app.getInitOptions().setBusLogging(logBus);
app.addInitTask(new InitTaskCrashHandler());
app.addInitTask(new InitTaskPluginScreenshot("screenshots"));
app.addInitTask(new InitTaskIonizables() {
@Override
public void after()
{
Ion.register(mightypork.rogue.world.level.Level.class);
Ion.register(Inventory.class);
}
});
final Level logLevelWrite = llFile, logLevelPrint = llSyso;
app.addInitTask(new InitTaskLog() {
@Override
public void init()
{
setArchiveCount(5);
setLevels(logLevelWrite, logLevelPrint);
setLogDir("logs");
setLogName("runtime");
}
});
app.addInitTask(new InitTaskLogHeader() {
@Override
public void before()
{
Log.i("## Starting Rogue v." + Const.VERSION + " ##");
}
});
app.addInitTask(new InitTaskDisplay() {
@Override
public void init()
{
final int w = App.cfg().getValue("display.width");
final int h = App.cfg().getValue("display.height");
final boolean fs = App.cfg().getValue("display.fullscreen");
setSize(w, h);
setResizable(true);
setFullscreen(fs);
setTitle(Const.TITLEBAR);
setTargetFps(Const.FPS_RENDER);
}
});
app.addInitTask(new InitTaskCustom("global_keys", new String[] { "config" }) {
@Override
public void run()
{
bindEventToKey(new FullscreenToggleRequest(), "global.fullscreen");
bindEventToKey(new ScreenshotRequest(), "global.screenshot");
final Runnable quitTask = new Runnable() {
@Override
public void run()
{
App.shutdown();
}
};
App.input().bindKey(App.cfg().getKeyStroke("global.quit"), Trigger.RISING, quitTask);
App.input().bindKey(App.cfg().getKeyStroke("global.quit_force"), Trigger.RISING, quitTask);
}
private void bindEventToKey(final BusEvent<?> event, String strokeName)
{
App.input().bindKey(App.cfg().getKeyStroke(strokeName), Trigger.RISING, new Runnable() {
@Override
public void run()
{
App.bus().send(event);
}
});
}
});
app.addInitTask(new InitTaskMainLoop() {
@Override
protected MainLoop getLoopImpl()
{
final MainLoop loop = new DeltaMainLoop();
return loop;
}
});
app.addInitTask(new InitTaskScreens() {
@Override
protected Renderable getMainRenderableImpl()
{
final ScreenRegistry screens = new ScreenRegistry();
app.addChildClient(screens);
/* game screen references world provider instance */
App.bus().subscribe(new RogueStateManager());
App.bus().subscribe(WorldProvider.get());
screens.addOverlay(new CrossfadeOverlay());
screens.addScreen("main_menu", new ScreenMainMenu());
screens.addScreen("select_world", new ScreenSelectWorld());
screens.addScreen("game", new ScreenGame());
screens.addScreen("story", new ScreenStory());
screens.addOverlay(new FpsOverlay());
screens.addOverlay(new LoadingOverlay());
return screens;
}
});
app.start();
}

@ -1,35 +1,15 @@
package mightypork.rogue;
import junk.AppInitOptions;
import mightypork.gamecore.backends.lwjgl.LwjglBackend;
import mightypork.gamecore.backends.lwjgl.LwjglInputModule;
import mightypork.gamecore.core.App;
import mightypork.gamecore.core.config.Config;
import mightypork.gamecore.core.events.MainLoopRequest;
import mightypork.gamecore.core.events.ShutdownEvent;
import mightypork.gamecore.core.plugins.screenshot.ScreenshotRequest;
import mightypork.gamecore.graphics.FullscreenToggleRequest;
import mightypork.gamecore.graphics.GraphicsModule;
import mightypork.gamecore.core.plugins.screenshot.ScreenshotRequestListener;
import mightypork.gamecore.gui.events.ViewportChangeEvent;
import mightypork.gamecore.gui.events.ViewportChangeListener;
import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.gamecore.input.Trigger;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.RogueStateRequest;
import mightypork.rogue.screens.FpsOverlay;
import mightypork.rogue.screens.LoadingOverlay;
import mightypork.rogue.screens.game.ScreenGame;
import mightypork.rogue.screens.menu.ScreenMainMenu;
import mightypork.rogue.screens.select_world.ScreenSelectWorld;
import mightypork.rogue.screens.story.ScreenStory;
import mightypork.rogue.world.Inventory;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.level.Level;
import mightypork.utils.eventbus.BusEvent;
import mightypork.utils.ion.Ion;
import mightypork.utils.logging.Log;
/**
@ -37,144 +17,51 @@ import mightypork.utils.logging.Log;
*
* @author Ondřej Hruška (MightyPork)
*/
public final class RogueApp extends App implements ViewportChangeListener {
public final class RogueApp extends App implements ViewportChangeListener, ScreenshotRequestListener {
public RogueApp()
{
super(new LwjglBackend());
final AppInitOptions opt = getInitOptions();
opt.addRoutes(new RogueRoutes());
opt.addResources(new RogueResources());
opt.addKeys(new RogueKeys());
opt.addConfig(new RogueConfig());
opt.setBusLogging(true);
opt.setConfigFile("config.ini", "Rogue config file");
opt.setLogOptions("logs", "runtime", 5, java.util.logging.Level.ALL);
}
@Override
protected void registerIonizables()
{
super.registerIonizables();
Ion.register(Level.class);
Ion.register(Inventory.class);
}
@Override
protected void initDisplay(GraphicsModule gfx)
{
// init based on config
final int w = Config.getValue("display.width");
final int h = Config.getValue("display.height");
final boolean fs = Config.getValue("display.fullscreen");
gfx.setSize(w, h);
gfx.setResizable(true);
gfx.setFullscreen(fs);
gfx.setTitle(Const.TITLEBAR);
gfx.setTargetFps(Const.FPS_RENDER);
gfx.createDisplay();
}
@Override
protected void initScreens(ScreenRegistry screens)
{
super.initScreens(screens);
/* game screen references world provider instance */
WorldProvider.setBaseDir(this);
getEventBus().subscribe(new RogueStateManager(this));
screens.addScreen("main_menu", new ScreenMainMenu(this));
screens.addScreen("select_world", new ScreenSelectWorld(this));
screens.addScreen("game", new ScreenGame(this));
screens.addScreen("story", new ScreenStory(this));
screens.addOverlay(new FpsOverlay(this));
screens.addOverlay(new LoadingOverlay(this));
}
@Override
protected void initInputSystem(LwjglInputModule input)
{
// this will work only with reusable events (such as requests)
bindEventToKey(new FullscreenToggleRequest(), "global.fullscreen");
bindEventToKey(new ScreenshotRequest(), "global.screenshot");
bindEventToKey(new ShutdownEvent(), "global.quit");
bindEventToKey(new ShutdownEvent(), "global.quit_force");
}
private void bindEventToKey(final BusEvent<?> event, String strokeName)
public void onScreenshotRequest()
{
getInput().bindKey(Config.getKeyStroke(strokeName), Trigger.RISING, new Runnable() {
@Override
public void run()
{
getEventBus().send(event);
}
});
Res.sound("gui.shutter").play(0.8);
}
@Override
protected void postInit()
{
getEventBus().send(new MainLoopRequest(new Runnable() {
bus().send(new MainLoopRequest(new Runnable() {
@Override
public void run()
{
if (Config.getValue("opt.show_story")) {
Config.setValue("opt.show_story", false);
getEventBus().send(new RogueStateRequest(RogueState.STORY, true));
if (cfg().getValue("opt.show_story")) {
cfg().setValue("opt.show_story", false);
bus().send(new RogueStateRequest(RogueState.STORY, true));
} else {
getEventBus().send(new RogueStateRequest(RogueState.MAIN_MENU, true));
bus().send(new RogueStateRequest(RogueState.MAIN_MENU, true));
}
}
}, false));
}
@Override
public void onViewportChanged(ViewportChangeEvent event)
{
// save viewport size to config file
final boolean fs = gfx().isFullscreen();
Config.setValue("display.fullscreen", fs);
cfg().setValue("display.fullscreen", fs);
if (!fs) {
Config.setValue("display.width", gfx().getWidth());
Config.setValue("display.height", gfx().getHeight());
cfg().setValue("display.width", gfx().getWidth());
cfg().setValue("display.height", gfx().getHeight());
}
}
@Override
public void onScreenshotRequest()
{
// screenshot sound
Res.sound("gui.shutter").play(0.8);
}
@Override
protected void writeLogHeader()
{
Log.i("## Starting Rogue v." + Const.VERSION + " ##");
super.writeLogHeader();
}
}

@ -1,19 +0,0 @@
package mightypork.rogue;
import mightypork.utils.config.propmgr.PropertyManager;
public class RogueConfig implements ConfigSetup {
@Override
public void addOptions(PropertyManager prop)
{
prop.addBoolean("display.fullscreen", false, "Start in fullscreen (remembers state at exit)");
prop.addInteger("display.width", 1024, "Initial width (remembers from last time)");
prop.addInteger("display.height", 768, "Initial height (remembers from last time)");
prop.addBoolean("opt.show_story", true, "Show story on start-up.");
}
}

@ -0,0 +1,63 @@
package mightypork.rogue;
import mightypork.gamecore.core.config.Config;
import mightypork.gamecore.core.config.InitTaskConfig;
public class RogueInitConfig extends InitTaskConfig {
@Override
protected Config buildConfig()
{
final Config cfg = new Config("config.ini", "Rogue config file");
cfg.addBoolean("display.fullscreen", false, "Start in fullscreen (remembers state at exit)");
cfg.addInteger("display.width", 1024, "Initial width (remembers from last time)");
cfg.addInteger("display.height", 768, "Initial height (remembers from last time)");
cfg.addBoolean("opt.show_story", true, "Show story on start-up.");
// keys
cfg.addKeyStroke("global.quit", "CTRL+Q", "Quit the game");
cfg.addKeyStroke("global.quit_force", "CTRL+SHIFT+Q", "Quit the game without asking, low-level");
cfg.addKeyStroke("global.screenshot", "F2", "Take screenshot (save into working directory)");
cfg.addKeyStroke("global.fullscreen", "F11", "Toggle fullscreen");
cfg.addKeyStroke("global.fps_meter", "F3", "Toggle FPS meter overlay");
cfg.addKeyStroke("general.close", "ESC", "Leave a dialog or screen");
cfg.addKeyStroke("general.cancel", "ESC", "\"Cancel\" option in dialogs");
cfg.addKeyStroke("general.confirm", "ENTER", "\"Confirm\" option in dialogs");
cfg.addKeyStroke("general.yes", "Y", "\"Yes\" option in dialogs");
cfg.addKeyStroke("general.no", "N", "\"No\" option in dialogs");
cfg.addKeyStroke("game.quit", "ESC", "Quit to menu");
cfg.addKeyStroke("game.save", "CTRL+S", "Save to file");
cfg.addKeyStroke("game.load", "CTRL+L", "Load from file");
cfg.addKeyStroke("game.zoom", "Z", "Toggle zoom");
cfg.addKeyStroke("game.minimap", "M", "Toggle minimap");
cfg.addKeyStroke("game.eat", "E", "Eat smallest food item");
cfg.addKeyStroke("game.drop", "D", "Drop last picked item");
cfg.addKeyStroke("game.inventory", "I", "Toggle inventory view");
cfg.addKeyStroke("game.pause", "P", "Pause the game");
cfg.addKeyStroke("game.walk.up", "UP", "Walk north");
cfg.addKeyStroke("game.walk.down", "DOWN", "Walk south");
cfg.addKeyStroke("game.walk.left", "LEFT", "Walk west");
cfg.addKeyStroke("game.walk.right", "RIGHT", "Walk east");
cfg.addKeyStroke("game.cheat.xray", "CTRL+SHIFT+X", "Cheat to see unexplored tiles");
cfg.addKeyStroke("game.inv.use", "E", "Use (eat or equip) the selected item");
cfg.addKeyStroke("game.inv.drop", "D", "Drop the selected item");
cfg.addKeyStroke("game.inv.move.left", "LEFT", "Move inventory cursor left");
cfg.addKeyStroke("game.inv.move.right", "RIGHT", "Move inventory cursor right");
cfg.addKeyStroke("game.inv.move.up", "UP", "Move inventory cursor up");
cfg.addKeyStroke("game.inv.move.down", "DOWN", "Move inventory cursor down");
return cfg;
}
}

@ -2,7 +2,8 @@ package mightypork.rogue;
import mightypork.gamecore.audio.SoundRegistry;
import mightypork.gamecore.backends.lwjgl.graphics.font.LwjglFont;
import mightypork.gamecore.core.App;
import mightypork.gamecore.core.init.InitTaskResources;
import mightypork.gamecore.graphics.fonts.DeferredFont;
import mightypork.gamecore.graphics.fonts.FontRegistry;
import mightypork.gamecore.graphics.fonts.Glyphs;
@ -11,77 +12,75 @@ import mightypork.gamecore.graphics.textures.ITexture;
import mightypork.gamecore.graphics.textures.QuadGrid;
import mightypork.gamecore.graphics.textures.TextureRegistry;
import mightypork.gamecore.graphics.textures.WrapMode;
import mightypork.gamecore.resources.ResourceInitializer;
import mightypork.utils.math.constraints.rect.Rect;
public class RogueResources implements ResourceInitializer {
public class RogueInitResources extends InitTaskResources {
@Override
public void addFonts(FontRegistry fonts)
{
DeferredFont font;
//fonts.loadFont("polygon_pixel", new DeferredFont("/res/font/PolygonPixel5x7Standard.ttf", Glyphs.basic, 16));
fonts.addFont("press_start", font = new LwjglFont("/res/font/PressStart2P.ttf", Glyphs.basic, 16));
fonts.addFont("battlenet", font = new LwjglFont("/res/font/battlenet.ttf", Glyphs.basic, 16));
fonts.addFont("press_start", font = App.gfx().createFont("/res/font/PressStart2P.ttf", Glyphs.basic, 16));
fonts.addFont("battlenet", font = App.gfx().createFont("/res/font/battlenet.ttf", Glyphs.basic, 16));
font.setDiscardRatio(3 / 16D, 2 / 16D);
fonts.addFont("tinyutf", font = new LwjglFont("/res/font/TinyUnicode2.ttf", Glyphs.basic, 16));
fonts.addFont("tinyutf", font = App.gfx().createFont("/res/font/TinyUnicode2.ttf", Glyphs.basic, 16));
font.setDiscardRatio(5 / 16D, 3 / 16D);
// aliases
fonts.addAlias("thick", "press_start");
fonts.addAlias("thin", "battlenet");
fonts.addAlias("tiny", "tinyutf");
}
@Override
public void addSounds(SoundRegistry sounds)
{
//sounds.addLoop("music.dungeon", "/res/audio/music/Lightless_Dawn.ogg", 1, 1, 3, 1.5);
sounds.addLoop("music.menu", "/res/audio/music/Home_Base_Groove.ogg", 1, 0.7, 3, 1.5);
sounds.addLoop("music.dungeon", "/res/audio/music/8bit_Dungeon_Level.ogg", 1, 0.6, 3, 1.5);
//sounds.addLoop("music.dungeon2.boss", "/res/audio/music/8bit_Dungeon_Boss.ogg", 1, 0.6, 3, 1.5);
sounds.addEffect("gui.shutter", "/res/audio/effects/shutter.ogg", 1, 1);
sounds.addEffect("gui.click", "/res/audio/effects/click.ogg", 1, 1);
sounds.addEffect("game.win", "/res/audio/effects/win.ogg", 1, 0.7);
sounds.addEffect("game.lose", "/res/audio/effects/lose.ogg", 1, 1);
sounds.addEffect("item.drop", "/res/audio/effects/drop.ogg", 1, 1);
sounds.addEffect("item.pickup", "/res/audio/effects/pickup.ogg", 1, 1);
sounds.addEffect("item.break", "/res/audio/effects/break.ogg", 1, 1);
sounds.addEffect("player.eat", "/res/audio/effects/eat.ogg", 1, 1);
sounds.addEffect("player.hurt", "/res/audio/effects/hurt.ogg", 1, 1);
sounds.addEffect("crate.open", "/res/audio/effects/crate.ogg", 1, 1);
sounds.addEffect("door.open", "/res/audio/effects/door.ogg", 1, 1);
sounds.addEffect("door.close", "/res/audio/effects/door.ogg", 0.8, 1);
sounds.addEffect("rat.sqeak1", "/res/audio/effects/mouse1.ogg", 1, 1);
sounds.addEffect("rat.sqeak2", "/res/audio/effects/mouse2.ogg", 1, 1);
sounds.addEffect("rat.sqeak3", "/res/audio/effects/mouse3.ogg", 1, 1);
sounds.addEffect("rat.sqeak4", "/res/audio/effects/mouse4.ogg", 1, 1);
sounds.addEffect("rat.sqeak5", "/res/audio/effects/mouse5.ogg", 1, 1);
}
@Override
public void addTextures(TextureRegistry textures)
{
ITexture texture;
QuadGrid grid;
// gui
texture = textures.loadTexture("/res/img/gui.png", FilterMode.NEAREST, WrapMode.CLAMP);
// small gui elements
grid = texture.grid(32, 32);
textures.add("hud.heart.on", grid.makeQuad(0, 0));
@ -89,14 +88,14 @@ public class RogueResources implements ResourceInitializer {
textures.add("hud.heart.half", grid.makeQuad(2, 0));
textures.add("hud.xp.on", grid.makeQuad(0, 1));
textures.add("hud.xp.off", grid.makeQuad(1, 1));
// nav
grid = texture.grid(8, 8);
textures.add("nav.bg", grid.makeQuad(0, 7, 4, 1));
textures.add("nav.button.bg.base", grid.makeQuad(4, 7));
textures.add("nav.button.bg.hover", grid.makeQuad(5, 7));
textures.add("nav.button.bg.down", grid.makeQuad(6, 7));
textures.add("nav.button.fg.eat", grid.makeQuad(0, 6));
textures.add("nav.button.fg.inventory", grid.makeQuad(1, 6));
textures.add("nav.button.fg.attack", grid.makeQuad(2, 6));
@ -107,10 +106,10 @@ public class RogueResources implements ResourceInitializer {
textures.add("nav.button.fg.magnify", grid.makeQuad(7, 6));
textures.add("nav.button.fg.save", grid.makeQuad(7, 5));
textures.add("nav.button.fg.load", grid.makeQuad(6, 5));
textures.add("inv.slot.base", grid.makeQuad(0, 5));
textures.add("inv.slot.selected", grid.makeQuad(1, 5));
// sprites
texture = textures.loadTexture("/res/img/sprites.png", FilterMode.NEAREST, WrapMode.CLAMP);
grid = texture.grid(8, 8);
@ -119,7 +118,7 @@ public class RogueResources implements ResourceInitializer {
textures.add("sprite.rat.brown", grid.makeSheet(0, 2, 4, 1));
textures.add("sprite.rat.boss", grid.makeSheet(0, 3, 4, 1));
textures.add("sprite.zzz", grid.makeQuad(0, 7)); // sleep thingy
// logo
texture = textures.loadTexture("/res/img/logo.png", FilterMode.NEAREST, WrapMode.CLAMP);
textures.add("logo", texture.makeQuad(Rect.make(0, 0, 0.543, 0.203)));
@ -127,52 +126,52 @@ public class RogueResources implements ResourceInitializer {
textures.add("death", grid.makeQuad(0, 2));
textures.add("death2", grid.makeQuad(1, 2, 1.5, 1));
textures.add("win", grid.makeQuad(2.5, 2, 1.5, 1));
grid = texture.grid(8, 4);
textures.add("story_1", grid.makeQuad(0, 2, 3, 1));
textures.add("story_2", grid.makeQuad(3, 2, 3, 1));
textures.add("story_3", grid.makeQuad(0, 3, 3, 1));
// tiles
texture = textures.addTexture("tiles", "/res/img/tiles.png", FilterMode.NEAREST, WrapMode.CLAMP);
grid = texture.grid(8, 8);
textures.add("tile.brick.floor", grid.makeSheet(0, 1, 5, 1));
textures.add("tile.brick.wall", grid.makeSheet(0, 0, 8, 1));
textures.add("tile.brick.door.closed", grid.makeQuad(1, 2));
textures.add("tile.brick.door.open", grid.makeQuad(2, 2));
textures.add("tile.brick.door.secret", grid.makeSheet(0, 3, 2, 1));
textures.add("tile.brick.passage", grid.makeSheet(3, 2, 4, 1));
textures.add("tile.brick.stairs.up", grid.makeQuad(0, 6));
textures.add("tile.brick.stairs.down", grid.makeQuad(1, 6));
textures.add("tile.extra.chest.closed", grid.makeQuad(0, 4));
textures.add("tile.extra.chest.open", grid.makeQuad(1, 4));
// shadows
textures.add("tile.shadow.n", grid.makeQuad(0, 7));
textures.add("tile.shadow.s", grid.makeQuad(0, 7).flipY());
textures.add("tile.shadow.w", grid.makeQuad(1, 7));
textures.add("tile.shadow.e", grid.makeQuad(1, 7).flipX());
textures.add("tile.shadow.nw", grid.makeQuad(2, 7));
textures.add("tile.shadow.ne", grid.makeQuad(2, 7).flipX());
textures.add("tile.shadow.sw", grid.makeQuad(2, 7).flipY());
textures.add("tile.shadow.se", grid.makeQuad(2, 7).flipY().flipX());
// unexplored fog
textures.add("tile.ufog.n", grid.makeQuad(3, 7));
textures.add("tile.ufog.s", grid.makeQuad(3, 7).flipY());
textures.add("tile.ufog.w", grid.makeQuad(4, 7));
textures.add("tile.ufog.e", grid.makeQuad(4, 7).flipX());
textures.add("tile.ufog.nw", grid.makeQuad(5, 7));
textures.add("tile.ufog.ne", grid.makeQuad(5, 7).flipX());
textures.add("tile.ufog.sw", grid.makeQuad(5, 7).flipY());
textures.add("tile.ufog.se", grid.makeQuad(5, 7).flipY().flipX());
textures.add("tile.ufog.full", grid.makeQuad(6, 7));
texture = textures.addTexture("items", "/res/img/items.png", FilterMode.NEAREST, WrapMode.CLAMP);
grid = texture.grid(8, 8);
textures.add("item.meat", grid.makeQuad(0, 0));
@ -187,5 +186,5 @@ public class RogueResources implements ResourceInitializer {
textures.add("item.knife", grid.makeQuad(1, 1));
textures.add("item.twig", grid.makeQuad(2, 1));
}
}

@ -0,0 +1,24 @@
package mightypork.rogue;
import java.io.File;
import mightypork.gamecore.core.init.InitTaskWorkdir;
public class RogueInitWorkdir extends InitTaskWorkdir {
public RogueInitWorkdir(File workdir)
{
super(workdir, true);
}
@Override
public void init()
{
addPath("slot1", "saves/slot_1.ion");
addPath("slot2", "saves/slot_2.ion");
addPath("slot3", "saves/slot_3.ion");
}
}

@ -1,46 +0,0 @@
package mightypork.rogue;
public class RogueKeys implements KeySetup {
@Override
public void addKeys(KeyOpts keys)
{
keys.addKey("global.quit", "CTRL+Q", "Quit the game");
keys.addKey("global.quit_force", "CTRL+SHIFT+Q", "Quit the game without asking, low-level");
keys.addKey("global.screenshot", "F2", "Take screenshot (save into working directory)");
keys.addKey("global.fullscreen", "F11", "Toggle fullscreen");
keys.addKey("global.fps_meter", "F3", "Toggle FPS meter overlay");
keys.addKey("general.close", "ESC", "Leave a dialog or screen");
keys.addKey("general.cancel", "ESC", "\"Cancel\" option in dialogs");
keys.addKey("general.confirm", "ENTER", "\"Confirm\" option in dialogs");
keys.addKey("general.yes", "Y", "\"Yes\" option in dialogs");
keys.addKey("general.no", "N", "\"No\" option in dialogs");
keys.addKey("game.quit", "ESC", "Quit to menu");
keys.addKey("game.save", "CTRL+S", "Save to file");
keys.addKey("game.load", "CTRL+L", "Load from file");
keys.addKey("game.zoom", "Z", "Toggle zoom");
keys.addKey("game.minimap", "M", "Toggle minimap");
keys.addKey("game.eat", "E", "Eat smallest food item");
keys.addKey("game.drop", "D", "Drop last picked item");
keys.addKey("game.inventory", "I", "Toggle inventory view");
keys.addKey("game.pause", "P", "Pause the game");
keys.addKey("game.walk.up", "UP", "Walk north");
keys.addKey("game.walk.down", "DOWN", "Walk south");
keys.addKey("game.walk.left", "LEFT", "Walk west");
keys.addKey("game.walk.right", "RIGHT", "Walk east");
keys.addKey("game.cheat.xray", "CTRL+SHIFT+X", "Cheat to see unexplored tiles");
keys.addKey("game.inv.use", "E", "Use (eat or equip) the selected item");
keys.addKey("game.inv.drop", "D", "Drop the selected item");
keys.addKey("game.inv.move.left", "LEFT", "Move inventory cursor left");
keys.addKey("game.inv.move.right", "RIGHT", "Move inventory cursor right");
keys.addKey("game.inv.move.up", "UP", "Move inventory cursor up");
keys.addKey("game.inv.move.down", "DOWN", "Move inventory cursor down");
}
}

@ -1,14 +0,0 @@
package mightypork.rogue;
public class RogueRoutes implements RouteSetup {
@Override
public void addRoutes(RouteOpts routeOpts)
{
routeOpts.addPath("slot1", "saves/slot_1.ion");
routeOpts.addPath("slot2", "saves/slot_2.ion");
routeOpts.addPath("slot3", "saves/slot_3.ion");
}
}

@ -18,43 +18,35 @@ import mightypork.utils.logging.Log;
* @author Ondřej Hruška (MightyPork)
*/
public class WorldProvider extends BusNode {
public static synchronized void init()
{
if (inst == null) {
inst = new WorldProvider();
}
}
public WorldProvider()
{
setListening(false);
}
private static WorldProvider inst;
private static WorldProvider inst = new WorldProvider();
public static WorldProvider get()
{
if (inst == null) {
throw new IllegalStateException("World provider not initialized.");
}
return inst;
}
private World world;
private final PlayerControl playerControl = new PlayerControl() {
@Override
protected World provideWorld()
{
return world;
}
};
/**
* Create and register a world based on a seed
*
@ -68,35 +60,35 @@ public class WorldProvider extends BusNode {
setWorld(w);
return w;
}
public World getWorld()
{
return world;
}
public void setWorld(World newWorld)
{
if (world != null) removeChildClient(world);
world = newWorld;
if (newWorld == null) return;
addChildClient(world);
}
public void loadWorld(File file) throws IOException
{
Log.f2("Loading world from: " + file);
final IonDataBundle bu = Ion.fromFile(file);
setWorld(bu.loadBundled("world", new World()));
world.setSaveFile(file);
}
public void saveWorld(File file) throws IOException
{
if (world == null) {
@ -105,21 +97,21 @@ public class WorldProvider extends BusNode {
if (file == null) {
throw new IllegalStateException("Trying to save world to a NULL file.");
}
if (world.isGameOver()) {
throw new IllegalStateException("Cannot save, player is dead.");
}
Log.f2("Saving world to: " + file);
final IonDataBundle bu = new IonDataBundle();
bu.put("level", world.getPlayer().getLevelNumber());
bu.putBundled("world", world);
Ion.toFile(file, bu);
}
/**
* Save to world's assigned save file.
*
@ -129,20 +121,20 @@ public class WorldProvider extends BusNode {
{
saveWorld(world.getSaveFile());
}
public Level getCurrentLevel()
{
return getWorld().getPlayer().getLevel();
}
public PlayerFacade getPlayer()
{
return getWorld().getPlayer();
}
/**
* @return constant player control (world independent)
*/
@ -150,5 +142,5 @@ public class WorldProvider extends BusNode {
{
return playerControl;
}
}

@ -1,15 +1,12 @@
package mightypork.rogue.world.gui;
import mightypork.gamecore.core.App;
import mightypork.gamecore.gui.components.InputComponent;
import mightypork.gamecore.input.events.MouseButtonEvent;
import mightypork.gamecore.input.events.MouseButtonHandler;
import mightypork.rogue.Const;
import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.tile.Tile;
import mightypork.utils.math.algo.Coord;
import mightypork.utils.math.color.Color;
import mightypork.utils.math.color.pal.RGB;
@ -20,34 +17,34 @@ import mightypork.utils.math.constraints.vect.Vect;
public class Minimap extends InputComponent implements MouseButtonHandler {
private final RectVar bounds = Rect.makeVar();
private int unit = 0;
private final Num translucency = Num.make(0.8);
private final Color playerColor = RGB.RED;
@Override
protected void renderComponent()
{
Color.pushAlpha(translucency);
final Level lvl = WorldProvider.get().getCurrentLevel();
unit = (int) Math.min(Math.max(2, Math.ceil((height().value() / 2) / (lvl.getHeight() + 2))), 10);
final Vect plCoord = WorldProvider.get().getPlayer().getVisualPos();
final int lw = lvl.getWidth();
final int lh = lvl.getHeight();
final Vect tl = topRight().sub(unit * lw, 0);
bounds.setTo(tl, unit * lw, unit * lh);
final Coord point = new Coord(tl.xi(), tl.yi());
// FIXME do not use LWJGL directly
/*
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glBegin(GL11.GL_QUADS);
@ -80,12 +77,12 @@ public class Minimap extends InputComponent implements MouseButtonHandler {
GL11.glVertex2d(plx + unit, ply + unit);
GL11.glVertex2d(plx, ply + unit);
GL11.glEnd();
GL11.glEnd();*/
Color.popAlpha();
}
@Override
public void receive(MouseButtonEvent event)
{
@ -93,14 +90,14 @@ public class Minimap extends InputComponent implements MouseButtonHandler {
if (event.isUp()) {
final Vect relative = event.getPos().sub(bounds.origin());
final Coord actual = Coord.make(relative.xi() / unit, relative.yi() / unit);
final PlayerFacade player = WorldProvider.get().getPlayer();
if (player.getLevel().getTile(actual).isExplored()) {
player.navigateTo(actual);
}
}
event.consume();
}
}

@ -5,7 +5,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import mightypork.gamecore.backends.lwjgl.LwjglInputModule;
import mightypork.gamecore.core.App;
import mightypork.gamecore.core.config.Config;
import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
@ -22,52 +22,62 @@ import mightypork.utils.math.constraints.vect.Vect;
public class MIPKeyboard extends MapInteractionPlugin implements DelegatingClient, PlayerStepEndListener, Updateable {
// FIXME cannot be static.
//@formatter:off
private static final KeyStroke[] keys = {
Config.getKeyStroke("game.walk.left"),
Config.getKeyStroke("game.walk.right"),
Config.getKeyStroke("game.walk.up"),
Config.getKeyStroke("game.walk.down")
};
private static final Move[] sides = { Moves.W, Moves.E, Moves.N, Moves.S };
//@formatter:on
private final KeyBindingPool kbp = new KeyBindingPool();
private final List<Object> clients = new ArrayList<>();
{
clients.add(kbp);
}
private KeyStroke[] getKeys()
{
//@formatter:off
final Config cfg = App.cfg();
return new KeyStroke[] {
cfg.getKeyStroke("game.walk.left"),
cfg.getKeyStroke("game.walk.right"),
cfg.getKeyStroke("game.walk.up"),
cfg.getKeyStroke("game.walk.down")
};
//@formatter:on
}
@Override
public boolean doesDelegate()
{
return true;
}
@Override
public Collection<?> getChildClients()
{
return clients;
}
public MIPKeyboard(MapView mapView)
{
super(mapView);
final KeyStroke[] keys = getKeys();
// bind keys
for (int i = 0; i < 4; i++) {
final int j = i;
kbp.bindKey(keys[i], Trigger.RISING, new Runnable() {
@Override
public void run()
{
@ -76,41 +86,43 @@ public class MIPKeyboard extends MapInteractionPlugin implements DelegatingClien
});
}
}
@Override
public void onStepFinished(EntityPlayer player)
{
walkByKey();
}
@Override
public boolean onClick(Vect mouse, int button, boolean down)
{
return false;
}
private void clickSide(Move side)
{
if (isImmobile() || getPlayer().isMoving()) return;
mapView.plc.clickTile(side);
}
private boolean walkByKey()
{
if (isImmobile()) return false;
if (mapView.plc.getPlayer().getMoveProgress() < 0.8) return false;
if (Keys.getActiveMods() != Keys.MOD_NONE) return false;
if (LwjglInputModule.getActiveKeyMod() != Keys.MOD_NONE) return false;
final KeyStroke[] keys = getKeys();
for (int i = 0; i < 4; i++) {
if (keys[i].isDown()) {
final Move side = sides[i];
if (mapView.plc.canGo(side)) {
mapView.plc.go(side);
@ -122,8 +134,8 @@ public class MIPKeyboard extends MapInteractionPlugin implements DelegatingClien
}
return false;
}
@Override
public void update(double delta)
{

Loading…
Cancel
Save