diff --git a/TODO.txt b/TODO.txt deleted file mode 100644 index 4c55b6f..0000000 --- a/TODO.txt +++ /dev/null @@ -1,19 +0,0 @@ -# TODOs - -[x] add nineslice drawcmd functions - [x] draw_* - [x] exec_* - -[ ] add text rendering - [x] loading fonts - [x] managing font style - [x] rendering fonts to surface to texture - [x] correctly scaling fonts - [ ] cache rendered text - -[ ] add imgui - [ ] ui windows - [ ] input fields - [ ] buttons - [ ] radios - [ ] multibox diff --git a/button.png b/button.png deleted file mode 100644 index 99c7158..0000000 Binary files a/button.png and /dev/null differ diff --git a/player.png b/player.png deleted file mode 100644 index 72cff48..0000000 Binary files a/player.png and /dev/null differ diff --git a/src/world.c b/src/corelib/world.c similarity index 100% rename from src/world.c rename to src/corelib/world.c diff --git a/src/world.h b/src/corelib/world.h similarity index 100% rename from src/world.h rename to src/corelib/world.h diff --git a/src/engine.c b/src/engine.c index bdf201a..d3b6e14 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1,4 +1,5 @@ #include "engine.h" +#include "world.h" #include "corelib/assets.h" #include "corelib/render.h" #include "corelib/input.h" @@ -47,7 +48,8 @@ int _engine_run() { .running = 1, }; - load_game(); + input_init(); + world_clear(); start_game(); timespec_get(&start_last_frame, TIME_UTC); @@ -58,10 +60,13 @@ int _engine_run() { if(next_time.tv_nsec < start_last_frame.tv_nsec) _delta_time = 0; start_last_frame = next_time; _handle_events(); + update_input(); _render_mode = 1; update_ui(); _render_mode = 0; + update_objects(); // update world objects update_game(); + draw_objects(); // draw world objects swap_buffer(); } return 0; diff --git a/src/engine.h b/src/engine.h index ada21c4..87bf672 100644 --- a/src/engine.h +++ b/src/engine.h @@ -9,11 +9,10 @@ extern float delta_time(); /* TO BE DEFINED IN GAME */ -extern void load_game(); -extern void game_exit(); extern void start_game(); extern void update_game(); extern void update_ui(); +extern void game_exit(); #ifdef __cplusplus } diff --git a/src/game.c b/src/game.c index c2feec3..95016d2 100644 --- a/src/game.c +++ b/src/game.c @@ -1,6 +1,5 @@ #include "engine.h" #include "world.h" -#include "player.h" #include "corelib/input.h" #include "corelib/render.h" #include "corelib/assets.h" @@ -8,83 +7,45 @@ #include "SDL2/SDL_mouse.h" #include "SDL2/SDL_scancode.h" -int dragging = 0; -int drawing = 0; -spritesheet_t world_sheet; - void on_quit_key(int down) { + // Q is pressed or released if(down) { + // stop running when Q is pressed g_context.running = 0; } } +void on_horizontal(int axis) { + // when A or D is pressed or released +} + +void on_vertical(int axis) { + // W or S is pressed or released +} + void on_click(int down) { - drawing = down; -} - -void on_erase(int down) { - drawing = -down; -} - -void on_drag_world(float dx, float dy) { - if(dragging) { - g_active_view.x -= dx * g_active_view.width; - g_active_view.y -= dy * g_active_view.width; - } -} - -void on_middle_mouse(int down) { - dragging = down; -} - -void on_debug_frame(int down) { - if(down) { - d_debug_next_frame = 1; - } -} - - -void on_button_zoom(int axis) { - if(axis != 0) { - g_active_view.width += axis; - } -} - -void on_scroll_zoom(float delta) { - g_active_view.width -= delta * 0.5f; -} - -void load_game() { - world_sheet = make_spritesheet("tileset.png", 189, 189); - - input_init(); - world_clear(); - add_key_listener(SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_Q, &on_quit_key); - add_key_listener(SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_TAB, &on_debug_frame); - add_key_listener(SDL_SCANCODE_MINUS, SDL_SCANCODE_EQUALS, &on_button_zoom); - add_mouse_button_listener(SDL_BUTTON_LMASK, &on_click); - add_mouse_button_listener(SDL_BUTTON_RMASK, &on_erase); - add_mouse_button_listener(SDL_BUTTON_MMASK, &on_middle_mouse); - add_mouse_listener(&on_drag_world); - add_scroll_listener(&on_scroll_zoom); - - create_player(); + // when the left mouse button is pressed down + // float mouse_x, mouse_y; + // mouse_world_position(&mouse_x, &mouse_y); } void start_game() { + // called when the game first run g_active_view.width = 21; + add_key_listener(SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_Q, &on_quit_key); + add_key_listener(SDL_SCANCODE_S, SDL_SCANCODE_W, &on_horizontal); + add_key_listener(SDL_SCANCODE_A, SDL_SCANCODE_D, &on_vertical); + add_mouse_button_listener(SDL_BUTTON_LMASK, &on_click); } void update_game() { - if(drawing == 1) { - drawing = 2; - } - update_objects(); - draw_objects(); + // called every frame, + // render calls made in this function will be in *world* space } void update_ui() { - update_input(); + // called every frame, + // render calls made in this function will be in *screen* space } void game_exit() {} diff --git a/src/player.c b/src/player.c deleted file mode 100644 index 4fada2e..0000000 --- a/src/player.c +++ /dev/null @@ -1,41 +0,0 @@ -#include "player.h" -#include "layers.h" -#include "world.h" -#include "input.h" -#include "engine.h" -#include - -float player_move_x = 0; -float player_move_y = 0; -float player_xv = 0; -float player_yv = 0; -object_t* player_instance = NULL; - -void player_update(object_t *object) { - float m = sqrtf(player_move_x*player_move_x + player_move_y*player_move_y); - if(m == FP_NAN) m = 1; - m = 1.f/m; - player_xv = player_move_x * 3.f * m, - player_yv = player_move_y * 3.f * m; - object->sprite.x += player_xv * delta_time(); - object->sprite.y += player_yv * delta_time(); -} - -object_t* create_player() { - player_instance = make_object(); - player_instance->evt_update = &player_update; - player_instance->sprite = make_sprite("player.png", 0, 0); - - add_key_listener(SDL_SCANCODE_A, SDL_SCANCODE_D, &player_axis_horizontal); - add_key_listener(SDL_SCANCODE_S, SDL_SCANCODE_W, &player_axis_vertical); - - return player_instance; -} - -void player_axis_horizontal(int axis) { - player_move_x = axis; -} - -void player_axis_vertical(int axis) { - player_move_y = -axis; -} diff --git a/src/player.h b/src/player.h deleted file mode 100644 index 3f116e9..0000000 --- a/src/player.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _player_h -#define _player_h - -struct object_t; - -extern float player_move_x, player_move_y, - player_xv, player_yv; -extern struct object_t* player_instance; - -void player_update(struct object_t* object); -struct object_t* create_player(); - -extern void player_axis_horizontal(int axis); -extern void player_axis_vertical(int axis); - -#endif /* _player_h */ diff --git a/tileset.png b/tileset.png deleted file mode 100644 index 9c774d9..0000000 Binary files a/tileset.png and /dev/null differ diff --git a/ui_font.otf b/ui_font.otf deleted file mode 100644 index 5e87de2..0000000 Binary files a/ui_font.otf and /dev/null differ