Commit | Line | Data |
---|---|---|
21c4e167 H |
1 | /** |
2 | * nInvaders - a space invaders clone for ncurses | |
3 | * Copyright (C) 2002-2003 Dettus | |
4 | * | |
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. | |
9 | * | |
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. | |
14 | * | |
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 | |
18 | * | |
19 | * homepage: http://ninvaders.sourceforge.net | |
20 | * mailto: ninvaders-devel@lists.sourceforge.net | |
21 | * | |
22 | */ | |
23 | ||
24 | ||
25 | #include "ufo.h" | |
26 | #include "aliens.h" | |
27 | #include "nInvaders.h" | |
28 | ||
29 | static int fShowUfo = 0; | |
30 | ||
31 | /** | |
32 | * initialize ufo attributes | |
33 | */ | |
34 | void ufoReset() | |
35 | { | |
36 | ufoClear(ufo.posX, ufo.posY); // clear old position of player | |
37 | ||
38 | fShowUfo = 0; // do not show ufo | |
39 | ufo.posY = UFOPOSY; // set vertical Position | |
40 | ufo.posX = SCREENWIDTH - UFOWIDTH;// set horizontal Position | |
41 | } | |
42 | ||
43 | /** | |
44 | * move ufo horizontally to position posX | |
45 | */ | |
46 | static void ufoMove(int posX) | |
47 | { | |
48 | ufoClear(ufo.posX, ufo.posY); // clear sprite | |
49 | ufo.posX = posX; | |
50 | ufoRefresh(); | |
51 | ufoDisplay(ufo.posX, ufo.posY); | |
52 | } | |
53 | ||
54 | ||
55 | /** | |
56 | * move ufo and check if it reached the left screen border | |
57 | */ | |
58 | void ufoMoveLeft() | |
59 | { | |
60 | // check if space between ufo and screen border is big enough | |
61 | if (ufo.posX > 1) { | |
62 | // desired movement is possible | |
63 | ufoMove(ufo.posX - 1); | |
64 | } else { | |
65 | ufoReset(); | |
66 | } | |
67 | } | |
68 | ||
69 | /** | |
70 | * check if the first screen line is free for the ufo and | |
71 | * display it randomly | |
72 | */ | |
73 | int ufoShowUfo() | |
74 | { | |
75 | if (aliens.posY > 0 && fShowUfo == 0) { // aliens one line down | |
76 | if ((random() % 200) == 0) { | |
77 | fShowUfo = 1; | |
78 | } | |
79 | } | |
80 | ||
81 | return fShowUfo; | |
82 | } | |
83 | ||
84 | /** | |
85 | * check if ufo was hit by player and delete it from screen | |
86 | */ | |
87 | int ufoHitCheck(int shotX, int shotY) | |
88 | { | |
89 | int fUfoWasHit = 0; | |
90 | ||
91 | // if shot reached vertikal position of ufo | |
92 | if (shotY == UFOPOSY) { | |
93 | // if shot hits ufo | |
94 | if (shotX >= ufo.posX && shotX <= ufo.posX + UFOWIDTH -1) { | |
95 | ufoReset(); | |
96 | fUfoWasHit = 1; | |
97 | } | |
98 | } | |
99 | ||
100 | return fUfoWasHit; | |
101 | } |