diff options
| author | realtradam <[email protected]> | 2023-06-05 04:41:51 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2023-06-05 04:41:51 -0400 |
| commit | d40893aa03f75d68c8770823b9eb96847dd16426 (patch) | |
| tree | 46ca8536378f7d14086609a95671166a0d0243be | |
| parent | 8d1a2e890f132175feae0c817b5f8c4848a81bf1 (diff) | |
| download | rodeo_sample_game-d40893aa03f75d68c8770823b9eb96847dd16426.tar.gz rodeo_sample_game-d40893aa03f75d68c8770823b9eb96847dd16426.zip | |
begin rewriting rodeo kit to avoid exposed pointers
| m--------- | external/RodeoKit | 0 | ||||
| -rw-r--r-- | external_assets/shell.html | 4 | ||||
| -rw-r--r-- | src/bullet.c | 56 | ||||
| -rw-r--r-- | src/bullet.h | 1 | ||||
| -rw-r--r-- | src/debug.c | 10 | ||||
| -rw-r--r-- | src/enemies.c | 109 | ||||
| -rw-r--r-- | src/input.h | 22 | ||||
| -rw-r--r-- | src/main.c | 58 | ||||
| -rw-r--r-- | src/menu.c | 70 | ||||
| -rw-r--r-- | src/player.c | 94 | ||||
| -rw-r--r-- | src/sprite.c | 8 | ||||
| -rw-r--r-- | src/sprite.h | 2 | ||||
| -rw-r--r-- | src/wall.c | 70 |
13 files changed, 255 insertions, 249 deletions
diff --git a/external/RodeoKit b/external/RodeoKit -Subproject 40a78e6865794db16988bf92a99f69c88c152c8 +Subproject 06a3fc95288b8301a3b872ec5b4e906240f76fe diff --git a/external_assets/shell.html b/external_assets/shell.html index ef4b569..55a7ff2 100644 --- a/external_assets/shell.html +++ b/external_assets/shell.html @@ -30,8 +30,8 @@ <link rel="shortcut icon" href="https://dev.catgirls.rodeo/assets/favicon-32x32.png"> <style> - body { margin: 0px; background-color: black; } - canvas.emscripten { border: 0px none; background-color: black; } + body { margin: 0px; background-color: black; width: 100%; } + canvas.emscripten { border: 0px none; background-color: black; width: inherit; } </style> <script type='text/javascript' src="https://cdn.jsdelivr.net/gh/eligrey/FileSaver.js/dist/FileSaver.min.js"> </script> <script type='text/javascript'> diff --git a/src/bullet.c b/src/bullet.c index 52f3778..c1a3f36 100644 --- a/src/bullet.c +++ b/src/bullet.c @@ -5,8 +5,8 @@ #include "wall.h" #include "rodeo/collision.h" -static rodeo_texture_2d_t bullet_texture; -static rodeo_audio_sound_t *pop_sound; +static rodeo_gfx_texture_2d_t bullet_texture; +static rodeo_audio_sound_t pop_sound; //static rodeo_collision_2d_world_t bullet_collision_world; static rodeo_collision_2d_world_t player_bullet_collision_world = {0}; static rodeo_collision_2d_world_t enemy_bullet_collision_world = {0}; @@ -15,14 +15,14 @@ static cvec_bullet_t bullets = {0}; void init_bullets(void) { - bullet_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/bullet.png")); + bullet_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/bullet.png")); pop_sound = rodeo_audio_sound_create_from_path(cstr_lit("assets/pop.wav")); } void deinit_bullets(void) { - rodeo_texture_2d_destroy(&bullet_texture); + rodeo_gfx_texture_2d_destroy(bullet_texture); rodeo_audio_sound_destroy(pop_sound); rodeo_collision_2d_world_destroy(&player_bullet_collision_world); rodeo_collision_2d_world_destroy(&enemy_bullet_collision_world); @@ -54,12 +54,14 @@ spawn_bullet( bullet.id = rodeo_collision_2d_world_item_create( bullet_world, (rodeo_collision_2d_world_item_t){ - .x = x, - .y = y, + .rect = { + .x = x, + .y = y, + .width = 25.0f, + .height = 25.0f + }, .dx = dx, .dy = dy, - .width = 25.0f, - .height = 25.0f } )->id; return cvec_bullet_t_push( @@ -73,13 +75,13 @@ move_bullets(void) { c_foreach(i, cvec_collision_2d_world_item, player_bullet_collision_world) { cvec_collision_2d_world_item_value *bullet = i.ref; - bullet->x += bullet->dx; - bullet->y += bullet->dy; + bullet->rect.x += bullet->dx; + bullet->rect.y += bullet->dy; } c_foreach(i, cvec_collision_2d_world_item, enemy_bullet_collision_world) { cvec_collision_2d_world_item_value *bullet = i.ref; - bullet->x += bullet->dx; - bullet->y += bullet->dy; + bullet->rect.x += bullet->dx; + bullet->rect.y += bullet->dy; } } @@ -103,41 +105,31 @@ draw_bullets(void) c_foreach(i, cvec_collision_2d_world_item, player_bullet_collision_world) { cvec_collision_2d_world_item_value *bullet = i.ref; bullet_t *bullet_obj = get_bullet_by_id(i.ref->id); - rodeo_texture_2d_draw( - &(rodeo_rectangle_t){ - .x = bullet->x, - .y = bullet->y, - .width = bullet->width, - .height = bullet->height, - }, - &(rodeo_rectangle_t){ + rodeo_gfx_texture_2d_draw( + bullet->rect, + (rodeo_rectangle_t){ .x = 0, .y = 0, .width = 25, .height = 25 }, - &bullet_obj->color, - &bullet_texture + bullet_obj->color, + bullet_texture ); } c_foreach(i, cvec_collision_2d_world_item, enemy_bullet_collision_world) { cvec_collision_2d_world_item_value *bullet = i.ref; bullet_t *bullet_obj = get_bullet_by_id(i.ref->id); - rodeo_texture_2d_draw( - &(rodeo_rectangle_t){ - .x = bullet->x, - .y = bullet->y, - .width = bullet->width, - .height = bullet->height, - }, - &(rodeo_rectangle_t){ + rodeo_gfx_texture_2d_draw( + bullet->rect, + (rodeo_rectangle_t){ .x = 0, .y = 0, .width = 25, .height = 25 }, - &bullet_obj->color, - &bullet_texture + bullet_obj->color, + bullet_texture ); } } diff --git a/src/bullet.h b/src/bullet.h index 027dd0c..bf34af6 100644 --- a/src/bullet.h +++ b/src/bullet.h @@ -1,7 +1,6 @@ #pragma once #include "rodeo.h" -#include "rodeo/collision.h" typedef struct diff --git a/src/debug.c b/src/debug.c index 0dddf54..d981c0f 100644 --- a/src/debug.c +++ b/src/debug.c @@ -17,7 +17,7 @@ void draw_debug_text(cstr renderer_name, float fps_display) 2, 2, " frame count: %"PRIu64" ", - rodeo_frame_count_get() + rodeo_gfx_frame_count_get() ); rodeo_debug_text_draw( @@ -47,4 +47,12 @@ void draw_debug_text(cstr renderer_name, float fps_display) " total count: %d ", get_ghost_count() + get_enemy_count() ); + + rodeo_debug_text_draw( + 2, + 7, + " res: %"PRIu16"x%"PRIu16" ", + rodeo_window_screen_width_get(), + rodeo_window_screen_height_get() + ); } diff --git a/src/enemies.c b/src/enemies.c index 596d6b3..69e23a8 100644 --- a/src/enemies.c +++ b/src/enemies.c @@ -7,10 +7,10 @@ static rodeo_collision_2d_world_t collision_enemies_world = {0}; static rodeo_collision_2d_world_t collision_ghosts_world = {0}; -//static rodeo_texture_2d_t hinotamatchi_texture; -//static rodeo_texture_2d_t amonghost_texture; -//static rodeo_texture_2d_t squid_texture; -static rodeo_texture_2d_t enemy_texture; +//static rodeo_gfx_texture_2d_t hinotamatchi_texture; +//static rodeo_gfx_texture_2d_t amonghost_texture; +//static rodeo_gfx_texture_2d_t squid_texture; +static rodeo_gfx_texture_2d_t enemy_texture; static cvec_enemy_t enemies = {0}; static cvec_enemy_t ghosts = {0}; static float spawn_cooldown = 0; @@ -22,10 +22,10 @@ init_enemies(void) { //collision_enemies_world = rodeo_collision_2d_world_create(); //enemies = cvec_enemy_t_init(); - //squid_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/squid.png")); - //hinotamatchi_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/hinotamatchi.png")); - //amonghost_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/amonghost.png")); - enemy_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/enemy_sheet.png")); + //squid_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/squid.png")); + //hinotamatchi_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/hinotamatchi.png")); + //amonghost_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/amonghost.png")); + enemy_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/enemy_sheet.png")); } void @@ -35,10 +35,10 @@ deinit_enemies(void) rodeo_collision_2d_world_destroy(&collision_ghosts_world); cvec_enemy_t_drop(&enemies); cvec_enemy_t_drop(&ghosts); - //rodeo_texture_2d_destroy(&hinotamatchi_texture); - //rodeo_texture_2d_destroy(&squid_texture); - //rodeo_texture_2d_destroy(&amonghost_texture); - rodeo_texture_2d_destroy(&enemy_texture); + //rodeo_gfx_texture_2d_destroy(&hinotamatchi_texture); + //rodeo_gfx_texture_2d_destroy(&squid_texture); + //rodeo_gfx_texture_2d_destroy(&amonghost_texture); + rodeo_gfx_texture_2d_destroy(enemy_texture); } void @@ -88,7 +88,10 @@ spawn_enemy(float x, float y) enemy_count++; } - rodeo_collision_2d_world_item_t collision = (rodeo_collision_2d_world_item_t){.x = x, .y = y, .width = 40, .height = 40}; + rodeo_collision_2d_world_item_t collision = (rodeo_collision_2d_world_item_t) + { + .rect = { .x = x, .y = y, .width = 40, .height = 40 } + }; world_id id = rodeo_collision_2d_world_item_create(collision_world, collision)->id; return cvec_enemy_t_push( @@ -126,7 +129,10 @@ spawn_ghost(float x, float y) enemy_count++; } - rodeo_collision_2d_world_item_t collision = (rodeo_collision_2d_world_item_t){.x = x, .y = y, .width = 40, .height = 40}; + rodeo_collision_2d_world_item_t collision = (rodeo_collision_2d_world_item_t) + { + .rect = { .x = x, .y = y, .width = 40, .height = 40 } + }; world_id id = rodeo_collision_2d_world_item_create(collision_world, collision)->id; return cvec_enemy_t_push( @@ -176,21 +182,16 @@ draw_enemy(cvec_collision_2d_world_item_value *enemy) break; } - rodeo_texture_2d_draw( - &(rodeo_rectangle_t){ - .x = enemy->x, - .y = enemy->y, - .width = enemy->width, - .height = enemy->height, - }, - &(rodeo_rectangle_t){ + rodeo_gfx_texture_2d_draw( + enemy->rect, + (rodeo_rectangle_t){ .x = 0 + (40 * (float)enemy_obj->weapon.type), .y = 0, .width = 40, .height = 40 }, - &color, - &enemy_texture + color, + enemy_texture ); } @@ -216,8 +217,8 @@ enemy_overlap_resolver( enemy_t *enemy_b = get_enemy_by_id(b->id); vec2 direction; glm_vec2_sub( - (vec2){b->x, b->y}, - (vec2){a->x, a->y}, + (vec2){b->rect.x, b->rect.y}, + (vec2){a->rect.x, a->rect.y}, direction ); glm_vec2_normalize(direction); @@ -245,9 +246,9 @@ move_enemies(void) { continue; } - enemy->x += enemy->dx * rodeo_frame_time_get() / (1000.0f/60.0f); + enemy->rect.x += enemy->dx * rodeo_gfx_frame_time_get() / (1000.0f/60.0f); enemy->dx = 0; - enemy->y += enemy->dy * rodeo_frame_time_get() / (1000.0f/60.0f); + enemy->rect.y += enemy->dy * rodeo_gfx_frame_time_get() / (1000.0f/60.0f); enemy->dy = 0; } c_foreach(i, cvec_enemy_t, ghosts) { @@ -256,9 +257,9 @@ move_enemies(void) { continue; } - enemy->x += enemy->dx * rodeo_frame_time_get() / (1000.0f/60.0f); + enemy->rect.x += enemy->dx * rodeo_gfx_frame_time_get() / (1000.0f/60.0f); enemy->dx = 0; - enemy->y += enemy->dy * rodeo_frame_time_get() / (1000.0f/60.0f); + enemy->rect.y += enemy->dy * rodeo_gfx_frame_time_get() / (1000.0f/60.0f); enemy->dy = 0; } } @@ -287,8 +288,8 @@ enemies_attempt_weapon_fire(void) cvec_collision_2d_world_item_value *enemy = rodeo_collision_2d_world_item_get_by_id(i.ref->id); vec2 dest; glm_vec2_sub( - (vec2){ player->x, player->y }, - (vec2){ enemy->x, enemy->y }, + (vec2){ player->rect.x, player->rect.y }, + (vec2){ enemy->rect.x, enemy->rect.y }, dest ); glm_vec2_normalize(dest); @@ -305,8 +306,8 @@ enemies_attempt_weapon_fire(void) glm_vec2_scale(dest, 1.0, dest); spawn_bullet( - enemy->x, - enemy->y, + enemy->rect.x, + enemy->rect.y, dest[0], dest[1], get_enemy_bullet_world(), @@ -320,7 +321,7 @@ enemies_attempt_weapon_fire(void) } else { - i.ref->weapon.cooldown -= rodeo_frame_time_get()/1000.0f; + i.ref->weapon.cooldown -= rodeo_gfx_frame_time_get()/1000.0f; } } break; @@ -334,8 +335,8 @@ enemies_attempt_weapon_fire(void) cvec_collision_2d_world_item_value *enemy = rodeo_collision_2d_world_item_get_by_id(i.ref->id); vec2 dest; glm_vec2_sub( - (vec2){ player->x, player->y }, - (vec2){ enemy->x, enemy->y }, + (vec2){ player->rect.x, player->rect.y }, + (vec2){ enemy->rect.x, enemy->rect.y }, dest ); glm_vec2_normalize(dest); @@ -380,8 +381,8 @@ enemies_attempt_weapon_fire(void) //glm_vec2_scale(dest, 1.0, dest); spawn_bullet( - enemy->x, - enemy->y, + enemy->rect.x, + enemy->rect.y, bullet1[0], bullet1[1], get_enemy_bullet_world(), @@ -393,8 +394,8 @@ enemies_attempt_weapon_fire(void) } ); spawn_bullet( - enemy->x, - enemy->y, + enemy->rect.x, + enemy->rect.y, bullet2[0], bullet2[1], get_enemy_bullet_world(), @@ -406,8 +407,8 @@ enemies_attempt_weapon_fire(void) } ); spawn_bullet( - enemy->x, - enemy->y, + enemy->rect.x, + enemy->rect.y, bullet3[0], bullet3[1], get_enemy_bullet_world(), @@ -419,8 +420,8 @@ enemies_attempt_weapon_fire(void) } ); spawn_bullet( - enemy->x, - enemy->y, + enemy->rect.x, + enemy->rect.y, bullet4[0], bullet4[1], get_enemy_bullet_world(), @@ -434,7 +435,7 @@ enemies_attempt_weapon_fire(void) } else { - i.ref->weapon.cooldown -= rodeo_frame_time_get()/1000.0f; + i.ref->weapon.cooldown -= rodeo_gfx_frame_time_get()/1000.0f; } } break; @@ -546,12 +547,12 @@ group_follow_target(rodeo_collision_2d_world_item_t *target) enemy->dy = direction[1]; */ vec2 source = { - enemy->x, - enemy->y + enemy->rect.x, + enemy->rect.y }; vec2 dest = { - target->x, - target->y + target->rect.x, + target->rect.y }; vec2 direction; glm_vec2_sub(dest, source, direction); @@ -572,9 +573,9 @@ random_enemy_create( { float spawn_coords[2]; cvec_collision_2d_world_item_value* p = get_player_position(); - float player_coords[2] = {p->x, p->y}; - float player_radius = p->height * 2 + 100; - for (int i = 0; i < 100; ++i) { + float player_coords[2] = {p->rect.x, p->rect.y}; + float player_radius = p->rect.height * 2 + 100; + for (int i = 0; i < 10; ++i) { spawn_coords[0] = (float)rodeo_random_double_get() * bounds.width + bounds.x; spawn_coords[1] = (float)rodeo_random_double_get() * bounds.height + bounds.y; float dist = glm_vec2_distance(spawn_coords, player_coords); @@ -592,7 +593,7 @@ attempt_random_enemy_spawn( rodeo_rectangle_t bounds ) { - spawn_cooldown -= rodeo_frame_time_get(); + spawn_cooldown -= rodeo_gfx_frame_time_get(); if (spawn_cooldown <= 0 && get_enemy_count() + get_ghost_count() <= 100) { // faster spawning for testing //spawn_cooldown += ((float)rodeo_random_double_get() * 15.0f) + 4.50f; diff --git a/src/input.h b/src/input.h index 4624d88..c5e96f1 100644 --- a/src/input.h +++ b/src/input.h @@ -4,17 +4,17 @@ typedef struct { - rodeo_input_scene_t *scene; - rodeo_input_scene_t *menu_scene; - rodeo_input_command_t *menu_accept; - rodeo_input_command_t *create; - rodeo_input_command_t *left; - rodeo_input_command_t *right; - rodeo_input_command_t *up; - rodeo_input_command_t *down; - rodeo_input_command_t *play_sound; - rodeo_input_command_t *play_sound2; - rodeo_input_command_t *play_sound3; + rodeo_input_scene_t scene; + rodeo_input_scene_t menu_scene; + rodeo_input_command_t menu_accept; + rodeo_input_command_t create; + rodeo_input_command_t left; + rodeo_input_command_t right; + rodeo_input_command_t up; + rodeo_input_command_t down; + rodeo_input_command_t play_sound; + rodeo_input_command_t play_sound2; + rodeo_input_command_t play_sound3; } scenes_and_commands_t; @@ -20,14 +20,14 @@ float fps_display; void main_loop(void) { - if(rodeo_frame_count_get() % 10 == 0) + if(rodeo_gfx_frame_count_get() % 10 == 0) { - fps_display = rodeo_frame_perSecond_get(); + fps_display = rodeo_gfx_frame_perSecond_get(); } - - mrodeo_frame_do() + mrodeo_gfx_frame_do() { + rodeo_input_poll(); if (get_player_hp() > 0 && get_menu_state() == menu_state_inactive) { // retrieve and apply player input @@ -75,40 +75,42 @@ main_loop(void) } draw_menu(); - /*draw_debug_text( - renderer_name, - fps_display - );*/ - } + draw_debug_text(renderer_name, fps_display); } -int + int main(void) { inputs_register_do() { mrodeo_window_do(window_height, window_width, cstr_lit("Bubbles, Behind")) { - renderer_name = rodeo_renderer_name_get(); - rodeo_frame_limit_set(60); - - game_systems_init_do() + mrodeo_gfx_do() { - // use to test manually spawning enemies - //spawn_enemy(400.0f,700.0f); - //spawn_enemy(900.0f,700.0f); - //spawn_enemy(400.0f,100.0f); - //spawn_enemy(900.0f,100.0f); - //for(int i = 0; i < 1500; ++i) - //{ - // float rng1 = ((float)rodeo_random_double_get() * 100) + 150; - // float rng2 = ((float)rodeo_random_double_get() * 100) + 150; - // spawn_ghost(rng1,rng2); - //} - rodeo_mainLoop_run( - main_loop - ); + mrodeo_audio_do(8) + { + renderer_name = rodeo_gfx_renderer_name_get(); + //rodeo_gfx_frame_limit_set(60); + + game_systems_init_do() + { + // use to test manually spawning enemies + //spawn_enemy(400.0f,700.0f); + //spawn_enemy(900.0f,700.0f); + //spawn_enemy(400.0f,100.0f); + //spawn_enemy(900.0f,100.0f); + //for(int i = 0; i < 1500; ++i) + //{ + // float rng1 = ((float)rodeo_random_double_get() * 100) + 150; + // float rng2 = ((float)rodeo_random_double_get() * 100) + 150; + // spawn_ghost(rng1,rng2); + //} + rodeo_mainLoop_run( + main_loop + ); + } + } } } } @@ -4,9 +4,9 @@ #include "player.h" #include "rodeo.h" -rodeo_texture_2d_t splash_texture; -rodeo_texture_2d_t main_menu_texture; -rodeo_texture_2d_t gameover_texture; +rodeo_gfx_texture_2d_t splash_texture; +rodeo_gfx_texture_2d_t main_menu_texture; +rodeo_gfx_texture_2d_t gameover_texture; menu_state_t menu_state; float splash_timer; rodeo_rectangle_t screen_dimensions = (rodeo_rectangle_t){.x = 0, .y = 0, .width = 1600, .height = 900}; @@ -14,9 +14,9 @@ rodeo_rectangle_t screen_dimensions = (rodeo_rectangle_t){.x = 0, .y = 0, .width void init_menu(void) { - splash_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/splash.png")); - main_menu_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/main_menu.png")); - gameover_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/restart_menu.png")); + splash_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/splash.png")); + main_menu_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/main_menu.png")); + gameover_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/restart_menu.png")); menu_state = menu_state_main; splash_timer = 3000.0f; @@ -26,9 +26,9 @@ init_menu(void) void deinit_menu(void) { - rodeo_texture_2d_destroy(&splash_texture); - rodeo_texture_2d_destroy(&main_menu_texture); - rodeo_texture_2d_destroy(&gameover_texture); + rodeo_gfx_texture_2d_destroy(splash_texture); + rodeo_gfx_texture_2d_destroy(main_menu_texture); + rodeo_gfx_texture_2d_destroy(gameover_texture); } void @@ -37,12 +37,12 @@ draw_menu(void) float transparency = 0.65f; if (splash_timer > 0 && menu_state == menu_state_splash) { - splash_timer -= rodeo_frame_time_get(); - rodeo_texture_2d_draw( - &screen_dimensions, - &screen_dimensions, - NULL, - &splash_texture + splash_timer -= rodeo_gfx_frame_time_get(); + rodeo_gfx_texture_2d_draw( + screen_dimensions, + screen_dimensions, + (rodeo_color_RGBAFloat_t){.array = {1,1,1,1}}, + splash_texture ); if (splash_timer <= 0) { menu_state = menu_state_main; @@ -51,32 +51,32 @@ draw_menu(void) else if (menu_state == menu_state_main) { - rodeo_texture_2d_draw( - &screen_dimensions, - &screen_dimensions, - &(rodeo_color_RGBAFloat_t){ .array = { 0,0,0,transparency }}, - NULL + rodeo_gfx_texture_2d_draw( + screen_dimensions, + screen_dimensions, + (rodeo_color_RGBAFloat_t){ .array = { 0,0,0,transparency }}, + (rodeo_gfx_texture_2d_t){0} ); - rodeo_texture_2d_draw( - &screen_dimensions, - &screen_dimensions, - NULL, - &main_menu_texture + rodeo_gfx_texture_2d_draw( + screen_dimensions, + screen_dimensions, + (rodeo_color_RGBAFloat_t){.array = {1,1,1,1}}, + main_menu_texture ); } else if (menu_state == menu_state_gameover) { - rodeo_texture_2d_draw( - &screen_dimensions, - &screen_dimensions, - &(rodeo_color_RGBAFloat_t){ .array = { 0,0,0,transparency }}, - NULL + rodeo_gfx_texture_2d_draw( + screen_dimensions, + screen_dimensions, + (rodeo_color_RGBAFloat_t){ .array = { 0,0,0,transparency }}, + (rodeo_gfx_texture_2d_t){0} ); - rodeo_texture_2d_draw( - &screen_dimensions, - &screen_dimensions, - NULL, - &gameover_texture + rodeo_gfx_texture_2d_draw( + screen_dimensions, + screen_dimensions, + (rodeo_color_RGBAFloat_t){.array = {1,1,1,1}}, + gameover_texture ); } } diff --git a/src/player.c b/src/player.c index f954319..8c4a855 100644 --- a/src/player.c +++ b/src/player.c @@ -14,10 +14,10 @@ struct player_t { sprite_t sprite; - rodeo_texture_2d_t texture; - rodeo_texture_2d_t shadow_texture; - rodeo_texture_2d_t aim_texture; - rodeo_texture_2d_t heart_texture; + rodeo_gfx_texture_2d_t texture; + rodeo_gfx_texture_2d_t shadow_texture; + rodeo_gfx_texture_2d_t aim_texture; + rodeo_gfx_texture_2d_t heart_texture; int32_t hp; float damage_timer; //ms float damage_cooldown_rate; @@ -33,7 +33,7 @@ struct player_t player = { 0 }; typedef struct player_t player_t; -static rodeo_audio_sound_t *bubbles_sound; +static rodeo_audio_sound_t bubbles_sound; // 0-19 jumping // 61 standing @@ -48,23 +48,25 @@ void init_player(void) { bubbles_sound = rodeo_audio_sound_create_from_path(cstr_lit("assets/blowing_bubbles.wav")); - player.texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/mainblob-128.png")); - player.shadow_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/blobshadow.png")); - player.aim_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/aim.png")); - player.heart_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/heart.png")); - player.sprite.config.texture = &player.texture; + player.texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/mainblob-128.png")); + player.shadow_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/blobshadow.png")); + player.aim_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/aim.png")); + player.heart_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/heart.png")); + player.sprite.config.texture = player.texture; //player_collision_world = rodeo_collision_2d_world_create(); player_collision_world = (rodeo_collision_2d_world_t){0}; player.collision_id = rodeo_collision_2d_world_item_create( &player_collision_world, (rodeo_collision_2d_world_item_t){ - .width = orc_size[0], - .height = orc_size[1] + .rect = { + .width = orc_size[0], + .height = orc_size[1] + } } )->id; player.sprite = (sprite_t){ .config = { - .texture = &player.texture, + .texture = player.texture, .width = 128, .height = 128, .count = 61 @@ -79,7 +81,7 @@ init_player(void) void deinit_player(void) { - rodeo_texture_2d_destroy(&player.texture); + rodeo_gfx_texture_2d_destroy(player.texture); rodeo_collision_2d_world_destroy(&player_collision_world); //player_collision_world = (rodeo_collision_2d_world_t){0}; rodeo_audio_sound_destroy(bubbles_sound); @@ -95,8 +97,8 @@ reset_player(void) cvec_collision_2d_world_item_value *player_position = get_player_position(); player_position->dx = 0; player_position->dy = 0; - player_position->x = 630.0f; - player_position->y = 263.0f; + player_position->rect.x = 630.0f; + player_position->rect.y = 263.0f; player.weapon.cooldown = 0; } @@ -104,28 +106,28 @@ void draw_player(void) { float transparency = 1.0f; - if(!(player.damage_timer >= player.damage_cooldown_rate || (rodeo_frame_count_get() % 8 < 4))) + if(!(player.damage_timer >= player.damage_cooldown_rate || (rodeo_gfx_frame_count_get() % 8 < 4))) { transparency = 0.33f; } cvec_collision_2d_world_item_value *player_position = rodeo_collision_2d_world_item_get_by_id(player.collision_id); const float scale = 0.25f; draw_aim(aim_position.x, aim_position.y, scale); - rodeo_texture_2d_draw( - &(rodeo_rectangle_t){ - .x = player_position->x,// - ((float)sprite->config.width * scale / 2), - .y = player_position->y + (96 * scale),// - ((float)sprite->config.height * scale / 2), + rodeo_gfx_texture_2d_draw( + (rodeo_rectangle_t){ + .x = player_position->rect.x,// - ((float)sprite->config.width * scale / 2), + .y = player_position->rect.y + (96 * scale),// - ((float)sprite->config.height * scale / 2), .width = 128 * scale, .height = (13.0f / 30.0f * 128.0f) * scale, }, - &(rodeo_rectangle_t){ + (rodeo_rectangle_t){ .width = 30, .height = 13 }, - &(rodeo_color_RGBAFloat_t){ .array = { 1.0f, 1.0f, 1.0f, 1.0f } }, - &player.shadow_texture + (rodeo_color_RGBAFloat_t){ .array = { 1.0f, 1.0f, 1.0f, 1.0f } }, + player.shadow_texture ); - draw_sprite(&player.sprite, player_position->x, player_position->y, scale, (rodeo_color_RGBAFloat_t){ .array = {1,1,1,transparency} }); + draw_sprite(&player.sprite, player_position->rect.x, player_position->rect.y, scale, (rodeo_color_RGBAFloat_t){ .array = {1,1,1,transparency} }); } void @@ -139,11 +141,11 @@ draw_hp_bar(void) "%f\n", 10.0f + (40.0f * (float)i) );*/ - rodeo_texture_2d_draw( - &(rodeo_rectangle_t){ .x = 10.0f + (40.0f * (float)i), .y = 10, .width = 35, .height = 35 }, - &(rodeo_rectangle_t){ .x = 0, .y = 0, .width = 35, .height = 35 }, - NULL, - &player.heart_texture); + rodeo_gfx_texture_2d_draw( + (rodeo_rectangle_t){ .x = 10.0f + (40.0f * (float)i), .y = 10, .width = 35, .height = 35 }, + (rodeo_rectangle_t){ .x = 0, .y = 0, .width = 35, .height = 35 }, + (rodeo_color_RGBAFloat_t){.array = {1,1,1,1}}, + player.heart_texture); } } @@ -168,8 +170,8 @@ parse_player_input(void) { glm_vec2_normalize(inputs); } - player_position->dx = inputs[0] * (rodeo_frame_time_get() / (1000.0f/60.0f) * ((60.0f - (float)player.sprite.iter) / 60.0f)) * 7; - player_position->dy = inputs[1] * (rodeo_frame_time_get() / (1000.0f/60.0f) * ((60.0f - (float)player.sprite.iter) / 60.0f)) * 7; + player_position->dx = inputs[0] * (rodeo_gfx_frame_time_get() / (1000.0f/60.0f) * ((60.0f - (float)player.sprite.iter) / 60.0f)) * 7; + player_position->dy = inputs[1] * (rodeo_gfx_frame_time_get() / (1000.0f/60.0f) * ((60.0f - (float)player.sprite.iter) / 60.0f)) * 7; if(((inputs[0] != 0) || (inputs[1] != 0)) && player.move_state == mv_state_standing) { @@ -187,7 +189,7 @@ move_player(void) { if(player.move_state != mv_state_standing) { - player.sprite.iter += 1 * rodeo_frame_time_get() / (1000.0f/60.0f); + player.sprite.iter += 1 * rodeo_gfx_frame_time_get() / (1000.0f/60.0f); player.sprite.iter = fmodf(player.sprite.iter, (float)player.sprite.config.count); if(player.sprite.iter > 19) { @@ -204,9 +206,9 @@ move_player(void) } cvec_collision_2d_world_item_value *player_position = rodeo_collision_2d_world_item_get_by_id(player.collision_id); - player_position->x += player_position->dx; + player_position->rect.x += player_position->dx; player_position->dx = 0; - player_position->y += player_position->dy; + player_position->rect.y += player_position->dy; player_position->dy = 0; update_aim_position(); } @@ -217,7 +219,7 @@ player_shoot(rodeo_collision_2d_world_t *bullet_collision_world) if(player.weapon.cooldown > 0) { - player.weapon.cooldown -= rodeo_frame_time_get() / 1000; + player.weapon.cooldown -= rodeo_gfx_frame_time_get() / 1000; } if(player.move_state == mv_state_mid_air) { @@ -230,7 +232,7 @@ player_shoot(rodeo_collision_2d_world_t *bullet_collision_world) glm_vec2_sub( (vec2){aim_position.x, aim_position.y}, - (vec2){player_position->x, player_position->y}, + (vec2){player_position->rect.x, player_position->rect.y}, direction_vec ); glm_vec2_normalize(direction_vec); @@ -251,8 +253,8 @@ player_shoot(rodeo_collision_2d_world_t *bullet_collision_world) glm_vec2_scale(result_vec, 5.0f, result_vec); spawn_bullet( - (float)player_position->x + (orc_size[0] / 2.0f) - 9.0f, - (float)player_position->y + (orc_size[1] / 2.0f) - 16.0f, + (float)player_position->rect.x + (orc_size[0] / 2.0f) - 9.0f, + (float)player_position->rect.y + (orc_size[1] / 2.0f) - 16.0f, (float)(result_vec[0]), (float)(result_vec[1]), //(float)((int8_t)(rodeo_random_uint64_get() % 10) - 5), @@ -327,7 +329,7 @@ void player_bullet_resolver( void detect_player_enemy_collisions(void) { - player.damage_timer += rodeo_frame_time_get(); + player.damage_timer += rodeo_gfx_frame_time_get(); rodeo_collision_2d_world_compare_other(&player_collision_world, get_enemies_world(), player_enemy_resolver); rodeo_collision_2d_world_compare_other(&player_collision_world, get_enemy_bullet_world(), player_bullet_resolver); } @@ -348,7 +350,7 @@ void update_aim_position(void) { cvec_collision_2d_world_item_value *player_position = get_player_position(); - vec2 player_position_vec = { player_position->x, player_position->y }; + vec2 player_position_vec = { player_position->rect.x, player_position->rect.y }; vec2 aim_position_vec = { aim_position.x, aim_position.y }; float distance = glm_vec2_distance2(player_position_vec, aim_position_vec); // move towards player @@ -367,20 +369,20 @@ update_aim_position(void) void draw_aim(float player_x, float player_y, float scale) { - rodeo_texture_2d_draw( - &(rodeo_rectangle_t){ + rodeo_gfx_texture_2d_draw( + (rodeo_rectangle_t){ //.x = player_x - (((128.0f * scale) * 1.3f) - (128.0f * scale) ), .x = player_x - (((128.0f * scale) * 0.6f) / 2), .y = player_y + ((((44.0f) * scale) * 0.6f) / 2) + (80.0f * scale), .width = (128 * scale) * 1.6f, .height = (44 * scale) * 1.6f, }, - &(rodeo_rectangle_t){ + (rodeo_rectangle_t){ .width = 128, .height = 44, }, - &(rodeo_color_RGBAFloat_t){ .array = {0.9f,0.9f,0.9f,1.0} }, - &player.aim_texture + (rodeo_color_RGBAFloat_t){ .array = {0.9f,0.9f,0.9f,1.0} }, + player.aim_texture ); } diff --git a/src/sprite.c b/src/sprite.c index d966da9..0e5d7e8 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -5,20 +5,20 @@ void draw_sprite(sprite_t *sprite, float x, float y, float scale, rodeo_color_RGBAFloat_t color) { - rodeo_texture_2d_draw( - &(rodeo_rectangle_t){ + rodeo_gfx_texture_2d_draw( + (rodeo_rectangle_t){ .x = x,// - ((float)sprite->config.width * scale / 2), .y = y,// - ((float)sprite->config.height * scale / 2), .width = (float)sprite->config.width * scale, .height = (float)sprite->config.height * scale }, - &(rodeo_rectangle_t){ + (rodeo_rectangle_t){ .x = (float)sprite->config.width * (float)(uint32_t)sprite->iter, .y = 0, .width = (float)sprite->config.width, .height = (float)sprite->config.height }, - &color, + color, sprite->config.texture ); } diff --git a/src/sprite.h b/src/sprite.h index 9a44ea3..c1a5c0e 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -11,7 +11,7 @@ struct uint32_t width; uint32_t height; uint32_t count; - rodeo_texture_2d_t *texture; + rodeo_gfx_texture_2d_t texture; } config; } sprite_t; @@ -2,18 +2,18 @@ #include "rodeo.h" static rodeo_collision_2d_world_t collision_wall_world; -rodeo_texture_2d_t wall_texture; -rodeo_texture_2d_t floor_texture; -rodeo_texture_2d_t goat_texture; -rodeo_texture_2d_t logo_texture; +rodeo_gfx_texture_2d_t wall_texture; +rodeo_gfx_texture_2d_t floor_texture; +rodeo_gfx_texture_2d_t goat_texture; +rodeo_gfx_texture_2d_t logo_texture; void init_wall(void) { - wall_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/walls.png")); - floor_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/floor.png")); - goat_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/goat_on_a_pole.png")); - logo_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/tojam2023_tagline_header_clear.png")); + wall_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/walls.png")); + floor_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/floor.png")); + goat_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/goat_on_a_pole.png")); + logo_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/tojam2023_tagline_header_clear.png")); uint16_t window_width = 1600; uint16_t window_height = 900; collision_wall_world = rodeo_collision_2d_world_create(); @@ -47,10 +47,10 @@ void deinit_wall(void) { rodeo_collision_2d_world_destroy(&collision_wall_world); - rodeo_texture_2d_destroy(&wall_texture); - rodeo_texture_2d_destroy(&floor_texture); - rodeo_texture_2d_destroy(&goat_texture); - rodeo_texture_2d_destroy(&logo_texture); + rodeo_gfx_texture_2d_destroy(wall_texture); + rodeo_gfx_texture_2d_destroy(floor_texture); + rodeo_gfx_texture_2d_destroy(goat_texture); + rodeo_gfx_texture_2d_destroy(logo_texture); } rodeo_collision_2d_world_t * @@ -71,10 +71,12 @@ new_wall( &collision_wall_world, (rodeo_collision_2d_world_item_t) { - .x = x, - .y = y, - .width = width, - .height = height + .rect = { + .x = x, + .y = y, + .width = width, + .height = height + } }); } @@ -85,8 +87,8 @@ coords_inside_wall( ) { c_foreach(i, cvec_collision_2d_world_item, collision_wall_world) { - if (x >= i.ref->x && x <= i.ref->x + i.ref->width && - y >= i.ref->y && y <= i.ref->y + i.ref->height) { + if (x >= i.ref->rect.x && x <= i.ref->rect.x + i.ref->rect.width && + y >= i.ref->rect.y && y <= i.ref->rect.y + i.ref->rect.height) { return true; } } @@ -101,25 +103,25 @@ moving_wall_resolver( { rodeo_collision_2d_world_item_t *p = obj_collision; rodeo_collision_2d_world_item_t *w = wall_collision; - rodeo_collision_2d_world_item_t step = (rodeo_collision_2d_world_item_t){ - .x = p->x + p->dx * rodeo_frame_time_get() / (1000.0f/60.0f), - .y = p->y + p->dy * rodeo_frame_time_get() / (1000.0f/60.0f), - .width = p->width, - .height = p->height + rodeo_rectangle_t step = { + .x = p->rect.x + p->dx * rodeo_gfx_frame_time_get() / (1000.0f/60.0f), + .y = p->rect.y + p->dy * rodeo_gfx_frame_time_get() / (1000.0f/60.0f), + .width = p->rect.width, + .height = p->rect.height }; - rodeo_rectangle_t intersection = rodeo_collision_2d_get_collision_rect(&step, w); + rodeo_rectangle_t intersection = rodeo_collision_2d_get_collision_rect(step, w->rect); // left collision if (intersection.width < intersection.height) { // colliding left/right // if x equal push right if (intersection.x == step.x) { - p->x = w->x + w->width; + p->rect.x = w->rect.x + w->rect.width; if (p->dx < 0) { p->dx = 0; } // else push left } else { - p->x = w->x - p->width; + p->rect.x = w->rect.x - p->rect.width; if (p->dx > 0) { p->dx = 0; } @@ -129,13 +131,13 @@ moving_wall_resolver( // colliding up/down // if y equal push down if (intersection.y == step.y) { - p->y = w->y + w->height; + p->rect.y = w->rect.y + w->rect.height; if (p->dy < 0) { p->dy = 0; } // else push up } else { - p->y = w->y - p->height; + p->rect.y = w->rect.y - p->rect.height; if (p->dy > 0) { p->dy = 0; } @@ -143,7 +145,7 @@ moving_wall_resolver( } // tunneled into a hitbox // don't allow movement - else if (p->width == w->width && p->height == w->height) { + else if (p->rect.width == w->rect.width && p->rect.height == w->rect.height) { p->dx = 0; p->dy = 0; } @@ -156,10 +158,10 @@ draw_level(void) rodeo_rectangle_t logo_size = (rodeo_rectangle_t){0,0,1024,400}; rodeo_rectangle_t logo_dest = (rodeo_rectangle_t){1600-(1024*0.25f),10,1024*0.25f,400*0.25f}; rodeo_rectangle_t goat_size = (rodeo_rectangle_t){0,0,529,1038}; - rodeo_rectangle_t goat_dest = (rodeo_rectangle_t){(1600.0f/2)-(529/2*0.07f),(900.0f/2)-(1038/2*0.07f),529*0.07f,1038*0.07f}; - rodeo_texture_2d_draw(&rect, &rect, &(rodeo_color_RGBAFloat_t){ .array = {0.96f, 0.41f, 0.1f, 1.0f} }, &wall_texture); - rodeo_texture_2d_draw(&rect, &rect, &(rodeo_color_RGBAFloat_t){ .array = {0.52f, 0.31f, 0.73f, 0.33f} }, &floor_texture); - rodeo_texture_2d_draw(&goat_dest, &goat_size, &(rodeo_color_RGBAFloat_t){ .array = {1,1,1,1} }, &goat_texture); - rodeo_texture_2d_draw(&logo_dest, &logo_size, &(rodeo_color_RGBAFloat_t){ .array = {1,1,1,1} }, &logo_texture); + rodeo_rectangle_t goat_dest = (rodeo_rectangle_t){(1600.0f/2)-(529.0f/2*0.07f),(900.0f/2)-(1038.0f/2*0.07f),529*0.07f,1038*0.07f}; + rodeo_gfx_texture_2d_draw(rect, rect, (rodeo_color_RGBAFloat_t){ .array = {0.96f, 0.41f, 0.1f, 1.0f} }, wall_texture); + rodeo_gfx_texture_2d_draw(rect, rect, (rodeo_color_RGBAFloat_t){ .array = {0.52f, 0.31f, 0.73f, 0.33f} }, floor_texture); + rodeo_gfx_texture_2d_draw(goat_dest, goat_size, (rodeo_color_RGBAFloat_t){ .array = {1,1,1,1} }, goat_texture); + rodeo_gfx_texture_2d_draw(logo_dest, logo_size, (rodeo_color_RGBAFloat_t){ .array = {1,1,1,1} }, logo_texture); } |
