source: ttyvaders/trunk/src/bonus.c @ 1057

Last change on this file since 1057 was 1057, checked in by Sam Hocevar, 14 years ago
  • Bring the tree back in sync with the new libcaca API.
  • Property svn:keywords set to Id
File size: 2.9 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: bonus.c 1057 2006-09-18 16:54:08Z 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
29cucul_canvas_t *heart_sprite;
30cucul_canvas_t *gem_sprite;
31
32void init_bonus(game *g, bonus *bo)
33{
34    cucul_buffer_t *b;
35    int i;
36
37    for(i = 0; i < BONUS; i++)
38    {
39        bo->type[i] = BONUS_NONE;
40    }
41
42    b = cucul_load_file("data/bonheart.caca");
43    heart_sprite = cucul_import_canvas(b, "");
44    cucul_free_buffer(b);
45
46    b = cucul_load_file("data/bongem.caca");
47    gem_sprite = cucul_import_canvas(b, "");
48    cucul_free_buffer(b);
49}
50
51void draw_bonus(game *g, bonus *bo)
52{
53    int i;
54
55    for(i = 0; i < BONUS; i++)
56    {
57        switch(bo->type[i])
58        {
59            case BONUS_GREEN:
60                cucul_set_canvas_frame(gem_sprite, (bo->n[i]/2 % 3) ? 0 : 1);
61                cucul_blit(g->cv, bo->x[i], bo->y[i], gem_sprite, NULL);
62                break;
63            case BONUS_LIFE:
64                cucul_set_canvas_frame(heart_sprite, (bo->n[i] % 3) ? 0 : 1);
65                cucul_blit(g->cv, bo->x[i], bo->y[i], heart_sprite, NULL);
66                break;
67            case BONUS_NONE:
68                break;
69        }
70    }
71}
72
73void update_bonus(game *g, bonus *bo)
74{
75    int i;
76
77    for(i = 0; i < BONUS; i++)
78    {
79        switch(bo->type[i])
80        {
81            case BONUS_GREEN:
82                bo->n[i]++;
83                bo->y[i]++;
84                if(bo->y[i] > g->h)
85                {
86                    bo->type[i] = BONUS_NONE;
87                }
88                break;
89            case BONUS_LIFE:
90                bo->n[i]++;
91                bo->y[i]++;
92                if(bo->y[i] > g->h)
93                {
94                    bo->type[i] = BONUS_NONE;
95                }
96                break;
97            case BONUS_NONE:
98                break;
99        }
100    }
101}
102
103void add_bonus(game *g, bonus *bo, int x, int y, int type)
104{
105    int i;
106
107    for(i = 0; i < BONUS; i++)
108    {
109        if(bo->type[i] == BONUS_NONE)
110        {
111            bo->type[i] = type;
112            bo->x[i] = x;
113            bo->y[i] = y;
114            bo->n[i] = 0;
115            break;
116        }
117    }
118}
119
Note: See TracBrowser for help on using the repository browser.