Repository navigation
Expand file tree
/
Copy pathEnemyBug.cpp
More file actions
67 lines (61 loc) · 1.79 KB
/
Copy pathEnemyBug.cpp
File metadata and controls
67 lines (61 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "EnemyBug.h"
void EnemyBug::OnCreate()
{
// Set initial movement direction
m_direction = SOUTH;
// Get movement speed from config value
m_movementSpeed = orxConfig_GetFloat("MovementSpeed");
// Get direction change interval from config value
m_directionChangeInterval = orxConfig_GetFloat("DirectionChangeInterval");
}
void EnemyBug::OnDelete()
{
// Do nothing when deleted
}
void EnemyBug::Update(const orxCLOCK_INFO &_rstInfo)
{
// Always initialize thy variables
orxVECTOR speed = orxVECTOR_0;
// Set rotation, flip, and speed based on the object's
// current direction of movement.
switch (m_direction)
{
orxBOOL flipX, flipY;
case NORTH:
speed.fY = -m_movementSpeed;
SetRotation(270 * orxMATH_KF_DEG_TO_RAD);
SetFlip(false, false);
break;
case SOUTH:
speed.fY = m_movementSpeed;
SetRotation(90 * orxMATH_KF_DEG_TO_RAD);
SetFlip(false, false);
break;
case WEST:
speed.fX = -m_movementSpeed;
SetRotation(0 * orxMATH_KF_DEG_TO_RAD);
SetFlip(true, false);
GetFlip(flipX, flipY);
break;
case EAST:
speed.fX = m_movementSpeed;
SetRotation(0);
SetFlip(false, false);
GetFlip(flipX, flipY);
break;
default:
orxASSERT(false);
}
// Update object's speed of movement
SetSpeed(speed);
// Time since direction change exceeds interval of direction change?
if ((m_timeSinceDirectionChange += _rstInfo.fDT) >= m_directionChangeInterval)
{
// Reset time
m_timeSinceDirectionChange = 0;
// Pick random number between bounds of Direction enum
orxU32 randomNum = orxMath_GetRandomU32(0, static_cast<orxU32>(LAST));
// Update object's direction of movement
m_direction = static_cast<Direction>(randomNum);
}
}