Compare commits
2 Commits
03b602de40
...
0daa45f7a1
Author | SHA1 | Date |
---|---|---|
|
0daa45f7a1 | |
|
aa2125c8f6 |
|
@ -30,7 +30,7 @@ typedef struct _CTransform_t
|
||||||
// Thus the size of the entity cannot be larger than the tile
|
// Thus the size of the entity cannot be larger than the tile
|
||||||
typedef struct _CTileCoord_t
|
typedef struct _CTileCoord_t
|
||||||
{
|
{
|
||||||
unsigned int tiles[4];
|
unsigned int tiles[8];
|
||||||
unsigned int n_tiles;
|
unsigned int n_tiles;
|
||||||
}CTileCoord_t;
|
}CTileCoord_t;
|
||||||
|
|
||||||
|
|
42
scene_impl.c
42
scene_impl.c
|
@ -65,8 +65,7 @@ static void movement_update_system(Scene_t* scene)
|
||||||
sc_map_foreach_value(&scene->ent_manager.entities_map[PLAYER_ENT_TAG], p_player)
|
sc_map_foreach_value(&scene->ent_manager.entities_map[PLAYER_ENT_TAG], p_player)
|
||||||
{
|
{
|
||||||
CTransform_t* p_ctransform = get_component(&scene->ent_manager, p_player, CTRANSFORM_COMP_T);
|
CTransform_t* p_ctransform = get_component(&scene->ent_manager, p_player, CTRANSFORM_COMP_T);
|
||||||
p_ctransform->accel.x = data->player_dir.x * 200 * 1.0 / mag;
|
p_ctransform->accel = Vector2Scale(Vector2Normalize(data->player_dir), 600);
|
||||||
p_ctransform->accel.y = data->player_dir.y * 200 * 1.0 / mag;
|
|
||||||
}
|
}
|
||||||
data->player_dir.x = 0;
|
data->player_dir.x = 0;
|
||||||
data->player_dir.y = 0;
|
data->player_dir.y = 0;
|
||||||
|
@ -76,9 +75,12 @@ static void movement_update_system(Scene_t* scene)
|
||||||
CTransform_t * p_ctransform;
|
CTransform_t * p_ctransform;
|
||||||
sc_map_foreach_value(&scene->ent_manager.component_map[CTRANSFORM_COMP_T], p_ctransform)
|
sc_map_foreach_value(&scene->ent_manager.component_map[CTRANSFORM_COMP_T], p_ctransform)
|
||||||
{
|
{
|
||||||
p_ctransform->velocity = Vector2Add(
|
p_ctransform->velocity = Vector2Scale(
|
||||||
|
Vector2Add(
|
||||||
p_ctransform->velocity,
|
p_ctransform->velocity,
|
||||||
Vector2Scale(p_ctransform->accel, delta_time)
|
Vector2Scale(p_ctransform->accel, delta_time)
|
||||||
|
),
|
||||||
|
0.95
|
||||||
);
|
);
|
||||||
|
|
||||||
// Store previous position before update
|
// Store previous position before update
|
||||||
|
@ -119,32 +121,21 @@ static void update_tilemap_system(Scene_t *scene)
|
||||||
p_tilecoord->n_tiles = 0;
|
p_tilecoord->n_tiles = 0;
|
||||||
|
|
||||||
// Compute new occupied tile positions and add
|
// Compute new occupied tile positions and add
|
||||||
unsigned int tile_x = (p_ctransform->position.x) / TILE_SIZE;
|
unsigned int tile_x1 = (p_ctransform->position.x) / TILE_SIZE;
|
||||||
unsigned int tile_y = (p_ctransform->position.y) / TILE_SIZE;
|
unsigned int tile_y1 = (p_ctransform->position.y) / TILE_SIZE;
|
||||||
p_tilecoord->tiles[0] = tile_y * tilemap.width + tile_x;
|
unsigned int tile_x2 = (p_ctransform->position.x + p_bbox->size.x) / TILE_SIZE;
|
||||||
p_tilecoord->n_tiles++;
|
unsigned int tile_y2 = (p_ctransform->position.y + p_bbox->size.y) / TILE_SIZE;
|
||||||
|
|
||||||
bool check_x = (tile_x + 1) < tilemap.width;
|
for (unsigned int tile_y=tile_y1; tile_y <= tile_y2; tile_y++)
|
||||||
bool check_y = (tile_y + 1) < tilemap.height;
|
|
||||||
if (check_x)
|
|
||||||
{
|
{
|
||||||
p_tilecoord->tiles[p_tilecoord->n_tiles++] = p_tilecoord->tiles[0] + 1;
|
for (unsigned int tile_x=tile_x1; tile_x <= tile_x2; tile_x++)
|
||||||
}
|
|
||||||
if (check_y)
|
|
||||||
{
|
{
|
||||||
p_tilecoord->tiles[p_tilecoord->n_tiles++] = p_tilecoord->tiles[0] + tilemap.width;
|
unsigned int tile_idx = tile_y * tilemap.width + tile_x;
|
||||||
}
|
p_tilecoord->tiles[p_tilecoord->n_tiles++] = tile_idx;
|
||||||
if (check_x && check_y)
|
|
||||||
{
|
|
||||||
p_tilecoord->tiles[p_tilecoord->n_tiles++] = p_tilecoord->tiles[0] + tilemap.width + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i=0;i<p_tilecoord->n_tiles;++i)
|
|
||||||
{
|
|
||||||
unsigned int tile_idx = p_tilecoord->tiles[i];
|
|
||||||
sc_map_put_64(&(tilemap.tiles[tile_idx].entities_set), p_ent->m_id, 0);
|
sc_map_put_64(&(tilemap.tiles[tile_idx].entities_set), p_ent->m_id, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void player_collision_system(Scene_t *scene)
|
static void player_collision_system(Scene_t *scene)
|
||||||
|
@ -240,9 +231,10 @@ void init_level_scene(LevelScene_t *scene)
|
||||||
sc_map_put_64(&scene->scene.action_map, KEY_LEFT, ACTION_LEFT);
|
sc_map_put_64(&scene->scene.action_map, KEY_LEFT, ACTION_LEFT);
|
||||||
sc_map_put_64(&scene->scene.action_map, KEY_RIGHT, ACTION_RIGHT);
|
sc_map_put_64(&scene->scene.action_map, KEY_RIGHT, ACTION_RIGHT);
|
||||||
|
|
||||||
scene->data.tilemap.width = 16;
|
scene->data.tilemap.width = 32;
|
||||||
scene->data.tilemap.height = 16;
|
scene->data.tilemap.height = 16;
|
||||||
scene->data.tilemap.n_tiles = 16*16;
|
assert(32*16 <= MAX_N_TILES);
|
||||||
|
scene->data.tilemap.n_tiles = 32*16;
|
||||||
scene->data.tilemap.tiles = all_tiles;
|
scene->data.tilemap.tiles = all_tiles;
|
||||||
for (size_t i=0; i<MAX_N_TILES;i++)
|
for (size_t i=0; i<MAX_N_TILES;i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,7 +9,7 @@ struct sc_queue_32 key_buffer;
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
sc_queue_init(&key_buffer);
|
sc_queue_init(&key_buffer);
|
||||||
InitWindow(640, 640, "raylib");
|
InitWindow(1280, 640, "raylib");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
init_memory_pools();
|
init_memory_pools();
|
||||||
LevelScene_t scene;
|
LevelScene_t scene;
|
||||||
|
@ -18,7 +18,7 @@ int main(void)
|
||||||
|
|
||||||
CBBox_t *p_bbox = add_component(&scene.scene.ent_manager, p_ent, CBBOX_COMP_T);
|
CBBox_t *p_bbox = add_component(&scene.scene.ent_manager, p_ent, CBBOX_COMP_T);
|
||||||
p_bbox->size.x = 30;
|
p_bbox->size.x = 30;
|
||||||
p_bbox->size.y = 30;
|
p_bbox->size.y = 45;
|
||||||
add_component(&scene.scene.ent_manager, p_ent, CTRANSFORM_COMP_T);
|
add_component(&scene.scene.ent_manager, p_ent, CTRANSFORM_COMP_T);
|
||||||
add_component(&scene.scene.ent_manager, p_ent, CTILECOORD_COMP_T);
|
add_component(&scene.scene.ent_manager, p_ent, CTILECOORD_COMP_T);
|
||||||
update_entity_manager(&scene.scene.ent_manager);
|
update_entity_manager(&scene.scene.ent_manager);
|
||||||
|
|
Loading…
Reference in New Issue