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
RevLine 
[36]1/*
[1456]2 *  ttyvaders     Textmode shoot'em up
3 *  Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
[36]5 *
[1456]6 *  $Id: explosions.c 3423 2009-04-28 16:55:01Z sam $
[36]7 *
[1460]8 *  This program is free software. It comes without any warranty, to
[1456]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.
[36]13 */
[18]14
[110]15#include "config.h"
16
[18]17#include <stdlib.h>
18
19#include "common.h"
20
[2990]21caca_canvas_t *medium_sprite;
22caca_canvas_t *small_sprite;
[140]23
[88]24void init_explosions(game *g, explosions *ex)
[18]25{
26    int i;
27
[88]28    for(i = 0; i < EXPLOSIONS; i++)
[18]29    {
[20]30        ex->type[i] = EXPLOSION_NONE;
[18]31    }
[140]32
[3423]33    medium_sprite = caca_create_canvas(0, 0);
34    caca_import_file(medium_sprite, "data/xplmed.txt", "utf8");
[1057]35
[3423]36    small_sprite = caca_create_canvas(0, 0);
37    caca_import_file(small_sprite, "data/xplsmall.txt", "utf8");
[18]38}
39
[88]40void add_explosion(game *g, explosions *ex, int x, int y, int vx, int vy, int type)
[18]41{
42    int i;
43
[88]44    for(i = 0; i < EXPLOSIONS; i++)
[18]45    {
[88]46        if(ex->type[i] == EXPLOSION_NONE)
[18]47        {
[20]48            ex->type[i] = type;
[18]49            ex->x[i] = x;
50            ex->y[i] = y;
51            ex->vx[i] = vx;
52            ex->vy[i] = vy;
[88]53            switch(type)
[18]54            {
[20]55                case EXPLOSION_MEDIUM:
56                    ex->n[i] = 11;
57                    break;
58                case EXPLOSION_SMALL:
59                    ex->n[i] = 7;
60                    break;
[18]61            }
62            break;
63        }
64    }
65}
66
[88]67void draw_explosions(game *g, explosions *ex)
[18]68{
69    int i;
70
[88]71    for(i = 0; i < EXPLOSIONS; i++)
[18]72    {
73#if 0
[3423]74        caca_set_fg_color(g->cv, CACA_GREEN);
[2990]75        caca_goto(g->cv, ex->x[i] + 3, ex->y[i]);
76        switch(caca_rand(0,2))
[18]77        {
78        case 0:
[2990]79            caca_putchar(g->cv, 'p');
80            caca_putchar(g->cv, 'i');
81            caca_putchar(g->cv, 'f');
[18]82            break;
83        case 1:
[2990]84            caca_putchar(g->cv, 'p');
85            caca_putchar(g->cv, 'a');
86            caca_putchar(g->cv, 'f');
[18]87            break;
88        case 2:
[2990]89            caca_putchar(g->cv, 'p');
90            caca_putchar(g->cv, 'o');
91            caca_putchar(g->cv, 'u');
92            caca_putchar(g->cv, 'f');
[18]93            break;
94        }
[2990]95        caca_putchar(g->cv, '!');
[18]96#endif
97
[88]98        switch(ex->type[i])
[18]99        {
[20]100            case EXPLOSION_MEDIUM:
[3423]101                caca_set_frame(medium_sprite, 10 - ex->n[i]);
[2990]102                caca_blit(g->cv, ex->x[i], ex->y[i], medium_sprite, NULL);
[18]103                break;
[20]104            case EXPLOSION_SMALL:
[3423]105                caca_set_frame(small_sprite, 6 - ex->n[i]);
[2990]106                caca_blit(g->cv, ex->x[i], ex->y[i], small_sprite, NULL);
[18]107                break;
[20]108            case EXPLOSION_NONE:
109                break;
[18]110        }
111    }
112}
113
[88]114void update_explosions(game *g, explosions *ex)
[18]115{
116    int i;
117
[88]118    for(i = 0; i < EXPLOSIONS; i++)
[18]119    {
[88]120        switch(ex->type[i])
[18]121        {
[20]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]--;
[88]127                if(ex->n[i] < 0)
[20]128                {
129                    ex->type[i] = EXPLOSION_NONE;
130                }
131                break;
132            case EXPLOSION_NONE:
133                break;
[18]134        }
135    }
136}
137
Note: See TracBrowser for help on using the repository browser.