ufo.c
2.3 KB
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
/**
* nInvaders - a space invaders clone for ncurses
* Copyright (C) 2002-2003 Dettus
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* homepage: http://ninvaders.sourceforge.net
* mailto: ninvaders-devel@lists.sourceforge.net
*
*/
#include "ufo.h"
#include "aliens.h"
#include "nInvaders.h"
static int fShowUfo = 0;
/**
* initialize ufo attributes
*/
void ufoReset()
{
ufoClear(ufo.posX, ufo.posY); // clear old position of player
fShowUfo = 0; // do not show ufo
ufo.posY = UFOPOSY; // set vertical Position
ufo.posX = SCREENWIDTH - UFOWIDTH;// set horizontal Position
}
/**
* move ufo horizontally to position posX
*/
static void ufoMove(int posX)
{
ufoClear(ufo.posX, ufo.posY); // clear sprite
ufo.posX = posX;
ufoRefresh();
ufoDisplay(ufo.posX, ufo.posY);
}
/**
* move ufo and check if it reached the left screen border
*/
void ufoMoveLeft()
{
// check if space between ufo and screen border is big enough
if (ufo.posX > 1) {
// desired movement is possible
ufoMove(ufo.posX - 1);
} else {
ufoReset();
}
}
/**
* check if the first screen line is free for the ufo and
* display it randomly
*/
int ufoShowUfo()
{
if (aliens.posY > 0 && fShowUfo == 0) { // aliens one line down
if ((random() % 200) == 0) {
fShowUfo = 1;
}
}
return fShowUfo;
}
/**
* check if ufo was hit by player and delete it from screen
*/
int ufoHitCheck(int shotX, int shotY)
{
int fUfoWasHit = 0;
// if shot reached vertikal position of ufo
if (shotY == UFOPOSY) {
// if shot hits ufo
if (shotX >= ufo.posX && shotX <= ufo.posX + UFOWIDTH -1) {
ufoReset();
fUfoWasHit = 1;
}
}
return fUfoWasHit;
}