-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.c
81 lines (63 loc) · 1.68 KB
/
map.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
#include "map.h"
#include <curses.h>
#include <ncurses.h>
#include <stdlib.h>
#include "draw.h"
#include "player.h"
#define token_paste(x, y) x##y
#define map_color_generate(base) init_pair(token_paste(base, _PAIR), token_paste(base, _COLOR), token_paste(base, _COLOR))
WINDOW *map_window;
void map_draw(int offset_y, int offset_x) {
window_rectangle_draw(map_window, 0, 0, MAP_HEIGHT, MAP_WIDTH, 'g', MAP_TILE_GRASS_PAIR);
for(int i = 0; i < MAP_COUNT; i+=1) {
window_rectangle_draw(
map_window,
MAP_MAP[i][0], //- offset_y, // y
MAP_MAP[i][1], //- offset_x, // x
MAP_MAP[i][2], // height
MAP_MAP[i][3], // width
MAP_MAP[i][4], // character
MAP_MAP[i][5] // pair
);
}
pnoutrefresh(
map_window,
offset_y,
offset_x,
0,
0,
screen_height - 1,
screen_width - 1
);
}
bool map_cant_move(int y, int x) {
unsigned char character = mvwinch(map_window, y, x);
for(int i = 0; i < MAP_COLLIDERS_COUNT; i++) {
if(character == MAP_COLLIDERS[i])
return true;
}
return false;
}
void map_camera_draw() {
int offset_y = 0;
int offset_x = 0;
int half_width = screen_width / 2;
int half_height = screen_height / 2;
if(player_y > half_height) {
offset_y = player_y - half_height;
}
if(player_x > half_width) {
offset_x = player_x - half_width;
}
map_draw(offset_y, offset_x);
}
void map_init() {
map_window = newpad(MAP_HEIGHT, MAP_WIDTH);
map_color_generate(MAP_TILE_PLAYER);
map_color_generate(MAP_TILE_GRASS);
map_color_generate(MAP_TILE_WATER);
map_color_generate(MAP_TILE_MOUNTAIN);
map_color_generate(MAP_TILE_ENEMY);
map_color_generate(MAP_COLOR_HEALTHBAR_RED);
map_color_generate(MAP_COLOR_HEALTHBAR_BLACK);
}