-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap_cross.c
114 lines (94 loc) · 1.97 KB
/
map_cross.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
#include <stdbool.h>
#include <glib.h>
#include <SDL.h>
#include <SDL_ttf.h>
#include "config.h"
#include "types.h"
#include "platform.h"
#include "protocol.h"
#include "world.h"
#include "map.h"
struct state
{
bool follow_y;
jint y;
};
static void update_player_pos(void *data);
static char *describe(void *data, GPtrArray *attribs)
{
struct state *state = data;
if (state->follow_y) g_ptr_array_add(attribs, "follow");
return "cross-section";
}
static bool update_alt(struct state *state, jint y)
{
if (y < 0)
y = 0;
else if (y >= CHUNK_YSIZE)
y = CHUNK_YSIZE - 1;
if (y != state->y)
{
state->y = y;
map_update_all();
return true;
}
return false;
}
static bool handle_key(void *data, SDL_KeyboardEvent *e)
{
struct state *state = data;
switch (e->keysym.unicode)
{
case 'f':
state->follow_y ^= true;
update_player_pos(data);
map_mode_changed();
return false;
}
switch (e->keysym.sym)
{
case SDLK_UP:
return update_alt(state, state->y + 1);
case SDLK_DOWN:
return update_alt(state, state->y - 1);
default:
return false;
}
}
static void update_player_pos(void *data)
{
struct state *state = data;
if (state->follow_y)
{
update_alt(state, player_pos.y);
map_repaint();
}
}
static void update_time(void *data)
{
return;
}
static jint mapped_y(void *data, struct chunk *c, unsigned char *b, jint bx, jint bz)
{
struct state *state = data;
return state->y;
}
static rgba_t block_color(void *data, struct chunk *c, unsigned char *b, jint bx, jint bz, jint y)
{
return block_colors[b[y]];
}
struct map_mode *map_init_cross_mode(void)
{
struct state *state = g_new(struct state, 1);
state->follow_y = true;
state->y = 0;
struct flat_mode flat_mode;
flat_mode.data = state;
flat_mode.describe = describe;
flat_mode.handle_key = handle_key;
flat_mode.update_player_pos = update_player_pos;
flat_mode.update_time = update_time;
flat_mode.mapped_y = mapped_y;
flat_mode.block_color = block_color;
return map_init_flat_mode(flat_mode);
}