Skip to content

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 the Game in the GameApplication 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 is World.
  • 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 the Animation class.
    • If you use gamelib-framework module, AbstractActor class can help you to create your first actors.
  • 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.

Base interfaces and classes of Gamelib

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:

  1. Update state of the game (primarily, state of actors in the scene).
  2. Render the current scene.
  3. 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:

  1. Update the scene:
    1. Call the execute(float deltaTime) method for every action currently scheduled on the scene.
    2. Remove all actions that return true from the isDone() method. The removed actions will not be executed again in subsequent cycles of the loop.
    3. Call sceneUpdating(Scene scene) method of each registered SceneListener.
  2. Render the scene:
    1. Render the scene map.
    2. Render the map overlay.
    3. Render animations of actors on the scene.
    4. Render the scene overlay.
    5. Call sceneRendered(Scene scene) method of each registered SceneListener.
  3. Render the game overlay.
  4. Repeat the process after the time for one frame passes.

  1. The time for a frame is 1/60 of a second for frame rate of 60 frames per second.