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

Last change on this file since 153 was 153, checked in by Sam Hocevar, 20 years ago
  • libee/graphics.c: + Renamed ee_color() to ee_set_color(), wrote ee_get_color().
  • libee/line.c: + Implemented draw_polyline() and draw_thin_polyline().
  • libee/sprite.c: + Removed the f member of struct ee_sprite. + Implemented ee_get_sprite_{width|height|dx|dy}(). + Restore the color fater ee_draw_sprite() is called.
  • libee/box.c: + Fixed a bug causing improper box clipping at the right and the bottom.
  • data/foo_fighter: + Fixed bugs in the sprite.
  • src/intro.c: + Test effects for the future game's intro.
  • test/spritedit.c: + Added stuff to the sprite editor. We can now navigate through frames.
  • Property svn:keywords set to Id
File size: 3.5 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 153 2003-11-12 01:48:58Z 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
29struct ee_sprite *medium_sprite;
30struct ee_sprite *small_sprite;
31
32void init_explosions(game *g, explosions *ex)
33{
34    int i;
35
36    for(i = 0; i < EXPLOSIONS; i++)
37    {
38        ex->type[i] = EXPLOSION_NONE;
39    }
40
41    medium_sprite = ee_load_sprite("data/explosion_medium");
42    small_sprite = ee_load_sprite("data/explosion_small");
43}
44
45void add_explosion(game *g, explosions *ex, int x, int y, int vx, int vy, int type)
46{
47    int i;
48
49    for(i = 0; i < EXPLOSIONS; i++)
50    {
51        if(ex->type[i] == EXPLOSION_NONE)
52        {
53            ex->type[i] = type;
54            ex->x[i] = x;
55            ex->y[i] = y;
56            ex->vx[i] = vx;
57            ex->vy[i] = vy;
58            switch(type)
59            {
60                case EXPLOSION_MEDIUM:
61                    ex->n[i] = 11;
62                    break;
63                case EXPLOSION_SMALL:
64                    ex->n[i] = 7;
65                    break;
66            }
67            break;
68        }
69    }
70}
71
72void draw_explosions(game *g, explosions *ex)
73{
74    int i;
75
76    for(i = 0; i < EXPLOSIONS; i++)
77    {
78#if 0
79        ee_set_color(GREEN);
80        ee_goto(ex->x[i] + 3, ex->y[i]);
81        switch(ee_rand(0,2))
82        {
83        case 0:
84            ee_putchar('p');
85            ee_putchar('i');
86            ee_putchar('f');
87            break;
88        case 1:
89            ee_putchar('p');
90            ee_putchar('a');
91            ee_putchar('f');
92            break;
93        case 2:
94            ee_putchar('p');
95            ee_putchar('o');
96            ee_putchar('u');
97            ee_putchar('f');
98            break;
99        }
100        ee_putchar('!');
101#endif
102
103        switch(ex->type[i])
104        {
105            case EXPLOSION_MEDIUM:
106                ee_draw_sprite(ex->x[i], ex->y[i], medium_sprite,
107                               10 - ex->n[i]);
108                break;
109            case EXPLOSION_SMALL:
110                ee_draw_sprite(ex->x[i], ex->y[i], small_sprite,
111                               6 - ex->n[i]);
112                break;
113            case EXPLOSION_NONE:
114                break;
115        }
116    }
117}
118
119void update_explosions(game *g, explosions *ex)
120{
121    int i;
122
123    for(i = 0; i < EXPLOSIONS; i++)
124    {
125        switch(ex->type[i])
126        {
127            case EXPLOSION_MEDIUM:
128            case EXPLOSION_SMALL:
129                ex->x[i] += ex->vx[i];
130                ex->y[i] += ex->vy[i];
131                ex->n[i]--;
132                if(ex->n[i] < 0)
133                {
134                    ex->type[i] = EXPLOSION_NONE;
135                }
136                break;
137            case EXPLOSION_NONE:
138                break;
139        }
140    }
141}
142
Note: See TracBrowser for help on using the repository browser.