1 | /* |
---|
2 | * ttyvaders Textmode shoot'em up |
---|
3 | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: aliens.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 *foo_sprite; |
---|
30 | struct ee_sprite *bar_sprite; |
---|
31 | struct ee_sprite *baz_sprite; |
---|
32 | |
---|
33 | void init_aliens(game *g, aliens *al) |
---|
34 | { |
---|
35 | int i; |
---|
36 | |
---|
37 | for(i = 0; i < ALIENS; i++) |
---|
38 | { |
---|
39 | al->type[i] = ALIEN_NONE; |
---|
40 | } |
---|
41 | |
---|
42 | foo_sprite = ee_load_sprite("data/foo_fighter"); |
---|
43 | bar_sprite = ee_load_sprite("data/bar_fighter"); |
---|
44 | baz_sprite = ee_load_sprite("data/baz_fighter"); |
---|
45 | } |
---|
46 | |
---|
47 | void draw_aliens(game *g, aliens *al) |
---|
48 | { |
---|
49 | int i; |
---|
50 | |
---|
51 | for(i = 0; i < ALIENS; i++) |
---|
52 | { |
---|
53 | switch(al->type[i]) |
---|
54 | { |
---|
55 | case ALIEN_FOO: |
---|
56 | ee_draw_sprite(al->x[i], al->y[i], foo_sprite, al->img[i] % 8); |
---|
57 | break; |
---|
58 | case ALIEN_BAR: |
---|
59 | ee_draw_sprite(al->x[i], al->y[i], bar_sprite, al->img[i] % 2); |
---|
60 | break; |
---|
61 | case ALIEN_BAZ: |
---|
62 | ee_draw_sprite(al->x[i], al->y[i], baz_sprite, al->img[i] % 6); |
---|
63 | break; |
---|
64 | case ALIEN_NONE: |
---|
65 | break; |
---|
66 | } |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | void update_aliens(game *g, aliens *al) |
---|
71 | { |
---|
72 | int i; |
---|
73 | |
---|
74 | for(i = 0; i < ALIENS; i++) |
---|
75 | { |
---|
76 | /* If alien died, make it explode */ |
---|
77 | if(al->type[i] != ALIEN_NONE && al->life[i] < 0) |
---|
78 | { |
---|
79 | add_explosion(g, g->ex, al->x[i], al->y[i], 0, 0, EXPLOSION_MEDIUM); |
---|
80 | al->type[i] = ALIEN_NONE; |
---|
81 | add_bonus(g, g->bo, al->x[i], al->y[i], ee_rand(0,4) ? BONUS_GREEN : BONUS_LIFE); |
---|
82 | } |
---|
83 | |
---|
84 | /* Update coordinates */ |
---|
85 | switch(al->type[i]) |
---|
86 | { |
---|
87 | case ALIEN_FOO: |
---|
88 | case ALIEN_BAR: |
---|
89 | case ALIEN_BAZ: |
---|
90 | al->x[i] = ((al->x[i] + 5) % (g->w + 3)) - 3; |
---|
91 | al->y[i] = al->y[i] + (rand() % 8) / 7 - (rand() % 8) / 7; |
---|
92 | al->img[i] = al->img[i] + 1; |
---|
93 | |
---|
94 | /* Check bounds */ |
---|
95 | if(al->y[i] < 0 ) al->y[i] = 0; |
---|
96 | if(al->y[i] > g->w - 1 ) al->y[i] = g->w - 1; |
---|
97 | break; |
---|
98 | case ALIEN_NONE: |
---|
99 | break; |
---|
100 | } |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | void add_alien(game *g, aliens *al, int x, int y, int type) |
---|
105 | { |
---|
106 | int i; |
---|
107 | |
---|
108 | for(i = 0; i < ALIENS; i++) |
---|
109 | { |
---|
110 | if(al->type[i] == ALIEN_NONE) |
---|
111 | { |
---|
112 | al->type[i] = type; |
---|
113 | al->x[i] = x; |
---|
114 | al->y[i] = y; |
---|
115 | al->img[i] = 0; |
---|
116 | |
---|
117 | switch(al->type[i]) |
---|
118 | { |
---|
119 | case ALIEN_FOO: |
---|
120 | al->life[i] = 3; |
---|
121 | break; |
---|
122 | case ALIEN_BAR: |
---|
123 | al->life[i] = 3; |
---|
124 | break; |
---|
125 | case ALIEN_BAZ: |
---|
126 | al->life[i] = 3; |
---|
127 | break; |
---|
128 | case ALIEN_NONE: |
---|
129 | break; |
---|
130 | } |
---|
131 | |
---|
132 | break; |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|