2 * nInvaders - a space invaders clone for ncurses
3 * Copyright (C) 2002-2003 Dettus
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (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. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * homepage: http://ninvaders.sourceforge.net
20 * mailto: ninvaders-devel@lists.sourceforge.net
28 #include "nInvaders.h"
30 typedef struct Player Player
;
33 int posX
; // horizontal position of player
34 int posY
; // vertical position of player
35 int speed
; // 0: no movement; 1: one per turn; etc.
36 int missileFired
; // 0: missile not running; 1: missile running
37 int missileX
; // horizontal position of missile
38 int missileY
; // vertical position of missile
44 * initialize player attributes
48 // if missile was fired clear that position
49 if (player
.missileFired
== 1) {
50 playerMissileClear(player
.missileX
, player
.missileY
);
53 playerClear(player
.posX
, player
.posY
); // clear old position of player
55 player
.posY
= PLAYERPOSY
; // set vertical Position
56 player
.posX
= 0; // set horizontal Position
58 player
.missileFired
= 0;
62 playerDisplay(player
.posX
, player
.posY
); // display new position of player
67 * move player horizontally to position newPosX
69 static void playerMove(int newPosX
)
71 playerClear(player
.posX
, player
.posY
); // clear sprite
72 player
.posX
= newPosX
; // make movement
73 playerDisplay(player
.posX
, player
.posY
); // display sprite
82 // check if space between player and border of screen is big enough
83 if (player
.posX
> 0 + player
.speed
) {
84 // desired movement is possible
85 playerMove(player
.posX
- player
.speed
);
87 // space too small, move to left-most position
96 void playerMoveRight()
98 // check if space between player and border of screen is big enough
99 if (player
.posX
< SCREENWIDTH
- PLAYERWIDTH
- player
.speed
) {
100 // desired movement is possible
101 playerMove(player
.posX
+ player
.speed
);
103 // space too small, move to right-most position
104 playerMove(SCREENWIDTH
- PLAYERWIDTH
);
110 * toggle turbo mode on (if key is kept pressed)
119 * toggle turbo mode off (if key is kept pressed)
121 void playerTurboOff()
128 * player was hit by an alien shot
130 int playerHitCheck(int hostileShotX
, int hostileShotY
)
132 int fPlayerWasHit
= 0;
134 // if shot reached vertikal position of player
135 if (hostileShotY
== PLAYERPOSY
) {
136 // if shot hits player
137 if (hostileShotX
>= player
.posX
&& hostileShotX
<= player
.posX
+ PLAYERWIDTH
-1) {
138 fPlayerWasHit
= 1; // set return value
142 return fPlayerWasHit
; // return if player was hit
149 void playerLaunchMissile()
151 // only launch missile if no other is on its way
152 if (player
.missileFired
== 0) {
153 player
.missileFired
= 1; // missile is on its way
154 player
.missileX
= player
.posX
+ PLAYERWIDTH
/ 2; // launched from the middle of player...
155 player
.missileY
= PLAYERPOSY
; // ...at same horizontal position
163 static void playerReloadMissile()
165 player
.missileFired
= 0; // no player missile flying
170 * move player missile and do alien/bunker hit testing
171 * return value - 0: still some aliens left, 1: no aliens left
173 int playerMoveMissile()
175 int fNoAliensLeft
= 0; // return value
176 int alienTypeHit
= 0;
178 // only do movements if there is a missile to move
179 if (player
.missileFired
== 1) {
181 playerMissileClear(player
.missileX
, player
.missileY
); // clear old missile position
182 playerDisplay(player
.posX
, player
.posY
); // todo: check if this can be removed later if missiled is fired,
183 //the middle of player is cleared
184 player
.missileY
--; // move missile
186 // if missile out of battlefield
187 if (player
.missileY
< 0) {
188 playerReloadMissile(); // reload missile
190 playerMissileDisplay(player
.missileX
, player
.missileY
); // display missile at new position
193 // if missile hits an alien (TODO)
194 alienTypeHit
= aliensHitCheck(player
.missileX
, player
.missileY
);
195 if (alienTypeHit
!= 0) {
197 doScoring(alienTypeHit
); // increase score
198 playerReloadMissile(); // reload missile
200 aliensClear(aliens
.posX
, aliens
.posY
, aliens
.right
, aliens
.bottom
); // clear old posiiton of aliens
208 weite
= (shipnum
+ (skill_level
* 10) - (level
* 5) + 5) / 10;
213 playerMissileClear(player
.missileX
, player
.missileY
); // clear old missile position
214 aliensDisplay(aliens
.posX
, aliens
.posY
, aliens
.right
, aliens
.bottom
); // display aliens
217 // if missile hits a bunker
218 if (bunkersHitCheck(player
.missileX
, player
.missileY
) == 1) {
219 bunkersClearElement(player
.missileX
, player
.missileY
); // clear element of bunker
220 playerReloadMissile(); // reload player missile
223 // if missile hits ufo
224 if (ufoHitCheck(player
.missileX
, player
.missileY
) == 1) {
225 doScoring(UFO_ALIEN_TYPE
);
226 playerReloadMissile();
230 return fNoAliensLeft
;
237 void playerExplode(){
238 playerExplosionDisplay(player
.posX
, player
.posY
);
239 playerDisplay(player
.posX
, player
.posY
);
This page took 2.224395 seconds and 4 git commands to generate.