diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/debug.c | 50 | ||||
| -rw-r--r-- | src/debug.h | 6 | ||||
| -rw-r--r-- | src/enemies.c | 134 | ||||
| -rw-r--r-- | src/enemies.h | 8 | ||||
| -rw-r--r-- | src/init.c | 23 | ||||
| -rw-r--r-- | src/init.h | 13 | ||||
| -rw-r--r-- | src/main.c | 131 |
7 files changed, 236 insertions, 129 deletions
diff --git a/src/debug.c b/src/debug.c new file mode 100644 index 0000000..0dddf54 --- /dev/null +++ b/src/debug.c @@ -0,0 +1,50 @@ +#include "rodeo.h" +#include "enemies.h" +#include "debug.h" + +void draw_debug_text(cstr renderer_name, float fps_display) +{ + rodeo_debug_text_draw( + 1, + 1, + " using %s renderer ", + cstr_str( + &renderer_name + ) + ); + + rodeo_debug_text_draw( + 2, + 2, + " frame count: %"PRIu64" ", + rodeo_frame_count_get() + ); + + rodeo_debug_text_draw( + 2, + 3, + " fps: %.2f ", + fps_display + ); + + rodeo_debug_text_draw( + 2, + 4, + " enemy count: %d ", + get_enemy_count() + ); + + rodeo_debug_text_draw( + 2, + 5, + " ghost count: %d ", + get_ghost_count() + ); + + rodeo_debug_text_draw( + 2, + 6, + " total count: %d ", + get_ghost_count() + get_enemy_count() + ); +} diff --git a/src/debug.h b/src/debug.h new file mode 100644 index 0000000..6a47c6e --- /dev/null +++ b/src/debug.h @@ -0,0 +1,6 @@ +#include "stc/cstr.h" + +void draw_debug_text( + cstr renderer_name, + float fps_display +); diff --git a/src/enemies.c b/src/enemies.c index abb8646..10378da 100644 --- a/src/enemies.c +++ b/src/enemies.c @@ -7,22 +7,25 @@ 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 hinotamatchi_texture; +//static rodeo_texture_2d_t amonghost_texture; +//static rodeo_texture_2d_t squid_texture; +static rodeo_texture_2d_t enemy_texture; static cvec_enemy_t enemies = {0}; static cvec_enemy_t ghosts = {0}; static float spawn_cooldown = 0; -static uint16_t enemy_count = 0; +static uint32_t enemy_count = 0; +static uint32_t ghost_count = 0; void 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")); + //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")); } void @@ -32,37 +35,89 @@ 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(&hinotamatchi_texture); + //rodeo_texture_2d_destroy(&squid_texture); + //rodeo_texture_2d_destroy(&amonghost_texture); + rodeo_texture_2d_destroy(&enemy_texture); } -uint16_t +uint32_t get_enemy_count(void) { return enemy_count; } +uint32_t +get_ghost_count(void) +{ + return ghost_count; +} + enemy_t* spawn_enemy(float x, float y) { uint64_t rng = rodeo_random_uint64_get(); - cvec_enemy_t *enemy_obj_world = &enemies; - rodeo_collision_2d_world_t *enemy_collision_world = &collision_enemies_world; + cvec_enemy_t *obj_world = &enemies; + rodeo_collision_2d_world_t *collision_world = &collision_enemies_world; + + // debug to force specific enemies to spawn + //rng = (rng % 2) ? enemy_weapon_fourcross : enemy_weapon_none; + //rng = enemy_weapon_fourcross; + //rng = enemy_weapon_none; + if(rng % 3 == enemy_weapon_basic) + { + obj_world = &ghosts; + collision_world = &collision_ghosts_world; + ghost_count++; + } + else + { + enemy_count++; + } + + rodeo_collision_2d_world_item_t collision = (rodeo_collision_2d_world_item_t){.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( + obj_world, + (enemy_t){ + .hp = 20.0, + .move_speed = ((float)(rng % 3) + 1.0f) * 0.3f, + .behavior = enemy_ai_follow, + .weapon = { + .firerate = -((rng % 3) - 2.0f) * 1.6f, + .type = rng % 3, + .cooldown = 0, + }, + .id = id + }); +} + +enemy_t* +spawn_ghost(float x, float y) +{ + uint64_t rng = rodeo_random_uint64_get(); + cvec_enemy_t *obj_world = &enemies; + rodeo_collision_2d_world_t *collision_world = &collision_enemies_world; + rng = enemy_weapon_basic; if(rng % 3 == enemy_weapon_basic) { - enemy_obj_world = &ghosts; - enemy_collision_world = &collision_ghosts_world; + obj_world = &ghosts; + collision_world = &collision_ghosts_world; + ghost_count++; + } + else + { + enemy_count++; } - rodeo_collision_2d_world_item_t enemy_collision = (rodeo_collision_2d_world_item_t){.x = x, .y = y, .width = 40, .height = 40}; - world_id id = rodeo_collision_2d_world_item_create(enemy_collision_world, enemy_collision)->id; - enemy_count++; + rodeo_collision_2d_world_item_t collision = (rodeo_collision_2d_world_item_t){.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( - enemy_obj_world, + obj_world, (enemy_t){ .hp = 20.0, .move_speed = ((float)(rng % 3) + 1.0f) * 0.3f, @@ -79,7 +134,6 @@ spawn_enemy(float x, float y) void draw_enemy(cvec_collision_2d_world_item_value *enemy) { - rodeo_texture_2d_t *texture; rodeo_color_RGBAFloat_t color; enemy_t *enemy_obj = get_enemy_by_id(enemy->id); @@ -88,7 +142,6 @@ draw_enemy(cvec_collision_2d_world_item_value *enemy) { case enemy_weapon_none: { - texture = &hinotamatchi_texture; color = (rodeo_color_RGBAFloat_t){ .array = { 0.8f, 0.5f, 0.1f, 1.0f } }; @@ -96,7 +149,6 @@ draw_enemy(cvec_collision_2d_world_item_value *enemy) break; case enemy_weapon_basic: { - texture = &amonghost_texture; color = (rodeo_color_RGBAFloat_t){ .array = { 0.25f, 0.95f, 0.25f, 0.5f } }; @@ -104,7 +156,6 @@ draw_enemy(cvec_collision_2d_world_item_value *enemy) break; case enemy_weapon_fourcross: { - texture = &squid_texture; color = (rodeo_color_RGBAFloat_t){ .array = { 0.1f, 0.2f, 0.75f, 1.0f } }; @@ -112,6 +163,17 @@ draw_enemy(cvec_collision_2d_world_item_value *enemy) break; } + if (enemy->x > 1600 || enemy->x < 0 || enemy->y > 900 || enemy->x < 0) + { + rodeo_log( + rodeo_logLevel_error, + "Bad position, x:%f, y:%f", + enemy->x, + enemy->y + ); + return; + } + rodeo_texture_2d_draw( &(rodeo_rectangle_t){ @@ -121,13 +183,13 @@ draw_enemy(cvec_collision_2d_world_item_value *enemy) .height = enemy->height, }, &(rodeo_rectangle_t){ - .x = 0, + .x = 0 + (40 * (float)enemy_obj->weapon.type), .y = 0, .width = 40, .height = 40 }, &color, - texture + &enemy_texture ); } @@ -385,12 +447,12 @@ get_enemy_by_id( world_id id ) { - c_foreach(i, cvec_enemy_t, enemies) { - if (i.ref->id.id == id.id) { - return i.ref; - } + cvec_enemy_t *enemy_vec = &enemies; + if (id.world == &collision_ghosts_world) + { + enemy_vec = &ghosts; } - c_foreach(i, cvec_enemy_t, ghosts) { + c_foreach(i, cvec_enemy_t, *enemy_vec) { if (i.ref->id.id == id.id) { return i.ref; } @@ -420,11 +482,15 @@ void enemy_destroy( cvec_enemy_t_value* enemy ) { - enemy_count--; cvec_enemy_t *enemy_vec = &enemies; if(enemy->weapon.type == enemy_weapon_basic) { enemy_vec = &ghosts; + ghost_count--; + } + else + { + enemy_count--; } rodeo_collision_2d_world_item_destroy_by_id(enemy->id); *enemy = *cvec_enemy_t_back(enemy_vec); @@ -526,10 +592,10 @@ attempt_random_enemy_spawn( ) { spawn_cooldown -= rodeo_frame_time_get(); - if (spawn_cooldown <= 0) { - spawn_cooldown += (float)rodeo_random_double_get() * 1500.0f + 450.0f; + if (spawn_cooldown <= 0 && get_enemy_count() + get_ghost_count() <= 100) { // faster spawning for testing - //spawn_cooldown += (float)rodeo_random_double_get() * 150.0f + 45.0f; + //spawn_cooldown += ((float)rodeo_random_double_get() * 15.0f) + 4.50f; + spawn_cooldown += ((float)rodeo_random_double_get() * 1500.0f) + 450.0f; return random_enemy_create(bounds); } return NULL; diff --git a/src/enemies.h b/src/enemies.h index a03162f..a67cc13 100644 --- a/src/enemies.h +++ b/src/enemies.h @@ -55,15 +55,21 @@ deinit_enemies(void); deinit_enemies() \ ) -uint16_t +uint32_t get_enemy_count(void); +uint32_t +get_ghost_count(void); + enemy_t* spawn_enemy( float x, float y ); +enemy_t* +spawn_ghost(float x, float y); + void draw_enemies(void); diff --git a/src/init.c b/src/init.c new file mode 100644 index 0000000..f168a33 --- /dev/null +++ b/src/init.c @@ -0,0 +1,23 @@ +#include "init.h" +#include "bullet.h" +#include "player.h" +#include "enemies.h" +#include "wall.h" + +void +init_game_systems(void) +{ + init_bullets(); + init_player(); + init_enemies(); + init_wall(); +} + +void +deinit_game_systems(void) +{ + deinit_bullets(); + deinit_player(); + deinit_enemies(); + deinit_wall(); +} diff --git a/src/init.h b/src/init.h new file mode 100644 index 0000000..bcc53d6 --- /dev/null +++ b/src/init.h @@ -0,0 +1,13 @@ +#include "rodeo.h" + +void +init_game_systems(void); + +void +deinit_game_systems(void); + +#define game_systems_init_do() \ + mrodeo_defer_do( \ + init_game_systems(), \ + deinit_game_systems() \ + ) @@ -6,147 +6,90 @@ #include "bullet.h" #include "enemies.h" #include "wall.h" -#include "rodeo/collision.h" +#include "debug.h" +#include "init.h" const uint16_t window_width = 1600; const uint16_t window_height = 900; - -cstr renderer; -float time_var; - -rodeo_audio_sound_t *scratch = NULL; -rodeo_audio_music_t *music = NULL; +// variables for storing debug info that can be displayed +cstr renderer_name; +float fps_display; void main_loop(void) { if(rodeo_frame_count_get() % 10 == 0) { - time_var = rodeo_frame_perSecond_get(); + fps_display = rodeo_frame_perSecond_get(); } + mrodeo_frame_do() { + // retrieve and apply player input parse_player_input(); - if(*(bool*)play_sound_input(NULL, NULL)) - { - rodeo_audio_sound_play(scratch); - } - if(*(bool*)play_sound_input2(NULL, NULL)) - { - rodeo_audio_music_play_fadeIn(music, 1000); - } - if(*(bool*)play_sound_input3(NULL, NULL)) - { - rodeo_audio_music_stop_fadeOut(1000); - } - player_shoot(get_player_bullet_world()); enemies_attempt_weapon_fire(); - if (get_enemy_count() < 50) - { - attempt_random_enemy_spawn((rodeo_rectangle_t){ 0, 0, window_width, window_height }); - } - + // spawn enemies + attempt_random_enemy_spawn((rodeo_rectangle_t){ 0, 0, window_width, window_height }); + + // run enemy movement ai group_follow_target(get_player_position()); - draw_level(); - draw_bullets(); - draw_player(); - draw_enemies(); - draw_hp_bar(); - detect_bullet_enemy_collisions(); detect_bullet_wall_collisions(); detect_player_enemy_collisions(); detect_player_wall_collisions(); detect_enemy_wall_collisions(); + // apply movements move_bullets(); move_enemies(); move_player(); - rodeo_debug_text_draw( - 1, - 1, - " using %s renderer ", - cstr_str( - &renderer - ) - ); - - rodeo_debug_text_draw( - 2, - 2, - " frame count: %"PRIu64" ", - rodeo_frame_count_get() - ); + draw_level(); + draw_bullets(); + draw_player(); + draw_enemies(); + draw_hp_bar(); - rodeo_debug_text_draw( - 2, - 3, - " fps: %.2f ", - time_var + draw_debug_text( + renderer_name, + fps_display ); - rodeo_debug_text_draw( - 2, - 4, - " enemy count: %d ", - get_enemy_count() - ); } } int main(void) { - rodeo_log( - rodeo_logLevel_info, - "Testing logging... It seems to work!" - ); - rodeo_log( - rodeo_logLevel_warning, - "Testing warning log level... It seems to work!" - ); - rodeo_log( - rodeo_logLevel_error, - "Testing error log level... It seems to work!" - ); - - - register_inputs(); inputs_register_do() { mrodeo_window_do(window_height, window_width, cstr_lit("Rodeo Window")) { - renderer = rodeo_renderer_name_get(); + renderer_name = rodeo_renderer_name_get(); rodeo_frame_limit_set(60); - scratch = rodeo_audio_sound_create_from_path(cstr_lit("assets/sample.wav")); - music = rodeo_audio_music_create_from_path(cstr_lit("assets/music.ogg")); - - bullets_init_do() + game_systems_init_do() { - player_init_do() - { - enemies_init_do() - { - wall_init_do() - { - //spawn_enemy(400.0f,700.0f); - //spawn_enemy(900.0f,700.0f); - //spawn_enemy(400.0f,100.0f); - //spawn_enemy(900.0f,100.0f); - rodeo_mainLoop_run( - main_loop - ); - } - } - } + // 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 + ); } } } |
