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

Last change on this file since 70 was 38, checked in by Sam Hocevar, 20 years ago
  • I think I fucked up the $Id tags on my previous commit.
File size: 3.3 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,v 1.3 2002/12/22 18:44:12 sam Exp $
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 <stdlib.h>
24
25#include "common.h"
26
27void init_bonus( game *g, bonus *bo )
28{
29    int i;
30
31    for( i = 0; i < BONUS; i++ )
32    {
33        bo->type[i] = BONUS_NONE;
34    }
35}
36
37void draw_bonus( game *g, bonus *bo )
38{
39    int i;
40
41    for( i = 0; i < BONUS; i++ )
42    {
43        switch( bo->type[i] )
44        {
45            case BONUS_GREEN:
46                gfx_color( (bo->n[i]/2 % 3) ? GREEN : WHITE );
47                gfx_goto( bo->x[i]+1, bo->y[i]-1 );
48                gfx_putchar( '_' );
49                gfx_goto( bo->x[i], bo->y[i] );
50                gfx_putstr( "/ \\" );
51                gfx_goto( bo->x[i], bo->y[i]+1 );
52                gfx_putstr( "\\_/" );
53                gfx_color( WHITE );
54                gfx_goto( bo->x[i]+1, bo->y[i] );
55                gfx_putchar( 'g' );
56                break;
57            case BONUS_LIFE:
58                gfx_color( (bo->n[i] % 3) ? RED : WHITE );
59                gfx_goto( bo->x[i]+1, bo->y[i]-1 );
60                gfx_putchar( '_' );
61                gfx_goto( bo->x[i]+3, bo->y[i]-1 );
62                gfx_putchar( '_' );
63                gfx_goto( bo->x[i], bo->y[i] );
64                gfx_putstr( "( ' )" );
65                gfx_goto( bo->x[i]+1, bo->y[i]+1 );
66                gfx_putstr( "`v'" );
67                gfx_color( WHITE );
68                gfx_goto( bo->x[i]+3, bo->y[i] );
69                gfx_putchar( '^' );
70                break;
71            case BONUS_NONE:
72                break;
73        }
74    }
75}
76
77void update_bonus( game *g, bonus *bo )
78{
79    int i;
80
81    for( i = 0; i < BONUS; i++ )
82    {
83        switch( bo->type[i] )
84        {
85            case BONUS_GREEN:
86                bo->n[i]++;
87                bo->y[i]++;
88                if( bo->y[i] > g->h )
89                {
90                    bo->type[i] = BONUS_NONE;
91                }
92                break;
93            case BONUS_LIFE:
94                bo->n[i]++;
95                bo->y[i]++;
96                if( bo->y[i] > g->h )
97                {
98                    bo->type[i] = BONUS_NONE;
99                }
100                break;
101            case BONUS_NONE:
102                break;
103        }
104    }
105}
106
107void add_bonus( game *g, bonus *bo, int x, int y, int type )
108{
109    int i;
110
111    for( i = 0; i < BONUS; i++ )
112    {
113        if( bo->type[i] == BONUS_NONE )
114        {
115            bo->type[i] = type;
116            bo->x[i] = x;
117            bo->y[i] = y;
118            bo->n[i] = 0;
119            break;
120        }
121    }
122}
123
Note: See TracBrowser for help on using the repository browser.