1 /*
2 * XGalaga-SDL - a SDL port of XGalaga, clone of the game Galaga
3 * Copyright (c) 1995-1998 Joe Rumsey (mrogre@mediaone.net)
4 * Copyright (c) 2010 Frank Zago
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301, USA.
20 */
21
22 #include <stdlib.h>
23
24 #include "xgalaga.h"
25
26 static struct explosion *first_exp;
27 static struct score_bubble *first_bub;
28
29 static struct W_Image *expImage, *bubbleImages[4];
30
undo_bubbles(void)31 static void undo_bubbles(void)
32 {
33 struct score_bubble *bub=first_bub, *nextbub;
34
35 while(bub) {
36 nextbub = bub->next;
37 if(bub->count <= 0) {
38 if(bub->prev)
39 bub->prev->next = bub->next;
40 if(bub->next)
41 bub->next->prev = bub->prev;
42 if(first_bub == bub)
43 first_bub = NULL;
44 free(bub);
45 }
46 bub=nextbub;
47 }
48 }
49
do_bubbles(void)50 static void do_bubbles(void)
51 {
52 struct score_bubble *bub=first_bub;
53
54 while(bub) {
55 if (gstate == PLAYING) {
56 bub->count--;
57 bub->y--;
58 }
59 S_DrawImage(bub->x-(bub->shape->width/2),
60 bub->y-(bub->shape->height/2),
61 0, bub->shape);
62 bub=bub->next;
63 }
64 }
65
undo_explosions(void)66 void undo_explosions(void)
67 {
68 struct explosion *exp=first_exp, *nextexp;
69
70 while(exp) {
71 nextexp = exp->next;
72 if(exp->frame >= exp->shape->frames) {
73 if(exp->prev)
74 exp->prev->next = exp->next;
75 if(exp->next)
76 exp->next->prev = exp->prev;
77 if(first_exp == exp)
78 first_exp = NULL;
79 free(exp);
80 }
81 exp=nextexp;
82 }
83 undo_bubbles();
84 }
85
do_explosions(void)86 void do_explosions(void)
87 {
88 struct explosion *exp=first_exp;
89
90 while(exp) {
91 S_DrawImage(exp->x-(exp->shape->width/2),
92 exp->y-(exp->shape->height/2),
93 exp->frame, exp->shape);
94 if(gstate == PLAYING)
95 exp->frame++;
96 exp=exp->next;
97 }
98 do_bubbles();
99 }
100
new_explosion(int x,int y,int type)101 void new_explosion(int x, int y, int type)
102 {
103 struct explosion *exp;
104
105 exp = malloc(sizeof(struct explosion));
106 exp->next = first_exp;
107 exp->prev = NULL;
108 if(exp->next)
109 exp->next->prev = exp;
110 first_exp = exp;
111
112 exp->x = x;
113 exp->y = y;
114 exp->frame = 0;
115 exp->shape = getImage(I_EXPLOSION);
116
117 switch(type) {
118 case 1:
119 play_sound(SND_EXPLOSION);
120 break;
121 case 2:
122 play_sound(SND_EXP_SB);
123 break;
124 case 0:
125 default:
126 play_sound(SND_TORPHIT);
127 break;
128 }
129 }
130
score_flagship(int x,int y,int ne)131 void score_flagship(int x, int y, int ne)
132 {
133 struct score_bubble *bub;
134
135 bub = malloc(sizeof(struct score_bubble));
136 bub->next = first_bub;
137 bub->prev = NULL;
138 if(bub->next)
139 bub->next->prev = bub;
140 first_bub = bub;
141
142 bub->x = x;
143 bub->y = y;
144 bub->count=25;
145 bub->shape = bubbleImages[ne];
146 switch(ne) {
147 case 0:
148 score+=500;
149 break;
150 case 1:
151 score+=1000;
152 break;
153 case 2:
154 score+=2000;
155 break;
156 case 3:
157 score+=4000;
158 break;
159 }
160 }
161
init_explosions(void)162 void init_explosions(void)
163 {
164 expImage = getImage(I_EXPLOSION);
165
166 bubbleImages[0] = getImage(I_S500);
167 bubbleImages[1] = getImage(I_S1000);
168 bubbleImages[2] = getImage(I_S2000);
169 bubbleImages[3] = getImage(I_S4000);
170 }
171