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