#include "game.h" #include "render.h" #include "engine.h" #include #include #include #include static void limit (int * pointer, int minimum, int maximum) { if (* pointer < minimum) { * pointer = minimum; } if (* pointer > maximum) { * pointer = maximum; } } static void idle_game (void) { return; } static void exit_game (void) { render_active = 0; } static void camera_move_right (void) { camera_x++; limit (& camera_x, 0, world_width - (render_width () / (int) (BASE_SIZE * render_zoom))); } static void camera_move_left (void) { camera_x--; limit (& camera_x, 0, world_width - (render_width () / (int) (BASE_SIZE * render_zoom))); } static void camera_move_down (void) { camera_y++; limit (& camera_y, 0, world_height - (render_height () / (int) (BASE_SIZE * render_zoom))); } static void camera_move_up (void) { camera_y--; limit (& camera_y, 0, world_height - (render_height () / (int) (BASE_SIZE * render_zoom))); } static void show_trait_menu (void) { menu_show [menu_traits] = menu_show [menu_traits] ? 0 : 1; } static void show_skill_menu (void) { menu_show [menu_skills] = menu_show [menu_skills] ? 0 : 1; } static void show_value_menu (void) { menu_show [menu_values] = menu_show [menu_values] ? 0 : 1; } static void show_resoo_menu (void) { menu_show [menu_resources] = menu_show [menu_resources] ? 0 : 1; } static void (* action_list [signal_count]) (void); int camera_x = 0; int camera_y = 0; void view_hud (int x, int y, int width, int height, int small, int alpha) { int i, j, u, v; u = width % ICON_SIZE; v = height % ICON_SIZE; width /= ICON_SIZE; height /= ICON_SIZE; if (alpha == 0) { for (i = 0; i < width - 1; ++i) { for (j = 0; j < height - 1; ++j) { render_sprite (neonui, x + i * ICON_SIZE + ICON_SIZE / 2, y + j * ICON_SIZE + ICON_SIZE / 2, 0, 0, ICON_SIZE, ICON_SIZE); } render_sprite (neonui, x + i * ICON_SIZE + ICON_SIZE / 2, y + height * ICON_SIZE + ICON_SIZE / 2, 0, 0, u, ICON_SIZE); } render_sprite (neonui, x + width * ICON_SIZE + ICON_SIZE / 2, y + height * ICON_SIZE + ICON_SIZE / 2, 0, 0, ICON_SIZE, v); } for (i = (small == 0) + 1; i < width - (small != 0); ++i) { render_sprite (neonui, x + (i - (small == 0)) * ICON_SIZE, y, 560, 0, ICON_SIZE, ICON_SIZE); render_sprite (neonui, x + (i - (small == 0)) * ICON_SIZE, y + ICON_SIZE * (height - 1) + v, 560, 0, ICON_SIZE, ICON_SIZE); } for (i = (small == 0) + 1; i < height - (small != 0); ++i) { render_sprite (neonui, x, y + (i - (small == 0)) * ICON_SIZE, 256, 128, ICON_SIZE, ICON_SIZE); render_sprite (neonui, x + ICON_SIZE * (width - 1) + u, y + (i - (small == 0)) * ICON_SIZE + v, 256, 128, ICON_SIZE, ICON_SIZE); } u += ICON_SIZE * (width - 2 * (small == 0) - 1); v += ICON_SIZE * (height - 2 * (small == 0) - 1); if (small == 0) { render_sprite (neonui, x, y, 288, 0, 3 * ICON_SIZE, 3 * ICON_SIZE); render_sprite (neonui, x + u, y, 384, 0, 3 * ICON_SIZE, 3 * ICON_SIZE); render_sprite (neonui, x, y + v, 288, 96, 3 * ICON_SIZE, 3 * ICON_SIZE); render_sprite (neonui, x + u, y + v, 384, 96, 3 * ICON_SIZE, 3 * ICON_SIZE); } else { render_sprite (neonui, x, y, 288, 192, ICON_SIZE, ICON_SIZE); render_sprite (neonui, x + u, y, 320, 192, ICON_SIZE, ICON_SIZE); render_sprite (neonui, x, y + v, 288, 224, ICON_SIZE, ICON_SIZE); render_sprite (neonui, x + u, y + v, 320, 224, ICON_SIZE, ICON_SIZE); } } void view_menu (int menu, int x, int y, int small, int align, int alpha) { int item, aligned_x, aligned_y, i, j; if (menu_show [menu] == 0) { return; } i = (int) strlen (menu_text [menu] [0]); j = menu_items [menu]; i += 2 * (small == 0) + 2; j += 2 * (small == 0) + 2; aligned_x = (align == 0) ? x : ((render_width () - ICON_SIZE * i) / 2); aligned_y = (align == 0) ? y : ((render_height () - ICON_SIZE * j) / 2); view_hud (aligned_x, aligned_y, i * ICON_SIZE, j * ICON_SIZE, small, alpha); aligned_x += ICON_SIZE + (small == 0) * ICON_SIZE; aligned_y += ICON_SIZE + (small == 0) * ICON_SIZE; for (item = 0; item < menu_items [menu]; ++item) { i = (menu_icon [menu] [item] / 10) * ICON_SIZE; j = (menu_icon [menu] [item] % 10) * ICON_SIZE; render_sprite (ui, aligned_x, aligned_y + item * ICON_SIZE, i, j, ICON_SIZE, ICON_SIZE); render_string (menu_text [menu] [item], aligned_x + ICON_SIZE, aligned_y + item * ICON_SIZE); } } void view_map (int offset_x, int offset_y) { int x, y, index; for (x = 0; (x < (render_width () - SIDE_SIZE) / (BASE_SIZE * render_zoom)) && (x < world_width); ++x) { for (y = 0; (y < render_height () / (BASE_SIZE * render_zoom)) && (y < world_height); ++y) { render_sprite (ashlands, (int) (x * BASE_SIZE * render_zoom), (int) (y * BASE_SIZE * render_zoom), 0, world [0] [(offset_x + x) * world_height + offset_y + y] * BASE_SIZE, BASE_SIZE, BASE_SIZE); } } (void)index; /*for (index = 0; index < world_model_limit; ++index) { if (world_model_x [0] [index] < offset_x) continue; if (world_model_y [0] [index] < offset_y) continue; if (world_model_x [0] [index] > (render_width () - SIDE_SIZE) / (BASE_SIZE * render_zoom)) continue; if (world_model_y [0] [index] > render_height () / (BASE_SIZE * render_zoom)) continue; x = (int) ((world_model_x [0] [index] - offset_x) * BASE_SIZE * render_zoom); y = (int) ((world_model_y [0] [index] - offset_y) * BASE_SIZE * render_zoom); render_sprite (model_1_1, x, y, 0, world_model [0] [index] * BASE_SIZE, BASE_SIZE, BASE_SIZE); }*/ } void view_map_overlay (void) { render_sprite (overui, ICON_SIZE, render_height () - 784 + ICON_SIZE, 0, 0, 1472, 784); } void view_side_hud (void) { return; } void bind (int signal_id, void (* action) (void)) { action_list [signal_id] = action; } void unbind (int signal_id) { action_list [signal_id] = idle_game; } void engine_configure (void) { int index; for (index = 0; index < signal_count; ++index) { unbind (index); } bind (signal_escape, exit_game); bind (signal_up, camera_move_up); bind (signal_down, camera_move_down); bind (signal_left, camera_move_left); bind (signal_right, camera_move_right); bind (signal_r, show_resoo_menu); bind (signal_t, show_trait_menu); bind (signal_s, show_skill_menu); bind (signal_v, show_value_menu); } void engine_synchronize (void) { /*if (IsKeyPressed (KEY_RIGHT)) { camera_x++; limit (& camera_x, 0, world_width - (render_width () / (int) (BASE_SIZE * render_zoom))); } if (IsKeyPressed (KEY_LEFT)) { camera_x--; limit (& camera_x, 0, world_width - (render_width () / (int) (BASE_SIZE * render_zoom))); } if (IsKeyPressed (KEY_DOWN)) { camera_y++; limit (& camera_y, 0, world_height - (render_height () / (int) (BASE_SIZE * render_zoom))); } if (IsKeyPressed (KEY_UP)) { camera_y--; limit (& camera_y, 0, world_height - (render_height () / (int) (BASE_SIZE * render_zoom))); } if (IsKeyPressed (KEY_T)) { menu_show [menu_traits] = menu_show [menu_traits] ? 0 : 1; } if (IsKeyPressed (KEY_S)) { menu_show [menu_skills] = menu_show [menu_skills] ? 0 : 1; } if (IsKeyPressed (KEY_V)) { menu_show [menu_values] = menu_show [menu_values] ? 0 : 1; } if (IsKeyPressed (KEY_R)) { menu_show [menu_resources] = menu_show [menu_resources] ? 0 : 1; }*/ action_list [signal] (); /*if (IsKeyPressed (KEY_P)) { dump_world_screenshot (); }*/ } /*static void dump_block (unsigned int * * * pixels, unsigned int * source, int index, int x, int y) { int i, j; for (i = 0; i < BASE_SIZE; ++i) { for (j = 0; j < BASE_SIZE; ++j) { pixels [x] [y] [i * BASE_SIZE + j] = source [index * BASE_SIZE * BASE_SIZE + i * BASE_SIZE + j]; } } } static void dump_world_screenshot (void) { unsigned int * * * screenshot; unsigned int * a; unsigned int map [28 * BASE_SIZE * 12 * BASE_SIZE]; int i, j, k; png_image input = { 0 }; png_image output = { 0 }; input.version = PNG_IMAGE_VERSION; png_image_begin_read_from_file (& input, "sprite/ashlands.png"); input.format = PNG_FORMAT_RGBA; png_image_finish_read (& input, NULL, map, 0, NULL); png_image_free (& input); a = calloc (CHAD_WORLD_SIZE * CHAD_WORLD_SIZE * BASE_SIZE * BASE_SIZE, sizeof (* a)); screenshot = calloc (CHAD_WORLD_SIZE, sizeof (* screenshot)); for (i = 0; i < CHAD_WORLD_SIZE; ++i) { screenshot [i] = calloc (CHAD_WORLD_SIZE, sizeof (* * screenshot)); for (j = 0; j < CHAD_WORLD_SIZE; ++j) { screenshot [i] [j] = calloc (BASE_SIZE * BASE_SIZE, sizeof (* * * screenshot)); } } for (i = 0; i < CHAD_WORLD_SIZE; ++i) { for (j = 0; j < CHAD_WORLD_SIZE; ++j) { dump_block (screenshot, map, world [0] [i] [j], i, j); } } for (i = 0; i < CHAD_WORLD_SIZE; ++i) { for (j = 0; j < CHAD_WORLD_SIZE; ++j) { for (k = 0; k < BASE_SIZE * BASE_SIZE; ++k) { a [(i * CHAD_WORLD_SIZE + j) * BASE_SIZE * BASE_SIZE + k] = screenshot [i] [j] [k]; } } } output.version = PNG_IMAGE_VERSION; output.format = PNG_FORMAT_RGBA; output.width = (unsigned int) (CHAD_WORLD_SIZE * BASE_SIZE); output.height = (unsigned int) (CHAD_WORLD_SIZE * BASE_SIZE); if (png_image_write_to_file (& output, "a.png", 0, a, 0, NULL) == 0) write (1, "\033[1;31mFailed to export render as PNG image!\033[0m\n", 49); png_image_free (& output); free (screenshot); free (a); }*/