forked from flightcrank/space-invaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
si.c
1450 lines (1012 loc) · 25.9 KB
/
si.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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//known bugs
//some times the bullet wont go past through a base if it hits on the far left edge. cause unknowen
//its the same bug that i found in my invaders drawing code. using the objects own hitbox as the SDL_Rect
//as the destination rectangle to blit to. using a seperate local rect in the drawing code solves it.
#include <stdlib.h>
#include <stdio.h>
#include "SDL/SDL.h"
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
#define E_WIDTH 30
#define WIDTH 600
#define HEIGHT 600
#define E_WIDTH 30
#define E_HEIGHT 30
#define P_WIDTH 30
#define P_HEIGHT 10
#define B_WIDTH 5
#define B_HEIGHT 15
#define P_BULLETS 1
#define E_BULLETS 3
#define BASE 4
#define BASE_WIDTH 60
#define BASE_HEIGHT 40
/*TODO
* Comment the hell out of this.
*/
enum colour_t {red, green, purple};
enum direction_t {left, right, stationary};
enum state_t {menu, options, game, game_over, pause};
enum ck_t {magenta, lime};
struct score_t {
unsigned int shots;
unsigned int points;
unsigned int level;
};
struct saucer_t {
SDL_Rect hitbox;
unsigned int alive;
enum direction_t direction;
};
struct enemy_t {
SDL_Rect hitbox;
enum colour_t colour;
unsigned int alive;
unsigned int points;
};
struct invaders_t {
struct enemy_t enemy[5][10];
enum direction_t direction;
unsigned int killed;
int speed;
int state;
int state_speed;
Uint32 state_time;
};
struct base_t {
SDL_Rect hitbox;
};
struct player_t {
SDL_Rect hitbox;
int lives;
};
struct bullet_t {
SDL_Rect hitbox;
unsigned int alive;
};
//global variables, for convenience.
static SDL_Surface *screen;
static SDL_Surface *title_screen;
static SDL_Surface *cmap;
static SDL_Surface *invadersmap;
static SDL_Surface *player_img;
static SDL_Surface *saucer_img;
static SDL_Surface *base_img[4];
static SDL_Surface *damage_img;
static SDL_Surface *damage_top_img;
static SDL_Surface *game_over_img;
struct score_t score;
struct invaders_t invaders;
struct saucer_t saucer;
struct base_t base[BASE];
struct player_t player;
struct bullet_t bullets[P_BULLETS];
struct bullet_t e_bullets[E_BULLETS];
unsigned int pause_len;
Uint32 pause_time;
enum state_t state;
Uint32 title_time;
void draw_string(char s[], int x, int y);
void pause_for(unsigned int len);
int load_image(char filename[], SDL_Surface **surface, enum ck_t colour_key);
//Initialize the score structure and game state
void init_score() {
score.shots = 0;
score.points = 0;
score.level = 1;
}
//Initialize the enemies starting positions, direction, speed and colour
void init_invaders() {
invaders.direction = right;
invaders.speed = 1;
invaders.state = 0;
invaders.killed = 0;
invaders.state_speed = 1000;
invaders.state_time = SDL_GetTicks();
int i,j;
int x = 0;
int y = 30;
for (i = 0; i < 5; i++) {
for (j = 0; j < 10; j++) {
invaders.enemy[i][j].alive = 1;
invaders.enemy[i][j].hitbox.x = x;
invaders.enemy[i][j].hitbox.y = y;
invaders.enemy[i][j].hitbox.w = E_WIDTH;
invaders.enemy[i][j].hitbox.h = E_HEIGHT;
x += E_WIDTH + 15; // gap size
if (i == 0) {
invaders.enemy[i][j].colour = purple;
invaders.enemy[i][j].points = 30;
} else if (i >= 1 && i < 3) {
invaders.enemy[i][j].colour = green;
invaders.enemy[i][j].points = 20;
} else {
invaders.enemy[i][j].colour = red;
invaders.enemy[i][j].points = 10;
}
}
x = 0; //reset line
y += E_HEIGHT + 15;
}
}
//Initialize the player starting position and dimensions
void init_player() {
player.hitbox.x = (WIDTH / 2) - (P_WIDTH / 2);
player.hitbox.y = HEIGHT - (P_HEIGHT + 10);
player.hitbox.w = P_WIDTH;
player.hitbox.h = P_HEIGHT;
player.lives = 3;
}
//Initialize the bases starting position and dimensions
void init_bases() {
int i;
int base_total = BASE_WIDTH * 4;
int space_left = WIDTH - base_total;
int even_space = space_left / 5; // 5 gaps
int x = even_space;
int y = 500;
for (i = 0; i < BASE; i++) {
base[i].hitbox.x = x;
base[i].hitbox.y = y;
base[i].hitbox.w = BASE_WIDTH;
base[i].hitbox.h = BASE_HEIGHT;
x += BASE_WIDTH + even_space; //distance apart
}
load_image("base.bmp", &base_img[0], magenta);
load_image("base.bmp", &base_img[1], magenta);
load_image("base.bmp", &base_img[2], magenta);
load_image("base.bmp", &base_img[3], magenta);
}
//Initialize the player bullets dimensions
void init_bullets(struct bullet_t b[], int max) {
int i;
for (i = 0; i < max; i++) {
b[i].alive = 0;
b[i].hitbox.x = 0;
b[i].hitbox.y = 0;
b[i].hitbox.w = B_WIDTH;
b[i].hitbox.h = B_HEIGHT;
}
}
//Initialize the saucer position and dimensions
void init_saucer() {
saucer.hitbox.x = 0;
saucer.hitbox.y = 0;
saucer.hitbox.w = 30;
saucer.hitbox.h = 20;
saucer.alive = 0;
saucer.direction = right;
}
//Draw the background
void draw_background () {
SDL_Rect src;
src.x = 0;
src.y = 0;
src.w = screen->w;
src.h = screen->h;
SDL_FillRect(screen,&src,0);
}
//Draw the HUD
void draw_hud() {
SDL_Rect r;
r.x = WIDTH;
r.y = 0;
r.w = SCREEN_WIDTH - WIDTH;
r.h = SCREEN_HEIGHT;
SDL_FillRect(screen, &r, 41);
char score_label[] = "Score";
draw_string(score_label, WIDTH, 0);
char score_num[10];
snprintf(score_num, 10, "%d", score.points);
draw_string(score_num, WIDTH, 20);
char level[] = "Level";
draw_string(level, WIDTH, 60);
char level_num[2];
snprintf(level_num, 2, "%d", score.level);
draw_string(level_num, WIDTH, 80);
char lives[] = "Lives";
draw_string(lives, WIDTH, 120);
char lives_num[2];
snprintf(lives_num, 2, "%d", player.lives);
draw_string(lives_num, WIDTH, 140);
char author[] = "Coded by";
draw_string(author, WIDTH, 540);
char name[] = "J lambert";
draw_string(name, WIDTH, 560);
}
//Draw the title screen
void draw_title_screen() {
SDL_Rect src;
SDL_Rect dest;
src.x = 0;
src.y = 0;
src.w = title_screen->w;
src.h = title_screen->h;
dest.x = (SCREEN_WIDTH / 2) - (title_screen->w / 2);
dest.y = 0;
dest.w = title_screen->w;
dest.h = title_screen->h;
SDL_BlitSurface(title_screen, &src, screen, &dest);
}
//Draw the saucer if its alive
void draw_saucer() {
SDL_Rect src;
src.x = 0;
src.y = 0;
src.w = 30;
src.h = 20;
if (saucer.alive == 1) {
SDL_BlitSurface(saucer_img, &src, screen, &saucer.hitbox);
}
}
//Draw the invaders if there alive
void draw_invaders() {
SDL_Rect src, dest;
int i,j;
src.w = E_WIDTH;
src.h = E_HEIGHT;
for (i = 0; i < 5; i++) {
for (j = 0; j < 10; j++) {
if (invaders.enemy[i][j].alive == 1) {
//purple
if(i == 0) {
if (invaders.state == 0) {
src.x = 0;
src.y = 0;
} else {
src.x = 30;
src.y = 0;
}
//green
} else if (i > 0 && i < 3) {
if (invaders.state == 0) {
src.x = 0;
src.y = E_HEIGHT;
} else {
src.x = 30;
src.y = E_HEIGHT;
}
//red
} else {
if (invaders.state == 0) {
src.x = 0;
src.y = E_HEIGHT * 2;
} else {
src.x = 30;
src.y = E_HEIGHT * 2;
}
}
dest.x = invaders.enemy[i][j].hitbox.x;
dest.y = invaders.enemy[i][j].hitbox.y;
dest.w = invaders.enemy[i][j].hitbox.w;
dest.h = invaders.enemy[i][j].hitbox.h;
SDL_BlitSurface(invadersmap, &src, screen, &dest);
}
}
}
}
//Draw the bases
void draw_bases() {
SDL_Rect src;
src.x = 0;
src.y = 0;
src.w = BASE_WIDTH;
src.h = BASE_HEIGHT;
int i;
for(i = 0; i < BASE; i++) {
SDL_BlitSurface(base_img[i], &src, screen, &base[i].hitbox);
}
}
//Draw the player
void draw_player() {
SDL_Rect src;
src.x = 0;
src.y = 0;
src.w = P_WIDTH;
src.h = P_HEIGHT;
SDL_BlitSurface(player_img, &src, screen, &player.hitbox);
}
//Draw both the enemy and the players bullets if there alive
void draw_bullets(struct bullet_t b[], int max) {
//Uint8 c = SDL_MapRGB(screen->format, 255, 255, 255);
int i;
for (i = 0; i < max; i++) {
if (b[i].alive == 1) {
SDL_FillRect(screen, &b[i].hitbox, 255);
}
}
}
//Draw a char
int draw_char(char c, int x, int y) {
SDL_Rect src;
SDL_Rect dest;
int i,j;
char *map[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"abcdefghijklmnopqrstuvwxyz",
"!@#$%^&*()_+{}|:\"<>?,.;'-=",
"0123456789"};
src.x = 0;
src.y = 0;
src.w = 20;
src.h = 20;
dest.x = x;
dest.y = y;
dest.w = 20;
dest.h = 20;
for (i = 0; i < 4; i++) {
for(j = 0; j < strlen(map[i]); j++) {
if (c == map[i][j]) {
SDL_BlitSurface(cmap, &src, screen, &dest);
return 0;
}
src.x += 20;
}
src.y += 20;//move down one line on the image file
src.x = 0; //reset to start of line
}
return 0;
}
//Draw a string of chars
void draw_string(char s[], int x, int y) {
int i;
for (i = 0; i < strlen(s); i++) {
draw_char(s[i],x,y);
x += 20;
}
}
//Draw Game Over message
void draw_game_over() {
SDL_Rect src;
SDL_Rect dest;
src.x = 0;
src.y = 0;
src.w = game_over_img->w;
src.h = game_over_img->h;
dest.x = (WIDTH / 2) - (game_over_img->w / 2);
dest.y = (HEIGHT / 2) - (game_over_img->h / 2);
dest.w = game_over_img->w;
dest.h = game_over_img->h;
SDL_BlitSurface(game_over_img, &src, screen, &dest);
}
//Set invader movment speed
void set_invaders_speed() {
switch (invaders.killed) {
case 10:
invaders.speed = 2;
invaders.state_speed = 800;
break;
case 20:
invaders.speed = 4;
invaders.state_speed = 600;
break;
case 30:
invaders.speed = 8;
invaders.state_speed = 200;
break;
case 40:
invaders.speed = 16;
invaders.state_speed = 0;
break;
}
}
//Move positions of both enemy and player bullets on screen
int move_bullets(struct bullet_t b[], int max, int speed) {
int i;
for(i = 0; i < max; i++) {
if (b[i].alive == 1) {
b[i].hitbox.y += speed;
if (b[i].hitbox.y <= 0) {
b[i].alive = 0;
}
if (b[i].hitbox.y + b[i].hitbox.h >= HEIGHT) {
b[i].alive = 0;
}
}
}
return 0;
}
//Move invaders down one space once the reach the edge
void move_invaders_down() {
int i,j;
for (i = 0; i < 5; i++) {
for (j = 0; j < 10; j++) {
invaders.enemy[i][j].hitbox.y += 15;
}
}
}
//Move invaders based on there current direction
int move_invaders(int speed) {
set_invaders_speed();
int i,j;
switch (invaders.direction) {
case left:
for (i = 0; i < 10; i++) {
for (j = 0; j < 5; j++) {
if (invaders.enemy[j][i].alive == 1) {
if (invaders.enemy[j][i].hitbox.x <= 0) {
invaders.direction = right;
move_invaders_down();
return 0;
}
if (invaders.state_time + invaders.state_speed < SDL_GetTicks()) {
invaders.state_time = SDL_GetTicks();
if (invaders.state == 1) {
invaders.state = 0;
} else {
invaders.state = 1;
}
}
//move invader speed number of pixels
invaders.enemy[j][i].hitbox.x -= invaders.speed;
}
}
}
break;
case right:
for (i = 9; i >= 0; i--) {
for (j = 0; j < 5; j++) {
if (invaders.enemy[j][i].alive == 1) {
if (invaders.enemy[j][i].hitbox.x + E_WIDTH >= WIDTH) {
invaders.direction = left;
move_invaders_down();
return 0;
}
if (invaders.state_time + invaders.state_speed < SDL_GetTicks()) {
invaders.state_time = SDL_GetTicks();
if (invaders.state == 1) {
invaders.state = 0;
} else {
invaders.state = 1;
}
}
invaders.enemy[j][i].hitbox.x += invaders.speed;
}
}
}
break;
default:
break;
}
return 0;
}
//Move player left or right
void move_player(enum direction_t direction) {
if (direction == left) {
if (player.hitbox.x > 0) {
player.hitbox.x -= 10;
}
} else if (direction == right) {
if (player.hitbox.x + player.hitbox.w < WIDTH){
player.hitbox.x += 10;
}
}
}
//Move saucer based on there current direction
void move_saucer() {
if (saucer.alive == 1) {
if (saucer.direction == left) {
saucer.hitbox.x -= 5;
if (saucer.hitbox.x < 0) {
saucer.alive = 0;
saucer.hitbox.x = 0;
saucer.direction = right;
}
}
if (saucer.direction == right) {
saucer.hitbox.x += 5;
if (saucer.hitbox.x + saucer.hitbox.w > WIDTH) {
saucer.alive = 0;
saucer.hitbox.x = WIDTH - saucer.hitbox.w;
saucer.direction = left;
}
}
}
}
//Detect any collision between any two non rotated rectangles
int collision(SDL_Rect a, SDL_Rect b) {
if (a.y + a.h < b.y) {
return 0;
}
if (a.y > b.y + b.h) {
return 0;
}
if (a.x > b.x + b.w) {
return 0;
}
if (a.x + a.w < b.x) {
return 0;
}
return 1;
}
//Create damage to the base sprite for player and enemy bullet collisions
void bullet_base_damage(struct base_t *base, int b_num, struct bullet_t *bullet, int l) {
int i;
int x,y;
SDL_Rect src;
SDL_Rect dest;
SDL_LockSurface(base_img[b_num]);
Uint8 *raw_pixels;
raw_pixels = (Uint8 *) base_img[b_num]->pixels;
int pix_offset;
//bottom
if (l == 0) {
//how far from the left did the bullet hit the base sprite
x = (bullet->hitbox.x + 3) - base->hitbox.x;
//start from bottom of the base sprite
y = base->hitbox.h - 1;
for(i = 0; i < base->hitbox.h; i++) {
//the x calculation can get us to pixel column 60 when 59 is the maximum (0 - 59 is 60 pixels)
if (x >= BASE_WIDTH) {
x = BASE_WIDTH - 1;
}
pix_offset = y * base_img[b_num]->pitch + x;
//found part part of the base sprite that is NOT magenta(index)
//searching from the bottom up
if (raw_pixels[pix_offset] != 227) {
bullet->alive = 0;
src.x = 0;
src.y = 0;
src.w = 11;
src.h = 15;
dest.x = x - 3;
dest.y = y - 14;
dest.w = 11;
dest.h = 15;
SDL_UnlockSurface(base_img[b_num]);
SDL_BlitSurface(damage_img, &src, base_img[b_num], &dest);
break;
}
y--;
}
}
//top
if (l == 1) {
//how far from the left did the bullet hit the base sprite
x = (bullet->hitbox.x + 3) - base->hitbox.x;
//start from top of the base sprite
y = 0;
for(i = 0; i < base->hitbox.h; i++) {
//the x calculation can get us to pixel column 60 when 59 is the maximum (0 - 59 is 60 pixels)
if (x >= BASE_WIDTH) {
x = BASE_WIDTH - 1;
}
pix_offset = y * base_img[b_num]->pitch + x;
//found part part of the base sprite that is NOT magenta(index)
//searching from the top down
if (raw_pixels[pix_offset] != 227) {
bullet->alive = 0;
src.x = 0;
src.y = 0;
src.w = 11;
src.h = 15;
dest.x = x - 3;
dest.y = y;
dest.w = 11;
dest.h = 15;
SDL_UnlockSurface(base_img[b_num]);
SDL_BlitSurface(damage_top_img, &src, base_img[b_num], &dest);
break;
}
y++;
}
}
SDL_UnlockSurface(base_img[b_num]);
}
//Create damage to the base sprite for enemy and base collisions
void enemy_base_damage(struct enemy_t *enemy, struct base_t *base, int index) {
int x,y;
SDL_Rect dest;
//the x hot spot is taken from the top left of the sprite with the speed in pixels
//added ahead in case the enemy skips the last few pixels of the sprite and
//the collision is no longer detected. Speed in pixels is subtracted if traveling left
if (invaders.direction == right) {
x = (enemy->hitbox.x + invaders.speed) - base->hitbox.x;
y = enemy->hitbox.y - base->hitbox.y;
if (x > 0) {
dest.x = 0;
dest.y = y;
dest.w = x;
dest.h = enemy->hitbox.h;
SDL_FillRect(base_img[index], &dest, 227);
}
} else if (invaders.direction == left){
x = (enemy->hitbox.x + (enemy->hitbox.w - 1)) - invaders.speed;
x = x - base->hitbox.x;
y = enemy->hitbox.y - base->hitbox.y;
if (x < base->hitbox.w) {
dest.x = x;
dest.y = y;
dest.w = base->hitbox.w - 1;
dest.h = enemy->hitbox.h;
SDL_FillRect(base_img[index], &dest, 227);
}
}
}
//Look for collisions based on enemy and base rectangles
void enemy_base_collision() {
int i,j,k,c;
for (i = 0; i < 5; i++) {
for (j = 0; j < 10; j++) {
for (k = 0; k < BASE; k++) {
if (invaders.enemy[i][j].alive == 1) {
c = collision(invaders.enemy[i][j].hitbox,base[k].hitbox);
if (c == 1) {
enemy_base_damage(&invaders.enemy[i][j], &base[k], k);
}
}
}
}
}
}
//Look for collisions based on player bullet and invader rectangles
void enemy_hit_collision() {
int i,j,k,c;
for (i = 0; i < 5; i++) {
for (j = 0; j < 10; j++) {
if (invaders.enemy[i][j].alive == 1) {
for (k = 0; k < P_BULLETS; k++) {
if (bullets[k].alive == 1) {
c = collision(bullets[k].hitbox, invaders.enemy[i][j].hitbox);
if (c == 1) {
invaders.enemy[i][j].alive = 0;
bullets[k].alive = 0;
bullets[k].hitbox.x = 0;
bullets[k].hitbox.y = 0;
invaders.killed++;
score.points += invaders.enemy[i][j].points;
}
}
}
}
}
}
}
//Look for collisions based on enemy bullet and player rectangles
void player_hit_collision() {
int i,c;
for(i = 0; i < E_BULLETS; i++) {
if (e_bullets[i].alive == 1) {
c = collision(e_bullets[i].hitbox, player.hitbox);
if (c == 1) {
if (player.lives >= 0) {
player.lives--;
pause_for(500);
}
}
}
}
}
//Look for collisions based on player bullet and saucer rectangles
void saucer_hit_collision() {
int i,c;
if (saucer.alive == 1) {
for(i = 0; i < P_BULLETS; i++) {
if (bullets[i].alive == 1) {
c = collision(bullets[i].hitbox, saucer.hitbox);
if (c == 1) {
int r = rand() % 3;
switch (r) {
case 0:
score.points += 50;
break;
case 1:
score.points += 150;
break;