package com.jonathan.survivor;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.FPSLogger;
import com.esotericsoftware.spine.Slot;
import com.jonathan.survivor.managers.MusicManager;
import com.jonathan.survivor.managers.PreferencesManager;
import com.jonathan.survivor.managers.ProfileManager;
import com.jonathan.survivor.managers.SoundManager;
import com.jonathan.survivor.screens.CompanySplashScreen;
public class Survivor extends Game
{
/** Stores the default size of a GUI camera. Every GUI camera should have this size by default. However, this size can change depending on the aspect
* ratio of the screen. The width and height are modified to match the aspect ratio of the screen, to prevent stretching. This new size is stored
* inside the guiWidth/Height variable of each Screen instance
*/
public static final float DEFAULT_GUI_WIDTH = 480;
public static final float DEFAULT_GUI_HEIGHT = 320;
/** Stores the default size of a camera displaying the world. Every world camera should have this size by default. However, this size can change depending
* on the aspect ratio of the screen. The width and height are modified to match the aspect ratio of the screen, to prevent stretching. This new size is
* stored inside the worldWidth/Height variable of each Screen instance. This is in meters. With these values, 1 meter = 32 pixels.
*/
public static final float DEFAULT_WORLD_WIDTH = 15;
public static final float DEFAULT_WORLD_HEIGHT = 10;
/** Stores the scale of the world relative to screen coordinates. The GUI size will always target a specific resolution, say 480x320. The world will usually
* model its coordinate system in meters, with the same aspect ratio as the target device (e.g., 15x10, where 32 pixels=1 meter. Thus, in this case, the world
* is scaled 480/15 = 0.03125 times smaller than pixel coordinates. Thus, all texture have to be down-scaled by this factor to compensate for the smaller world.
* the scale is found by dividing the default width of the world by the default width of GUI (that is, the target resolution width of the game)*/
public static final float WORLD_SCALE = DEFAULT_WORLD_WIDTH / DEFAULT_GUI_WIDTH;
/** Stores the maximum amount of profiles the user can have. This is the amount of worlds that appear on the world selection list. */
public static final int MAX_PROFILES = 3;
/** Stores the universal Music Manager used by the game which plays music and controls the volume of music. */
private MusicManager musicManager;
/** Stores the universal Sound Manager used by the game which plays sounds and controls the volume of sound effects. */
private SoundManager soundManager;
/** Holds the PreferencesManager, used to modify and access the player's preferences, such as music/sound volume. */
private PreferencesManager preferencesManager;
/** Stores the universal Profile Manager used by the game which retrieves/saves profiles from/to the hard drive. */
private ProfileManager profileManager;
/** Stores the Settings instance used to save the user's profile. */
private Settings settings;
/** Stores whether or not we are in debug mode */
public static final boolean DEBUG_MODE = false;
/** Logs the framerate to the console */
private FPSLogger fpsCounter = new FPSLogger();
@Override
public void create()
{
//Creates a new Assets instance to be used as a singleton. Cannot be instantiated upon declaration in the Assets class, because static variables retain their value
//even after app destruction.
Assets.instance = new Assets();
//Creates a new MusicManager and SoundManager to play and manage music and sound effects.
musicManager = new MusicManager();
soundManager = new SoundManager();
//Instantiates the PreferencesManager used to access and modify the player's preferences, such as music and sound volume.
preferencesManager = new PreferencesManager();
preferencesManager.setAmountProfiles(0);
//Creates the profile manager instance, used to manage the profiles used by the user. Parameter specifies how many profiles the manager has to load.
profileManager = new ProfileManager(preferencesManager.getAmountProfiles());
profileManager.deleteAllProfiles();
//Creates a settings instance that will be used to save the player's profile. The passed ProfileManager will be used to save the profile to the hard drive.
settings = new Settings(profileManager);
//If the game is in debug mode
//if(DEBUG_MODE)
//Mute the music.
//musicManager.setVolume(0);
//Allows the touchDown() methods of InputProcessors to be called when the BACK button is pressed on Android devices.
Gdx.input.setCatchBackKey(true);
//Set the starting screen of the application to the CompanySplashScreen. This is done through the Game.setScreen(Screen) method.
setScreen(new CompanySplashScreen(this));
}
@Override
public void render()
{
//Calls the render method of the currently active screen.
super.render();
//Display the framerate if in debug mode.
if(DEBUG_MODE)
fpsCounter.log();
}
@Override
public void resume()
{
//Calls the resume method of the currently active screen
super.resume();
}
@Override
public void pause()
{
//Calls the pause method of the currently active screen.
super.pause();
}
@Override
public void resize(int width, int height)
{
//Calls the resize method of the currently active screen. Changes the guiWidth/Height and worldWidth/Height member variable of each screen accordingly.
super.resize(width, height);
}
/** Returns the universal MusicManager used by the game to play music and control its volume */
public MusicManager getMusicManager()
{
return musicManager;
}
/** Returns the universal SounddManager used by the game to play sounds and control their volume */
public SoundManager getSoundManager()
{
return soundManager;
}
/** Returns the universal ProfileManager used by the game to access the profiles owned by the user. */
public ProfileManager getProfileManager()
{
return profileManager;
}
/** Returns the universal PreferencesManager used by the game to store and retrieve the player's preferences. */
public PreferencesManager getPrefsManager()
{
return preferencesManager;
}
/** Returns the universal Settings instance used by the game to save player information to the hard drive. */
public Settings getSettings() {
return settings;
}
/** Called when the application quits. */
@Override
public void dispose()
{
//Calls the hide() method of the screen.
super.dispose();
//Saves the preferences to the hard drive before quitting the application.
preferencesManager.savePreferences();
//Free any resources allocated to any visual/audio assets used by the game.
Assets.instance.dispose();
//DONOT call. Otherwise, the screen's dispose method will be called twice, since it is already called from the Screen.hide() method on application quit.
//getScreen().dispose();
}
}