1 /* $Id: explosions.c,v 1.2 1998/04/30 05:11:54 mrogre Exp $ */
2 /* Copyright (c) 1998 Joe Rumsey (mrogre@mediaone.net) */
3 #include "copyright.h"
4 
5 #include <config.h>
6 
7 
8 #include <stdlib.h>
9 #include "Wlib.h"
10 #include "images.h"
11 #include "struct.h"
12 #include "data.h"
13 #include "proto.h"
14 #include "sound.h"
15 
16 static struct explosion *first_exp=0;
17 static struct score_bubble *first_bub=0;
18 
19 W_Image *expImage, *bubbleImages[4];
20 
undo_bubbles()21 static void undo_bubbles()
22 {
23     struct score_bubble *bub=first_bub, *nextbub;
24 
25     while(bub) {
26 	W_CacheClearArea(baseWin, bub->x-(bub->shape->width/2), bub->y-(bub->shape->height/2), bub->shape->width, bub->shape->height);
27 	nextbub = bub->next;
28 	if(bub->count <= 0) {
29 	    if(bub->prev)
30 		bub->prev->next = bub->next;
31 	    if(bub->next)
32 		bub->next->prev = bub->prev;
33 	    if(first_bub == bub)
34 		first_bub = 0;
35 	    free(bub);
36 	}
37 	bub=nextbub;
38     }
39 }
40 
do_bubbles()41 static void do_bubbles()
42 {
43     struct score_bubble *bub=first_bub;
44 
45     while(bub) {
46 	if(!paused) {
47 	    bub->count--;
48 	    bub->y--;
49 	}
50 	W_DrawImage(baseWin,
51 		    bub->x-(bub->shape->width/2),
52 		    bub->y-(bub->shape->height/2),
53 		    0, bub->shape, W_Red);
54 	bub=bub->next;
55     }
56 }
57 
undo_explosions()58 void undo_explosions()
59 {
60     struct explosion *exp=first_exp, *nextexp;
61 
62     while(exp) {
63 	W_CacheClearArea(baseWin, exp->x-(exp->shape->width/2), exp->y-(exp->shape->height/2), exp->shape->width, exp->shape->height);
64 	nextexp = exp->next;
65 	if(exp->frame >= exp->shape->frames) {
66 	    if(exp->prev)
67 		exp->prev->next = exp->next;
68 	    if(exp->next)
69 		exp->next->prev = exp->prev;
70 	    if(first_exp == exp)
71 		first_exp = 0;
72 	    free(exp);
73 	}
74 	exp=nextexp;
75     }
76     undo_bubbles();
77 }
78 
do_explosions()79 void do_explosions()
80 {
81     struct explosion *exp=first_exp;
82 
83     while(exp) {
84 	W_DrawImage(baseWin,
85 		    exp->x-(exp->shape->width/2),
86 		    exp->y-(exp->shape->height/2),
87 		    exp->frame, exp->shape, W_Red);
88 	if(!paused)
89 	    exp->frame++;
90 	exp=exp->next;
91     }
92     do_bubbles();
93 }
94 
new_explosion(int x,int y,int type)95 void new_explosion(int x, int y, int type)
96 {
97     struct explosion *exp;
98 
99     exp = malloc(sizeof(struct explosion));
100     exp->next = first_exp;
101     exp->prev = 0;
102     if(exp->next)
103 	exp->next->prev = exp;
104     first_exp = exp;
105 
106     exp->x = x;
107     exp->y = y;
108     exp->frame = 0;
109     exp->shape = getImage(I_EXPLOSION);
110 #ifdef SOUND
111     switch(type) {
112       case 1:
113 	play_sound(SND_EXPLOSION);
114 	break;
115       case 2:
116 	play_sound(SND_EXP_SB);
117 	break;
118       case 0:
119       default:
120 	play_sound(SND_TORPHIT);
121 	break;
122     }
123 #endif
124 }
125 
126 
score_flagship(int x,int y,int ne)127 void score_flagship(int x, int y, int ne)
128 {
129     struct score_bubble *bub;
130 
131     bub = malloc(sizeof(struct score_bubble));
132     bub->next = first_bub;
133     bub->prev = 0;
134     if(bub->next)
135 	bub->next->prev = bub;
136     first_bub = bub;
137 
138     bub->x = x;
139     bub->y = y;
140     bub->count=25;
141     bub->shape = bubbleImages[ne];
142     switch(ne) {
143       case 0:
144 	score+=500;
145 	break;
146       case 1:
147 	score+=1000;
148 	break;
149       case 2:
150 	score+=2000;
151 	break;
152       case 3:
153 	score+=4000;
154 	break;
155     }
156 }
157 
init_explosions()158 void init_explosions()
159 {
160     expImage = getImage(I_EXPLOSION);
161 
162     bubbleImages[0] = getImage(I_S500);
163     bubbleImages[1] = getImage(I_S1000);
164     bubbleImages[2] = getImage(I_S2000);
165     bubbleImages[3] = getImage(I_S4000);
166 }
167