Collectable Objects
From C4 Engine Wiki
Say you want to make a collectable object that increases the player's score.
This tutorial will help you do such a thing in the Game module that ships with C4.
Making an Entity
Look in MGControllers.h, and go to line 57.
You should see
// Entity types
First, we're going to add
kEntityRing = 'ring',
before
kEntityBighHealth
kEntityRing will tell the engine that there's a new entity and 'ring' tells the engine the name of the entity.
Now open MGControllers.cpp, and go to line 2092.
Go after the bracket, and press enter once and tab once, and add
case kEntityRing:
{
long score = player->GetPlayerScore();
if (score >= 999999) return;
player->SetPlayerScore(Min(score + 100, 999999));
}
GetPlayerScore does just as it says and gets the player's score. If the player's score is below 999999, then the Ring entity can be collected.
SetPlayerScore again does just as it says, and sets the player's score to the value that's defined by score + 100 .
The player's score is increased by 100 for every ring that's picked up in this case.
Making an Entity Collectable
Now we're going to open MGGame.h.
Go to line 116, and add Clonable ringClonable;, and on line 148 add PositionRegistration ringRegistration;
Now open MGGame.cpp.
Go to the Game::Game() instance and look for littleHealthClonable , and right below it add the following:
ringClonable(kEntityRing, "Ring"),
and then find littleHealthRegistration , and add the following right below it:
ringRegistration(kEntityRing, stringTable.GetString(StringID('POSI', 'RING'))),
The POSI string tells the engine that the object can be set using a position marker, while the RING string tells the engine what's the name of the object thats in that position.
Registering the Entity
While we're in MGGame.cpp, we're going to register the entity.
Go to line 234, and add:
Entity::RegisterClonable(&ringClonable);
Entity::RegisterClonable tells the engine that the Entity is clonable.
Now in line 269:
PositionMarker::RegisterPosition(&ringRegistration);
PositionMarker::RegisterPosition tells C4's World Editor, and the Engine itself, that the ring can be placed with a position marker.

