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

Last change on this file since 3423 was 3423, checked in by Sam Hocevar, 11 years ago
  • Toying around with the old ttyvaders version.
  • Property svn:keywords set to Id
File size: 3.3 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 3423 2009-04-28 16:55:01Z 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    int i;
27
28    for(i = 0; i < EXPLOSIONS; i++)
29    {
30        ex->type[i] = EXPLOSION_NONE;
31    }
32
33    medium_sprite = caca_create_canvas(0, 0);
34    caca_import_file(medium_sprite, "data/xplmed.txt", "utf8");
35
36    small_sprite = caca_create_canvas(0, 0);
37    caca_import_file(small_sprite, "data/xplsmall.txt", "utf8");
38}
39
40void add_explosion(game *g, explosions *ex, int x, int y, int vx, int vy, int type)
41{
42    int i;
43
44    for(i = 0; i < EXPLOSIONS; i++)
45    {
46        if(ex->type[i] == EXPLOSION_NONE)
47        {
48            ex->type[i] = type;
49            ex->x[i] = x;
50            ex->y[i] = y;
51            ex->vx[i] = vx;
52            ex->vy[i] = vy;
53            switch(type)
54            {
55                case EXPLOSION_MEDIUM:
56                    ex->n[i] = 11;
57                    break;
58                case EXPLOSION_SMALL:
59                    ex->n[i] = 7;
60                    break;
61            }
62            break;
63        }
64    }
65}
66
67void draw_explosions(game *g, explosions *ex)
68{
69    int i;
70
71    for(i = 0; i < EXPLOSIONS; i++)
72    {
73#if 0
74        caca_set_fg_color(g->cv, CACA_GREEN);
75        caca_goto(g->cv, ex->x[i] + 3, ex->y[i]);
76        switch(caca_rand(0,2))
77        {
78        case 0:
79            caca_putchar(g->cv, 'p');
80            caca_putchar(g->cv, 'i');
81            caca_putchar(g->cv, 'f');
82            break;
83        case 1:
84            caca_putchar(g->cv, 'p');
85            caca_putchar(g->cv, 'a');
86            caca_putchar(g->cv, 'f');
87            break;
88        case 2:
89            caca_putchar(g->cv, 'p');
90            caca_putchar(g->cv, 'o');
91            caca_putchar(g->cv, 'u');
92            caca_putchar(g->cv, 'f');
93            break;
94        }
95        caca_putchar(g->cv, '!');
96#endif
97
98        switch(ex->type[i])
99        {
100            case EXPLOSION_MEDIUM:
101                caca_set_frame(medium_sprite, 10 - ex->n[i]);
102                caca_blit(g->cv, ex->x[i], ex->y[i], medium_sprite, NULL);
103                break;
104            case EXPLOSION_SMALL:
105                caca_set_frame(small_sprite, 6 - ex->n[i]);
106                caca_blit(g->cv, ex->x[i], ex->y[i], small_sprite, NULL);
107                break;
108            case EXPLOSION_NONE:
109                break;
110        }
111    }
112}
113
114void update_explosions(game *g, explosions *ex)
115{
116    int i;
117
118    for(i = 0; i < EXPLOSIONS; i++)
119    {
120        switch(ex->type[i])
121        {
122            case EXPLOSION_MEDIUM:
123            case EXPLOSION_SMALL:
124                ex->x[i] += ex->vx[i];
125                ex->y[i] += ex->vy[i];
126                ex->n[i]--;
127                if(ex->n[i] < 0)
128                {
129                    ex->type[i] = EXPLOSION_NONE;
130                }
131                break;
132            case EXPLOSION_NONE:
133                break;
134        }
135    }
136}
137
Note: See TracBrowser for help on using the repository browser.