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 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 | |
---|
21 | caca_canvas_t *foo_sprite; |
---|
22 | caca_canvas_t *bar_sprite; |
---|
23 | caca_canvas_t *baz_sprite; |
---|
24 | |
---|
25 | void init_aliens(game *g, aliens *al) |
---|
26 | { |
---|
27 | int i; |
---|
28 | |
---|
29 | for(i = 0; i < ALIENS; i++) |
---|
30 | { |
---|
31 | al->type[i] = ALIEN_NONE; |
---|
32 | } |
---|
33 | |
---|
34 | foo_sprite = caca_create_canvas(0, 0); |
---|
35 | caca_import_file(foo_sprite, "data/foofight.txt", "utf8"); |
---|
36 | |
---|
37 | bar_sprite = caca_create_canvas(0, 0); |
---|
38 | caca_import_file(bar_sprite, "data/barfight.txt", "utf8"); |
---|
39 | |
---|
40 | baz_sprite = caca_create_canvas(0, 0); |
---|
41 | caca_import_file(baz_sprite, "data/bazfight.txt", "utf8"); |
---|
42 | } |
---|
43 | |
---|
44 | void draw_aliens(game *g, aliens *al) |
---|
45 | { |
---|
46 | int i; |
---|
47 | |
---|
48 | for(i = 0; i < ALIENS; i++) |
---|
49 | { |
---|
50 | switch(al->type[i]) |
---|
51 | { |
---|
52 | case ALIEN_FOO: |
---|
53 | caca_set_frame(foo_sprite, al->img[i] % 5); |
---|
54 | caca_blit(g->cv, al->x[i], al->y[i], foo_sprite, NULL); |
---|
55 | break; |
---|
56 | case ALIEN_BAR: |
---|
57 | caca_set_frame(bar_sprite, al->img[i] % 2); |
---|
58 | caca_blit(g->cv, al->x[i], al->y[i], bar_sprite, NULL); |
---|
59 | break; |
---|
60 | case ALIEN_BAZ: |
---|
61 | caca_set_frame(baz_sprite, al->img[i] % 4); |
---|
62 | caca_blit(g->cv, al->x[i], al->y[i], baz_sprite, NULL); |
---|
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], caca_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 | |
---|