Refactor out implementation of Player Entity
parent
7b3685b792
commit
3580209f71
|
@ -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
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
#include "assets_maps.h"
|
||||
|
||||
|
||||
const char* const player_sprite_map[N_PLAYER_SPRITES] = {
|
||||
"plr_stand",
|
||||
"plr_run",
|
||||
};
|
|
@ -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
|
|
@ -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 <stdio.h>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
|
@ -1,7 +1,6 @@
|
|||
#include "game_systems.h"
|
||||
#include "AABB.h"
|
||||
#include "constants.h"
|
||||
#include "assets_maps.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue