source: ttyvaders/trunk/src/bonus.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: 2.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: bonus.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 *heart_sprite;
22caca_canvas_t *gem_sprite;
23
24void init_bonus(game *g, bonus *bo)
25{
26    caca_buffer_t *b;
27    int i;
28
29    for(i = 0; i < BONUS; i++)
30    {
31        bo->type[i] = BONUS_NONE;
32    }
33
34    b = caca_load_file("data/bonheart.caca");
35    heart_sprite = caca_import_canvas(b, "");
36    caca_free_buffer(b);
37
38    b = caca_load_file("data/bongem.caca");
39    gem_sprite = caca_import_canvas(b, "");
40    caca_free_buffer(b);
41}
42
43void draw_bonus(game *g, bonus *bo)
44{
45    int i;
46
47    for(i = 0; i < BONUS; i++)
48    {
49        switch(bo->type[i])
50        {
51            case BONUS_GREEN:
52                caca_set_canvas_frame(gem_sprite, (bo->n[i]/2 % 3) ? 0 : 1);
53                caca_blit(g->cv, bo->x[i], bo->y[i], gem_sprite, NULL);
54                break;
55            case BONUS_LIFE:
56                caca_set_canvas_frame(heart_sprite, (bo->n[i] % 3) ? 0 : 1);
57                caca_blit(g->cv, bo->x[i], bo->y[i], heart_sprite, NULL);
58                break;
59            case BONUS_NONE:
60                break;
61        }
62    }
63}
64
65void update_bonus(game *g, bonus *bo)
66{
67    int i;
68
69    for(i = 0; i < BONUS; i++)
70    {
71        switch(bo->type[i])
72        {
73            case BONUS_GREEN:
74                bo->n[i]++;
75                bo->y[i]++;
76                if(bo->y[i] > g->h)
77                {
78                    bo->type[i] = BONUS_NONE;
79                }
80                break;
81            case BONUS_LIFE:
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_NONE:
90                break;
91        }
92    }
93}
94
95void add_bonus(game *g, bonus *bo, int x, int y, int type)
96{
97    int i;
98
99    for(i = 0; i < BONUS; i++)
100    {
101        if(bo->type[i] == BONUS_NONE)
102        {
103            bo->type[i] = type;
104            bo->x[i] = x;
105            bo->y[i] = y;
106            bo->n[i] = 0;
107            break;
108        }
109    }
110}
111
Note: See TracBrowser for help on using the repository browser.