Compare commits
2 Commits
a4c9a0d97c
...
b5f026c96b
Author | SHA1 | Date |
---|---|---|
|
b5f026c96b | |
|
29c9b4eec7 |
|
@ -1,4 +1,5 @@
|
|||
#include "mempool.h"
|
||||
#include "ent_impl.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
|
|
|
@ -16,9 +16,10 @@ enum EntitySpawnSelection {
|
|||
TOGGLE_LADDER,
|
||||
SPAWN_CRATE,
|
||||
SPAWN_METAL_CRATE,
|
||||
SPAWN_BOULDER,
|
||||
};
|
||||
|
||||
#define MAX_SPAWN_TYPE 5
|
||||
#define MAX_SPAWN_TYPE 6
|
||||
static unsigned int current_spawn_selection = 0;
|
||||
|
||||
static inline unsigned int get_tile_idx(int x, int y, const TileGrid_t* tilemap)
|
||||
|
@ -90,10 +91,22 @@ static void level_scene_render_func(Scene_t* scene)
|
|||
case CRATES_ENT_TAG:
|
||||
colour = p_bbox->fragile? BROWN : GRAY;
|
||||
break;
|
||||
case BOULDER_ENT_TAG:
|
||||
colour = GRAY;
|
||||
break;
|
||||
default:
|
||||
colour = BLACK;
|
||||
break;
|
||||
}
|
||||
|
||||
if (p_ent->m_tag == BOULDER_ENT_TAG)
|
||||
{
|
||||
DrawCircleV(Vector2Add(p_ct->position, p_bbox->half_size), p_bbox->half_size.x, colour);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawRectangle(p_ct->position.x, p_ct->position.y, p_bbox->size.x, p_bbox->size.y, colour);
|
||||
}
|
||||
DrawRectangle(p_ct->position.x, p_ct->position.y, p_bbox->size.x, p_bbox->size.y, colour);
|
||||
CHurtbox_t* p_hurtbox = get_component(p_ent, CHURTBOX_T);
|
||||
CHitBoxes_t* p_hitbox = get_component(p_ent, CHITBOXES_T);
|
||||
if (p_hitbox != NULL)
|
||||
|
@ -220,6 +233,16 @@ static void spawn_crate(Scene_t* scene, unsigned int tile_idx, bool metal)
|
|||
p_ctransform->position.y = (tile_idx / data->tilemap.width) * TILE_SIZE;
|
||||
}
|
||||
|
||||
static void spawn_boulder(Scene_t* scene, unsigned int tile_idx)
|
||||
{
|
||||
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
||||
Entity_t* p_boulder = create_boulder(&scene->ent_manager, &scene->engine->assets);
|
||||
|
||||
CTransform_t* p_ctransform = get_component(p_boulder, CTRANSFORM_COMP_T);
|
||||
p_ctransform->position.x = (tile_idx % data->tilemap.width) * TILE_SIZE;
|
||||
p_ctransform->position.y = (tile_idx / data->tilemap.width) * TILE_SIZE;
|
||||
}
|
||||
|
||||
static void toggle_block_system(Scene_t* scene)
|
||||
{
|
||||
// TODO: This system is not good as the interface between raw input and actions is broken
|
||||
|
@ -300,6 +323,9 @@ static void toggle_block_system(Scene_t* scene)
|
|||
case SPAWN_METAL_CRATE:
|
||||
spawn_crate(scene, tile_idx, true);
|
||||
break;
|
||||
case SPAWN_BOULDER:
|
||||
spawn_boulder(scene, tile_idx);
|
||||
break;
|
||||
}
|
||||
last_tile_idx = tile_idx;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#include "sc/map/sc_map.h"
|
||||
#include "sc/queue/sc_queue.h"
|
||||
|
||||
#define N_TAGS 4
|
||||
#define N_COMPONENTS 10
|
||||
#define N_TAGS 5
|
||||
#define N_COMPONENTS 11
|
||||
#define MAX_COMP_POOL_SIZE 1024
|
||||
typedef struct EntityManager EntityManager_t;
|
||||
typedef struct Entity Entity_t;
|
||||
|
@ -23,6 +23,7 @@ typedef enum ComponentEnum {
|
|||
CHITBOXES_T,
|
||||
CHURTBOX_T,
|
||||
CSPRITE_T,
|
||||
CMOVEABLE_T,
|
||||
} ComponentEnum_t;
|
||||
|
||||
typedef struct _CBBox_t {
|
||||
|
@ -135,6 +136,13 @@ typedef struct _CSprite_t {
|
|||
bool pause;
|
||||
} CSprite_t;
|
||||
|
||||
typedef struct _CMoveable_t {
|
||||
uint16_t move_speed;
|
||||
Vector2 prev_pos;
|
||||
Vector2 target_pos;
|
||||
bool gridmove;
|
||||
} CMoveable_t;
|
||||
|
||||
static inline void set_bbox(CBBox_t* p_bbox, unsigned int x, unsigned int y)
|
||||
{
|
||||
p_bbox->size.x = x;
|
||||
|
@ -143,16 +151,9 @@ static inline void set_bbox(CBBox_t* p_bbox, unsigned int x, unsigned int y)
|
|||
p_bbox->half_size.y = (unsigned int)(y / 2);
|
||||
}
|
||||
|
||||
typedef enum EntityTag {
|
||||
NO_ENT_TAG,
|
||||
PLAYER_ENT_TAG,
|
||||
ENEMY_ENT_TAG,
|
||||
CRATES_ENT_TAG,
|
||||
} EntityTag_t;
|
||||
|
||||
struct Entity {
|
||||
unsigned long m_id;
|
||||
EntityTag_t m_tag;
|
||||
unsigned int m_tag;
|
||||
bool m_alive;
|
||||
unsigned long components[N_COMPONENTS];
|
||||
EntityManager_t* manager;
|
||||
|
@ -172,7 +173,7 @@ void update_entity_manager(EntityManager_t* p_manager);
|
|||
void clear_entity_manager(EntityManager_t* p_manager);
|
||||
void free_entity_manager(EntityManager_t* p_manager);
|
||||
|
||||
Entity_t* add_entity(EntityManager_t* p_manager, EntityTag_t tag);
|
||||
Entity_t* add_entity(EntityManager_t* p_manager, unsigned int tag);
|
||||
void remove_entity(EntityManager_t* p_manager, unsigned long id);
|
||||
Entity_t *get_entity(EntityManager_t* p_manager, unsigned long id);
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ void free_entity_manager(EntityManager_t* p_manager)
|
|||
sc_queue_term(&p_manager->to_remove);
|
||||
}
|
||||
|
||||
Entity_t *add_entity(EntityManager_t* p_manager, EntityTag_t tag)
|
||||
Entity_t *add_entity(EntityManager_t* p_manager, unsigned int tag)
|
||||
{
|
||||
unsigned long e_idx = 0;
|
||||
Entity_t* p_ent = new_entity_from_mempool(&e_idx);
|
||||
|
|
|
@ -17,6 +17,7 @@ static CContainer_t ccontainer_buffer[MAX_COMP_POOL_SIZE];
|
|||
static CHitBoxes_t chitboxes_buffer[MAX_COMP_POOL_SIZE];
|
||||
static CHurtbox_t churtbox_buffer[MAX_COMP_POOL_SIZE];
|
||||
static CSprite_t csprite_buffer[MAX_COMP_POOL_SIZE];
|
||||
static CMoveable_t cmoveable_buffer[MAX_COMP_POOL_SIZE];
|
||||
|
||||
typedef struct ULongCircBuffer {
|
||||
unsigned long* buffer; // data buffer
|
||||
|
@ -86,6 +87,7 @@ static MemPool_t comp_mempools[N_COMPONENTS] = {
|
|||
{chitboxes_buffer, MAX_COMP_POOL_SIZE, sizeof(CHitBoxes_t), NULL, {0}},
|
||||
{churtbox_buffer, MAX_COMP_POOL_SIZE, sizeof(CHurtbox_t), NULL, {0}},
|
||||
{csprite_buffer, MAX_COMP_POOL_SIZE, sizeof(CSprite_t), NULL, {0}},
|
||||
{cmoveable_buffer, MAX_COMP_POOL_SIZE, sizeof(CMoveable_t), NULL, {0}},
|
||||
};
|
||||
static MemPool_t ent_mempool = {
|
||||
.buffer = entity_buffer,
|
||||
|
@ -155,7 +157,7 @@ Entity_t* new_entity_from_mempool(unsigned long* e_idx_ptr)
|
|||
ent->components[j] = MAX_COMP_POOL_SIZE;
|
||||
}
|
||||
ent->m_alive = true;
|
||||
ent->m_tag = NO_ENT_TAG;
|
||||
ent->m_tag = 0;
|
||||
return ent;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,18 @@
|
|||
#define __ENT_IMPL_H
|
||||
#include "assets.h"
|
||||
|
||||
typedef enum EntityTag {
|
||||
NO_ENT_TAG = 0,
|
||||
PLAYER_ENT_TAG,
|
||||
ENEMY_ENT_TAG,
|
||||
CRATES_ENT_TAG,
|
||||
BOULDER_ENT_TAG,
|
||||
} EntityTag_t;
|
||||
|
||||
|
||||
bool init_player_creation(const char* info_file, Assets_t* assets);
|
||||
Entity_t* create_player(EntityManager_t* ent_manager, Assets_t* assets);
|
||||
Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool metal);
|
||||
Entity_t* create_boulder(EntityManager_t* ent_manager, Assets_t* assets);
|
||||
|
||||
#endif // __ENT_IMPL_H
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "game_systems.h"
|
||||
#include "ent_impl.h"
|
||||
#include "AABB.h"
|
||||
#include "EC.h"
|
||||
#include "constants.h"
|
||||
|
|
|
@ -18,3 +18,22 @@ Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool meta
|
|||
p_hurtbox->fragile = !metal;
|
||||
return p_crate;
|
||||
}
|
||||
|
||||
Entity_t* create_boulder(EntityManager_t* ent_manager, Assets_t* assets)
|
||||
{
|
||||
Entity_t* p_boulder = add_entity(ent_manager, BOULDER_ENT_TAG);
|
||||
CBBox_t* p_bbox = add_component(p_boulder, CBBOX_COMP_T);
|
||||
|
||||
set_bbox(p_bbox, TILE_SIZE, TILE_SIZE);
|
||||
p_bbox->solid = true;
|
||||
p_bbox->fragile = false;
|
||||
|
||||
add_component(p_boulder, CTRANSFORM_COMP_T);
|
||||
add_component(p_boulder, CMOVEMENTSTATE_T);
|
||||
add_component(p_boulder, CTILECOORD_COMP_T);
|
||||
add_component(p_boulder, CMOVEABLE_T);
|
||||
CHurtbox_t* p_hurtbox = add_component(p_boulder, CHURTBOX_T);
|
||||
p_hurtbox->size = p_bbox->size;
|
||||
p_hurtbox->fragile = false;
|
||||
return p_boulder;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue