/
main.c
492 lines (369 loc) · 9.85 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
//You must change the print routine.
//Now you always print at $4000 video memory
//But video memory change between $4000 and $C000 every frame
//So you need to read $5c01 variable
//PRINT ROUTINE SCREWING WITH 128K mode!!! ERROR
//#pragma output CLIB_MALLOC_HEAP_SIZE = 10000
//#pragma output stack=50000
#pragma output STACKPTR = 56000
//56000
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
#include "mus/turner3.h"
#include <stdio.h>//being used to convert ints to strings
#include <stdlib.h>//standard library
#include "string.h"//part of z88dk
#include "spectrum.h"//part of z88dk spectrum related utilities
#include "fase.h"//our sprite library
//#include "utils.h"
#include "variables.h"//holds all global variables (my function)
//#include "screenutils.h"//printing messages to the screen TESTING (my function)
#include "gamedisplay.h"
#include "collision.h"//player collisions (my function)
#include "mapsandstart.h"
#include "movement.h"
#include "enemy.h"
#define gettile(x,y) tiles[x + (y << 4) - y ]
void main()
{
//DI;
//INIT;// initialize engine
start:
{//at the start of a game
speccy128k = false;//by defaut a 48k speccy
//is the game 128k
if( *is128 )
{
speccy128k = true;//detects a 128k machine
//EI;
//*intadr= IsrSound;
}
}
DI;
INIT;// initialize engine
while (1)//main menu
{
i= inp(0xf7fe) & 0x1f;
//call to music routine, stops on keypress
anteat();
if( i==0x1e )//press 1, select kempston joystick
{
Input = Joystick;
//kempston joystick and zx interface 2, port 1
break;
}
else if( i==0x1d )//press 2, select cursor joystick
{
Input = Cursors;
//cursor joystick
break;
}
else if( i==0x1b )//press 3, select keyboard control
{
Input = Keyboard;
//QAOP space
break;
}
else if( i==0x17 )//press 4 redefine keys
{
Redefine();
}
else if( i==0x0F )// press 5 for high score 0000 1111
{
//cls();
blockClear();
printHighScores();
while (1)
{
//z88dkPrint(pressSpace, 21,9);
//PrintStr128(pressSpace, 9, 21);
PrintStr(pressSpace, 0x0915);
i= inp(0x7ffe) & 0x1f;
anteat();
if( i==0x1e )
break;
}
Pause (30);
Bitmap(0, 0);
goto start;// start all over
}
}
//place sound effect here
SFX(5);
// DI;
//initialize variables before game start
{
//initialize variables
mapx = 0;
mapy = 0;
spacepressed = 0;
num_bullets = 0;
singleBullet = true; //true
//buildMap = 0;
//*shadow= 0;
x = vx = ax = 0;
y = vy = ay = 0;
level = gameMap = 0;//
//MAX of 12 levels
yourLives = 3;//yourLives = 5;//temp
yourScore = 0;//temp //2,147,483,647 max
//1147483647
movePlayer = 0;
enemySlowDown = 0;
enemySpeedUp = 20;//enemySpeedUp = 20;
enemyRetreat = 0;
enemySteps = 0;
isLevelRead = false;//used to read level into array
bulletDirection = 1;
playerDirection = 0;
oneUpDisplay = false;
runOnce = true;//so that uniques values can be read once per level
gameOver = false;
animate = 0;
stopPlayer = false;
debug = false;
if(speccy128k == true) {FRAME;}
//gets AI to work in 128k mode for some reason
}
while(1)//game loop
{
//we need to read level into array
//initialize level
//does not reread on playerDeath
if (isLevelRead == false)
{
runOnceperLevel();
//to test the levels
//gameMap = level = 0;
if (level > 12)
level = gameMap = 1;
if (gameMap > 12)
level = gameMap = 1;
levelPositioning[2] = ((short)level);//recast level to fit properly in array
startingPosition((short)levelPositioning);
x = levelPositioning[0];
y = levelPositioning[1];
//place our player
playerXpos = (unsigned char)(x >> 8);
playerYpos = (unsigned char)(y >> 8);
playerCharX = playerXpos >> 4;
playerCharY = playerYpos >> 4;
//enemyStart(level);//placement of enemies
//enemySlowDown = 0;
//enemySpeedUp --;//lower is faster
//if (enemySpeedUp < 0) enemySpeedUp = 0;//now an unsigned char, so this should be redundant
arrayCounter = 0;
screenScanX = 0;
screenScanY = 0;
screenCounter = 0;
screenCounterStart = 0;
screenCounterEnd = 0;//only use this during partial screen scanner in enemies.h
//have you collected the key
keyCollected = false;
*screen = gameMap;
singleBullet = true;//can fire again
bullets[0].y = 255;
FRAME;
//update sprites
for ( i = 0; i < 5; ++ i )
{
//FRAME;
sprites[i].n= data[0 | i<<2],
sprites[i].x= data[1 | i<<2],
sprites[i].y= data[2 | i<<2],
sprites[i].f= data[3 | i<<2];
}
FRAME;
cleanTaxicab();
TaxicabDifference();//taxicab runs ok
gateOpen = false;
keyCollected = false;
FRAME;
update_screen();
{
// find the area to be redrawn when a
//special object is collected
if (oneUpDisplay == true)
{
tiles[oneUpY * scrw + oneUpX] = 0;
tilepaint(oneUpX, oneUpY, oneUpX, oneUpY);
FRAME;
}
}
update_scoreboard();
FRAME;
vx = ax = 0;
vy = ay = 0;
isLevelRead = true;//level has now been read
// Sound to start
{
//place sound effect here
SFX(2);
Pause (10);
SFX(2);
Pause (10);
SFX(2);
}
M_OUTP(0xfe, 0);
}//end initialize level
//if (debug == true) Pause (0);
//tile elimination works ok here, but displays to player first
//now we play
if (isLevelRead == true)
{
FRAME;// this causes the engine to process a frame generating the scenario
// we seem to have to refresh when we read the tiles
continousGrassFire();
++ animate;
if (animate > 1)
animate = 0;
// movement of enemy sprites
for ( i = 1; i < 5; ++ i )
{
bulletHits();
{
{
enemyX = sprites[i].x;
enemyY = sprites[i].y;
enemyImage = sprites[i].n;
enemyF = sprites[i].f;
/*
enemyX = sprites[2].x;
enemyY = sprites[2].y;
enemyImage = sprites[2].n;
enemyF = sprites[2].f;
*/
//convert pixel position to character position
playerCharX = playerXpos >> 4;
playerCharY = playerYpos >> 4;
moveEnemy(enemyX, enemyY, enemyF);//temp
//enemyCollision(enemyX, enemyY);//temp
enemyCollision();//temp
sprites[i].x = enemyX;
sprites[i].y = enemyY;
sprites[i].n = enemyImage;
sprites[i].f = enemyF;
/*
sprites[2].x = enemyX;
sprites[2].y = enemyY;
sprites[2].n = enemyImage;
sprites[2].f = enemyF;
*/
//sprites[i].x && sprites[i].y == direction of sprites
//sprites[i].n == The .n is the number of the sprite
//(will draw a different sprite if changed
//the .f has no effect on the engine, but it's used by
//the demo to store the direction of movement
//(it's diagonal movement so only 4 directions).
}
if (enemySlowDown == 0)
{
enemySlowDown = 0;
}
++ enemySlowDown;
if (enemySlowDown == enemySpeedUp) enemySlowDown = 0;
//eventually enemySpeedUp will count down with each new level
// to be added for artificial stupidity
}
}
*drwout= (unsigned int)update_scoreboard;
// movement of bullets
for ( i = 0; i < num_bullets; ++ i )
{
if( dirbul[i]&3 )
{
if( dirbul[i]&1 )
{
if( bullets[i].x < scrw * 16 )
bullets[i].x += 4;
else
remove_bullet(i);
}
else
{
if( bullets[i].x > 4 )
bullets[i].x -= 4;
else
remove_bullet(i);
}
}
if( dirbul[i]&12 )
{
if( dirbul[i]&4 )
{
if( bullets[i].y<scrh*16 )
bullets[i].y+= 4;
else
remove_bullet(i);
}
else
{
if( bullets[i].y>4 )
bullets[i].y-= 4;
else
remove_bullet(i);
}
}
}
{
// printGrassFire();
tileCollision();
verticalMovement();
horizontalMovement();
//here X>>8 is from 0 to 240
//here Y>>8 is from 0 to 159
//here Y>>9 is from 0 to 207
playerXpos = (unsigned char)(x >> 8);
playerYpos = (unsigned char)(y >> 8);
}
//directional movement of the character
{
++ movePlayer;
if (movePlayer > 16) movePlayer = 0;
moveMainCharacter(movePlayer);
}
//move main character
sprites[0].x = x >> 8;
sprites[0].y = y >> 8;
//hard number if player tries to cheat by forcing to the right
if (sprites[0].x > 234)
{
playerDeath();
}
//beta testers cheat
/*
i= inp(0xbffe) & 0x1f;
if( i==0x0F )
{
warpLevel();
}*/
}
//game over check
if( yourLives < 1 ) //end game
{
//remove all sprites
for ( i = 0; i < 5; ++ i )
{
sprites[i].n = 129;
}
//bpoke (23553,128);//FASE Engine
if (bpeek (23553) == 128)
FRAME;
blockClear();
EXIT;// to stop the engine
//endgame();
PrintStr2(gameOverTXT, 0x0b03);
Pause (180);
//blockClear();
//check to see if your current score is a new high score
if (yourScore > scores[4].hiScoreList)
{
highScore();
}
Bitmap(0, 0);//display title screen
isLevelRead = false;//reset flag to re read level
INIT;// initialize engine
goto start;// start all over
}
}//end of play loop
}//end of program loop