source: ttyvaders/trunk/src/explosions.c @ 2990

Last change on this file since 2990 was 2990, checked in by Sam Hocevar, 11 years ago

Port ttyvaders to the unified libcaca 0.99.beta15 API.

  • Property svn:keywords set to Id
File size: 3.4 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 2990 2008-10-18 21:42:24Z sam $
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#include "config.h"
16
17#include <stdlib.h>
18
19#include "common.h"
20
21caca_canvas_t *medium_sprite;
22caca_canvas_t *small_sprite;
23
24void init_explosions(game *g, explosions *ex)
25{
26    caca_buffer_t *b;
27    int i;
28
29    for(i = 0; i < EXPLOSIONS; i++)
30    {
31        ex->type[i] = EXPLOSION_NONE;
32    }
33
34    b = caca_load_file("data/xplmed.caca");
35    medium_sprite = caca_import_canvas(b, "");
36    caca_free_buffer(b);
37
38    b = caca_load_file("data/xplsmall.caca");
39    small_sprite = caca_import_canvas(b, "");
40    caca_free_buffer(b);
41}
42
43void add_explosion(game *g, explosions *ex, int x, int y, int vx, int vy, int type)
44{
45    int i;
46
47    for(i = 0; i < EXPLOSIONS; i++)
48    {
49        if(ex->type[i] == EXPLOSION_NONE)
50        {
51            ex->type[i] = type;
52            ex->x[i] = x;
53            ex->y[i] = y;
54            ex->vx[i] = vx;
55            ex->vy[i] = vy;
56            switch(type)
57            {
58                case EXPLOSION_MEDIUM:
59                    ex->n[i] = 11;
60                    break;
61                case EXPLOSION_SMALL:
62                    ex->n[i] = 7;
63                    break;
64            }
65            break;
66        }
67    }
68}
69
70void draw_explosions(game *g, explosions *ex)
71{
72    int i;
73
74    for(i = 0; i < EXPLOSIONS; i++)
75    {
76#if 0
77        caca_set_fg_color(g->cv, CACA_COLOR_GREEN);
78        caca_goto(g->cv, ex->x[i] + 3, ex->y[i]);
79        switch(caca_rand(0,2))
80        {
81        case 0:
82            caca_putchar(g->cv, 'p');
83            caca_putchar(g->cv, 'i');
84            caca_putchar(g->cv, 'f');
85            break;
86        case 1:
87            caca_putchar(g->cv, 'p');
88            caca_putchar(g->cv, 'a');
89            caca_putchar(g->cv, 'f');
90            break;
91        case 2:
92            caca_putchar(g->cv, 'p');
93            caca_putchar(g->cv, 'o');
94            caca_putchar(g->cv, 'u');
95            caca_putchar(g->cv, 'f');
96            break;
97        }
98        caca_putchar(g->cv, '!');
99#endif
100
101        switch(ex->type[i])
102        {
103            case EXPLOSION_MEDIUM:
104                caca_set_canvas_frame(medium_sprite, 10 - ex->n[i]);
105                caca_blit(g->cv, ex->x[i], ex->y[i], medium_sprite, NULL);
106                break;
107            case EXPLOSION_SMALL:
108                caca_set_canvas_frame(small_sprite, 6 - ex->n[i]);
109                caca_blit(g->cv, ex->x[i], ex->y[i], small_sprite, NULL);
110                break;
111            case EXPLOSION_NONE:
112                break;
113        }
114    }
115}
116
117void update_explosions(game *g, explosions *ex)
118{
119    int i;
120
121    for(i = 0; i < EXPLOSIONS; i++)
122    {
123        switch(ex->type[i])
124        {
125            case EXPLOSION_MEDIUM:
126            case EXPLOSION_SMALL:
127                ex->x[i] += ex->vx[i];
128                ex->y[i] += ex->vy[i];
129                ex->n[i]--;
130                if(ex->n[i] < 0)
131                {
132                    ex->type[i] = EXPLOSION_NONE;
133                }
134                break;
135            case EXPLOSION_NONE:
136                break;
137        }
138    }
139}
140
Note: See TracBrowser for help on using the repository browser.