From 0c731d21fc5dbf68cd795af883e1b2ed367db9d9 Mon Sep 17 00:00:00 2001 From: Tobin Date: Sat, 18 Apr 2026 22:57:15 -0400 Subject: [PATCH] idk if this is the way to do this but it moves! --- main.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 0778a11..c95d5e9 100644 --- a/main.c +++ b/main.c @@ -56,16 +56,34 @@ int is_held(char k) return 0; } +static int player_x = 100; +static int player_y = 100; +static float player_vx = 0.0; +static float player_vy = 0.0; +static float player_ax = 0.0; +static float player_ay = 0.0; + void key_down(char k) { add_keydown(k); printf("%c pressed!\n", k); + switch (k) + { + case 'a': player_ax = -1; break; + case 'd': player_ax = 1; break; + case 0x20: /*jump();*/ break; + } } void key_up(char k) { remove_keydown(k); printf("%c un-pressed\n", k); + switch (k) + { + case 'a': player_ax = 0; break; + case 'd': player_ax = 0; break; + } } static int mousex = 0; @@ -102,6 +120,32 @@ void process_input(void) else if (e->type == MOUSEUP) mouse_up(e->mouse_button); } +void erase_entity(/*struct entity*/) +{ + /* get sprite info, etc */ + /* FIXME */ + cat_fill(1, 0, player_x, player_y, 50, 50, 0, 0, 0); +} + +void draw_entity(/* struct entity */) +{ + /* get sprite info, etc */ + /* FIXME */ + cat_fill(1, 1, player_x, player_y, 50, 50, 115, 72, 6); +} + +void erase_entities(void) +{ + /* TODO more than just player entity */ + erase_entity(/*player*/); +} + +void draw_entities(void) +{ + /* TODO more than just player entity */ + draw_entity(/*player*/); +} + static long last_sec = 0; static long last_nsec = 0; @@ -116,17 +160,24 @@ void tick(void) else if ((t.tv_sec - last_sec) > 0) goto yes; else if ((t.tv_nsec - last_nsec) > NS_PER_TICK) goto yes; else return; + /* do a tick */ yes: last_sec = t.tv_sec; last_nsec = t.tv_nsec; /* code to run every tick goes here */ + erase_entities(); + player_vx += player_ax; + player_vy += player_ay; + player_x += (int)player_vx; + player_y += (int)player_vy; + draw_entities(); } void game_loop(void) { + cat_render(); process_input(); tick(); - cat_render(); } int main(int argc, char** argv) @@ -134,6 +185,7 @@ int main(int argc, char** argv) cat_init(); cat_create_window(1920, 1080); cat_play_wav("etc/example.wav"); + /* layer, visibility, x, y, width, height, r, g, b */ cat_fill(0, 1, 0, 0, screen_width - 1, screen_height - 1, 132, 155, 132); while (1) game_loop(); return 0;