Gameplay kit
The gameplay module adds the parts most 2D games rebuild by hand: a character controller, hit points, hitboxes and hurtboxes, kill zones, checkpoints with respawn, pickups and timed removal. They are components, so they are set up in the Inspector, saved with the scene and driven from scripts with a few calls.
Quick start: Create → Gameplay → Platformer Character gives a node with a kinematic Rigid Body 2D, a collider, Motion 2D, Health, Hurtbox 2D and Respawn. Give it a script that calls Move and Jump, add a floor and press Play.
In the interactive guide, walk with A/D or the arrow keys and jump with Space, W or Up.
Two complete games use the kit: aego new mygame --example platformer (stomping enemies with a foot hitbox, a pit with a kill zone, a checkpoint, a persisted respawn point and an Animator for the player's look, with a slash on a hit frame) and aego new mygame --example topdown (a sword swung towards the stick, the mouse or the walking direction, enemies whose State Machine switches between Patrol and Chase while their Animator shows it, a lunge by root motion, coins and lava). The launcher offers both under Examples.
| Component | Purpose |
|---|---|
| Motion 2D | walks, jumps and slides a kinematic body: slopes, steps, moving platforms, top-down movement |
| Health | hit points, team, invulnerability after a hit, death and revive |
| Hurtbox 2D | area where hitboxes hurt a Health |
| Hitbox 2D | area that damages hurtboxes, with knockback |
| Lifetime | removes a node after some seconds |
| Kill Zone 2D | kills or respawns what falls into it |
| Checkpoint 2D | moves the respawn point |
| Respawn | brings a node back to its respawn point |
| Pickup 2D | fires Collected when a character touches it |
| State Machine | named states with Enter, Exit, Fixed and Update hooks in the node's scripts |
Everything runs during Play and in aego run, in the fixed step, and allocates nothing per step. Hurtboxes, hitboxes and zones are areas in their node's space, not physics colliders: they never push anything and need no collision layers.
Try it
Change the example parameters and compare the result. Reset restores the initial scene.
Scene7 nodes
Scriptmain.aes
package demo
import "aego/input"
// Player walks with A/D or the arrows and jumps with Space, W or Up.
script Player {
func Update(dt float) {
m := node.Get<Motion2D>()
x := 0.0
if input.Down(input.KeyA) || input.Down(input.KeyLeft) {
x -= 1
}
if input.Down(input.KeyD) || input.Down(input.KeyRight) {
x += 1
}
m.Move(x)
if input.KeyPressed(input.KeySpace) || input.KeyPressed(input.KeyW) || input.KeyPressed(input.KeyUp) {
m.Jump()
}
if input.KeyReleased(input.KeySpace) || input.KeyReleased(input.KeyW) || input.KeyReleased(input.KeyUp) {
m.JumpReleased()
}
}
}
// Lift moves a kinematic platform up and down.
script Lift {
@export var Travel Vec2 = Vec2{0, -3}
@export var Period float = 4
var t float
var start Vec2
func Ready() {
start = node.Transform2D().Position
}
func FixedUpdate(dt float) {
t += dt
phase := t / Period
k := phase - float(int(phase))
if k > 0.5 {
k = 1 - k
}
k *= 2
body := node.Get<Body2D>()
body.MoveTo(Vec2{start.X + Travel.X*k, start.Y + Travel.Y*k}, 0)
}
}
- Character motion Motion 2D moves a character with a kinematic Rigid Body 2D.
- Health and damage Health holds hit points.
- Hurtboxes A Hurtbox 2D is an area in its node's space where hitboxes hurt a Health: the one in its Health field, or the nearest Health on the node or above it.
- Hitboxes A Hitbox 2D damages the hurtboxes inside its area after the physics step.
- Lifetime Lifetime removes its node after Seconds of game time, or real time with Unscaled.
- Kill zones A Kill Zone 2D kills a Health whose node position enters the area, or triggers Respawn on a node without Health.
- Checkpoints A Checkpoint 2D moves the respawn point of a node with Respawn that enters it, to its own position or to the node in Spawn Point.
- Respawn Respawn brings its node back after death, after a kill zone, or when a script calls
Trigger(). - Pickups A Pickup 2D fires
Collected(by)when a node enters it: a tagged node, or any node with Motion 2D. - State machines A State Machine lists state names; the scripts on its node hold the behaviour.
- Time and replays Motion, hits, zones and respawns run in the fixed step:
gameplay.fsm_fixedand thengameplay.motionbefore physics, afterscript.fixed, andgameplay.postafter physics, before scripts receive collision events. - Scripting The components are reached with
node.Get<T>(); there is no module to import. - Editor tools The editor builds ready gameplay nodes, draws hit areas and shows the state of controllers, health and state machines during Play.
- Go The component types and their methods are the same as in scripts.