00001
#pragma warning(disable: 4786)
00002
00003
00004
#include "ennemies.h"
00005
#include "game_manager.h"
00006
00007
00008
00009 #define SQUARE_VIEW_RANGE_RED_BALL 20000
00010 #define SQUARE_VIEW_RANGE_BLUE_BALL 40000
00011
00012 #define POINTS_WHEN_BOMB_RED_BALL 500
00013 #define POINTS_WHEN_BOMB_BLUE_BALL 200
00014 #define POINTS_WHEN_BOMB_GREEN_BALL 50
00015
00016 #define POINTS_WHEN_TRAP_RED_BALL 1000
00017 #define POINTS_WHEN_TRAP_BLUE_BALL 400
00018 #define POINTS_WHEN_TRAP_GREEN_BALL 100
00019
00020
00021
00022
00023
00024
00025 cEnnemy::cEnnemy(
int x,
int y,
cSprite_Display_Def* def,
int speed,
int rayon):
cUnit(x,y,def,speed,rayon)
00026 {
00027
Initial_Position.
X = x;
00028
Initial_Position.
Y = y;
00029
Points_When_Killed = 0;
00030 }
00031
00032
00033 void cEnnemy::React_To_Bomb(
cBomb * bomb)
00034 {
00035
Reset();
00036
Game_Manager.
Remove_Bonus( bomb );
00037
Game_Manager.
Score +=
Points_When_Killed*(
Game_Manager.
Id_Level+1)*(
Game_Manager.
Id_Level+1);
00038 }
00039
00040
00041 void cEnnemy::Reset()
00042 {
00043 Px =
Initial_Position.
X;
00044 Py =
Initial_Position.
Y;
00045 bOn_The_Road =
false;
00046 Current_Path.clear();
00047 }
00048
00049
00050 void cEnnemy::React_To_Hologramme(
cHologramme * hologramme)
00051 {
00052
Game_Manager.
Remove_Bonus(hologramme);
00053 }
00054
00055
00056 void cEnnemy::React_To_Teleporteur(
cTeleporteur * teleporteur)
00057 {
00058
Game_Manager.
Remove_Bonus(teleporteur);
00059 assert(
Game_Manager.
bTeleporteur_In_Game );
00060
Game_Manager.
bTeleporteur_In_Game =
false;
00061 }
00062
00063
00064 void cEnnemy::React_To_Cadeau(
cCadeau * cadeau)
00065 {
00066
Game_Manager.
Remove_Bonus(cadeau);
00067 }
00068
00069
00070 bool cEnnemy::Get_Destination(
cPoint2D& destination)
00071 {
00072
unsigned int dist;
00073
unsigned int new_dist;
00074 std::list<cInteractive_Item*>::iterator bonus_itr;
00075
00076
00077 destination.
Set(
Game_Manager.
Player->
Px ,
Game_Manager.
Player->
Py );
00078
00079 dist =
Get_Square_Distance( destination ,
cPoint2D(Px,Py));
00080
00081
for( bonus_itr =
Game_Manager.
Bonus_List.begin() ; bonus_itr !=
Game_Manager.
Bonus_List.end() ; bonus_itr++)
00082 {
00083
if( (*bonus_itr)->Type ==
HOLOGRAMME)
00084 {
00085 new_dist =
Get_Square_Distance(
cPoint2D((*bonus_itr)->Px,(*bonus_itr)->Py)
00086 ,
cPoint2D(Px, Py) );
00087
if( new_dist < dist)
00088 {
00089 dist = new_dist;
00090 destination =
cPoint2D((*bonus_itr)->Px,(*bonus_itr)->Py );
00091 }
00092 }
00093 }
00094
00095
return true;
00096 }
00097
00098
00099 void cEnnemy::Update_Path()
00100 {
00101
cPoint2D destination;
00102 std::vector<cPoint2D> chemin;
00103 std::vector<cPoint2D>::iterator chemin_itr;
00104
00105
00106
if( !
Get_Destination(destination) )
00107 {
00108
00109
if( ! Current_Path.empty())
00110 {
00111
00112
return;
00113 }
00114
else
00115 {
00116 bOn_The_Road =
false;
00117 Current_Path.clear();
00118
return;
00119 }
00120 }
00121
00122
00123
00124
00125
00126
00127
if( ! Current_Path.empty())
00128
if( Current_Path.back() == destination )
00129
return;
00130
00131 chemin.clear();
00132
Game_Manager.
Game_World->
Find_Path(
cPoint2D(Px,Py) ,
00133 destination , chemin);
00134 Current_Path.clear();
00135 bOn_The_Road =
false;
00136
00137
for( chemin_itr=chemin.begin(); chemin_itr!=chemin.end() ; chemin_itr++)
00138 Current_Path.push_back( (*chemin_itr) );
00139 }
00140
00141
00142
00143
00144
00145
00146 cRed_Ball::cRed_Ball(
int x,
int y):
cEnnemy(x,y,
Game_Manager.pDisplay_Red_Ball,
SPEED_RED_BALL,
RAYON_RED_BALL)
00147 {
00148 Points_When_Killed =
POINTS_WHEN_BOMB_RED_BALL;
00149 }
00150
00151
00152 void cRed_Ball::React_To_Red_Trap(
cRed_Trap * trap)
00153 {
00154
00155
Game_Manager.
Kill_Ennemy(
this );
00156
Game_Manager.
Score +=
POINTS_WHEN_TRAP_RED_BALL*(
Game_Manager.
Id_Level+1)*(
Game_Manager.
Id_Level+1);
00157 }
00158
00159
00160 bool cRed_Ball::Get_Destination(
cPoint2D& destination)
00161 {
00162
unsigned int dist;
00163
unsigned int new_dist;
00164 std::list<cInteractive_Item*>::iterator bonus_itr;
00165
00166
00167 destination.
Set(
Game_Manager.
Player->
Px ,
Game_Manager.
Player->
Py );
00168
00169 dist =
Get_Square_Distance( destination ,
cPoint2D(Px,Py));
00170
00171
for( bonus_itr =
Game_Manager.
Bonus_List.begin() ; bonus_itr !=
Game_Manager.
Bonus_List.end() ; bonus_itr++)
00172 {
00173
if( (*bonus_itr)->Type ==
HOLOGRAMME)
00174 {
00175 new_dist =
Get_Square_Distance(
cPoint2D((*bonus_itr)->Px,(*bonus_itr)->Py)
00176 ,
cPoint2D(Px, Py) );
00177
if( new_dist < dist)
00178 {
00179 dist = new_dist;
00180 destination =
cPoint2D((*bonus_itr)->Px,(*bonus_itr)->Py );
00181 }
00182 }
00183 }
00184
00185
00186
if( dist <=
SQUARE_VIEW_RANGE_RED_BALL)
00187
return true;
00188
else
00189
return false;
00190
00191 }
00192
00193
00194
00195
00196
00197
00198 cBlue_Ball::cBlue_Ball(
int x,
int y):
cEnnemy(x,y,
Game_Manager.pDisplay_Blue_Ball,
SPEED_BLUE_BALL,
RAYON_BLUE_BALL)
00199 {
00200 Points_When_Killed =
POINTS_WHEN_BOMB_BLUE_BALL;
00201 }
00202
00203
00204 void cBlue_Ball::React_To_Blue_Trap(
cBlue_Trap * trap)
00205 {
00206
00207
Game_Manager.
Kill_Ennemy(
this );
00208
Game_Manager.
Score +=
POINTS_WHEN_TRAP_BLUE_BALL*(
Game_Manager.
Id_Level+1)*(
Game_Manager.
Id_Level+1);
00209 }
00210
00211
00212 bool cBlue_Ball::Get_Destination(
cPoint2D& destination)
00213 {
00214
unsigned int dist;
00215
unsigned int new_dist;
00216 std::list<cInteractive_Item*>::iterator bonus_itr;
00217
00218
00219 destination.
Set(
Game_Manager.
Player->
Px ,
Game_Manager.
Player->
Py );
00220
00221 dist =
Get_Square_Distance( destination ,
cPoint2D(Px,Py));
00222
00223
for( bonus_itr =
Game_Manager.
Bonus_List.begin() ; bonus_itr !=
Game_Manager.
Bonus_List.end() ; bonus_itr++)
00224 {
00225
if( (*bonus_itr)->Type ==
HOLOGRAMME)
00226 {
00227 new_dist =
Get_Square_Distance(
cPoint2D((*bonus_itr)->Px,(*bonus_itr)->Py)
00228 ,
cPoint2D(Px, Py) );
00229
if( new_dist < dist)
00230 {
00231 dist = new_dist;
00232 destination =
cPoint2D((*bonus_itr)->Px,(*bonus_itr)->Py );
00233 }
00234 }
00235 }
00236
00237
00238
if( dist <=
SQUARE_VIEW_RANGE_BLUE_BALL)
00239
return true;
00240
else
00241
return false;
00242
00243 }
00244
00245
00246
00247
00248 cGreen_Ball::cGreen_Ball(
int x,
int y):
cEnnemy(x,y,
Game_Manager.pDisplay_Green_Ball,
SPEED_GREEN_BALL,
RAYON_GREEN_BALL)
00249 {
00250 Points_When_Killed =
POINTS_WHEN_BOMB_GREEN_BALL;
00251 }
00252
00253
00254 void cGreen_Ball::React_To_Green_Trap(
cGreen_Trap * trap)
00255 {
00256
Game_Manager.
Kill_Ennemy(
this );
00257
Game_Manager.
Score +=
POINTS_WHEN_TRAP_GREEN_BALL*(
Game_Manager.
Id_Level+1)*(
Game_Manager.
Id_Level+1);
00258 }
00259
00260
00261 bool cGreen_Ball::Get_Destination(
cPoint2D& destination)
00262 {
00263 destination.
Set(
Game_Manager.
Player->
Px ,
Game_Manager.
Player->
Py );
00264
return true;
00265 }
00266
00267
00268