Redone signal system completely...
This commit is contained in:
parent
756b6d1047
commit
02d8a2bd0d
@ -1,3 +1,5 @@
|
|||||||
|
#include "game.h"
|
||||||
|
#include "render.h"
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -5,6 +7,27 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
|
|
||||||
|
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_x = 0;
|
||||||
int camera_y = 0;
|
int camera_y = 0;
|
||||||
|
|
||||||
@ -117,6 +140,50 @@ void view_side_hud (void) {
|
|||||||
return;
|
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) {
|
/*static void dump_block (unsigned int * * * pixels, unsigned int * source, int index, int x, int y) {
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
#ifndef UMORNA_ENGINE
|
#ifndef UMORNA_ENGINE
|
||||||
#define UMORNA_ENGINE
|
#define UMORNA_ENGINE
|
||||||
|
|
||||||
#include "game.h"
|
|
||||||
#include "render.h"
|
|
||||||
|
|
||||||
extern int camera_x;
|
extern int camera_x;
|
||||||
extern int camera_y;
|
extern int camera_y;
|
||||||
|
|
||||||
@ -17,4 +14,10 @@ extern void view_map_overlay (void);
|
|||||||
|
|
||||||
extern void view_side_hud (void);
|
extern void view_side_hud (void);
|
||||||
|
|
||||||
|
extern void bind (int signal, void (* action) (void));
|
||||||
|
extern void unbind (int signal);
|
||||||
|
|
||||||
|
extern void engine_configure (void);
|
||||||
|
extern void engine_synchronize (void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,7 +18,6 @@ static void define_menu (int show) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int menu_count = 0;
|
int menu_count = 0;
|
||||||
|
|
||||||
int menu_items [menu_limit];
|
int menu_items [menu_limit];
|
||||||
int menu_show [menu_limit];
|
int menu_show [menu_limit];
|
||||||
|
|
||||||
|
@ -78,7 +78,6 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern int menu_count;
|
extern int menu_count;
|
||||||
|
|
||||||
extern int menu_items [menu_limit];
|
extern int menu_items [menu_limit];
|
||||||
extern int menu_show [menu_limit];
|
extern int menu_show [menu_limit];
|
||||||
|
|
||||||
|
@ -5,11 +5,12 @@
|
|||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
int main (void) {
|
int main (void) {
|
||||||
game_configure ();
|
game_configure ();
|
||||||
|
|
||||||
render_configure ();
|
render_configure ();
|
||||||
|
engine_configure ();
|
||||||
|
|
||||||
while (render_active != 0) {
|
while (render_active != 0) {
|
||||||
|
engine_synchronize ();
|
||||||
render_synchronize ();
|
render_synchronize ();
|
||||||
|
|
||||||
view_map (camera_x, camera_y);
|
view_map (camera_x, camera_y);
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "engine.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
float render_zoom = 2.0;
|
|
||||||
|
|
||||||
static Texture2D render_texture [render_texture_count];
|
static Texture2D render_texture [render_texture_count];
|
||||||
|
|
||||||
static Font font = { 0 };
|
static Font font = { 0 };
|
||||||
@ -16,14 +13,14 @@ static void render_clean_up (void) {
|
|||||||
CloseWindow ();
|
CloseWindow ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float render_zoom = 2.0;
|
||||||
|
int render_active = 0;
|
||||||
|
|
||||||
|
int signal = signal_none;
|
||||||
|
|
||||||
int render_width (void) { return (GetScreenWidth ()); }
|
int render_width (void) { return (GetScreenWidth ()); }
|
||||||
int render_height (void) { return (GetScreenHeight ()); }
|
int render_height (void) { return (GetScreenHeight ()); }
|
||||||
|
|
||||||
static void limit (int * pointer, int minimum, int maximum) {
|
|
||||||
if (* pointer < minimum) { * pointer = minimum; }
|
|
||||||
if (* pointer > maximum) { * pointer = maximum; }
|
|
||||||
}
|
|
||||||
|
|
||||||
void render_sprite (int sprite, int x, int y, int u, int v, int width, int height) {
|
void render_sprite (int sprite, int x, int y, int u, int v, int width, int height) {
|
||||||
Rectangle source, destination;
|
Rectangle source, destination;
|
||||||
|
|
||||||
@ -49,8 +46,6 @@ void render_string (char * string, int x, int y) {
|
|||||||
DrawTextPro (font, string, position, dump, 0.0, FONT_SIZE, 4, tint);
|
DrawTextPro (font, string, position, dump, 0.0, FONT_SIZE, 4, tint);
|
||||||
}
|
}
|
||||||
|
|
||||||
int render_active = 0;
|
|
||||||
|
|
||||||
static void render_exit (void) {
|
static void render_exit (void) {
|
||||||
render_active = 0;
|
render_active = 0;
|
||||||
}
|
}
|
||||||
@ -86,21 +81,24 @@ void render_configure (void) {
|
|||||||
void render_synchronize (void) {
|
void render_synchronize (void) {
|
||||||
Color background = { 0, 0, 0, 0 };
|
Color background = { 0, 0, 0, 0 };
|
||||||
|
|
||||||
if (IsKeyPressed (KEY_RIGHT)) { camera_x++; limit (& camera_x, 0, world_width - (render_width () / (int) (BASE_SIZE * render_zoom))); }
|
EndDrawing ();
|
||||||
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; }
|
|
||||||
|
|
||||||
if (WindowShouldClose ()) { render_active = 0; }
|
if (WindowShouldClose ()) { render_active = 0; }
|
||||||
|
|
||||||
/*if (IsKeyPressed (KEY_P)) { dump_world_screenshot (); }*/
|
signal = GetKeyPressed ();
|
||||||
|
|
||||||
EndDrawing ();
|
switch (signal) {
|
||||||
|
case KEY_UP: signal = signal_up; break;
|
||||||
|
case KEY_DOWN: signal = signal_down; break;
|
||||||
|
case KEY_LEFT: signal = signal_left; break;
|
||||||
|
case KEY_RIGHT: signal = signal_right; break;
|
||||||
|
case KEY_ESCAPE: signal = signal_escape; break;
|
||||||
|
case KEY_R: signal = signal_r; break;
|
||||||
|
case KEY_T: signal = signal_t; break;
|
||||||
|
case KEY_S: signal = signal_s; break;
|
||||||
|
case KEY_V: signal = signal_v; break;
|
||||||
|
default: signal = signal_none; break;
|
||||||
|
}
|
||||||
|
|
||||||
BeginDrawing ();
|
BeginDrawing ();
|
||||||
|
|
||||||
|
@ -11,9 +11,24 @@ enum {
|
|||||||
render_texture_count
|
render_texture_count
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
signal_none,
|
||||||
|
signal_up, signal_down, signal_left, signal_right, signal_escape, signal_tabulator, signal_return, signal_new_line,
|
||||||
|
signal_a, signal_b, signal_c, signal_d, signal_e, signal_f, signal_g, signal_h,
|
||||||
|
signal_i, signal_j, signal_k, signal_l, signal_m, signal_n, signal_o, signal_p,
|
||||||
|
signal_q, signal_r, signal_s, signal_t, signal_u, signal_v, signal_w, signal_x,
|
||||||
|
signal_y, signal_z, signal_0, signal_1, signal_2, signal_3, signal_4, signal_5,
|
||||||
|
signal_6, signal_7, signal_8, signal_9, signal_l_bracket, signal_r_bracket, signal_minus, signal_equal,
|
||||||
|
signal_slash, signal_backslash, signal_quote, signal_backquote, signal_space, signal_backspace, signal_dot, signal_comma,
|
||||||
|
signal_cite, signal_caps_lock,
|
||||||
|
signal_count
|
||||||
|
};
|
||||||
|
|
||||||
extern float render_zoom;
|
extern float render_zoom;
|
||||||
extern int render_active;
|
extern int render_active;
|
||||||
|
|
||||||
|
extern int signal;
|
||||||
|
|
||||||
extern int render_width (void);
|
extern int render_width (void);
|
||||||
extern int render_height (void);
|
extern int render_height (void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user