From 092d9f8cbe9d7edc2e1c87e126c46744ced10e2b Mon Sep 17 00:00:00 2001 From: realtradam Date: Sun, 28 May 2023 13:38:17 -0400 Subject: cleanup + damage flicker --- src/input.c | 4 +- src/main.c | 202 +++++------------------------------------------------------ src/player.c | 30 +++------ src/sprite.c | 4 +- src/sprite.h | 2 +- 5 files changed, 29 insertions(+), 213 deletions(-) diff --git a/src/input.c b/src/input.c index 420648c..5d7571f 100644 --- a/src/input.c +++ b/src/input.c @@ -286,10 +286,10 @@ register_inputs(void) rodeo_input_command_register_binary_scancode(inputs.down, rodeo_input_binary_scancode_S); rodeo_input_command_register_binary_scancode(inputs.left, rodeo_input_binary_scancode_A); rodeo_input_command_register_binary_scancode(inputs.right, rodeo_input_binary_scancode_D); - rodeo_input_command_register_unboundedRange_mouse(inputs.up, rodeo_input_unboundedRange_mouse_Y); + /*rodeo_input_command_register_unboundedRange_mouse(inputs.up, rodeo_input_unboundedRange_mouse_Y); rodeo_input_command_register_unboundedRange_mouse(inputs.down, rodeo_input_unboundedRange_mouse_Y); rodeo_input_command_register_unboundedRange_mouse(inputs.left, rodeo_input_unboundedRange_mouse_X); - rodeo_input_command_register_unboundedRange_mouse(inputs.right, rodeo_input_unboundedRange_mouse_X); + rodeo_input_command_register_unboundedRange_mouse(inputs.right, rodeo_input_unboundedRange_mouse_X);*/ rodeo_input_command_register_boundedRange_controllerAxis(inputs.up, rodeo_input_boundedRange_controllerAxisLeft_Y); rodeo_input_command_register_boundedRange_controllerAxis(inputs.down, rodeo_input_boundedRange_controllerAxisLeft_Y); rodeo_input_command_register_boundedRange_controllerAxis(inputs.left, rodeo_input_boundedRange_controllerAxisLeft_X); diff --git a/src/main.c b/src/main.c index a8783f5..09902fc 100644 --- a/src/main.c +++ b/src/main.c @@ -8,8 +8,8 @@ #include "wall.h" #include "rodeo/collision.h" -const uint16_t window_width = 640; -const uint16_t window_height = 480; +const uint16_t window_width = 1600; +const uint16_t window_height = 900; cstr renderer; @@ -18,101 +18,11 @@ float time_var; rodeo_audio_sound_t *scratch = NULL; rodeo_audio_music_t *music = NULL; -typedef -struct -{ - float x; - float y; -} -summon_t; - -summon_t box1_position = { .x = 100, .y = 100 }; -summon_t box2_position = { .x = 100, .y = 100 }; - -float orc_size[] = {13.0f * 2.0f, 19.0f * 2.0f}; - -rodeo_vector2_t units[UINT16_MAX][2] = {0}; -uint16_t num_of_units = 0; - -const rodeo_color_RGBAFloat_t red = -{ - .colors.red = 1.0f, .colors.green = 0.0f, .colors.blue = 0.0f, - .colors.alpha = 1.0f -}; -const rodeo_color_RGBAFloat_t green = -{ - .colors.red = 0.0f, .colors.green = 1.0f, .colors.blue = 0.0f, - .colors.alpha = 1.0f -}; -const rodeo_color_RGBAFloat_t blue = -{ - .colors.red = 0.0f, .colors.green = 0.0f, .colors.blue = 1.0f, - .colors.alpha = 1.0f -}; -const rodeo_color_RGBAFloat_t pink = -{ - .colors.red = 1.0f, .colors.green = 0.0f, .colors.blue = 1.0f, - .colors.alpha = 1.0f -}; - -const rodeo_color_RGBAFloat_t red_clear = -{ - .colors.red = 1.0f, .colors.green = 0.0f, .colors.blue = 0.0f, - .colors.alpha = 0.5f -}; -const rodeo_color_RGBAFloat_t green_clear = -{ - .colors.red = 0.0f, .colors.green = 1.0f, .colors.blue = 0.0f, - .colors.alpha = 0.5f -}; -const rodeo_color_RGBAFloat_t blue_clear = -{ - .colors.red = 0.0f, .colors.green = 0.0f, .colors.blue = 1.0f, - .colors.alpha = 0.5f -}; -const rodeo_color_RGBAFloat_t pink_clear = -{ - .colors.red = 1.0f, .colors.green = 0.0f, .colors.blue = 1.0f, - .colors.alpha = 0.5f -}; - -rodeo_collision_2d_world_t world_orc; -rodeo_collision_2d_world_t world_other; - -world_id orc_collision_id; -world_id box_collision_ids[2] = { 0 }; - -void collision_resolve( - rodeo_collision_2d_world_item_t *a, - rodeo_collision_2d_world_item_t *b -) { - rodeo_log( - rodeo_logLevel_info, - "%d collided with %d", - a->id.id, b->id.id - ); - rodeo_collision_2d_world_item_destroy(b); -} - void main_loop(void) { if(rodeo_frame_count_get() % 10 == 0) { - /* for testing - rodeo_input_scene_unregister_callback( - *summon_units_input, - &scene, - register_type_e - ); - - rodeo_input_scene_register_callback( - *summon_units_input, - &scene, - register_type_q - ); - */ - time_var = rodeo_frame_perSecond_get(); } @@ -120,7 +30,6 @@ main_loop(void) { parse_player_input(); move_player(); - rodeo_collision_2d_world_compare_self(&world_orc, collision_resolve); if(*(bool*)play_sound_input(NULL, NULL)) { @@ -135,73 +44,20 @@ main_loop(void) rodeo_audio_music_stop_fadeOut(1000); } - //if(*(bool*)summon_units_input(NULL, NULL)) - //{ player_shoot(get_player_bullet_world()); - //} - - rodeo_rectangle_draw( - &(rodeo_rectangle_t){ 100, 100, 50, 50 }, - &red - ); - rodeo_rectangle_draw( - &(rodeo_rectangle_t){ 100, 160, 50, 50 }, - &green - ); - rodeo_rectangle_draw( - &(rodeo_rectangle_t){ 160, 100, 50, 50 }, - &blue - ); - rodeo_rectangle_draw( - &(rodeo_rectangle_t){ 160, 160, 50, 50 }, - &pink - ); - - rodeo_rectangle_draw( - &(rodeo_rectangle_t){ 300, 300, 50, 50 }, - &red_clear - ); - rodeo_rectangle_draw( - &(rodeo_rectangle_t){ 310, 310, 50, 50 }, - &green_clear - ); - rodeo_rectangle_draw( - &(rodeo_rectangle_t){ 320, 320, 50, 50 }, - &blue_clear - ); - rodeo_rectangle_draw( - &(rodeo_rectangle_t){ 330, 330, 50, 50 }, - &pink_clear - ); - - // debug test for collisions - /* - for(uint64_t i = 0; i < (sizeof(box_collision_ids) / sizeof(box_collision_ids[0])); ++i) - { - rodeo_collision_2d_world_item_t *box = rodeo_collision_2d_world_item_get_by_id(box_collision_ids[i]); - if(box != NULL) - { - rodeo_rectangle_draw( - &(rodeo_rectangle_t){ box->x, box->y, box->width, box->height }, - &pink - ); - } - } - */ - - enemies_attempt_weapon_fire(); - attempt_random_enemy_spawn((rodeo_rectangle_t){ 0, 0, window_width, window_height }); - - move_bullets(); - move_enemies(); - group_follow_target(get_player_position()); - draw_bullets(); - draw_player(); - draw_enemies(); - detect_bullet_enemy_collisions(); - detect_bullet_wall_collisions(); - detect_player_enemy_collisions(); - detect_player_wall_collisions(); + enemies_attempt_weapon_fire(); + attempt_random_enemy_spawn((rodeo_rectangle_t){ 0, 0, window_width, window_height }); + + move_bullets(); + move_enemies(); + group_follow_target(get_player_position()); + draw_bullets(); + draw_player(); + draw_enemies(); + detect_bullet_enemy_collisions(); + detect_bullet_wall_collisions(); + detect_player_enemy_collisions(); + detect_player_wall_collisions(); rodeo_debug_text_draw( 1, @@ -250,26 +106,6 @@ main(void) renderer = rodeo_renderer_name_get(); rodeo_frame_limit_set(60); - world_orc = rodeo_collision_2d_world_create(); - world_other = rodeo_collision_2d_world_create(); - - /* - rodeo_collision_2d_world_item_t test_collision_params = { - .x = 320, - .y = 240, - .width = orc_size[0], - .height = orc_size[1] - }; - box_collision_ids[0] = rodeo_collision_2d_world_item_create(&world_orc, test_collision_params)->id; - rodeo_collision_2d_world_item_t test2_collision_params = { - .x = 0, - .y = 240, - .width = orc_size[0], - .height = orc_size[1] - }; - box_collision_ids[1] = rodeo_collision_2d_world_item_create(&world_orc, test2_collision_params)->id; - */ - scratch = rodeo_audio_sound_create_from_path(cstr_lit("assets/sample.wav")); music = rodeo_audio_music_create_from_path(cstr_lit("assets/music.ogg")); @@ -277,10 +113,6 @@ main(void) init_player(); init_enemies(); init_wall(); - //spawn_enemy(240, 240); - //spawn_enemy(100, 100); - //spawn_enemy(300, 100); - //spawn_enemy(200, 330); new_wall(0, -10, window_width, 10); new_wall(0, window_height, window_width, 10); new_wall(-10, 0, 10, window_height); @@ -291,10 +123,6 @@ main(void) ); deinit_player(); - - rodeo_collision_2d_world_destroy(&world_orc); - rodeo_collision_2d_world_destroy(&world_other); - deinit_enemies(); } diff --git a/src/player.c b/src/player.c index 85cf840..5a8ba0f 100644 --- a/src/player.c +++ b/src/player.c @@ -16,6 +16,7 @@ struct player_t rodeo_texture_2d_t aim_texture; int32_t hp; float damage_timer; //ms + float damage_cooldown_rate; world_id collision_id; move_state_t move_state; struct player_weapon @@ -70,6 +71,7 @@ init_player(void) player.weapon.spread = 0.425f; aim_position.x = 101; aim_position.y = 100; + player.damage_cooldown_rate = 1000.0f; } void @@ -82,6 +84,11 @@ deinit_player(void) void draw_player(void) { + float transparency = 1.0f; + if(!(player.damage_timer >= player.damage_cooldown_rate || (rodeo_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); @@ -99,26 +106,7 @@ draw_player(void) &(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); - /* - cvec_collision_2d_world_item_value *player = rodeo_collision_2d_world_item_get_by_id(player_collision_id); - rodeo_texture_2d_draw( - &(rodeo_rectangle_t){ - .x = (float)(int32_t)player->x - (orc_size[0] / 2.0f), - .y = (float)(int32_t)player->y - (orc_size[1] / 2.0f) , - .width = orc_size[0], - .height = orc_size[1], - }, - &(rodeo_rectangle_t){ - .x = 5, - .y = 5, - .width = 13, - .height = 19 - }, - NULL, - &player_texture - ); - */ + draw_sprite(&player.sprite, player_position->x, player_position->y, scale, (rodeo_color_RGBAFloat_t){ .array = {1,1,1,transparency} }); } void @@ -233,7 +221,7 @@ void player_enemy_resolver( rodeo_logLevel_info, "player is dead" );*/ - } else if (player.damage_timer > 1000.0) { + } else if (player.damage_timer >= player.damage_cooldown_rate) { rodeo_log( rodeo_logLevel_info, "player health is now %d", diff --git a/src/sprite.c b/src/sprite.c index a46f1d0..cf7d22d 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -3,7 +3,7 @@ #include "sprite.h" void -draw_sprite(sprite_t *sprite, float x, float y, float scale) +draw_sprite(sprite_t *sprite, float x, float y, float scale, rodeo_color_RGBAFloat_t color) { rodeo_texture_2d_draw( &(rodeo_rectangle_t){ @@ -18,7 +18,7 @@ draw_sprite(sprite_t *sprite, float x, float y, float scale) .width = (float)sprite->config.width, .height = (float)sprite->config.height }, - &(rodeo_color_RGBAFloat_t){ .array = { 1.0f, 1.0f, 1.0f, 1.0f } }, + &color, sprite->config.texture ); } diff --git a/src/sprite.h b/src/sprite.h index 81ad5fa..c6656e6 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -17,5 +17,5 @@ struct sprite_t; void -draw_sprite(sprite_t *sprite, float x, float y, float scale); +draw_sprite(sprite_t *sprite, float x, float y, float scale, rodeo_color_RGBAFloat_t color); -- cgit v1.2.3