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

Last change on this file since 110 was 110, checked in by Sam Hocevar, 17 years ago
  • src/*.c: + Added missing #include "config.h". + Fixed a nasty bug in ee_rand() calls.
  • Property svn:keywords set to Id
File size: 3.2 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 110 2003-11-09 23:34:24Z 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
29void init_bonus(game *g, bonus *bo)
30{
31    int i;
32
33    for(i = 0; i < BONUS; i++)
34    {
35        bo->type[i] = BONUS_NONE;
36    }
37}
38
39void draw_bonus(game *g, bonus *bo)
40{
41    int i;
42
43    for(i = 0; i < BONUS; i++)
44    {
45        switch(bo->type[i])
46        {
47            case BONUS_GREEN:
48                ee_color((bo->n[i]/2 % 3) ? EE_GREEN : EE_WHITE);
49                ee_goto(bo->x[i]+1, bo->y[i]-1);
50                ee_putchar('_');
51                ee_goto(bo->x[i], bo->y[i]);
52                ee_putstr("/ \\");
53                ee_goto(bo->x[i], bo->y[i]+1);
54                ee_putstr("\\_/");
55                ee_color(EE_WHITE);
56                ee_goto(bo->x[i]+1, bo->y[i]);
57                ee_putchar('g');
58                break;
59            case BONUS_LIFE:
60                ee_color((bo->n[i] % 3) ? EE_RED : EE_WHITE);
61                ee_goto(bo->x[i]+1, bo->y[i]-1);
62                ee_putchar('_');
63                ee_goto(bo->x[i]+3, bo->y[i]-1);
64                ee_putchar('_');
65                ee_goto(bo->x[i], bo->y[i]);
66                ee_putstr("( ' )");
67                ee_goto(bo->x[i]+1, bo->y[i]+1);
68                ee_putstr("`v'");
69                ee_color(EE_WHITE);
70                ee_goto(bo->x[i]+3, bo->y[i]);
71                ee_putchar('^');
72                break;
73            case BONUS_NONE:
74                break;
75        }
76    }
77}
78
79void update_bonus(game *g, bonus *bo)
80{
81    int i;
82
83    for(i = 0; i < BONUS; i++)
84    {
85        switch(bo->type[i])
86        {
87            case BONUS_GREEN:
88                bo->n[i]++;
89                bo->y[i]++;
90                if(bo->y[i] > g->h)
91                {
92                    bo->type[i] = BONUS_NONE;
93                }
94                break;
95            case BONUS_LIFE:
96                bo->n[i]++;
97                bo->y[i]++;
98                if(bo->y[i] > g->h)
99                {
100                    bo->type[i] = BONUS_NONE;
101                }
102                break;
103            case BONUS_NONE:
104                break;
105        }
106    }
107}
108
109void add_bonus(game *g, bonus *bo, int x, int y, int type)
110{
111    int i;
112
113    for(i = 0; i < BONUS; i++)
114    {
115        if(bo->type[i] == BONUS_NONE)
116        {
117            bo->type[i] = type;
118            bo->x[i] = x;
119            bo->y[i] = y;
120            bo->n[i] = 0;
121            break;
122        }
123    }
124}
125
Note: See TracBrowser for help on using the repository browser.