Compare commits

...

3 Commits

Author SHA1 Message Date
En Yi 8a39f85c45 Change key to toggle grid 2023-11-23 21:53:36 +08:00
En Yi f3d48281f5 Adjust bubbles draw position 2023-11-23 20:53:04 +08:00
En Yi d5c6d05558 Add action to set spawn point 2023-11-23 20:52:51 +08:00
4 changed files with 33 additions and 13 deletions

View File

@ -17,5 +17,6 @@ typedef enum ActionType
ACTION_NEXTLEVEL,
ACTION_PREVLEVEL,
ACTION_TOGGLE_GRID,
ACTION_SET_SPAWNPOINT,
}ActionType_t;
#endif // __ACTIONS_H

View File

@ -79,7 +79,9 @@ static inline unsigned int get_tile_idx(int x, int y, const TileGrid_t* tilemap)
return MAX_N_TILES;
}
// This means you might be able to have two editor scene without running into problems
static RenderTexture2D selection_section;
#define SELECTION_RENDER_HEIGHT (SELECTION_REGION_HEIGHT * 3)
static void level_scene_render_func(Scene_t* scene)
{
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
@ -98,7 +100,7 @@ static void level_scene_render_func(Scene_t* scene)
WHITE
);
draw_rec.width = SELECTION_REGION_WIDTH;
draw_rec.height = -(SELECTION_REGION_HEIGHT * 2 + 10);
draw_rec.height = -SELECTION_RENDER_HEIGHT;
Vector2 draw_pos = {data->game_rec.x, data->game_rec.y + data->game_rec.height + SELECTION_GAP};
@ -291,6 +293,12 @@ static void render_editor_game_scene(Scene_t* scene)
CTransform_t* p_ct = get_component(p_ent, CTRANSFORM_COMP_T);
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
// Draw the spawn point
if (p_ent->m_tag == PLAYER_ENT_TAG)
{
DrawCircleV(p_ent->spawn_pos, 6, PURPLE);
}
// Entity culling
Vector2 box_size = {0};
if (p_bbox != NULL) box_size = p_bbox->size;
@ -787,9 +795,11 @@ static void restart_editor_level(Scene_t* scene)
static void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
{
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
CPlayerState_t* p_playerstate;
sc_map_foreach_value(&scene->ent_manager.component_map[CPLAYERSTATE_T], p_playerstate)
Entity_t* p_player;
//sc_map_foreach_value(&scene->ent_manager.component_map[CPLAYERSTATE_T], p_playerstate)
sc_map_foreach_value(&scene->ent_manager.entities_map[PLAYER_ENT_TAG], p_player)
{
CPlayerState_t* p_playerstate = get_component(p_player, CPLAYERSTATE_T);
switch(action)
{
case ACTION_UP:
@ -898,6 +908,12 @@ static void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
data->show_grid = !data->show_grid;
}
break;
case ACTION_SET_SPAWNPOINT:
{
CTransform_t* p_ct = get_component(p_player, CTRANSFORM_COMP_T);
p_player->spawn_pos = p_ct->position;
}
break;
default:
break;
}
@ -923,7 +939,7 @@ void init_sandbox_scene(LevelScene_t* scene)
unsigned int tile_idx = (scene->data.tilemap.height - 1) * scene->data.tilemap.width + i;
change_a_tile(&scene->data.tilemap, tile_idx, SOLID_TILE);
}
selection_section = LoadRenderTexture(SELECTION_REGION_WIDTH, SELECTION_REGION_HEIGHT * 2 + 10);
selection_section = LoadRenderTexture(SELECTION_REGION_WIDTH, SELECTION_RENDER_HEIGHT);
BeginTextureMode(selection_section);
ClearBackground(LIGHTGRAY);
@ -1000,7 +1016,7 @@ void init_sandbox_scene(LevelScene_t* scene)
}
draw_pos.y += SELECTION_TILE_SIZE + 2;
DrawText("R to reset the map, Q/E to cycle the selection,\nF to toggle metal crates. T to toggle crate spawn behaviour", 0, draw_pos.y, 14, BLACK);
DrawText("R to reset the map, Q/E to cycle the selection,\nF to toggle metal crates. T to toggle crate spawn behaviour\nB to toggle grid, V to set spawn point", 0, draw_pos.y, 14, BLACK);
EndTextureMode();
@ -1060,7 +1076,8 @@ void init_sandbox_scene(LevelScene_t* scene)
sc_map_put_64(&scene->scene.action_map, KEY_T, ACTION_CRATE_ACTIVATION);
sc_map_put_64(&scene->scene.action_map, KEY_L, ACTION_EXIT);
sc_map_put_64(&scene->scene.action_map, KEY_R, ACTION_RESTART);
sc_map_put_64(&scene->scene.action_map, KEY_H, ACTION_TOGGLE_GRID);
sc_map_put_64(&scene->scene.action_map, KEY_B, ACTION_TOGGLE_GRID);
sc_map_put_64(&scene->scene.action_map, KEY_V, ACTION_SET_SPAWNPOINT);
}

View File

@ -1504,9 +1504,9 @@ void update_entity_emitter_system(Scene_t* scene)
{
Entity_t* p_ent = get_entity(&scene->ent_manager, ent_idx);
CTransform_t* p_ctransform = get_component(p_ent, CTRANSFORM_COMP_T);
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
Vector2 new_pos = p_ctransform->position;
new_pos.y += p_bbox->half_size.y;
//CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
Vector2 new_pos = Vector2Add(p_ctransform->position,p_emitter->offset);
//new_pos.y += p_bbox->half_size.y;
if (is_emitter_handle_alive(&scene->part_sys, p_emitter->handle))
{
update_emitter_handle_position(&scene->part_sys, p_emitter->handle, new_pos);
@ -1936,13 +1936,14 @@ void airtimer_update_system(Scene_t* scene)
{
if (!is_emitter_handle_alive(&scene->part_sys, p_emitter->handle))
{
Vector2 new_pos = p_ctransform->position;
new_pos.y += p_bbox->half_size.y;
//Vector2 new_pos = p_ctransform->position;
//new_pos.y += p_bbox->half_size.y;
ParticleEmitter_t emitter = {
.spr = get_sprite(&scene->engine->assets, "p_water"),
.config = get_emitter_conf(&scene->engine->assets, "pe_bubbling"),
.position = new_pos,
//.position = new_pos,
.position = p_ctransform->position,
.n_particles = 5,
.user_data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data),
.update_func = &floating_particle_system_update,

View File

@ -105,7 +105,8 @@ Entity_t* create_player(EntityManager_t* ent_manager)
p_cspr->sprites = player_sprite_map;
p_cspr->transition_func = &player_sprite_transition_func;
add_component(p_ent, CEMITTER_T);
CEmitter_t* p_emitter = add_component(p_ent, CEMITTER_T);
p_emitter->offset = (Vector2){7,0};
return p_ent;
}