1 | /* |
---|
2 | * ttyvaders Textmode shoot'em up |
---|
3 | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: explosions.c 1057 2006-09-18 16:54:08Z sam $ |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; either version 2 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | #include "config.h" |
---|
24 | |
---|
25 | #include <stdlib.h> |
---|
26 | |
---|
27 | #include "common.h" |
---|
28 | |
---|
29 | cucul_canvas_t *medium_sprite; |
---|
30 | cucul_canvas_t *small_sprite; |
---|
31 | |
---|
32 | void init_explosions(game *g, explosions *ex) |
---|
33 | { |
---|
34 | cucul_buffer_t *b; |
---|
35 | int i; |
---|
36 | |
---|
37 | for(i = 0; i < EXPLOSIONS; i++) |
---|
38 | { |
---|
39 | ex->type[i] = EXPLOSION_NONE; |
---|
40 | } |
---|
41 | |
---|
42 | b = cucul_load_file("data/xplmed.caca"); |
---|
43 | medium_sprite = cucul_import_canvas(b, ""); |
---|
44 | cucul_free_buffer(b); |
---|
45 | |
---|
46 | b = cucul_load_file("data/xplsmall.caca"); |
---|
47 | small_sprite = cucul_import_canvas(b, ""); |
---|
48 | cucul_free_buffer(b); |
---|
49 | } |
---|
50 | |
---|
51 | void add_explosion(game *g, explosions *ex, int x, int y, int vx, int vy, int type) |
---|
52 | { |
---|
53 | int i; |
---|
54 | |
---|
55 | for(i = 0; i < EXPLOSIONS; i++) |
---|
56 | { |
---|
57 | if(ex->type[i] == EXPLOSION_NONE) |
---|
58 | { |
---|
59 | ex->type[i] = type; |
---|
60 | ex->x[i] = x; |
---|
61 | ex->y[i] = y; |
---|
62 | ex->vx[i] = vx; |
---|
63 | ex->vy[i] = vy; |
---|
64 | switch(type) |
---|
65 | { |
---|
66 | case EXPLOSION_MEDIUM: |
---|
67 | ex->n[i] = 11; |
---|
68 | break; |
---|
69 | case EXPLOSION_SMALL: |
---|
70 | ex->n[i] = 7; |
---|
71 | break; |
---|
72 | } |
---|
73 | break; |
---|
74 | } |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | void draw_explosions(game *g, explosions *ex) |
---|
79 | { |
---|
80 | int i; |
---|
81 | |
---|
82 | for(i = 0; i < EXPLOSIONS; i++) |
---|
83 | { |
---|
84 | #if 0 |
---|
85 | cucul_set_fg_color(g->cv, CACA_COLOR_GREEN); |
---|
86 | cucul_goto(g->cv, ex->x[i] + 3, ex->y[i]); |
---|
87 | switch(cucul_rand(0,2)) |
---|
88 | { |
---|
89 | case 0: |
---|
90 | cucul_putchar(g->cv, 'p'); |
---|
91 | cucul_putchar(g->cv, 'i'); |
---|
92 | cucul_putchar(g->cv, 'f'); |
---|
93 | break; |
---|
94 | case 1: |
---|
95 | cucul_putchar(g->cv, 'p'); |
---|
96 | cucul_putchar(g->cv, 'a'); |
---|
97 | cucul_putchar(g->cv, 'f'); |
---|
98 | break; |
---|
99 | case 2: |
---|
100 | cucul_putchar(g->cv, 'p'); |
---|
101 | cucul_putchar(g->cv, 'o'); |
---|
102 | cucul_putchar(g->cv, 'u'); |
---|
103 | cucul_putchar(g->cv, 'f'); |
---|
104 | break; |
---|
105 | } |
---|
106 | cucul_putchar(g->cv, '!'); |
---|
107 | #endif |
---|
108 | |
---|
109 | switch(ex->type[i]) |
---|
110 | { |
---|
111 | case EXPLOSION_MEDIUM: |
---|
112 | cucul_set_canvas_frame(medium_sprite, 10 - ex->n[i]); |
---|
113 | cucul_blit(g->cv, ex->x[i], ex->y[i], medium_sprite, NULL); |
---|
114 | break; |
---|
115 | case EXPLOSION_SMALL: |
---|
116 | cucul_set_canvas_frame(small_sprite, 6 - ex->n[i]); |
---|
117 | cucul_blit(g->cv, ex->x[i], ex->y[i], small_sprite, NULL); |
---|
118 | break; |
---|
119 | case EXPLOSION_NONE: |
---|
120 | break; |
---|
121 | } |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | void update_explosions(game *g, explosions *ex) |
---|
126 | { |
---|
127 | int i; |
---|
128 | |
---|
129 | for(i = 0; i < EXPLOSIONS; i++) |
---|
130 | { |
---|
131 | switch(ex->type[i]) |
---|
132 | { |
---|
133 | case EXPLOSION_MEDIUM: |
---|
134 | case EXPLOSION_SMALL: |
---|
135 | ex->x[i] += ex->vx[i]; |
---|
136 | ex->y[i] += ex->vy[i]; |
---|
137 | ex->n[i]--; |
---|
138 | if(ex->n[i] < 0) |
---|
139 | { |
---|
140 | ex->type[i] = EXPLOSION_NONE; |
---|
141 | } |
---|
142 | break; |
---|
143 | case EXPLOSION_NONE: |
---|
144 | break; |
---|
145 | } |
---|
146 | } |
---|
147 | } |
---|
148 | |
---|