Inside The Script - SickheadGames/AdventureKit GitHub Wiki

Structure

The demo that comes with the kit is a useful starting point for anyone creating a top down action, adventure, or even RPG game. It is structured like most all TGB games:

  • adventureKit
    • data
      • audio - All our sound files.
      • images - All the local demo art... menu screens, button art, etc.
      • levels - The level files.
      • particles - Nothing in here!
      • tilemaps - The tilemaps and layer files for the levels.
  • gameScripts - All the game script files.
  • gui - The gui screens.
  • managed - Internal stuff managed by TGB editors.

NOTE: If your looking for the rest of the art you need to look in the resources/adventureKitArt folder.

For the remainder of this page we'll focus on the game scripts.

Game Scripts

The demo uses config datablocks heavily as a sort of constructor or template for initializing objects. The config datablocks are described in detail in the level building tutorial. Here we'll go over each object from the framework and try to provide some important information on what they do and how they work.

Player

The Player object is the base for the user controlled player and AI players. It provides the core features for spawning, damage and death, firing the weapon, sound effects, and movement. Player::update(), which is called on each scene graph update, does the bulk of the work transforming the current movement state to velocities on the sprite, animating it appropriately, and changing sound states.

One of the more elaborate sections of the code deals with jumping. To jump the Player object creates a simple t2dPath on the fly based on the jump direction. The player is then mounted to the path until it reaches the end of the jump. The jump code is quite convoluted because of some of the limits of t2dPath as of TGB 1.1.1. With more control over the time to travel the path and looping, the jump code could be re-written in a simpler fashion.

AiPlayer

The AiPlayer object extends the Player object adding Steering and AiGoalThink objects. AiPlayer::getMove() is overloaded from Player so that the Steering object can drive the movement of the AiPlayer. The Steering object itself is controlled by AiGoalThink and other AiGoal objects.

The AiPlayer::update() works a little differently here than in the Player object. While the Player is updated every time the scene graph is, each AiPlayer starts it's own scheduled update. By using schedules we sort of timeslice updates spreading the update cost for lots of AIs over multiple frames. This technique is used by multiple objects in the kit framework.

SoundEmitter

The SoundEmitter object provides simple 2D sound attenuation based on the position of the emitter to the Camera object. It does this by updating the volume of playing sounds every few milliseconds. The area which the sound emitter effects works in one of three ways:

  • If the ambient field is enabled then on attenuation is done.
  • If the emitter is mounted to an object the width of the emitter's bounding box is used to define the radius of the sound.
  • If not mounted, the width and height of the bounding box define a sort of capsule of sound.

The sound itself doesn't just linearly ramp up as it approaches the center of the radius. Instead we opted for a linear ramp up to 50% of the radius then the sound plays at full volume.

The biggest issue with the SoundEmitter object is the inconsistency and general bugginess of OpenAL in TGB 1.1.1. GG is working on upgrading the sound layer to correct this.

Breakable

The Breakable object is used to do the breakable walls as well as the exploding TNT barrels in the kit demo. It's all based on the single Breakable::damage() function which enables various effects based on what was set in the config datablock or in LevelBuilder.

Camera

The Camera object is similar to other camera objects seen in various TGB demos. It is mounted by the t2dSceneWindow which follows it's position to move the camera around the world. The camera itself can be given a target to follow, which in the case of the kit demo is the Player object. The Camera object also supports a time based zoom in/out feature. The Camera::update() is called from Level::onUpdateScene() and takes care of the tracking and zooming.

EnemySpawn / EnemySpawnConfig

The EnemySpawn object spawns one or more enemies at level start and respawns them when they are killed based on simple. It triggers a change in camera zoom when a Player object walks into it's bounding box.

Globals

We try to avoid them, but there are a few global objects which come in handy in the demo:

  • $player --- The current player object. Be sure to test it with isObject() as it could be deleted.
  • $camera --- The one camera object in the scene.
  • $aiPlayers --- This is a SimSet of all the active AiPlayer objects. It is used from a few console functions.
  • $levelScene --- The one and only level scene graph object created during mission load.

Console Commands

There are several new console commands the kit adds which you'll find useful when working on your game:

  • toggleDebugBanner() - Enables/disables the debug banner with all the TGB performance information.
  • toggleCollisionShapes() - Enables/disables the rendering of the collision shapes for each scene object.
  • toggleBoundingBoxes() - Enables/disables the rendering of the bounding boxes for each scene object.
  • loadLevel( %levelFile, %optionalSpawnPoint ) - Starts the loading of a level. The level name doesn't need to include the path to the default level folder or even the level file extension.
  • respawn( %optionalSpawnPoint ) - Kills the player and respawns him at a new random spawn point or the one passed to the call.
  • suicide() - Kills the player.
  • god() - Toggles god mode where you're invulnerable to all damage.
  • ghost() - Toggles ghost mode where you have no collision and can walk thru walls.
  • letThereBeNight() - An experimental feature which fakes a night scene without the need for additional art.
  • letThereBeLight() - Restores the scene from the night mode.