From bc403da11b441aee651782ceac72314720fc228d Mon Sep 17 00:00:00 2001 From: xolatile Date: Fri, 22 Dec 2023 02:09:39 -0500 Subject: [PATCH] Added map scrolling and camera... --- source/engine.c | 14 ++++++++------ source/engine.h | 5 ++++- source/game.h | 2 ++ source/main.c | 33 +++++++++++++++++++++++++++------ 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/source/engine.c b/source/engine.c index 0e758b0..b4a7e7e 100644 --- a/source/engine.c +++ b/source/engine.c @@ -1,5 +1,8 @@ #include "engine.h" +int camera_x = 30; +int camera_y = 30; + void view_unit (int race, int unit, int x, int y) { int u, v, width, height; @@ -100,14 +103,13 @@ void view_neon_menu (int menu, int align, int x, int y) { } } -void view_map (void) { +void view_map (int offset_x, int offset_y) { int x, y; - for (x = 0; x < CHAD_WORLD_WIDTH; ++x) { - if (x * BASE_SIZE * render_zoom > render_width () - SIDE_SIZE) break; - - for (y = 0; y < CHAD_WORLD_HEIGHT; ++y) { - render_sprite (ashlands, (int) (x * BASE_SIZE * render_zoom), (int) (y * BASE_SIZE * render_zoom), 0, chad_world [0] [x] [y] * BASE_SIZE, BASE_SIZE, BASE_SIZE); + for (x = 0; x < (render_width () - SIDE_SIZE) / (BASE_SIZE * render_zoom); ++x) { + for (y = 0; y < render_height () / (BASE_SIZE * render_zoom); ++y) { + render_sprite (ashlands, (int) (x * BASE_SIZE * render_zoom), (int) (y * BASE_SIZE * render_zoom), 0, + chad_world [0] [offset_x + x] [offset_y + y] * BASE_SIZE, BASE_SIZE, BASE_SIZE); } } } diff --git a/source/engine.h b/source/engine.h index 460dded..d92b918 100644 --- a/source/engine.h +++ b/source/engine.h @@ -7,6 +7,9 @@ #include +extern int camera_x; +extern int camera_y; + extern void view_unit (int race, int unit, int x, int y); extern void view_menu (int menu, int align, int x, int y); @@ -15,7 +18,7 @@ extern void view_hud (int alpha, int width, int height, int x, int y); extern void view_neon_menu (int menu, int align, int x, int y); -extern void view_map (void); +extern void view_map (int offset_x, int offset_y); extern void view_base_1 (int index, int x, int y); extern void view_base_2 (int index, int x, int y); diff --git a/source/game.h b/source/game.h index b8683d6..14d4160 100644 --- a/source/game.h +++ b/source/game.h @@ -12,8 +12,10 @@ #define CHAD_UNIT_LIMIT (54) #define CHAD_HERO_LIMIT ( 1) #define CHAD_BLOCK_LIMIT (28) +#define CHAD_MODEL_LIMIT (72) #define CHAD_WORLD_LIMIT ( 1) +#define CHAD_WORLD_MODEL (120) #define CHAD_WORLD_WIDTH (120) #define CHAD_WORLD_HEIGHT ( 60) diff --git a/source/main.c b/source/main.c index 2aa2e19..183a3b3 100644 --- a/source/main.c +++ b/source/main.c @@ -3,6 +3,22 @@ #include "engine.h" #include "menu.h" +#include + +extern int snprintf (char *, unsigned long, const char *, ...); + +static void limit (int * pointer, int minimum, int maximum) { + if ((* pointer >= minimum) && (* pointer <= maximum)) { return; } + if (* pointer < minimum) { * pointer = minimum; } + if (* pointer > maximum) { * pointer = maximum; } +} + +static void debug (void) { + char string [64] = ""; + snprintf (string, 64, "%i -- %i", camera_x, camera_y); + render_string (string, 0, 0); +} + int main (void) { game_configure (); @@ -17,7 +33,7 @@ int main (void) { ClearBackground (tint); - view_map (); + view_map (camera_x, camera_y); view_base_1 (0, 32, 128); view_base_1 (1, 32, 512); @@ -31,14 +47,19 @@ int main (void) { view_unit (elf, i, 900 + 32 * i, 96); } */ - if (IsKeyPressed (KEY_RIGHT)) { menu_show [menu_traits] = menu_show [menu_traits] ? 0 : 1; } - if (IsKeyPressed (KEY_LEFT)) { menu_show [menu_skills] = menu_show [menu_skills] ? 0 : 1; } - if (IsKeyPressed (KEY_DOWN)) { menu_show [menu_values] = menu_show [menu_values] ? 0 : 1; } - if (IsKeyPressed (KEY_UP)) { menu_show [menu_resources] = menu_show [menu_resources] ? 0 : 1; } + if (IsKeyPressed (KEY_RIGHT)) { camera_x++; limit (& camera_x, 0, CHAD_WORLD_WIDTH * BASE_SIZE - render_width ()); } + if (IsKeyPressed (KEY_LEFT)) { camera_x--; limit (& camera_x, 0, CHAD_WORLD_WIDTH * BASE_SIZE - render_width ()); } + if (IsKeyPressed (KEY_DOWN)) { camera_y++; limit (& camera_y, 0, CHAD_WORLD_HEIGHT * BASE_SIZE - render_height ()); } + if (IsKeyPressed (KEY_UP)) { camera_y--; limit (& camera_y, 0, CHAD_WORLD_HEIGHT * BASE_SIZE - render_height ()); } + + 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; } view_hud (0, SIDE_SIZE, render_height (), render_width () - SIDE_SIZE, 0); view_hud (1, render_width () - SIDE_SIZE, render_height (), 0, 0); - +debug (); view_neon_menu (menu_resources, 1, 0, 0); view_neon_menu (menu_traits, 1, 0, 0);