Overview¶
Gamelib is a small library written in Java for creating games during introductory OOP course.
Basic game building blocks¶
There are several base entities that constitute a game created with GameLib. They can be found as interfaces in the core GameLib module.
Game
represents a game application. It consists of one or more scenes, one of which is always active - it is shown in the game window. There is a default implementation of theGame
in theGameApplication
class.Scene
can be described as a 2D game environment, consisting of a map (graphical representation of the environment), a collection of actors (entities within the environment), and a collection of actions (behaviour of either actors or environment). Its default implementation isWorld
.Actor
represents a game entity like a player, an enemy, a wrench, etc. It has its position in the scene and is graphically represented by a sprite created from theAnimation
class.- If you use
gamelib-framework
module,AbstractActor
class can help you to create your first actors.
- If you use
Action
represents an encapsulated piece of actor’s behaviour. All actions are executed by scene, one by one, each time the scene is going to be rendered on screen (usually, 60 times per second). After an action is executed, it may change its status to done, in which case it won’t be executed anymore when the scene is rendered again (see the game loop section below).- If you use
gamelib-framework
module,AbstractAction
class can help you to create your first actions.
- If you use
There are also several basic graphical entities:
Animation
is a visual representation of an actor in a scene. It can be static or animated sprite of the actor.SceneMap
is a graphical representation of scene environment that consist of tiles (usually with dimensions of 16x16 pixels). It may contain additional information, e.g., presence of walls or markers positioned on predefined areas. It supports loading map files created with Tiled map editor.Overlay
is used to draw simple shapes and texts above other graphical layers. A separate overlay is available for map, scene, and game.
The game loop¶
The game loop is responsible for repeatedly updating the state of the game as the time changes. As the game author, you have the possibility to execute custom code at different stages of the loop.
At the highest level of abstraction, the game loop simply looks like this:
- Update state of the game (primarily, state of actors in the scene).
- Render the current scene.
- Repeat the process after the time for one frame1 passes.
When using the default Scene
‘s implementation World
, the game loop and its stages are as follows:
- Update the scene:
- Call the
execute(float deltaTime)
method for every action currently scheduled on the scene. - Remove all actions that return
true
from theisDone()
method. The removed actions will not be executed again in subsequent cycles of the loop. - Call
sceneUpdating(Scene scene)
method of each registeredSceneListener
.
- Call the
- Render the scene:
- Render the scene map.
- Render the map overlay.
- Render animations of actors on the scene.
- Render the scene overlay.
- Call
sceneRendered(Scene scene)
method of each registeredSceneListener
.
- Render the game overlay.
- Repeat the process after the time for one frame passes.
-
The time for a frame is 1/60 of a second for frame rate of 60 frames per second. ↩