1 | |
---|
2 | #include <stdlib.h> |
---|
3 | |
---|
4 | #include "common.h" |
---|
5 | |
---|
6 | static void draw_nuke( int x, int y, int frame ); |
---|
7 | static void draw_circle( int x, int y, int r ); |
---|
8 | |
---|
9 | void init_weapons( game *g, weapons *wp ) |
---|
10 | { |
---|
11 | int i; |
---|
12 | |
---|
13 | for( i = 0; i < WEAPONS; i++ ) |
---|
14 | { |
---|
15 | wp->x[i] = -1; |
---|
16 | wp->y[i] = -1; |
---|
17 | wp->v[i] = 0; |
---|
18 | wp->n[i] = 0; |
---|
19 | wp->type[i] = 0; |
---|
20 | } |
---|
21 | } |
---|
22 | |
---|
23 | void draw_weapons( game *g, weapons *wp ) |
---|
24 | { |
---|
25 | int i; |
---|
26 | |
---|
27 | for( i = 0; i < WEAPONS; i++ ) |
---|
28 | { |
---|
29 | if( wp->x[i] >= 0 ) |
---|
30 | { |
---|
31 | switch( wp->type[i] ) |
---|
32 | { |
---|
33 | case 2: |
---|
34 | draw_nuke( wp->x[i], wp->y[i], wp->n[i] ); |
---|
35 | break; |
---|
36 | case 1: |
---|
37 | default: |
---|
38 | GFX_COLOR( WHITE ); |
---|
39 | GFX_GOTO( wp->x[i], wp->y[i] ); |
---|
40 | GFX_WRITE( '|' ); |
---|
41 | GFX_COLOR( CYAN ); |
---|
42 | GFX_GOTO( wp->x[i], wp->y[i] + 1 ); |
---|
43 | GFX_WRITE( '|' ); |
---|
44 | break; |
---|
45 | } |
---|
46 | } |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | void update_weapons( game *g, weapons *wp ) |
---|
51 | { |
---|
52 | int i; |
---|
53 | |
---|
54 | for( i = 0; i < WEAPONS; i++ ) |
---|
55 | { |
---|
56 | if( wp->y[i] < 0 ) |
---|
57 | { |
---|
58 | wp->x[i] = -1; |
---|
59 | wp->y[i] = -1; |
---|
60 | } |
---|
61 | else |
---|
62 | { |
---|
63 | switch( wp->type[i] ) |
---|
64 | { |
---|
65 | case 2: |
---|
66 | wp->n[i]--; |
---|
67 | if( wp->n[i]-- < 0 ) |
---|
68 | { |
---|
69 | wp->y[i] = -1; |
---|
70 | } |
---|
71 | break; |
---|
72 | case 1: |
---|
73 | default: |
---|
74 | wp->y[i] += wp->v[i]; |
---|
75 | break; |
---|
76 | } |
---|
77 | |
---|
78 | /* Check collisions */ |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | void add_weapon( game *g, weapons *wp, int x, int y, int type ) |
---|
84 | { |
---|
85 | int i; |
---|
86 | |
---|
87 | for( i = 0; i < WEAPONS; i++ ) |
---|
88 | { |
---|
89 | if( wp->y[i] < 0 ) |
---|
90 | { |
---|
91 | wp->x[i] = x; |
---|
92 | wp->y[i] = y; |
---|
93 | wp->type[i] = type; |
---|
94 | wp->v[i] = -2; |
---|
95 | wp->n[i] = 30; |
---|
96 | break; |
---|
97 | } |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | static void draw_nuke( int x, int y, int frame ) |
---|
102 | { |
---|
103 | int r = (34 - frame) * (34 - frame) / 10; |
---|
104 | |
---|
105 | /* Lots of duplicate pixels, but we don't care */ |
---|
106 | GFX_COLOR( BLUE ); |
---|
107 | draw_circle( x, y, r++ ); |
---|
108 | GFX_COLOR( CYAN ); |
---|
109 | draw_circle( x, y, r++ ); |
---|
110 | GFX_COLOR( WHITE ); |
---|
111 | draw_circle( x, y, r++ ); |
---|
112 | draw_circle( x, y, r++ ); |
---|
113 | } |
---|
114 | |
---|
115 | static void draw_circle( int x, int y, int r ) |
---|
116 | { |
---|
117 | int test, dx, dy; |
---|
118 | |
---|
119 | /* Optimized Bresenham. Kick ass. */ |
---|
120 | for( test = 0, dx = 0, dy = r ; dx <= dy ; dx++ ) |
---|
121 | { |
---|
122 | GFX_WRITETO( x + dx, y + dy / 2, '#' ); |
---|
123 | GFX_WRITETO( x - dx, y + dy / 2, '#' ); |
---|
124 | GFX_WRITETO( x + dx, y - dy / 2, '#' ); |
---|
125 | GFX_WRITETO( x - dx, y - dy / 2, '#' ); |
---|
126 | |
---|
127 | GFX_WRITETO( x + dy, y + dx / 2, '#' ); |
---|
128 | GFX_WRITETO( x - dy, y + dx / 2, '#' ); |
---|
129 | GFX_WRITETO( x + dy, y - dx / 2, '#' ); |
---|
130 | GFX_WRITETO( x - dy, y - dx / 2, '#' ); |
---|
131 | |
---|
132 | test += test > 0 ? dx - dy-- : dx; |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|