-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCAlien.cpp
151 lines (126 loc) · 2.61 KB
/
CAlien.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "CAlien.h"
#include "CObjectManager.h"
#include "ComponentEnums.h"
#include <cstdlib>
CAlien::CAlien(void)
{
}
CAlien::~CAlien(void)
{
}
void CAlien::RegisterComponentType()
{
CObjectManager::getInstance()->RegisterComponentType(CID_ALIEN, CreateMe, DestroyMe);
}
IComponent* CAlien::CreateMe()
{
return new CAlien;
}
bool CAlien::DestroyMe(IComponent *p)
{
delete p;
return true;
}
bool CAlien::Init(CObjectId oid, CParameterNode ¶mNode)
{
this->SetObjectId(oid);
return true;
}
void CAlien::Deinit()
{
}
EComponentTypeId CAlien::GetComponentTypeId()
{
return CID_ALIEN;
}
void CAlien::HandleMessage(CObjectId oid, MessageTypeId msg)
{
switch( msg ){
case M_MOVE_RIGHT:
{
break;
}
case M_MOVE_LEFT:
{
break;
}
case M_MOVE_ALIEN:
{
break;
}
case M_MOVE_UP:
{
break;
}
case M_MOVE_DOWN:
{
break;
}
case M_FIRE_ROCKET:
{
break;
}
case M_FIRE_BOMB:
{
break;
}
case M_CHECK_COLLISION_WITH_PLAYER:
{
break;
}
case M_CHECK_COLLISION_WITH_ALIEN:
{
break;
}
case M_CHECK_COLLISION_WITH_BOMB:
{
break;
}
case M_CHECK_COLLISION_WITH_ROCKET:
{
break;
}
case M_RENDER:
{
break;
}
case M_TAKE_DAMAGE:
{
break;
}
case M_DEALTH:
{
if( oid == this->GetObjectId() )
{
CObjectManager::getInstance()->PostMessageToComponents(this->GetObjectId(),M_ALIEN_DEALTH);
CObjectManager::getInstance()->AddToRemoveList(this->GetObjectId());
}
break;
}
case M_ALIEN_DEALTH:
{
break;
}
case M_UPDATE:
{
CObjectManager::getInstance()->PostMessage(this->GetObjectId(),M_MOVE_ALIEN);
CObjectManager::getInstance()->PostMessage(this->GetObjectId(),M_CHECK_COLLISION_WITH_ROCKET);
CObjectManager::getInstance()->PostMessage(this->GetObjectId(),M_CHECK_COLLISION_WITH_PLAYER);
break;
}
default:
break;
}
}
void CAlien::Update(IDiceInvaders* system)
{
CObjectManager::getInstance()->PostMessage(this->GetObjectId(),M_MOVE_ALIEN);
CObjectManager::getInstance()->PostMessage(this->GetObjectId(),M_CHECK_COLLISION_WITH_ROCKET);
CObjectManager::getInstance()->PostMessage(this->GetObjectId(),M_CHECK_COLLISION_WITH_PLAYER);
int fire = rand() % 100;
int fire2 = rand() % 100;
int fire3 = rand() % 100;
int fire4 = rand() % 100;
if( (fire < 1) && (fire2 == 28) && (fire3 < 30) )
CObjectManager::getInstance()->PostMessage(this->GetObjectId(),M_FIRE_BOMB);
}