2 Copyright © 2004 Parallel Realities
3 Copyright © 2007-2008 Kővágó Zoltán <DirtY.iCE.hu@gmail.com>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "gettext.hpp"
24 #include "console/console.hpp"
28 game
.getCheckPoint(&player
.x
, &player
.y
);
33 player
.environment
= ENV_AIR
;
36 addTeleportParticles(player
.x
+ 10, player
.y
+ 10, 50, SND_TELEPORT2
);
38 Math::removeBit(&player
.flags
, ENT_FLIES
);
39 Math::removeBit(&player
.flags
, ENT_TELEPORTING
);
40 player
.setSprites(graphics
.getSprite("BobRight", true), graphics
.getSprite("BobLeft", true), graphics
.getSprite("BobSpin", true));
43 map
.windChangeTime
= 90;
49 int amount
= (game
.gore
) ? 25 : 150;
51 for (int i
= 0 ; i
< amount
; i
++)
53 x
= player
.x
+ Math::rrand(-3, 3);
54 y
= player
.y
+ Math::rrand(-3, 3);
58 dx
= Math::rrand(-5, 5);
59 dy
= Math::rrand(-15, -5);
60 addEffect(x
, y
, dx
, dy
, EFF_BLEEDS
);
64 dx
= Math::rrand(-5, 5);
65 dy
= Math::rrand(-5, 5);
66 addColoredEffect(x
, y
, dx
, dy
, graphics
.yellow
, EFF_COLORED
+ EFF_WEIGHTLESS
);
70 (game
.gore
) ? audio
.playSound(SND_SPLAT
, CH_ANY
) : audio
.playSound(SND_POP
, CH_ANY
);
73 void checkPlayerBulletCollisions(Entity
*bullet
)
75 if ((bullet
->health
< 1) || (player
.health
<= -60))
80 if ((player
.flags
& ENT_TELEPORTING
) || (game
.missionOver
> 0))
85 if (bullet
->owner
!= &player
)
87 if (Collision::collision(&player
, bullet
))
89 if ((!player
.immune
) && (!(bullet
->flags
& ENT_EXPLODES
)))
91 addBlood(&player
, bullet
->dx
/ 4, Math::rrand(-6, -3), 1);
92 audio
.playSound(SND_HIT
, CH_ANY
);
93 if (game
.missionOverReason
== MIS_INPROGRESS
)
95 player
.health
-= bullet
->damage
;
100 Math::removeBit(&bullet
->flags
, ENT_SPARKS
);
101 Math::removeBit(&bullet
->flags
, ENT_PUFFS
);
103 if (player
.health
<= 0)
105 player
.dx
= bullet
->dx
;
107 audio
.playSound(SND_DEATH1
+ rand() % 3, CH_DEATH
);
111 if (bullet
->id
== WP_LASER
)
113 debug
<< "Laser Hit Player" << std::endl
;
114 throwAndDamageEntity(&player
, 0, -3, 3, -8);
127 int x
= (int) player
.x
- map
.offsetX
;
128 int y
= (int) player
.y
- map
.offsetY
;
130 if (engine
.cheatHealth
)
132 player
.health
= MAX_HEALTH
;
135 if (game
.missionOverReason
== MIS_PLAYERESCAPE
)
140 if (player
.y
> (map
.limitDown
+ 500))
142 if (game
.missionOver
== 0)
147 if (player
.health
> 0)
149 game
.setMissionOver(MIS_PLAYEROUT
);
153 game
.setMissionOver(MIS_PLAYERDEAD
);
157 if (player
.flags
& ENT_TELEPORTING
)
163 if (game
.missionOverReason
== MIS_PLAYEROUT
)
165 graphics
.blit(player
.getFaceImage(), x
, y
, graphics
.screen
, false);
170 if ((player
.health
< 1) || (player
.immune
> 120))
172 if (player
.health
<= -60)
179 if (game
.hasAquaLung
)
186 graphics
.blit(player
.getFaceImage(), x
, y
, graphics
.screen
, false);
188 if (player
.health
< 1)
193 if (player
.health
<= -60)
201 if ((!(player
.flags
& ENT_FLIES
)) && (!map
.isIceLevel
))
206 // toggles the Jetpack if available
207 if (engine
.isKey(KEY_JETPACK
))
209 if ((game
.hasJetPack
) || (engine
.cheatExtras
))
211 if (player
.flags
& ENT_FLIES
)
213 Math::removeBit(&player
.flags
, ENT_FLIES
);
214 player
.setSprites(graphics
.getSprite("BobRight", true), graphics
.getSprite("BobLeft", true), graphics
.getSprite("BobSpin", true));
218 if ((player
.fuel
> 3) && (player
.environment
== ENV_AIR
))
220 Math::addBit(&player
.flags
, ENT_FLIES
);
221 player
.setSprites(graphics
.getSprite("JPBobRight", true), graphics
.getSprite("JPBobLeft", true), graphics
.getSprite("BobSpin", true));
223 else if ((player
.environment
== ENV_WATER
))
225 engine
.setInfoMessage(_("Jetpack cannot be used underwater"), 0, INFO_NORMAL
);
229 engine
.setInfoMessage(_("Jetpack is recharging..."), 0, INFO_NORMAL
);
235 engine
.setInfoMessage(_("Don't have jetpack!"), 0, INFO_NORMAL
);
238 engine
.clearKey(KEY_JETPACK
);
241 if (map
.isBlizzardLevel
)
243 if ((!engine
.isKey(KEY_LEFT
)) && (!engine
.isKey(KEY_RIGHT
)))
245 if ((player
.dx
> -2) && (player
.dx
< 2))
247 player
.dx
+= map
.windPower
* 0.1;
253 if (engine
.isKey(KEY_LEFT
) || engine
.getJoyLeft())
255 else if (engine
.isKey(KEY_RIGHT
) || engine
.getJoyRight())
259 player
.face
= dir
< 0 ? 1 : 0;
261 if (player
.flags
& ENT_FLIES
|| map
.isIceLevel
)
262 player
.dx
+= (engine
.cheatSpeed
? 0.3f
: 0.1f
) * dir
;
264 player
.dx
= (engine
.cheatSpeed
? 3 * dir
: dir
) * PLAYER_WALK_SPEED
;
266 if (player
.flags
& ENT_FLIES
)
267 Math::limitFloat(&player
.dx
, (engine
.cheatSpeed
? -3 : -1) * PLAYER_FLY_SPEED
, (engine
.cheatSpeed
? 3 : 1) * PLAYER_FLY_SPEED
);
268 else if (map
.isIceLevel
)
269 Math::limitFloat(&player
.dx
, (engine
.cheatSpeed
? -3.75f
: -1.25f
) * PLAYER_WALK_SPEED
, (engine
.cheatSpeed
? 3.75f
: 1.25f
) * PLAYER_WALK_SPEED
);
271 if (!(player
.flags
& ENT_FLIES
))
275 else if (!(player
.flags
& ENT_FLIES
))
278 player
.currentFrame
= 0;
281 Math::limitFloat(&player
.x
, 10, map
.limitRight
+ 608);
282 Math::limitFloat(&player
.y
, map
.limitUp
+ 5, (MAPHEIGHT
* BRICKSIZE
) + 64);
285 if ((engine
.isKey(KEY_UP
)) || engine
.getJoyUp())
287 if (engine
.isKey(KEY_DOWN
) || engine
.getJoyDown())
290 if (player
.flags
& ENT_FLIES
)
292 player
.dy
+= (engine
.cheatSpeed
? 0.3f
: 0.1f
) * dir
;
293 Math::limitFloat(&player
.dy
, (engine
.cheatSpeed
? -3 : -1) * PLAYER_FLY_SPEED
, (engine
.cheatSpeed
? 3 : 1) * PLAYER_FLY_SPEED
);
295 else if (dir
== -1 && player
.environment
== ENV_AIR
&& player
.falling
== false)
297 player
.falling
= true;
298 player
.dy
= (engine
.cheatSpeed
? 3 : 1) * PLAYER_JUMP_SPEED
;
299 engine
.clearKey(KEY_UP
);
301 else if (player
.environment
!= ENV_AIR
)
303 player
.dy
= (engine
.cheatSpeed
? 3 : 1) * (dir
< 0 ? -PLAYER_WALK_SPEED
: 2);
309 if (engine
.keyState
[SDLK_1
])
310 player
.currentWeapon
= &weapon
[WP_PISTOL
];
311 else if (engine
.keyState
[SDLK_2
])
312 player
.currentWeapon
= &weapon
[WP_MACHINEGUN
];
313 else if (engine
.keyState
[SDLK_3
])
314 player
.currentWeapon
= &weapon
[WP_GRENADES
];
315 else if (engine
.keyState
[SDLK_4
])
316 player
.currentWeapon
= &weapon
[WP_LASER
];
317 else if (engine
.keyState
[SDLK_5
])
318 player
.currentWeapon
= &weapon
[WP_SPREAD
];
322 // Math::limitFloat(&player.x, 10, map.limitRight + 608);
323 // moveEntity() limits x < 10
324 if (player
.x
> map
.limitRight
+ 608)
326 player
.x
= map
.limitRight
+ 608;
332 // Math::limitFloat(&player.y, map.limitUp + 5, (MAPHEIGHT * BRICKSIZE) + 64);
333 if (player
.y
< map
.limitUp
+ 5)
335 player
.y
= map
.limitUp
+ 5;
341 else if (player
.y
> (MAPHEIGHT
* BRICKSIZE
) + 64)
343 player
.y
= (MAPHEIGHT
* BRICKSIZE
) + 64;
346 if (engine
.isKey(KEY_FIRE
) || engine
.mouseLeft
)
348 if (player
.reload
== 0)
351 Math::calculateSlope(engine
.getMouseX(), engine
.getMouseY(), x
, y
, &dx
, &dy
);
352 speed
= player
.currentWeapon
->getSpeed(false);
353 dx
*= speed
; dy
*= speed
;
354 addBullet(&player
, dx
, dy
);
355 if (player
.currentWeapon
== &weapon
[WP_SPREAD
])
357 addBullet(&player
, dx
, dy
+ 2);
358 addBullet(&player
, dx
, dy
- 2);
363 if (player
.environment
== ENV_WATER
)
365 Math::removeBit(&player
.flags
, ENT_FLIES
);
367 addBubble(player
.x
, player
.y
);
369 if ((player
.thinktime
== 30) && (player
.oxygen
== 0))
371 audio
.playSound(SND_DROWNING
, CH_ANY
);
377 if (player
.fuel
== 0)
379 player
.setSprites(graphics
.getSprite("BobRight", true), graphics
.getSprite("BobLeft", true), graphics
.getSprite("BobSpin", true));
382 if ((game
.hasAquaLung
) || (engine
.cheatExtras
))
387 if (engine
.cheatFuel
)
392 if (((player
.immune
% 5) == 0) && (!(player
.flags
& ENT_TELEPORTING
)))
394 if ((game
.missionOverReason
== MIS_COMPLETE
) || (game
.missionOverReason
== MIS_INPROGRESS
) || (game
.missionOverReason
== MIS_GAMECOMPLETE
))
396 if (player
.flags
& ENT_FLIES
)
399 addFireTrailParticle(player
.x
+ (player
.face
* 16) + Math::rrand(-1, 1), player
.y
+ 10 + Math::rrand(-1, 1));
401 graphics
.blit(player
.getFaceImage(), x
, y
, graphics
.screen
, false);