-
Notifications
You must be signed in to change notification settings - Fork 0
/
maptest.c
76 lines (64 loc) · 1.46 KB
/
maptest.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
#include "engine.h"
#include "heatmap.h"
static heatmap *my_heatmap = NULL;
static void red_to_green(float f)
{
f = 1.0 - f;
if (f < 0) {
f = 0.0;
} else if(f > 1) {
f = 1.0;
}
if (f < .5) {
draw_color(255, 255 * 2 * f, 0, 255);
} else {
draw_color(255 - 255 * 2 * (f - .5), 255, 0, 255);
}
}
static void draw_map()
{
for (int i = 0; i <my_heatmap->length; ++i) {
int x = i % my_heatmap->width;
int y = i / my_heatmap->width;
if (my_heatmap->avoid[i]) {
draw_color(128, 128, 128, 255);
} else {
red_to_green(my_heatmap->data[i] / 15.0);
}
draw_fill_rect4(x * 10, y * 10, 10, 10);
}
}
static void maptest_init(void **data)
{
my_heatmap = heatmap_new(10, 10, 15);
heatmap_set(my_heatmap, 0,0,0);
for (int i = 3; i <= 7; ++i) {
heatmap_set_avoid(my_heatmap, i, 3, 1);
heatmap_set_avoid(my_heatmap, i, 7, 1);
heatmap_set_avoid(my_heatmap, 3, i, 1);
heatmap_set_avoid(my_heatmap, 7, i, 1);
}
heatmap_set_avoid(my_heatmap, 7, 7, 0);
heatmap_update(my_heatmap, 0, NULL);
}
static void maptest_update(void *data, float delta)
{
}
static void on_key_up(int key, void* data)
{
engine_quit();
}
void maptest_draw(void *data)
{
draw_color(0, 0, 0, 255);
clear_screen();
draw_color(0, 0, 255, 255);
draw_map();
}
static struct game_ctx ret = {
.game_init = maptest_init,
.game_update = maptest_update,
.game_draw = maptest_draw,
.game_on_key_up = on_key_up,
};
ENGINE_MAIN(&ret)