Tutorial: Adding a New Game Object
Register a new ObjectType, map its sprite icon, and place it in a level.
Step 1 — Add the ObjectType Enum Value
File: include/GalaxyEggbert/def/ObjectType.hpp
// After ObjectType203:
ObjectType204 = 204, // MyNewObject
Step 2 — Add an Icon Mapping in Decor::GetIcon()
File: src/GalaxyEggbert/Game/Decor.cpp
case ObjectType204:
// element.png icon 42 — static
return 42;
Icon indices reference the element.png sprite sheet
(600×1740 px, 60×60 tiles, 10 cols × 29 rows, 290 icons).
Choose an appropriate icon that visually represents your object.
If the object animates, return baseIcon + (animPhase / frameDivisor) % frameCount.
Step 3 — Add Contact Behaviour in Decor::Update()
In the per-object contact check inside Decor::Update(), handle your object type:
if (obj.type == ObjectType204 && distance < 0.85f) {
// e.g., treat it as a collectible:
collected_++;
obj.active = false;
obj.node->Remove();
}
Step 4 — Place the Object in a Level
In a mobile-eggbert .txt level file, add a MoveObject entry:
MoveObject
numObject=204
posStart=50.0 1.0 50.0
posEnd=50.0 1.0 50.0
speed=0.0
...
Or call Decor::PlaceObject() directly from the demo world builder:
decor_->PlaceObject(ObjectType204, Vector3(50, 1, 50));
Step 5 — Build and Test
cmake --build cmake-build-debug --parallel
cd cmake-build-debug/bin && ./GalaxyEggbert
Navigate Blupi to the object. Verify it renders with the correct sprite and triggers the expected behaviour on contact.