54#include <allegro5/allegro.h>
55#include <allegro5/allegro_image.h>
56#include <allegro5/allegro_primitives.h>
57#include <allegro5/allegro_font.h>
58#include <allegro5/allegro_ttf.h>
91#define PLAYER_MOVE_SPEED 4.0f
92#define JUMP_VELOCITY 9.0f
93#define JUMP_GRAVITY 20.0f
94#define CAM_SMOOTHING 8.0f
95#define PLAYER_MAX_HEIGH_DIFF 1
100#define TERRAIN_SABLE 2
101#define TERRAIN_CHEMIN 3
102#define TERRAIN_TEMPLE3 4
103#define TERRAIN_TEMPLE4 5
104#define TERRAIN_PAILLE 6
105#define TERRAIN_ROCAILLE 7
109 "Water",
"Lava",
"Sand",
"Road",
"Temple Light",
"Temple Dark",
"Straw",
"Rock"};
113 "DATAS/tiles/eau_centre.bmp",
114 "DATAS/tiles/lave.bmp",
115 "DATAS/tiles/sable_centre.bmp",
116 "DATAS/tiles/chemin_centre.bmp",
117 "DATAS/tiles/temple3.bmp",
118 "DATAS/tiles/temple4.bmp",
119 "DATAS/tiles/paille.bmp",
120 "DATAS/tiles/rocaille.bmp"};
123#define NUM_PROJECTIONS ISO_NUM_PROJECTIONS
126#define NUM_MASKS ISO_NUM_MASKS
228#define MAP_FILE "iso_gui_map.isom"
236 if (fx < 0.0f) fx = 0.0f;
237 if (fy < 0.0f) fy = 0.0f;
238 if (fx > (
float)
MAP_W - 1e-4f) fx = (float)
MAP_W - 1e-4f;
239 if (fy > (
float)
MAP_H - 1e-4f) fy = (
float)
MAP_H - 1e-4f;
251 if (fx < 0.0f) fx = 0.0f;
252 if (fy < 0.0f) fy = 0.0f;
253 if (fx > (
float)
MAP_W - 1e-4f) fx = (float)
MAP_W - 1e-4f;
254 if (fy > (
float)
MAP_H - 1e-4f) fy = (
float)
MAP_H - 1e-4f;
256 int ix = (int)floorf(fx);
257 int iy = (int)floorf(fy);
266 float frac_x = fx - (float)ix;
267 float frac_y = fy - (float)iy;
270 int ix1 = (ix + 1 <
MAP_W) ? ix + 1 : ix;
271 int iy1 = (iy + 1 <
MAP_H) ? iy + 1 : iy;
277 float max_h = h00 + (float)max_climb;
278 if (h10 > max_h) h10 = max_h;
279 if (h01 > max_h) h01 = max_h;
280 if (h11 > max_h) h11 = max_h;
282 float top = h00 + (h10 - h00) * frac_x;
283 float bot = h01 + (h11 - h01) * frac_x;
284 return top + (bot - top) * frac_y;
292 al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
293 float cy = sy - 8.0f * zoom;
300 float shadow_cx, shadow_cy;
302 al_draw_filled_ellipse(sx, shadow_cy, 4.0f * zoom, 2.0f * zoom,
303 al_map_rgba(0, 0, 0, 60));
306 al_draw_filled_circle(sx, cy, 5.0f * zoom,
307 al_map_rgba(50, 200, 50, (
unsigned char)(220.0f * alpha)));
308 al_draw_circle(sx, cy, 5.0f * zoom,
309 al_map_rgba(255, 255, 255, (
unsigned char)(200.0f * alpha)), 1.5f);
315 al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
316 float cy = sy - 8.0f * zoom;
319 al_draw_filled_circle(sx, cy, 5.0f * zoom,
320 al_map_rgba(80, 120, 255, (
unsigned char)(220.0f * alpha)));
321 al_draw_circle(sx, cy, 5.0f * zoom,
322 al_map_rgba(200, 200, 255, (
unsigned char)(200.0f * alpha)), 1.5f);
324 al_draw_filled_ellipse(sx, cy + 8.0f * zoom, 4.0f * zoom, 2.0f * zoom,
325 al_map_rgba(0, 0, 0, 60));
331 al_draw_circle(tcx, tcy, 5.0f * zoom, al_map_rgba(255, 80, 80, 180), 1.5f);
332 al_draw_filled_ellipse(tcx, tcy + 8.0f * zoom, 4.0f * zoom, 2.0f * zoom,
333 al_map_rgba(255, 0, 0, 30));
339 srand((
unsigned)time(NULL));
341 for (
int y = 0; y <
MAP_H; y++)
342 for (
int x = 0; x <
MAP_W; x++) {
347 for (
int patch = 0; patch < 15; patch++) {
349 int cx = rand() %
MAP_W;
350 int cy = rand() %
MAP_H;
351 int radius = 2 + rand() % 4;
352 for (
int dy = -radius; dy <= radius; dy++)
353 for (
int dx = -radius; dx <= radius; dx++) {
354 int x = cx + dx, y = cy + dy;
355 if (x < 0 || x >=
MAP_W || y < 0 || y >=
MAP_H)
continue;
356 float dist = sqrtf((
float)(dx * dx + dy * dy));
357 if (dist <= radius && (rand() % 100) < (
int)(100.0f * (1.0f - dist / (
float)(radius + 1))))
362 for (
int hill = 0; hill < 8; hill++) {
364 int cx = rand() %
MAP_W;
365 int cy = rand() %
MAP_H;
366 int radius = 2 + rand() % 3;
367 for (
int dy = -radius; dy <= radius; dy++)
368 for (
int dx = -radius; dx <= radius; dx++) {
369 int x = cx + dx, y = cy + dy;
370 if (x < 0 || x >=
MAP_W || y < 0 || y >=
MAP_H)
continue;
371 float dist = sqrtf((
float)(dx * dx + dy * dy));
372 if (dist > radius)
continue;
373 int h = (int)((
float)peak_h * (1.0f - dist / (float)(radius + 1)) + 0.5f);
393 for (
int y = 0; y <
MAP_H; y++)
394 for (
int x = 0; x <
MAP_W; x++) {
396 if (h > drop_max_h) drop_max_h = h;
444 for (
int y = 0; y <
MAP_H; y++)
445 for (
int x = 0; x <
MAP_W; x++) {
447 if (h > ghost_max_h) ghost_max_h = h;
481int main(
int argc,
char* argv[]) {
488 n_abort(
"Could not init Allegro.\n");
490 if (!al_init_image_addon()) {
493 if (!al_init_primitives_addon()) {
496 if (!al_init_font_addon()) {
500 al_install_keyboard();
503 al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE);
506 n_abort(
"Unable to create display\n");
508 al_set_window_title(
display,
"Nilorea Isometric Engine + GUI Demo");
510 ALLEGRO_FONT* font = al_create_builtin_font();
512 n_abort(
"Unable to create builtin font\n");
518 n_abort(
"Failed to create ISO_MAP!\n");
527 n_abort(
"Failed to create camera!\n");
556 10, 185, 150, 20, 0.0, (
double)
MAX_HEIGHT, 0.0,
603 10, 23, 180, 66, NULL, NULL);
612 10, 111, 180, 66, NULL, NULL);
627 10, 243, 180, 20, 0.01, 2.0, 0.2,
633 10, 287, 180, 20, 0.01, 5.0, 0.5,
640 int saved_bmp_flags = al_get_new_bitmap_flags();
641 al_set_new_bitmap_flags(saved_bmp_flags & ~(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR));
660 al_set_new_bitmap_flags(saved_bmp_flags);
666 for (
int y = 0; y <
MAP_H && y < loaded->
height; y++)
667 for (
int x = 0; x <
MAP_W && x < loaded->
width; x++) {
680 float sx_center, sy_center;
693 ALLEGRO_TIMER* timer = al_create_timer(1.0 /
FPS);
694 ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
695 al_register_event_source(queue, al_get_display_event_source(
display));
696 al_register_event_source(queue, al_get_timer_event_source(timer));
697 al_register_event_source(queue, al_get_keyboard_event_source());
698 al_register_event_source(queue, al_get_mouse_event_source());
700 al_start_timer(timer);
702 bool key_up =
false, key_down =
false, key_left =
false, key_right =
false;
703 bool key_space =
false;
704 float scroll_speed = 4.0f;
705 float dt = 1.0f / (float)
FPS;
717 al_wait_for_event(queue, &ev);
726 case ALLEGRO_EVENT_TIMER: {
734 float target_fx, target_fy;
745 float path_dist = sqrtf(path_dx * path_dx + path_dy * path_dy);
747 if (path_dist <= step) {
758 player_fx += (path_dx / path_dist) * step;
759 player_fy += (path_dy / path_dist) * step;
767 float move_dx = 0.0f, move_dy = 0.0f;
768 if (key_up) move_dy -= 1.0f;
769 if (key_down) move_dy += 1.0f;
770 if (key_left) move_dx -= 1.0f;
771 if (key_right) move_dx += 1.0f;
773 if (move_dx != 0.0f && move_dy != 0.0f) {
774 move_dx *= 0.70710678f;
775 move_dy *= 0.70710678f;
805 if (move_dx != 0.0f || move_dy != 0.0f) {
807 float new_fx =
player_fx + move_dx * speed;
808 float new_fy =
player_fy + move_dy * speed;
810 if (new_fx < 0.1f) new_fx = 0.1f;
811 if (new_fx > (
float)
MAP_W - 0.1f) new_fx = (float)
MAP_W - 0.1f;
812 if (new_fy < 0.1f) new_fy = 0.1f;
813 if (new_fy > (
float)
MAP_H - 0.1f) new_fy = (
float)
MAP_H - 0.1f;
815 int new_tile_x = (int)floorf(new_fx);
816 int new_tile_y = (int)floorf(new_fy);
818 bool can_move =
true;
820 if (new_tile_x >= 0 && new_tile_x <
MAP_W &&
821 new_tile_y >= 0 && new_tile_y <
MAP_H) {
828 if ((
float)target_h >
player_z + 0.5f)
843 float slide_fx =
player_fx + move_dx * speed;
844 if (slide_fx < 0.1f) slide_fx = 0.1f;
845 if (slide_fx > (
float)
MAP_W - 0.1f) slide_fx = (float)
MAP_W - 0.1f;
846 int slide_tx = (int)floorf(slide_fx);
849 if (slide_tx >= 0 && slide_tx <
MAP_W) {
855 if ((
float)th >
player_z + 0.5f) can_x =
false;
866 float slide_fy =
player_fy + move_dy * speed;
867 if (slide_fy < 0.1f) slide_fy = 0.1f;
868 if (slide_fy > (
float)
MAP_H - 0.1f) slide_fy = (float)
MAP_H - 0.1f;
869 int slide_ty = (int)floorf(slide_fy);
872 if (slide_ty >= 0 && slide_ty <
MAP_H) {
878 if ((
float)th >
player_z + 0.5f) can_y =
false;
918 float sdx = 0.0f, sdy = 0.0f;
919 if (key_left) sdx += scroll_speed /
camera->
zoom;
920 if (key_right) sdx -= scroll_speed /
camera->
zoom;
921 if (key_up) sdy += scroll_speed /
camera->
zoom;
922 if (key_down) sdy -= scroll_speed /
camera->
zoom;
923 if (sdx != 0.0f || sdy != 0.0f)
929 double now = al_get_time();
992 for (
int y = 0; y <
MAP_H; y++)
993 for (
int x = 0; x <
MAP_W; x++) {
995 if (h > drop_max_h) drop_max_h = h;
1020 int ghost_max_h = 0;
1021 for (
int y = 0; y <
MAP_H; y++)
1022 for (
int x = 0; x <
MAP_W; x++) {
1024 if (h > ghost_max_h) ghost_max_h = h;
1091 snprintf(hbuf,
sizeof(hbuf),
"Height: %d",
paint_height);
1138 case ALLEGRO_EVENT_KEY_DOWN:
1139 switch (ev.keyboard.keycode) {
1141 case ALLEGRO_KEY_LEFT:
1145 case ALLEGRO_KEY_RIGHT:
1149 case ALLEGRO_KEY_UP:
1153 case ALLEGRO_KEY_DOWN:
1157 case ALLEGRO_KEY_SPACE:
1160 case ALLEGRO_KEY_ESCAPE:
1163 case ALLEGRO_KEY_PGDN:
1167 case ALLEGRO_KEY_PGUP:
1171 case ALLEGRO_KEY_EQUALS:
1172 case ALLEGRO_KEY_PAD_PLUS:
1175 case ALLEGRO_KEY_MINUS:
1176 case ALLEGRO_KEY_PAD_MINUS:
1193 case ALLEGRO_KEY_COMMA:
1198 case ALLEGRO_KEY_FULLSTOP:
1208 case ALLEGRO_EVENT_KEY_UP:
1209 switch (ev.keyboard.keycode) {
1210 case ALLEGRO_KEY_LEFT:
1214 case ALLEGRO_KEY_RIGHT:
1218 case ALLEGRO_KEY_UP:
1222 case ALLEGRO_KEY_DOWN:
1226 case ALLEGRO_KEY_SPACE:
1232 case ALLEGRO_EVENT_MOUSE_AXES:
1237 (
float)ev.mouse.
x, (
float)ev.mouse.y);
1241 case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
1245 (
float)ev.mouse.y, &wx, &wy);
1247 float click_fx = 0.0f, click_fy = 0.0f;
1249 &map_x, &map_y, &click_fx, &click_fy);
1250 if (map_x >= 0 && map_x < MAP_W && map_y >= 0 && map_y <
MAP_H) {
1259 int dest_x = map_x, dest_y = map_y;
1263 for (
int ring = 1; ring <= MAX(
MAP_W,
MAP_H) && !found; ring++) {
1264 for (
int ry = -ring; ry <= ring && !found; ry++)
1265 for (
int rx = -ring; rx <= ring && !found; rx++) {
1266 if (abs(rx) != ring && abs(ry) != ring)
continue;
1267 int nx = map_x + rx, ny = map_y + ry;
1268 if (nx >= 0 && nx < MAP_W && ny >= 0 && ny <
MAP_H &&
1289 if (final_tx == map_x && final_ty == map_y) {
1321 case ALLEGRO_EVENT_DISPLAY_CLOSE:
1325 case ALLEGRO_EVENT_DISPLAY_RESIZE:
1326 al_acknowledge_resize(
display);
1336 al_set_target_backbuffer(
display);
1337 al_clear_to_color(al_map_rgb(20, 25, 30));
1348 int iso_num_objects = 0;
1357 iso_objects[iso_num_objects].
user_data = NULL;
1366 iso_objects[iso_num_objects].
fx = (float)dr_pos.
x;
1367 iso_objects[iso_num_objects].
fy = (float)dr_pos.
y;
1368 iso_objects[iso_num_objects].
fz = dr_h;
1372 iso_objects[iso_num_objects].
user_data = NULL;
1387 iso_num_objects > 0 ? iso_objects : NULL,
1396 snprintf(sbuf,
sizeof(sbuf),
"Pos:(%.1f,%.1f) Z:%.1f GndH:%.1f %s | Zoom:%.1fx",
1400 snprintf(sbuf,
sizeof(sbuf),
"Paint height:%d | Zoom:%.1fx | Slope max:%d",
1403 snprintf(sbuf,
sizeof(sbuf),
"Brush:[%s] | Zoom:%.1fx | Slope max:%d",
1408 snprintf(sbuf,
sizeof(sbuf),
"Proj: %s (%.1f deg)",
1413 snprintf(sbuf,
sizeof(sbuf),
"Hover: (%d,%d) H:%d T:%s",
1446 al_destroy_font(font);
1447 al_destroy_timer(timer);
1448 al_destroy_event_queue(queue);
1451 return EXIT_SUCCESS;
ALLEGRO_DISPLAY * display
void on_grid_toggle(int widget_id, void *user_data)
void on_player_toggle(int widget_id, void *user_data)
void on_smooth_toggle(int widget_id, void *user_data)
void on_ghost_toggle(int widget_id, void *user_data)
void on_proj_select(int widget_id, void *user_data)
void on_height_toggle(int widget_id, void *user_data)
static float interpolate_height_at_clamped(float fx, float fy, int max_climb)
static int gui_btn_smooth
static void draw_ghost_object(float sx, float sy, float zoom, float alpha, void *user_data)
static float ghost_path_angle
static int player_path_idx
static ASTAR_PATH * player_path
static void on_reset_click(int id, void *data)
static int gui_sld_dr_blend_time
static ALLEGRO_BITMAP * transition_tiles[8][(16+16)]
static int gui_sld_dr_threshold
static double ghost_last_send
static int gui_sld_height
static float ghost_path_radius
static void draw_player_object(float sx, float sy, float zoom, float alpha, void *user_data)
static N_ISO_CAMERA * camera
static void randomize_map(void)
static int gui_sld_dr_interval
static float player_path_progress
static int gui_win_ghost_dr
static float player_click_fy
static int smooth_slope_max
static ALLEGRO_BITMAP * transition_masks[(16+16)]
static int gui_lbl_dr_threshold
static float player_screen_y
static float ghost_path_speed
static float player_screen_x
static float ghost_path_cy
static int gui_btn_player
static ALLEGRO_BITMAP * tile_bitmaps[8]
static bool redraw_needed
static const char * terrain_files[8]
static float ghost_screen_x
static int gui_lbl_dr_algo
static float ghost_true_y
static int gui_rad_dr_blend
static int gui_btn_height
static float ghost_path_cx
static float player_click_fx
#define PLAYER_MOVE_SPEED
#define PLAYER_MAX_HEIGH_DIFF
static int gui_lbl_dr_interval
static DR_ENTITY * ghost_dr
static float ghost_screen_y
static int gui_btn_proj[4]
static double ghost_send_interval
static float ghost_true_x
static const char * terrain_names[8]
static int gui_lbl_dr_blend_time
static int gui_lbl_dr_blend
static int gui_lbl_height
static int gui_rad_dr_algo
static float interpolate_height_at(float fx, float fy)
static int gui_lbl_status
static N_GUI_CTX * gui_ctx
static bool player_on_ground
ASTAR_NODE * nodes
array of path nodes from start to goal
int length
number of nodes in the path
ASTAR_PATH * n_astar_find_path(const ASTAR_GRID *grid, int sx, int sy, int sz, int gx, int gy, int gz, int diagonal, ASTAR_HEURISTIC heuristic)
Find a path using A* search.
uint8_t n_astar_grid_get_walkable(const ASTAR_GRID *grid, int x, int y, int z)
Get a cell's walkability.
#define ASTAR_ALLOW_DIAGONAL
Movement mode: 8-dir (2D) or 26-dir (3D)
void n_astar_grid_free(ASTAR_GRID *grid)
Free a grid and all its internal data.
void n_astar_path_free(ASTAR_PATH *path)
Free a path returned by n_astar_find_path.
@ ASTAR_HEURISTIC_CHEBYSHEV
max of axis deltas (optimal for 8-dir)
Grid structure holding walkability, costs, and dimensions.
The computed path result.
void n_abort(char const *format,...)
abort program with a text
DR_ALGO algo
Extrapolation algorithm.
double blend_time
Duration of convergence blend in seconds.
DR_BLEND blend_mode
Convergence blending mode.
double pos_threshold
Position error threshold for sending updates (distance)
void dr_entity_destroy(DR_ENTITY **entity_ptr)
Destroy a dead reckoning entity and set the pointer to NULL.
static DR_VEC3 dr_vec3(double x, double y, double z)
Create a DR_VEC3 from components.
void dr_entity_set_threshold(DR_ENTITY *entity, double threshold)
Set the position error threshold for triggering network updates.
void dr_entity_compute(DR_ENTITY *entity, double time, DR_VEC3 *out_pos)
Compute the dead reckoned display position at a given time.
DR_ENTITY * dr_entity_create(DR_ALGO algo, DR_BLEND blend_mode, double pos_threshold, double blend_time)
Create a new dead reckoning entity.
void dr_entity_set_blend_time(DR_ENTITY *entity, double blend_time)
Set the convergence blend duration.
DR_BLEND
Dead reckoning convergence/blending mode.
void dr_entity_set_blend_mode(DR_ENTITY *entity, DR_BLEND blend_mode)
Set the convergence blending mode.
bool dr_entity_check_threshold(const DR_ENTITY *entity, const DR_VEC3 *true_pos, const DR_VEC3 *true_vel, const DR_VEC3 *true_acc, double time)
Check whether the owner's true state has diverged from the dead reckoned prediction beyond the config...
DR_ALGO
Dead reckoning extrapolation algorithm.
void dr_entity_set_algo(DR_ENTITY *entity, DR_ALGO algo)
Set the extrapolation algorithm.
void dr_entity_receive_state(DR_ENTITY *entity, const DR_VEC3 *pos, const DR_VEC3 *vel, const DR_VEC3 *acc, double time)
Receive a new authoritative state update from the network.
void dr_entity_set_position(DR_ENTITY *entity, const DR_VEC3 *pos, const DR_VEC3 *vel, const DR_VEC3 *acc, double time)
Force-set entity position without triggering convergence blending.
@ DR_BLEND_PVB
Projective Velocity Blending (recommended)
@ DR_ALGO_VEL_ACC
Velocity + acceleration: P(t) = P0 + V0*t + 0.5*A0*t^2.
Dead reckoned entity with extrapolation and convergence state.
3D vector used for position, velocity, and acceleration
void n_gui_set_display_size(N_GUI_CTX *ctx, float w, float h)
Set the display (viewport) size for global scrollbar computation.
int n_gui_button_is_toggled(N_GUI_CTX *ctx, int widget_id)
Check if a toggle button is currently in the "on" state.
#define N_GUI_ALIGN_LEFT
left aligned text
int n_gui_add_slider(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, double min_val, double max_val, double initial, int mode, void(*on_change)(int, double, void *), void *user_data)
Add a slider widget.
int n_gui_wants_mouse(N_GUI_CTX *ctx)
Check if the mouse is currently over any open GUI window.
int n_gui_radiolist_add_item(N_GUI_CTX *ctx, int widget_id, const char *text)
add an item to a radiolist widget
void n_gui_label_set_text(N_GUI_CTX *ctx, int widget_id, const char *text)
set the text of a label widget
int n_gui_add_listbox(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, int selection_mode, void(*on_select)(int, int, int, void *), void *user_data)
Add a listbox widget.
#define N_GUI_SLIDER_VALUE
slider uses raw start/end values
int n_gui_process_event(N_GUI_CTX *ctx, ALLEGRO_EVENT event)
Process an allegro event through the GUI system.
int n_gui_add_label(N_GUI_CTX *ctx, int window_id, const char *text, float x, float y, float w, float h, int align)
Add a static text label.
int n_gui_add_radiolist(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, void(*on_select)(int, int, void *), void *user_data)
Add a radio list widget (single selection with radio bullets)
void n_gui_close_window(N_GUI_CTX *ctx, int window_id)
Close (hide) a window.
void n_gui_listbox_set_selected(N_GUI_CTX *ctx, int widget_id, int index, int selected)
set the selection state of a listbox item
double n_gui_slider_get_value(N_GUI_CTX *ctx, int widget_id)
get the current value of a slider widget
int n_gui_listbox_add_item(N_GUI_CTX *ctx, int widget_id, const char *text)
add an item to a listbox widget
int n_gui_radiolist_get_selected(N_GUI_CTX *ctx, int widget_id)
get the selected item index in a radiolist widget
#define N_GUI_SELECT_SINGLE
single item selection
void n_gui_button_set_toggled(N_GUI_CTX *ctx, int widget_id, int toggled)
Set the toggle state of a button.
int n_gui_add_toggle_button(N_GUI_CTX *ctx, int window_id, const char *label, float x, float y, float w, float h, int shape, int initial_state, void(*on_click)(int, void *), void *user_data)
Add a toggle button widget (stays clicked/unclicked on single click)
int n_gui_listbox_get_selected(N_GUI_CTX *ctx, int widget_id)
get the index of the first selected item in a listbox
void n_gui_draw(N_GUI_CTX *ctx)
Draw all visible windows and their widgets.
void n_gui_button_set_keycode(N_GUI_CTX *ctx, int widget_id, int keycode, int modifiers)
Bind a keyboard key with optional modifier requirements to a button.
int n_gui_add_window(N_GUI_CTX *ctx, const char *title, float x, float y, float w, float h)
Add a new pseudo-window to the context.
N_GUI_CTX * n_gui_new_ctx(ALLEGRO_FONT *default_font)
Create a new GUI context.
void n_gui_destroy_ctx(N_GUI_CTX **ctx)
Destroy a GUI context and all its windows/widgets.
void n_gui_open_window(N_GUI_CTX *ctx, int window_id)
Open (show) a window.
void n_gui_slider_set_value(N_GUI_CTX *ctx, int widget_id, double value)
set the value of a slider widget
#define N_GUI_SHAPE_ROUNDED
rounded rectangle shape
void n_gui_radiolist_set_selected(N_GUI_CTX *ctx, int widget_id, int index)
set the selected item in a radiolist widget
void n_gui_set_widget_visible(N_GUI_CTX *ctx, int widget_id, int visible)
Show or hide a widget.
int n_gui_add_button(N_GUI_CTX *ctx, int window_id, const char *label, float x, float y, float w, float h, int shape, void(*on_click)(int, void *), void *user_data)
Add a button widget to a window.
The top-level GUI context that holds all windows.
float fz
height in map units (elevation)
float fy
fractional map Y position
int height
map height in tiles (Y axis)
float occluded_alpha
overlay alpha when behind tiles [0..1], 0=hidden, 0.35=ghost, 1=always visible
float tile_lift
vertical pixel offset per height unit
float angle_deg
current projection angle in degrees
int smooth_height
0 = CUT mode (cliff walls), 1 = SMOOTH mode (per-corner slopes)
int hover_mx
hovered tile X (-1 = none)
float fx
fractional map X position
void * user_data
user data passed to draw callback
N_ISO_OBJECT_DRAW_FN draw
draw callback
float zoom
zoom factor (1.0 = no zoom)
int is_occluded
OUTPUT: set to 1 if behind tiles during last iso_map_draw() call.
float y
camera Y offset (world units, pre-zoom)
int width
map width in tiles (X axis)
int show_grid
1 = draw grid overlay
int smooth_slope_max
max height diff rendered as slope (default 1)
int hover_my
hovered tile Y (-1 = none)
float x
camera X offset (world units, pre-zoom)
ISO_PROJECTION proj
current projection parameters
void iso_map_set_height(ISO_MAP *map, int mx, int my, int h)
Set the height at a cell (clamped to [0, max_height])
ISO_MAP * iso_map_new(int width, int height, int num_terrains, int max_height)
Create a new height-aware isometric map.
void n_iso_camera_zoom(N_ISO_CAMERA *cam, float dz, float mouse_x, float mouse_y)
Zoom the camera toward a screen-space point.
void n_iso_camera_center_on(N_ISO_CAMERA *cam, float world_x, float world_y, int screen_w, int screen_h)
Center the camera so that a world point is at screen center.
int iso_map_save(const ISO_MAP *map, const char *filename)
Save ISO_MAP to a binary file.
void iso_map_lerp_projection(ISO_MAP *map, float dt)
Smoothly interpolate the projection angle toward the target.
void iso_mask_tile_to_diamond(ALLEGRO_BITMAP *bmp, int tile_w, int tile_h)
Mask a tile bitmap to the isometric diamond shape.
ISO_MAP * iso_map_load(const char *filename)
Load ISO_MAP from a binary file.
void n_iso_camera_free(N_ISO_CAMERA **cam)
Free a camera and set the pointer to NULL.
const char * iso_projection_name(int preset)
Get the display name for a projection preset.
void n_iso_camera_follow(N_ISO_CAMERA *cam, float target_x, float target_y, int screen_w, int screen_h, float smoothing, float dt)
Smoothly follow a world-space target.
int iso_map_get_terrain(const ISO_MAP *map, int mx, int my)
Get the terrain type at a cell.
void iso_map_draw(const ISO_MAP *map, ALLEGRO_BITMAP **tile_bitmaps, ALLEGRO_BITMAP ***transition_tiles, int num_masks, ALLEGRO_BITMAP **overlay_bitmaps, int num_overlay_tiles, float cam_px, float cam_py, float zoom, int screen_w, int screen_h, int player_mode, N_ISO_OBJECT *objects, int num_objects)
Draw the full ISO_MAP with segment-sorted rendering.
void iso_map_to_screen(const ISO_MAP *map, int mx, int my, int h, float *screen_x, float *screen_y)
Convert map tile coordinates to screen pixel coordinates.
void iso_map_set_projection(ISO_MAP *map, int preset, float tile_width)
Set projection parameters from a preset and tile width.
void n_iso_camera_screen_to_world(const N_ISO_CAMERA *cam, float sx, float sy, float *wx, float *wy)
Convert screen pixel coordinates to world coordinates.
void iso_map_to_screen_f(const ISO_MAP *map, float fmx, float fmy, float h, float *screen_x, float *screen_y)
Convert map coordinates to screen coordinates (float version).
void iso_map_free(ISO_MAP **map_ptr)
Free an ISO_MAP and set the pointer to NULL.
void iso_generate_transition_tiles(ALLEGRO_BITMAP ***tiles, ALLEGRO_BITMAP **masks, ALLEGRO_BITMAP **tile_bitmaps, int num_terrains, int tile_w, int tile_h)
Pre-composite transition tiles (terrain texture * alpha mask).
void iso_map_set_projection_target(ISO_MAP *map, int preset)
Set the target projection for smooth interpolation.
void iso_map_set_terrain(ISO_MAP *map, int mx, int my, int terrain)
Set the terrain type at a cell.
void iso_generate_transition_masks(ALLEGRO_BITMAP **masks, int tile_w, int tile_h)
Generate the 32 procedural transition alpha masks (16 edge + 16 corner).
int iso_map_get_height(const ISO_MAP *map, int mx, int my)
Get the height at a cell.
float iso_map_interpolate_height(const ISO_MAP *map, float fx, float fy)
Bilinear height interpolation at fractional map coordinates.
#define ISO_PROJ_CLASSIC
Projection ID: classic 2:1 isometric (~26.565 degree angle)
void n_iso_camera_world_to_screen(const N_ISO_CAMERA *cam, float wx, float wy, float *sx, float *sy)
Convert world coordinates to screen pixel coordinates.
void iso_screen_to_map_height_f(const ISO_MAP *map, float screen_x, float screen_y, int tile_w, int tile_h, int *mx, int *my, float *out_fx, float *out_fy)
Height-aware screen-to-map conversion returning fractional tile coordinates.
void iso_screen_to_map_height(const ISO_MAP *map, float screen_x, float screen_y, int tile_w, int tile_h, int *mx, int *my)
Height-aware screen-to-map conversion with diamond hit testing.
void n_iso_camera_scroll(N_ISO_CAMERA *cam, float dx, float dy)
Scroll the camera by (dx, dy) world units.
N_ISO_CAMERA * n_iso_camera_new(float zoom_min, float zoom_max)
Create a new 2D isometric camera.
Height-aware isometric map with terrain and height layers.
2D isometric camera for viewport management.
Drawable object for depth-sorted isometric rendering.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_INFO
informational
A* Pathfinding API for 2D and 3D grids.
Common headers and low-level functions & define.
Dead Reckoning API for latency hiding in networked games.
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.
Isometric/axonometric tile engine with height maps, terrain transitions, and A* pathfinding integrati...
List structures and definitions.
N_STR and string function declaration.