Integrate water runner into main scene
parent
0a76826c27
commit
ec8f8b6a36
|
@ -1,5 +1,6 @@
|
||||||
#include "scene_impl.h"
|
#include "scene_impl.h"
|
||||||
#include "game_systems.h"
|
#include "game_systems.h"
|
||||||
|
#include "water_flow.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "ent_impl.h"
|
#include "ent_impl.h"
|
||||||
#include "mempool.h"
|
#include "mempool.h"
|
||||||
|
@ -23,9 +24,10 @@ enum EntitySpawnSelection {
|
||||||
SPAWN_CRATE_ARROW_D,
|
SPAWN_CRATE_ARROW_D,
|
||||||
SPAWN_CRATE_BOMB,
|
SPAWN_CRATE_BOMB,
|
||||||
SPAWN_BOULDER,
|
SPAWN_BOULDER,
|
||||||
|
SPAWN_WATER_RUNNER,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_SPAWN_TYPE 12
|
#define MAX_SPAWN_TYPE 13
|
||||||
static unsigned int current_spawn_selection = 0;
|
static unsigned int current_spawn_selection = 0;
|
||||||
static bool metal_toggle = false;
|
static bool metal_toggle = false;
|
||||||
|
|
||||||
|
@ -49,21 +51,6 @@ static inline unsigned int get_tile_idx(int x, int y, const TileGrid_t* tilemap)
|
||||||
return MAX_N_TILES;
|
return MAX_N_TILES;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* get_spawn_selection_string(enum EntitySpawnSelection sel)
|
|
||||||
{
|
|
||||||
switch(sel)
|
|
||||||
{
|
|
||||||
case TOGGLE_TILE: return "solid tile";
|
|
||||||
case TOGGLE_ONEWAY: return "wooden tile";
|
|
||||||
case TOGGLE_LADDER: return "ladder";
|
|
||||||
case TOGGLE_SPIKE: return "spike";
|
|
||||||
case TOGGLE_WATER: return "water";
|
|
||||||
case SPAWN_CRATE: return "crate";
|
|
||||||
case SPAWN_BOULDER: return "boulder";
|
|
||||||
default: return "unknown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void level_scene_render_func(Scene_t* scene)
|
static void level_scene_render_func(Scene_t* scene)
|
||||||
{
|
{
|
||||||
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
||||||
|
@ -248,6 +235,14 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sc_map_foreach_value(&scene->ent_manager.entities_map[DYNMEM_ENT_TAG], p_ent)
|
||||||
|
{
|
||||||
|
CWaterRunner_t* p_runner = get_component(p_ent, CWATERRUNNER_T);
|
||||||
|
|
||||||
|
unsigned int x = ((p_runner->current_tile) % tilemap.width) * tilemap.tile_size;
|
||||||
|
unsigned int y = ((p_runner->current_tile) / tilemap.width) * tilemap.tile_size;
|
||||||
|
DrawCircle(x+16, y+16, 8, ColorAlpha(BLUE, 0.6));
|
||||||
|
}
|
||||||
for (size_t i = 0; i < tilemap.n_tiles; ++i)
|
for (size_t i = 0; i < tilemap.n_tiles; ++i)
|
||||||
{
|
{
|
||||||
int x = (i % tilemap.width) * TILE_SIZE;
|
int x = (i % tilemap.width) * TILE_SIZE;
|
||||||
|
@ -297,7 +292,7 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
const Color draw_colour[MAX_SPAWN_TYPE] = {
|
const Color draw_colour[MAX_SPAWN_TYPE] = {
|
||||||
BLACK, MAROON, ORANGE, ColorAlpha(RAYWHITE, 0.5), ColorAlpha(BLUE, 0.5),
|
BLACK, MAROON, ORANGE, ColorAlpha(RAYWHITE, 0.5), ColorAlpha(BLUE, 0.5),
|
||||||
crate_colour, crate_colour, crate_colour, crate_colour, crate_colour, crate_colour,
|
crate_colour, crate_colour, crate_colour, crate_colour, crate_colour, crate_colour,
|
||||||
ColorAlpha(RAYWHITE, 0.5)
|
ColorAlpha(RAYWHITE, 0.5), ColorAlpha(RAYWHITE, 0.5)
|
||||||
};
|
};
|
||||||
for (uint8_t i = 0; i < MAX_SPAWN_TYPE; ++i)
|
for (uint8_t i = 0; i < MAX_SPAWN_TYPE; ++i)
|
||||||
{
|
{
|
||||||
|
@ -352,6 +347,9 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
case SPAWN_CRATE_BOMB:
|
case SPAWN_CRATE_BOMB:
|
||||||
DrawCircleV(Vector2Add(draw_pos, half_size), half_size.x, BLACK);
|
DrawCircleV(Vector2Add(draw_pos, half_size), half_size.x, BLACK);
|
||||||
break;
|
break;
|
||||||
|
case SPAWN_WATER_RUNNER:
|
||||||
|
DrawCircleV(Vector2Add(draw_pos, half_size), half_size.x, ColorAlpha(BLUE, 0.2));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
draw_pos.x += SELECTION_TILE_SIZE;
|
draw_pos.x += SELECTION_TILE_SIZE;
|
||||||
|
@ -411,6 +409,9 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
case SPAWN_CRATE_BOMB:
|
case SPAWN_CRATE_BOMB:
|
||||||
DrawCircleV(Vector2Add(draw_pos, half_size), half_size.x, BLACK);
|
DrawCircleV(Vector2Add(draw_pos, half_size), half_size.x, BLACK);
|
||||||
break;
|
break;
|
||||||
|
case SPAWN_WATER_RUNNER:
|
||||||
|
DrawCircleV(Vector2Add(draw_pos, half_size), half_size.x, ColorAlpha(BLUE, 0.2));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For DEBUG
|
// For DEBUG
|
||||||
|
@ -436,8 +437,8 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
sprintf(buffer, "Ladder: %u", p_pstate->ladder_state);
|
sprintf(buffer, "Ladder: %u", p_pstate->ladder_state);
|
||||||
DrawText(buffer, gui_x, 150, 12, BLACK);
|
DrawText(buffer, gui_x, 150, 12, BLACK);
|
||||||
}
|
}
|
||||||
sprintf(buffer, "Spawn Entity: %s", get_spawn_selection_string(current_spawn_selection));
|
//sprintf(buffer, "Spawn Entity: %s", get_spawn_selection_string(current_spawn_selection));
|
||||||
DrawText(buffer, gui_x, 240, 12, BLACK);
|
//DrawText(buffer, gui_x, 240, 12, BLACK);
|
||||||
sprintf(buffer, "Number of Entities: %u", sc_map_size_64v(&scene->ent_manager.entities));
|
sprintf(buffer, "Number of Entities: %u", sc_map_size_64v(&scene->ent_manager.entities));
|
||||||
DrawText(buffer, gui_x, 270, 12, BLACK);
|
DrawText(buffer, gui_x, 270, 12, BLACK);
|
||||||
sprintf(buffer, "FPS: %u", GetFPS());
|
sprintf(buffer, "FPS: %u", GetFPS());
|
||||||
|
@ -540,9 +541,25 @@ static void toggle_block_system(Scene_t* scene)
|
||||||
case SPAWN_CRATE_BOMB:
|
case SPAWN_CRATE_BOMB:
|
||||||
spawn_crate(scene, tile_idx, metal_toggle, CONTAINER_BOMB);
|
spawn_crate(scene, tile_idx, metal_toggle, CONTAINER_BOMB);
|
||||||
break;
|
break;
|
||||||
|
case SPAWN_WATER_RUNNER:
|
||||||
|
{
|
||||||
|
Entity_t* p_ent = create_water_runner(&scene->ent_manager, DEFAULT_MAP_WIDTH, DEFAULT_MAP_HEIGHT, tile_idx);
|
||||||
|
if (p_ent != NULL)
|
||||||
|
{
|
||||||
|
CTransform_t* p_ct = get_component(p_ent, CTRANSFORM_COMP_T);
|
||||||
|
p_ct->position.x = (tile_idx % tilemap.width) * tilemap.tile_size;
|
||||||
|
p_ct->position.y = (tile_idx / tilemap.width) * tilemap.tile_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
change_a_tile(&tilemap, tile_idx, new_type);
|
change_a_tile(&tilemap, tile_idx, new_type);
|
||||||
last_tile_idx = tile_idx;
|
last_tile_idx = tile_idx;
|
||||||
|
CWaterRunner_t* p_crunner;
|
||||||
|
sc_map_foreach_value(&scene->ent_manager.component_map[CWATERRUNNER_T], p_crunner)
|
||||||
|
{
|
||||||
|
p_crunner->state = BFS_RESET;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON))
|
else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON))
|
||||||
{
|
{
|
||||||
|
@ -565,8 +582,17 @@ static void toggle_block_system(Scene_t* scene)
|
||||||
unsigned int tile_idx = p_tilecoord->tiles[i];
|
unsigned int tile_idx = p_tilecoord->tiles[i];
|
||||||
sc_map_del_64v(&(tilemap.tiles[tile_idx].entities_set), m_id);
|
sc_map_del_64v(&(tilemap.tiles[tile_idx].entities_set), m_id);
|
||||||
}
|
}
|
||||||
|
//remove_entity(&scene->ent_manager, m_id);
|
||||||
|
CWaterRunner_t* p_crunner = get_component(ent, CWATERRUNNER_T);
|
||||||
|
if (p_crunner == NULL)
|
||||||
|
{
|
||||||
remove_entity(&scene->ent_manager, m_id);
|
remove_entity(&scene->ent_manager, m_id);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
free_water_runner(ent, &scene->ent_manager);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -673,6 +699,7 @@ void init_level_scene(LevelScene_t* scene)
|
||||||
sc_array_add(&scene->scene.systems, &camera_update_system);
|
sc_array_add(&scene->scene.systems, &camera_update_system);
|
||||||
sc_array_add(&scene->scene.systems, &player_dir_reset_system);
|
sc_array_add(&scene->scene.systems, &player_dir_reset_system);
|
||||||
sc_array_add(&scene->scene.systems, &player_respawn_system);
|
sc_array_add(&scene->scene.systems, &player_respawn_system);
|
||||||
|
sc_array_add(&scene->scene.systems, &update_water_runner_system);
|
||||||
sc_array_add(&scene->scene.systems, &toggle_block_system);
|
sc_array_add(&scene->scene.systems, &toggle_block_system);
|
||||||
|
|
||||||
// This avoid graphical glitch, not essential
|
// This avoid graphical glitch, not essential
|
||||||
|
|
Loading…
Reference in New Issue