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 153 2003-11-12 01:48:58Z 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 | |
---|
29 | struct ee_sprite *heart_sprite; |
---|
30 | struct ee_sprite *gem_sprite; |
---|
31 | |
---|
32 | void init_bonus(game *g, bonus *bo) |
---|
33 | { |
---|
34 | int i; |
---|
35 | |
---|
36 | for(i = 0; i < BONUS; i++) |
---|
37 | { |
---|
38 | bo->type[i] = BONUS_NONE; |
---|
39 | } |
---|
40 | |
---|
41 | heart_sprite = ee_load_sprite("data/heart"); |
---|
42 | gem_sprite = ee_load_sprite("data/gem"); |
---|
43 | } |
---|
44 | |
---|
45 | void draw_bonus(game *g, bonus *bo) |
---|
46 | { |
---|
47 | int i; |
---|
48 | |
---|
49 | for(i = 0; i < BONUS; i++) |
---|
50 | { |
---|
51 | switch(bo->type[i]) |
---|
52 | { |
---|
53 | case BONUS_GREEN: |
---|
54 | ee_draw_sprite(bo->x[i], bo->y[i], gem_sprite, |
---|
55 | (bo->n[i]/2 % 3) ? 0 : 1); |
---|
56 | break; |
---|
57 | case BONUS_LIFE: |
---|
58 | ee_draw_sprite(bo->x[i], bo->y[i], heart_sprite, |
---|
59 | (bo->n[i] % 3) ? 0 : 1); |
---|
60 | break; |
---|
61 | case BONUS_NONE: |
---|
62 | break; |
---|
63 | } |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | void update_bonus(game *g, bonus *bo) |
---|
68 | { |
---|
69 | int i; |
---|
70 | |
---|
71 | for(i = 0; i < BONUS; i++) |
---|
72 | { |
---|
73 | switch(bo->type[i]) |
---|
74 | { |
---|
75 | case BONUS_GREEN: |
---|
76 | bo->n[i]++; |
---|
77 | bo->y[i]++; |
---|
78 | if(bo->y[i] > g->h) |
---|
79 | { |
---|
80 | bo->type[i] = BONUS_NONE; |
---|
81 | } |
---|
82 | break; |
---|
83 | case BONUS_LIFE: |
---|
84 | bo->n[i]++; |
---|
85 | bo->y[i]++; |
---|
86 | if(bo->y[i] > g->h) |
---|
87 | { |
---|
88 | bo->type[i] = BONUS_NONE; |
---|
89 | } |
---|
90 | break; |
---|
91 | case BONUS_NONE: |
---|
92 | break; |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | void add_bonus(game *g, bonus *bo, int x, int y, int type) |
---|
98 | { |
---|
99 | int i; |
---|
100 | |
---|
101 | for(i = 0; i < BONUS; i++) |
---|
102 | { |
---|
103 | if(bo->type[i] == BONUS_NONE) |
---|
104 | { |
---|
105 | bo->type[i] = type; |
---|
106 | bo->x[i] = x; |
---|
107 | bo->y[i] = y; |
---|
108 | bo->n[i] = 0; |
---|
109 | break; |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|