-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
157 lines (132 loc) · 3.61 KB
/
main.c
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "vectorAPI.h"
#include "lunarLander.h"
#include <math.h>
#include <unistd.h>
int mainLoop();
lineVector *line1, *line2, *line3, *platform1, *platform2;
textVector *score, *fuel;
int main(int argc, char** argv)
{
initVect(120,40);
/*
* Building level
*/
initLander();
addLine(createLine(0,20,10,25));
addLine(createLine(10,24,17,29));
addLine(createLine(17,29,23,35));
platform1 = addLine(createLine(22,35,32,35)); // <- first platform
addLine(createLine(32,34,40,30));
line1 = addLine(createLine(40,30,43,20));
addLine(createLine(43,20,48,15));
line3 = addLine(createLine(48,15,58,20));
addLine(createLine(57,20,75,18));
line2 = addLine(createLine(75,18,85,26));
platform2 = addLine(createLine(84,26,94,26)); // <- second platform
addLine(createLine(94,25,105,15));
addLine(createLine(105,14,120,11));
addText(createText("3X Score",24,36));
addText(createText("2X Score",86,27));
addText(createText("SCORE: ",1,1));
addText(createText("FUEL: ",2,2));
score = addText(createText("0",7,1));
fuel = addText(createText("1000",7,2));
mainLoop();
return 0;
}
int mainLoop()
{
wchar_t ch = 0;
int running = 1;
int roundEnd = 0;
int i = 0;
while(running)
{
ch = getChar();
if(ch == 27)
break;
/*
* Rotates specified lines the
* specified amount (in radians
*/
rotateLine(line1,M_PI/1000);
rotateLine(line2,M_PI/900);
rotateLine(line3,-M_PI/900);
/*
* Firethruster handles input
*/
fireThruster(ch);
moveLander();
/*
* Time to sleep between frames
*/
usleep(1000);
if(roundEnd)
{
roundEnd = 0;
clearPrintScreen();
usleep(1000000);
if(fuel < 0)
running = 0;
}
/*
* Convert fuel int to string
* and add to textVector
*/
char fuelstr[7];
sprintf(fuelstr,"%d",fuel_int);
changeText(fuel,fuelstr);
char scorestr[7];
sprintf(scorestr,"%d",score_int);
changeText(score,scorestr);
draw();
switch(detectWin(platform1,platform2))
{
case 0:
break;
case 1:
printToScreen("Crashed!");
draw();
resetLander();
roundEnd = 1;
break;
case 21:
printToScreen("Landed too hard :( -100 fuel");
score_int += 50;
fuel_int -= 100;
draw();
resetLander();
roundEnd = 1;
break;
case 22:
printToScreen("Landed too hard :( -100 fuel");
score_int += 75;
fuel_int -= 100;
draw();
resetLander();
roundEnd = 1;
break;
case 31:
printToScreen("PERFECT LANDING!");
score_int += 300;
draw();
resetLander();
roundEnd = 1;
break;
case 32:
printToScreen("PERFECT LANDING!");
score_int += 200;
draw();
resetLander();
roundEnd = 1;
break;
case 4:
printToScreen("Out of fuel!");
draw();
resetLander();
roundEnd = 1;
}
}
exitVect();
return 0;
}