You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
3.4 KiB
129 lines
3.4 KiB
11 years ago
|
package mightypork.rogue;
|
||
|
|
||
11 years ago
|
|
||
11 years ago
|
import java.io.File;
|
||
11 years ago
|
|
||
11 years ago
|
import mightypork.gamecore.Config;
|
||
11 years ago
|
import mightypork.gamecore.app.BaseApp;
|
||
|
import mightypork.gamecore.app.MainLoop;
|
||
11 years ago
|
import mightypork.gamecore.app.MainLoopRequest;
|
||
11 years ago
|
import mightypork.gamecore.eventbus.BusEvent;
|
||
11 years ago
|
import mightypork.gamecore.gui.screens.ScreenRegistry;
|
||
|
import mightypork.gamecore.input.InputSystem;
|
||
11 years ago
|
import mightypork.gamecore.input.KeyConfig;
|
||
|
import mightypork.gamecore.input.KeyStroke.Edge;
|
||
11 years ago
|
import mightypork.gamecore.render.DisplaySystem;
|
||
11 years ago
|
import mightypork.gamecore.util.ion.Ion;
|
||
11 years ago
|
import mightypork.rogue.RogueStateManager.RogueState;
|
||
11 years ago
|
import mightypork.rogue.events.ActionRequest;
|
||
|
import mightypork.rogue.events.ActionRequest.RequestType;
|
||
11 years ago
|
import mightypork.rogue.events.GameStateRequest;
|
||
11 years ago
|
import mightypork.rogue.screens.FpsOverlay;
|
||
11 years ago
|
import mightypork.rogue.screens.LoadingOverlay;
|
||
11 years ago
|
import mightypork.rogue.screens.game.ScreenGame;
|
||
11 years ago
|
import mightypork.rogue.screens.layout_testing.LayoutTestScreen;
|
||
11 years ago
|
import mightypork.rogue.screens.menu.ScreenMainMenu;
|
||
11 years ago
|
import mightypork.rogue.screens.select_world.ScreenSelectWorld;
|
||
11 years ago
|
import mightypork.rogue.world.Inventory;
|
||
11 years ago
|
import mightypork.rogue.world.WorldProvider;
|
||
11 years ago
|
import mightypork.rogue.world.level.Level;
|
||
11 years ago
|
|
||
|
|
||
11 years ago
|
/**
|
||
|
* Main class
|
||
|
*
|
||
|
* @author MightyPork
|
||
|
*/
|
||
11 years ago
|
public final class RogueApp extends BaseApp {
|
||
11 years ago
|
|
||
11 years ago
|
public RogueApp(File workdir, boolean singleInstance)
|
||
11 years ago
|
{
|
||
11 years ago
|
super(workdir, singleInstance);
|
||
11 years ago
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
11 years ago
|
protected void registerIonizables()
|
||
11 years ago
|
{
|
||
11 years ago
|
super.registerIonizables();
|
||
11 years ago
|
|
||
11 years ago
|
Ion.registerType(Level.ION_MARK, Level.class);
|
||
11 years ago
|
Ion.registerType(Inventory.ION_MARK, Inventory.class);
|
||
11 years ago
|
}
|
||
|
|
||
|
|
||
11 years ago
|
@Override
|
||
11 years ago
|
protected void initDisplay(DisplaySystem display)
|
||
11 years ago
|
{
|
||
11 years ago
|
display.createMainWindow(Const.WINDOW_W, Const.WINDOW_H, true, Config.<Boolean> get("opt.fullscreen"), Const.TITLEBAR);
|
||
11 years ago
|
display.setTargetFps(Const.FPS_RENDER);
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
|
||
11 years ago
|
@Override
|
||
11 years ago
|
protected void initScreens(ScreenRegistry screens)
|
||
11 years ago
|
{
|
||
11 years ago
|
super.initScreens(screens);
|
||
|
|
||
11 years ago
|
/* game screen references world provider instance */
|
||
|
WorldProvider.init(this);
|
||
11 years ago
|
getEventBus().subscribe(new RogueStateManager(this));
|
||
11 years ago
|
|
||
|
|
||
11 years ago
|
screens.addScreen("main_menu", new ScreenMainMenu(this));
|
||
|
screens.addScreen("select_world", new ScreenSelectWorld(this));
|
||
11 years ago
|
screens.addScreen("game", new ScreenGame(this));
|
||
11 years ago
|
screens.addScreen("test.layout", new LayoutTestScreen(this));
|
||
11 years ago
|
|
||
|
screens.addOverlay(new FpsOverlay(this));
|
||
11 years ago
|
screens.addOverlay(new LoadingOverlay(this));
|
||
11 years ago
|
}
|
||
|
|
||
|
|
||
11 years ago
|
@Override
|
||
11 years ago
|
protected void initInputSystem(InputSystem input)
|
||
11 years ago
|
{
|
||
11 years ago
|
// this will work only with reusable events (such as requests)
|
||
11 years ago
|
bindEventToKey(new ActionRequest(RequestType.FULLSCREEN), "key.global.fullscreen");
|
||
|
bindEventToKey(new ActionRequest(RequestType.SCREENSHOT), "key.global.screenshot");
|
||
11 years ago
|
|
||
11 years ago
|
bindEventToKey(new GameStateRequest(RogueState.EXIT), "key.global.quit");
|
||
|
bindEventToKey(new GameStateRequest(RogueState.MAIN_MENU), "key.global.menu");
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
|
||
11 years ago
|
private void bindEventToKey(final BusEvent<?> event, String strokeName)
|
||
11 years ago
|
{
|
||
11 years ago
|
getInput().bindKey(KeyConfig.get(strokeName), Edge.RISING, new Runnable() {
|
||
11 years ago
|
|
||
|
@Override
|
||
|
public void run()
|
||
|
{
|
||
11 years ago
|
getEventBus().send(event);
|
||
11 years ago
|
}
|
||
|
});
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
|
||
|
@Override
|
||
|
protected MainLoop createMainLoop()
|
||
|
{
|
||
11 years ago
|
return new RogueMainLoop(this);
|
||
11 years ago
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
protected void postInit()
|
||
|
{
|
||
11 years ago
|
getEventBus().send(new MainLoopRequest(new Runnable() {
|
||
|
|
||
|
@Override
|
||
|
public void run()
|
||
|
{
|
||
11 years ago
|
getEventBus().send(new GameStateRequest(RogueState.MAIN_MENU));
|
||
11 years ago
|
//getEventBus().send(new CrossfadeRequest("test.layout", true));
|
||
|
}
|
||
|
}));
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|