removed testing code from game.c and player.h/player.c' (#4) merge cleanup-testing-code into main

Reviewed-on: #4
removed all testing code and assets, as well as cleanup and organization
pull/5/head
Sara 2023-05-11 17:52:39 +00:00
commit 664e4561a0
12 changed files with 29 additions and 140 deletions

View File

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

View File

@ -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;

View File

@ -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
}

View File

@ -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() {}

View File

@ -1,41 +0,0 @@
#include "player.h"
#include "layers.h"
#include "world.h"
#include "input.h"
#include "engine.h"
#include <SDL2/SDL_scancode.h>
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;
}

View File

@ -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 */

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.