/** Called on game start */ public void setup() { instance = this; ground = false; isFlyMode = false; screenSelected = OptionsScreenEnum.mainScreen; LogHelper.init(); SaveData.initDirectory(this); RegistryRegistry.init(this); IconHelper.init(this); player = new Player(width / 2, 0, this); Block.blockInit(); selectedBlock = GameRegistry.getBlock(selectedBlockID); // Frame Stuffs size(1280, 720, OPENGL); if (frame != null) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL icon = classLoader.getResource(MainReference.ICON_LOCATION); frame.setTitle(MainReference.GAME_NAME); frame.setIconImage(getToolkit().getImage(icon)); } frameRate(MainReference.FRAME_RATE); addMouseWheelListener( new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent mwe) { mouseWheel(mwe.getWheelRotation()); } }); }
/** main game loop */ public void draw() { deltaTime = 1 / frameRate; if (screenSelected == OptionsScreenEnum.noScreen) { isSaving = true; saveDisplayCounter = 100; background(100, 100, 255); DrawingAndLogicHelper.drawGame(this); } else if (screenSelected == OptionsScreenEnum.mainPause) { background(100, 100, 175); DrawingAndLogicHelper.drawPauseMenu(this); if (saveDisplayCounter == 100) SaveData.saveGame(worldName); if (--saveDisplayCounter < 0) isSaving = false; } else if (screenSelected == OptionsScreenEnum.mainScreen) { background(100, 100, 207); DrawingAndLogicHelper.drawMainMenu(this); } else if (screenSelected == OptionsScreenEnum.worldMaker) { background(100, 100, 207); DrawingAndLogicHelper.drawWorldCreateMenu(this); } else if (screenSelected == OptionsScreenEnum.worldSelector) { background(100, 100, 207); DrawingAndLogicHelper.drawWorldSelectionMenu(this); } }
public void mouseReleased() { if (ButtonRegistry.flyMode.held) isFlyMode = !isFlyMode; if (ButtonRegistry.returnToGame.held) clearOptionsScreen(); if (ButtonRegistry.exitGame.held) BlockScape.endgame(); if (ButtonRegistry.returnToMenu.held) { setOptionsScreen(OptionsScreenEnum.mainScreen); ButtonRegistry.returnToMenu.held = false; } if (ButtonRegistry.loadWorld.held) { setOptionsScreen(OptionsScreenEnum.worldSelector); ButtonRegistry.loadWorld.held = false; ButtonRegistry.generateWorldButtons(); } if (ButtonRegistry.newWorld.held) { setOptionsScreen(OptionsScreenEnum.worldMaker); ButtonRegistry.newWorld.held = false; } if (ButtonRegistry.createWorld.held) { worldName = TextBoxRegistry.worldNamer.input; try { generateNewWorld(worldName, this); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { ButtonRegistry.createWorld.held = false; } clearOptionsScreen(); } if (ButtonRegistry.backFromCreate.held) { setOptionsScreen(OptionsScreenEnum.mainScreen); ButtonRegistry.backFromCreate.held = false; } for (Button b : ButtonRegistry.worldButtons) { if (b.held) { try { SaveData.loadGame(b.getText(), player); worldName = b.getText(); clearOptionsScreen(); } catch (Exception e) { e.printStackTrace(); } finally { b.held = false; } } } }