org.saltosion.pixelprophecy.Prophecy.java Source code

Java tutorial

Introduction

Here is the source code for org.saltosion.pixelprophecy.Prophecy.java

Source

/*
* Copyright (C) 2016 Saltosion
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNUss General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.saltosion.pixelprophecy;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.graphics.GL20;
import org.saltosion.pixelprophecy.gui.GUIManager;
import org.saltosion.pixelprophecy.input.GUIInputAdapter;
import org.saltosion.pixelprophecy.states.GameState;
import org.saltosion.pixelprophecy.states.LoadingState;
import org.saltosion.pixelprophecy.states.MainMenuState;
import org.saltosion.pixelprophecy.states.StateManager;
import org.saltosion.pixelprophecy.util.MapLoader;
import org.saltosion.pixelprophecy.util.Names;

public class Prophecy extends ApplicationAdapter {

    private StateManager stateManager;
    private GUIManager guiManager;

    @Override
    public void create() {
        // Initialize InputMultiplexer
        InputMultiplexer multiplexer = new InputMultiplexer();
        Gdx.input.setInputProcessor(multiplexer);

        // Initialize GUIManager
        guiManager = new GUIManager();
        multiplexer.addProcessor(new GUIInputAdapter(guiManager));

        //Initialize StateManager
        MapLoader mapLoader = new MapLoader();
        stateManager = new StateManager();
        stateManager.addState(Names.GAME_STATE, new GameState(multiplexer, guiManager, mapLoader));
        stateManager.addState(Names.LOADING_STATE, new LoadingState(guiManager, mapLoader));
        stateManager.addState(Names.MAINMENU_STATE, new MainMenuState(guiManager));
        stateManager.setState(Names.LOADING_STATE);
    }

    @Override
    public void render() {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        stateManager.update();
        guiManager.drawGUI();
    }

    @Override
    public void resize(int width, int height) {
        super.resize(width, height);
        stateManager.resize(width, height);
        guiManager.resize(width, height);
    }

    @Override
    public void dispose() {
        stateManager.dispose();
        super.dispose();
    }

}