Compare commits
No commits in common. "b5f026c96be8a775d400539e20580289cb0c2720" and "a4c9a0d97ca001d64ed0d7b1af4c2079b992e7ff" have entirely different histories.
b5f026c96b
...
a4c9a0d97c
|
@ -1,5 +1,4 @@
|
||||||
#include "mempool.h"
|
#include "mempool.h"
|
||||||
#include "ent_impl.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
|
|
@ -16,10 +16,9 @@ enum EntitySpawnSelection {
|
||||||
TOGGLE_LADDER,
|
TOGGLE_LADDER,
|
||||||
SPAWN_CRATE,
|
SPAWN_CRATE,
|
||||||
SPAWN_METAL_CRATE,
|
SPAWN_METAL_CRATE,
|
||||||
SPAWN_BOULDER,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_SPAWN_TYPE 6
|
#define MAX_SPAWN_TYPE 5
|
||||||
static unsigned int current_spawn_selection = 0;
|
static unsigned int current_spawn_selection = 0;
|
||||||
|
|
||||||
static inline unsigned int get_tile_idx(int x, int y, const TileGrid_t* tilemap)
|
static inline unsigned int get_tile_idx(int x, int y, const TileGrid_t* tilemap)
|
||||||
|
@ -91,22 +90,10 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
case CRATES_ENT_TAG:
|
case CRATES_ENT_TAG:
|
||||||
colour = p_bbox->fragile? BROWN : GRAY;
|
colour = p_bbox->fragile? BROWN : GRAY;
|
||||||
break;
|
break;
|
||||||
case BOULDER_ENT_TAG:
|
|
||||||
colour = GRAY;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
colour = BLACK;
|
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);
|
CHurtbox_t* p_hurtbox = get_component(p_ent, CHURTBOX_T);
|
||||||
CHitBoxes_t* p_hitbox = get_component(p_ent, CHITBOXES_T);
|
CHitBoxes_t* p_hitbox = get_component(p_ent, CHITBOXES_T);
|
||||||
if (p_hitbox != NULL)
|
if (p_hitbox != NULL)
|
||||||
|
@ -233,16 +220,6 @@ static void spawn_crate(Scene_t* scene, unsigned int tile_idx, bool metal)
|
||||||
p_ctransform->position.y = (tile_idx / data->tilemap.width) * TILE_SIZE;
|
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)
|
static void toggle_block_system(Scene_t* scene)
|
||||||
{
|
{
|
||||||
// TODO: This system is not good as the interface between raw input and actions is broken
|
// TODO: This system is not good as the interface between raw input and actions is broken
|
||||||
|
@ -323,9 +300,6 @@ static void toggle_block_system(Scene_t* scene)
|
||||||
case SPAWN_METAL_CRATE:
|
case SPAWN_METAL_CRATE:
|
||||||
spawn_crate(scene, tile_idx, true);
|
spawn_crate(scene, tile_idx, true);
|
||||||
break;
|
break;
|
||||||
case SPAWN_BOULDER:
|
|
||||||
spawn_boulder(scene, tile_idx);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
last_tile_idx = tile_idx;
|
last_tile_idx = tile_idx;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
#include "sc/map/sc_map.h"
|
#include "sc/map/sc_map.h"
|
||||||
#include "sc/queue/sc_queue.h"
|
#include "sc/queue/sc_queue.h"
|
||||||
|
|
||||||
#define N_TAGS 5
|
#define N_TAGS 4
|
||||||
#define N_COMPONENTS 11
|
#define N_COMPONENTS 10
|
||||||
#define MAX_COMP_POOL_SIZE 1024
|
#define MAX_COMP_POOL_SIZE 1024
|
||||||
typedef struct EntityManager EntityManager_t;
|
typedef struct EntityManager EntityManager_t;
|
||||||
typedef struct Entity Entity_t;
|
typedef struct Entity Entity_t;
|
||||||
|
@ -23,7 +23,6 @@ typedef enum ComponentEnum {
|
||||||
CHITBOXES_T,
|
CHITBOXES_T,
|
||||||
CHURTBOX_T,
|
CHURTBOX_T,
|
||||||
CSPRITE_T,
|
CSPRITE_T,
|
||||||
CMOVEABLE_T,
|
|
||||||
} ComponentEnum_t;
|
} ComponentEnum_t;
|
||||||
|
|
||||||
typedef struct _CBBox_t {
|
typedef struct _CBBox_t {
|
||||||
|
@ -136,13 +135,6 @@ typedef struct _CSprite_t {
|
||||||
bool pause;
|
bool pause;
|
||||||
} CSprite_t;
|
} 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)
|
static inline void set_bbox(CBBox_t* p_bbox, unsigned int x, unsigned int y)
|
||||||
{
|
{
|
||||||
p_bbox->size.x = x;
|
p_bbox->size.x = x;
|
||||||
|
@ -151,9 +143,16 @@ static inline void set_bbox(CBBox_t* p_bbox, unsigned int x, unsigned int y)
|
||||||
p_bbox->half_size.y = (unsigned int)(y / 2);
|
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 {
|
struct Entity {
|
||||||
unsigned long m_id;
|
unsigned long m_id;
|
||||||
unsigned int m_tag;
|
EntityTag_t m_tag;
|
||||||
bool m_alive;
|
bool m_alive;
|
||||||
unsigned long components[N_COMPONENTS];
|
unsigned long components[N_COMPONENTS];
|
||||||
EntityManager_t* manager;
|
EntityManager_t* manager;
|
||||||
|
@ -173,7 +172,7 @@ void update_entity_manager(EntityManager_t* p_manager);
|
||||||
void clear_entity_manager(EntityManager_t* p_manager);
|
void clear_entity_manager(EntityManager_t* p_manager);
|
||||||
void free_entity_manager(EntityManager_t* p_manager);
|
void free_entity_manager(EntityManager_t* p_manager);
|
||||||
|
|
||||||
Entity_t* add_entity(EntityManager_t* p_manager, unsigned int tag);
|
Entity_t* add_entity(EntityManager_t* p_manager, EntityTag_t tag);
|
||||||
void remove_entity(EntityManager_t* p_manager, unsigned long id);
|
void remove_entity(EntityManager_t* p_manager, unsigned long id);
|
||||||
Entity_t *get_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);
|
sc_queue_term(&p_manager->to_remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity_t *add_entity(EntityManager_t* p_manager, unsigned int tag)
|
Entity_t *add_entity(EntityManager_t* p_manager, EntityTag_t tag)
|
||||||
{
|
{
|
||||||
unsigned long e_idx = 0;
|
unsigned long e_idx = 0;
|
||||||
Entity_t* p_ent = new_entity_from_mempool(&e_idx);
|
Entity_t* p_ent = new_entity_from_mempool(&e_idx);
|
||||||
|
|
|
@ -17,7 +17,6 @@ static CContainer_t ccontainer_buffer[MAX_COMP_POOL_SIZE];
|
||||||
static CHitBoxes_t chitboxes_buffer[MAX_COMP_POOL_SIZE];
|
static CHitBoxes_t chitboxes_buffer[MAX_COMP_POOL_SIZE];
|
||||||
static CHurtbox_t churtbox_buffer[MAX_COMP_POOL_SIZE];
|
static CHurtbox_t churtbox_buffer[MAX_COMP_POOL_SIZE];
|
||||||
static CSprite_t csprite_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 {
|
typedef struct ULongCircBuffer {
|
||||||
unsigned long* buffer; // data buffer
|
unsigned long* buffer; // data buffer
|
||||||
|
@ -87,7 +86,6 @@ static MemPool_t comp_mempools[N_COMPONENTS] = {
|
||||||
{chitboxes_buffer, MAX_COMP_POOL_SIZE, sizeof(CHitBoxes_t), NULL, {0}},
|
{chitboxes_buffer, MAX_COMP_POOL_SIZE, sizeof(CHitBoxes_t), NULL, {0}},
|
||||||
{churtbox_buffer, MAX_COMP_POOL_SIZE, sizeof(CHurtbox_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}},
|
{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 = {
|
static MemPool_t ent_mempool = {
|
||||||
.buffer = entity_buffer,
|
.buffer = entity_buffer,
|
||||||
|
@ -157,7 +155,7 @@ Entity_t* new_entity_from_mempool(unsigned long* e_idx_ptr)
|
||||||
ent->components[j] = MAX_COMP_POOL_SIZE;
|
ent->components[j] = MAX_COMP_POOL_SIZE;
|
||||||
}
|
}
|
||||||
ent->m_alive = true;
|
ent->m_alive = true;
|
||||||
ent->m_tag = 0;
|
ent->m_tag = NO_ENT_TAG;
|
||||||
return ent;
|
return ent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,18 +2,8 @@
|
||||||
#define __ENT_IMPL_H
|
#define __ENT_IMPL_H
|
||||||
#include "assets.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);
|
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_player(EntityManager_t* ent_manager, Assets_t* assets);
|
||||||
Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool metal);
|
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
|
#endif // __ENT_IMPL_H
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "game_systems.h"
|
#include "game_systems.h"
|
||||||
#include "ent_impl.h"
|
|
||||||
#include "AABB.h"
|
#include "AABB.h"
|
||||||
#include "EC.h"
|
#include "EC.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
|
|
@ -18,22 +18,3 @@ Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool meta
|
||||||
p_hurtbox->fragile = !metal;
|
p_hurtbox->fragile = !metal;
|
||||||
return p_crate;
|
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