A Single Class Game attempt to bring in a minimum scope all the commons and standards game stack.
This small project based on some knowledge found on the Internet (so, you know that Internet is the truth :) You will be happy to discover a simple way to develop and build a small java game.
The game project repository contains:
singleclassgame
|_ .github \
| |_ ISSUE_TEMPLATE |
| |_ Bug_report.md > Some github specific files
| |_ Feature_request.md |
| /
|_ src
| |_ main \
| | |_ fr.snapgames.game.oneclassgame |
| | | |_ Game.java |
| |_ resources |
| |_ res > Project resources
| |_ audio |
| |_ sounds |
| |_ images |
| |_ application.ico /
|
|_ .travis.yml > Continuous build config file
|
|_ CODE_OF_CONDUCT.md \ Other specific
|_ LICENSE / github and license file
|
|_ README.md > this fantastic file
|_ pom.xml > where the magical wizard work.
The main parent class is Game, from the Game.java file. But all classes which used here are declared into the Game class.
Game
|_ COnfiguration
|_ KeyInputListener
|_ GameObject
|_ GameKeyListener
|_ PlayerKeyListener
|_ ...
Configurationclass is used to storekey=valueas a configuration store purpose,ResourceManagerprovides a basic service to load images and reduce memory usage,Vector2Dproposes a simplified 2D math vector implementation to manage physics computation,Windowis what it means to be a Window encapsulation of JDK one,VersionTracerclass proposes a dependencies and versions tracker about embedded libraries.
GameObjectis a default object managed by the game to be updated and displayed,- a
Cameraobject to make window view follow another object, KeyInputListeneris the main KeyListenr for the window displaying the game,GameKeyListeneris a key command manager for the Game itself. this is where the exit and pause request are processed,PlayerKeyListeneris a specific key listener to animate and move the playerGameObjectinstance.
Worlda class to manage a world context containing some physics parameters for the Physic computation performed at GameObject level (seeGameObect#updatePhysic(float)), like wind, world gravity, and soon other parameters.
- To manage Objects, I add a
BoundingBoxand aBoundingBoxTypeto encapsulate object with multiple box types (Rectangle, Circle, Ellipse, Capsules, etc...) - A
QuadTreeimplementation (from internet) provide the necessary structure to manage 2D space splitting to reduce Collision computation. CollisionManageris a class to detect and manage collision events betweenGameObjects. ACollisionResponseProcessorinterface can be implemented to manage those events for some specific case;ColliderResponseis one of it.
NOTE Must add some interactions between "player" and a map.
To make sounds, the game is enriched with a new SoundController and some entity to manage sounds: SoundClip.
SoundControlis the sound manager class, loading, playing and stopping sounds,SoundClipis a piece of sound to be played and managed by theSoundControlmanager.
One of the most important system in the game, is not only the Game Loop, but also the system that can switch from one state of the game (the title screen) to another (the main play state) one without pain: GameStateManager. This particular class will manage multiple implementations of the interface named GameState to change smoothly the game behavior, corresponding to any game play you want to provide. An abstract class, the AbstractGameState will provide the basic and default behavior of each game state.
Some, the classes added are :
GameStatedefining the basic interface to provide a new behavior to your game,AbstractGameStateto provide a default behavior and some implementation to the GameState interface,GameStateManagerwhich is the main State manager, to switch from state to another with only a simple method call.
This simple interface provide the main methods to be implemented into any game state:
initialize(Game)to initialize state at Game start,activate(Game)when the state must be activated by theGameStateManager(GSM),deactivate(Game)when the state will be deactivated by theGSM,input(Game)when the managerGSMwill delegate the input processing to this particular GameState implementation,update(Game,float)called byGSMto update the activated state,render(Game,Graphics2D)to letGSMdelegate the rendering of this state.
Let's see JavaDoc for more information.
The GameStateManager is the main class to manage and delegate processing to some specific behavior classes implementing the GameState interface.
- You must add your GameState implementation to the stack by calling the
add(GameState)method. - then you can activate your just added state by calling the
start(String name). this will automatically called thedeactivate(Game)method of the previous state, and then call theactivate(Game)method of your name state.
Those class methods are called from the main game loop (see Game#run() method) to manage input, update and render things into each of the game states.
The audio part of this new feature is coming from the freesound.org. The magical boing sound is coming from here
Fred D.