Each GameObject has up to 3 alarms to used. NOTE: GameObject Entity must be registered in order to process GameObject::alarm0, GameObject::alarm1, and GameObject::alarm2 callbacks.
More...
|
enum class | AlarmID { ALARM_0
, ALARM_1
, ALARM_2
} |
| Values that represent alarm Identifiers. More...
|
|
Each GameObject has up to 3 alarms to used. NOTE: GameObject Entity must be registered in order to process GameObject::alarm0, GameObject::alarm1, and GameObject::alarm2 callbacks.
Alarms are simple countdown mechanism to help control time-based events. Uses AlarmID for setting a specific alarm. Below is a simple example of a self-resetting alarm to make the Tank shoot at a constant rate
Tank::Tank( )
{
_fireBulletDelay = 2.0f;
_moveTimeDelay = 5.5f;
_terminationTimeDelay = 60.0f;
}
void Tank::alarm0()
{
this->fireBullet();
}
void Tank::alarm1()
{
Vect randomLocation = generateRandomPosition();
this->moveHere(randomLocation);
}
void Tank::alarm3()
{
this->terminate();
}
void Tank::terminate()
{
{
}
{
}
}
void submitAlarmRegistration(float timeDelay, AlarmID alarmID)
Submit alarm registration to the current scene.
Definition: Alarmable.cpp:52
void submitAlarmDeregistration(AlarmID alarmID)
Submit alarm deregistration to the current scene.
Definition: Alarmable.cpp:72
bool isRegisteredForAlarm(AlarmID alarmID) const
Query if 'alarmID' is registered.
Definition: Alarmable.cpp:90
◆ AlarmID
◆ alarm0()
void Alarmable::alarm0 |
( |
| ) |
|
|
privatevirtual |
Alarm 0.
To be implemented by user in object derived from GameObject (NOT directly derived from Alarmable).
◆ alarm1()
void Alarmable::alarm1 |
( |
| ) |
|
|
privatevirtual |
Alarm 1.
To be implemented by user in object derived from GameObject (NOT directly derived from Alarmable)
◆ alarm2()
void Alarmable::alarm2 |
( |
| ) |
|
|
privatevirtual |
Alarm 2.
To be implemented by user in object derived from GameObject (NOT directly derived from Alarmable)
◆ getTimeLeftForAlarm()
float Alarmable::getTimeLeftForAlarm |
( |
AlarmID |
alarmID | ) |
const |
|
protected |
Gets time left for a given alarm.
Used only if alarm is registered. Check using GameObject::isRegisteredForAlarm() before calling this function
- Parameters
-
alarmID | Identifier for the alarm. |
- Returns
- The time left for a given alarm.
◆ isRegisteredForAlarm()
bool Alarmable::isRegisteredForAlarm |
( |
AlarmID |
alarmID | ) |
const |
|
protected |
Query if 'alarmID' is registered.
- Parameters
-
alarmID | Identifier for the alarm. |
- Returns
- True if registered for alarm, false if not.
◆ submitAlarmDeregistration()
void Alarmable::submitAlarmDeregistration |
( |
AlarmID |
alarmID | ) |
|
|
protected |
Submit alarm deregistration to the current scene.
- Parameters
-
alarmID | Identifier for the alarm. |
◆ submitAlarmRegistration()
void Alarmable::submitAlarmRegistration |
( |
float |
timeDelay, |
|
|
AlarmID |
alarmID |
|
) |
| |
|
protected |
Submit alarm registration to the current scene.
- Parameters
-
timeDelay | The time delay. |
alarmID | Identifier for the alarm. |