source: libcaca/trunk/src/explosions.c @ 139

Last change on this file since 139 was 139, checked in by Sam Hocevar, 17 years ago
  • libee/sprite.c: + Made sprite loading more robust.
  • src/explosions.c: + No longer use ee_putchar etc. to draw our sprites, but use

ee_draw_sprite().

  • data/: + Drew explosion_medium and explosion_small sprites.
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
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 139 2003-11-10 21:17:47Z 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
29static void draw_small_explosion(int x, int y, int frame);
30static void draw_medium_explosion(int x, int y, int frame);
31
32struct ee_sprite *medium_sprite;
33struct ee_sprite *small_sprite;
34
35void init_explosions(game *g, explosions *ex)
36{
37    int i;
38
39    for(i = 0; i < EXPLOSIONS; i++)
40    {
41        ex->type[i] = EXPLOSION_NONE;
42    }
43
44    medium_sprite = ee_load_sprite("data/explosion_medium");
45    small_sprite = ee_load_sprite("data/explosion_small");
46}
47
48void add_explosion(game *g, explosions *ex, int x, int y, int vx, int vy, int type)
49{
50    int i;
51
52    for(i = 0; i < EXPLOSIONS; i++)
53    {
54        if(ex->type[i] == EXPLOSION_NONE)
55        {
56            ex->type[i] = type;
57            ex->x[i] = x;
58            ex->y[i] = y;
59            ex->vx[i] = vx;
60            ex->vy[i] = vy;
61            switch(type)
62            {
63                case EXPLOSION_MEDIUM:
64                    ex->n[i] = 11;
65                    break;
66                case EXPLOSION_SMALL:
67                    ex->n[i] = 7;
68                    break;
69            }
70            break;
71        }
72    }
73}
74
75void draw_explosions(game *g, explosions *ex)
76{
77    int i;
78
79    for(i = 0; i < EXPLOSIONS; i++)
80    {
81#if 0
82        ee_color(GREEN);
83        ee_goto(ex->x[i] + 3, ex->y[i]);
84        switch(ee_rand(0,2))
85        {
86        case 0:
87            ee_putchar('p');
88            ee_putchar('i');
89            ee_putchar('f');
90            break;
91        case 1:
92            ee_putchar('p');
93            ee_putchar('a');
94            ee_putchar('f');
95            break;
96        case 2:
97            ee_putchar('p');
98            ee_putchar('o');
99            ee_putchar('u');
100            ee_putchar('f');
101            break;
102        }
103        ee_putchar('!');
104#endif
105
106        switch(ex->type[i])
107        {
108            case EXPLOSION_MEDIUM:
109                draw_medium_explosion(ex->x[i], ex->y[i], ex->n[i]);
110                break;
111            case EXPLOSION_SMALL:
112                draw_small_explosion(ex->x[i], ex->y[i], ex->n[i]);
113                break;
114            case EXPLOSION_NONE:
115                break;
116        }
117    }
118}
119
120void update_explosions(game *g, explosions *ex)
121{
122    int i;
123
124    for(i = 0; i < EXPLOSIONS; i++)
125    {
126        switch(ex->type[i])
127        {
128            case EXPLOSION_MEDIUM:
129            case EXPLOSION_SMALL:
130                ex->x[i] += ex->vx[i];
131                ex->y[i] += ex->vy[i];
132                ex->n[i]--;
133                if(ex->n[i] < 0)
134                {
135                    ex->type[i] = EXPLOSION_NONE;
136                }
137                break;
138            case EXPLOSION_NONE:
139                break;
140        }
141    }
142}
143
144static void draw_small_explosion(int x, int y, int frame)
145{
146    ee_set_sprite_frame(small_sprite, 6 - frame);
147    ee_draw_sprite(x, y, small_sprite);
148}
149
150static void draw_medium_explosion(int x, int y, int frame)
151{
152    ee_set_sprite_frame(medium_sprite, 10 - frame);
153    ee_draw_sprite(x, y, medium_sprite);
154}
155
Note: See TracBrowser for help on using the repository browser.