/
graphics.c
122 lines (108 loc) · 3.07 KB
/
graphics.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <stdlib.h>
#include "config.h"
#include "objects.h"
#include "io.h"
#include "graphics.h"
int explosion_size;
void set_explosion_size(int n)
{
explosion_size = n;
}
void draw_explosion(struct explosion *e)
{
int i, j, oldx, oldy;
char c = ' ';
if (e->progress) {
oldx = e->x;
oldy = e->y;
for (j=0; j<30; j++) {
e->x = oldx;
e->y = oldy;
for (i=0; i<explosion_size; i++) {
switch (rand() % 4) {
case 0: e->x += 2; break;
case 1: e->x -= 2; break;
case 2: e->y++; break;
case 3: e->y--; break;
}
switch (rand() % 7) {
case 0: c='*'; break;
case 1: c='~'; break;
case 2: c='/'; break;
case 3: c='x'; break;
case 4:
case 5:
case 6: c=' '; break;
}
io_set_color(e->progress, (i*5) % e->progress, 0);
io_putc(e->x, e->y, c);
}
}
e->x = oldx;
e->y = oldy;
io_reset_color();
}
}
void draw_ship(struct player *p)
{
io_set_color((100 - p->health)*2, 55 + (p->health*2), 0);
io_puts(p->x, p->y, " -|\\");
io_puts(p->x, p->y+1, ">]]]]]>");
io_puts(p->x, p->y+2, " -|/");
io_reset_color();
}
void draw_enemy(struct enemy *e)
{
if (e->health) {
if ((int)e % 5) {
io_set_color(0x77, (int)(2.5 * e->health), 155 + (int)e % 100);
io_puts(e->x, e->y, "<<[[[\\");
io_puts(e->x, e->y+1, " (XXXX[");
io_puts(e->x, e->y+2, "<<[[[/");
} else {
io_set_color(155 + (int)e % 100, (int)(2.5 * e->health), 0x33);
io_puts(e->x, e->y, " /|- /");
io_puts(e->x, e->y+1, "<[[[[<");
io_puts(e->x, e->y+2, " \\|- \\");
}
io_reset_color();
}
}
void draw_bullet(struct bullet *b)
{
if (b->shot) {
io_putc(b->x+1, b->y+1, '=');
}
}
void draw_enemy_bullet(struct bullet *b)
{
if (b->shot) {
io_set_color(0xff, 0xff, 0x00);
io_puts(b->x+1, b->y, "~~");
io_puts(b->x+1, b->y+2, "~~");
io_reset_color();
}
}
void draw_background(unsigned int progress)
{
int x, y, paral, x_step, y_step;
x_step = X_MAX / STAR_BANNER_X_STARS;
if (x_step == 0) x_step = 1;
y_step = Y_MAX / STAR_BANNER_Y_STARS;
if (y_step == 0) y_step = 1;
for (paral=0; paral<STAR_BANNER_PARALAX; paral++) {
io_set_color(
(180 / STAR_BANNER_PARALAX) * (paral + 1),
(180 / STAR_BANNER_PARALAX) * (paral + 1),
(180 / STAR_BANNER_PARALAX) * (paral + 1));
for (y=0; y<Y_MAX/y_step; y++) {
for (x=0; x<X_MAX/x_step; x++) {
srand(progress/(STAR_BANNER_PARALAX-paral)+x+(Y_MAX*y));
if (! (rand() % (20*(paral+1)*(paral+1)))) {
io_putc(x*x_step, y*y_step, '.');
}
}
}
io_reset_color();
}
}