diff --git a/scenes/CMakeLists.txt b/scenes/CMakeLists.txt index 8f700ab..d712b54 100644 --- a/scenes/CMakeLists.txt +++ b/scenes/CMakeLists.txt @@ -1,6 +1,6 @@ add_subdirectory(engine) add_library(lib_scenes STATIC - assets_maps.c + player_ent.c editor_scene.c menu_scene.c game_systems.c diff --git a/scenes/assets_maps.c b/scenes/assets_maps.c deleted file mode 100644 index 459d0fa..0000000 --- a/scenes/assets_maps.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "assets_maps.h" - - -const char* const player_sprite_map[N_PLAYER_SPRITES] = { - "plr_stand", - "plr_run", -}; diff --git a/scenes/assets_maps.h b/scenes/assets_maps.h deleted file mode 100644 index 59fa3ff..0000000 --- a/scenes/assets_maps.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef __ASSETS_MAPS_H -#define __ASSETS_MAPS_H - -#define N_PLAYER_SPRITES 2 -enum PlayerSpriteEnum -{ - SPR_PLAYER_STAND = 0, - SPR_PLAYER_RUN -}; - -extern const char* const player_sprite_map[N_PLAYER_SPRITES]; - -#endif // __ASSETS_MAPS_H diff --git a/scenes/editor_scene.c b/scenes/editor_scene.c index 3aa6e11..644b4a8 100644 --- a/scenes/editor_scene.c +++ b/scenes/editor_scene.c @@ -1,7 +1,7 @@ #include "scene_impl.h" #include "game_systems.h" #include "constants.h" -#include "assets_maps.h" +#include "ent_impl.h" #include "raylib.h" #include "raymath.h" #include @@ -220,43 +220,6 @@ static void spawn_crate(Scene_t* scene, unsigned int tile_idx, bool metal) p_hurtbox->fragile = !metal; } -static void spawn_player(Scene_t* scene) -{ - Entity_t* p_ent = add_entity(&scene->ent_manager, PLAYER_ENT_TAG); - CBBox_t* p_bbox = add_component(&scene->ent_manager, p_ent, CBBOX_COMP_T); - - set_bbox(p_bbox, PLAYER_WIDTH, PLAYER_HEIGHT); - add_component(&scene->ent_manager, p_ent, CTRANSFORM_COMP_T); - - CJump_t* p_cjump = add_component(&scene->ent_manager, p_ent, CJUMP_COMP_T); - p_cjump->jump_speed = 680; - p_cjump->jumps = 1; - p_cjump->max_jumps = 1; - p_cjump->jump_ready = true; - add_component(&scene->ent_manager, p_ent, CPLAYERSTATE_T); - add_component(&scene->ent_manager, p_ent, CTILECOORD_COMP_T); - add_component(&scene->ent_manager, p_ent, CMOVEMENTSTATE_T); - CHitBoxes_t* p_hitbox = add_component(&scene->ent_manager, p_ent, CHITBOXES_T); - p_hitbox->n_boxes = 2; - p_hitbox->boxes[0] = (Rectangle) { - .x = 0, - .y = -1, - .width = p_bbox->size.x - 1, - .height = p_bbox->size.y + 2, - }; - p_hitbox->boxes[1] = (Rectangle) { - .x = -1, - .y = 0, - .width = p_bbox->size.x + 2, - .height = p_bbox->size.y - 1, - }; - CSprite_t* p_cspr = add_component(&scene->ent_manager, p_ent, CSPRITE_T); - p_cspr->sprite = get_sprite(&scene->engine->assets, "plr_stand"); - p_cspr->offset = (Vector2){0, -20}; - p_cspr->sprites_map = player_sprite_map; - p_cspr->transition_func = &player_sprite_transition_func; -} - static void toggle_block_system(Scene_t* scene) { // TODO: This system is not good as the interface between raw input and actions is broken @@ -473,7 +436,7 @@ void init_level_scene(LevelScene_t* scene) all_tiles[tile_idx].tile_type = SOLID_TILE; // for testing } - spawn_player(&scene->scene); + create_player(&scene->scene.ent_manager, &scene->scene.engine->assets); update_entity_manager(&scene->scene.ent_manager); } diff --git a/scenes/ent_impl.h b/scenes/ent_impl.h new file mode 100644 index 0000000..1458a1e --- /dev/null +++ b/scenes/ent_impl.h @@ -0,0 +1,8 @@ +#ifndef __ENT_IMPL_H +#define __ENT_IMPL_H +#include "entManager.h" +#include "assets.h" + +Entity_t* create_player(EntityManager_t* ent_manager, Assets_t* assets); + +#endif // __ENT_IMPL_H diff --git a/scenes/game_systems.c b/scenes/game_systems.c index 7094cee..3c2ba66 100644 --- a/scenes/game_systems.c +++ b/scenes/game_systems.c @@ -1,7 +1,6 @@ #include "game_systems.h" #include "AABB.h" #include "constants.h" -#include "assets_maps.h" #include static const Vector2 TILE_SZ = {TILE_SIZE, TILE_SIZE}; @@ -1134,8 +1133,3 @@ void term_level_scene_data(LevelSceneData_t* data) //sc_map_term_32(&data->collision_events); UnloadRenderTexture(data->game_viewport); // Unload render texture } - -unsigned int player_sprite_transition_func(Entity_t* ent) -{ - return SPR_PLAYER_RUN; -} diff --git a/scenes/game_systems.h b/scenes/game_systems.h index 61e6c5f..68e576c 100644 --- a/scenes/game_systems.h +++ b/scenes/game_systems.h @@ -16,6 +16,4 @@ void update_tilemap_system(Scene_t* scene); void hitbox_update_system(Scene_t* scene); void sprite_animation_system(Scene_t* scene); void camera_update_system(Scene_t* scene); - -unsigned int player_sprite_transition_func(Entity_t* ent); #endif // __GAME_SYSTEMS_H diff --git a/scenes/player_ent.c b/scenes/player_ent.c new file mode 100644 index 0000000..55f1231 --- /dev/null +++ b/scenes/player_ent.c @@ -0,0 +1,58 @@ +#include "ent_impl.h" +#include "constants.h" + +#define N_PLAYER_SPRITES 2 +enum PlayerSpriteEnum +{ + SPR_PLAYER_STAND = 0, + SPR_PLAYER_RUN +}; + +static const char* const player_sprite_map[N_PLAYER_SPRITES] = { + "plr_stand", + "plr_run", +}; + +static unsigned int player_sprite_transition_func(Entity_t* ent) +{ + return SPR_PLAYER_RUN; +} + +Entity_t* create_player(EntityManager_t* ent_manager, Assets_t* assets) +{ + Entity_t* p_ent = add_entity(ent_manager, PLAYER_ENT_TAG); + CBBox_t* p_bbox = add_component(ent_manager, p_ent, CBBOX_COMP_T); + + set_bbox(p_bbox, PLAYER_WIDTH, PLAYER_HEIGHT); + add_component(ent_manager, p_ent, CTRANSFORM_COMP_T); + + CJump_t* p_cjump = add_component(ent_manager, p_ent, CJUMP_COMP_T); + p_cjump->jump_speed = 680; + p_cjump->jumps = 1; + p_cjump->max_jumps = 1; + p_cjump->jump_ready = true; + add_component(ent_manager, p_ent, CPLAYERSTATE_T); + add_component(ent_manager, p_ent, CTILECOORD_COMP_T); + add_component(ent_manager, p_ent, CMOVEMENTSTATE_T); + CHitBoxes_t* p_hitbox = add_component(ent_manager, p_ent, CHITBOXES_T); + p_hitbox->n_boxes = 2; + p_hitbox->boxes[0] = (Rectangle) { + .x = 0, + .y = -1, + .width = p_bbox->size.x - 1, + .height = p_bbox->size.y + 2, + }; + p_hitbox->boxes[1] = (Rectangle) { + .x = -1, + .y = 0, + .width = p_bbox->size.x + 2, + .height = p_bbox->size.y - 1, + }; + CSprite_t* p_cspr = add_component(ent_manager, p_ent, CSPRITE_T); + p_cspr->sprite = get_sprite(assets, "plr_stand"); + p_cspr->offset = (Vector2){0, -20}; + p_cspr->sprites_map = player_sprite_map; + p_cspr->transition_func = &player_sprite_transition_func; + + return p_ent; +}