Compare commits

..

No commits in common. "9859854baa4b7928191ae3473b0664bc6b68848c" and "b70dcc1e98f0d8b514a97f8b0f07e4679cc0e672" have entirely different histories.

1 changed files with 130 additions and 209 deletions

View File

@ -15,22 +15,14 @@ enum EntitySpawnSelection {
TOGGLE_ONEWAY, TOGGLE_ONEWAY,
TOGGLE_LADDER, TOGGLE_LADDER,
TOGGLE_SPIKE, TOGGLE_SPIKE,
TOGGLE_WATER,
SPAWN_CRATE, SPAWN_CRATE,
SPAWN_METAL_CRATE, SPAWN_METAL_CRATE,
SPAWN_BOULDER, SPAWN_BOULDER,
}; };
#define MAX_SPAWN_TYPE 8 #define MAX_SPAWN_TYPE 7
static unsigned int current_spawn_selection = 0; static unsigned int current_spawn_selection = 0;
#define SELECTION_TILE_SIZE 32
#define SELECTION_TILE_HALFSIZE (SELECTION_TILE_SIZE >> 1)
#define SELECTION_GAP 5
#define SELECTION_REGION_WIDTH (SELECTION_TILE_SIZE * MAX_SPAWN_TYPE)
#define SELECTION_REGION_HEIGHT SELECTION_TILE_SIZE
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)
{ {
unsigned int tile_x = x / TILE_SIZE; unsigned int tile_x = x / TILE_SIZE;
@ -52,7 +44,6 @@ static char* get_spawn_selection_string(enum EntitySpawnSelection sel)
case TOGGLE_ONEWAY: return "wooden tile"; case TOGGLE_ONEWAY: return "wooden tile";
case TOGGLE_LADDER: return "ladder"; case TOGGLE_LADDER: return "ladder";
case TOGGLE_SPIKE: return "spike"; case TOGGLE_SPIKE: return "spike";
case TOGGLE_WATER: return "water";
case SPAWN_CRATE: return "wooden crate"; case SPAWN_CRATE: return "wooden crate";
case SPAWN_METAL_CRATE: return "metal crate"; case SPAWN_METAL_CRATE: return "metal crate";
case SPAWN_BOULDER: return "boulder"; case SPAWN_BOULDER: return "boulder";
@ -77,13 +68,6 @@ static void level_scene_render_func(Scene_t* scene)
int y = (i / tilemap.width) * TILE_SIZE; int y = (i / tilemap.width) * TILE_SIZE;
sprintf(buffer, "%u", sc_map_size_64v(&tilemap.tiles[i].entities_set)); sprintf(buffer, "%u", sc_map_size_64v(&tilemap.tiles[i].entities_set));
if (!tilemap.tiles[i].moveable)
{
// Draw water tile
Color water_colour = ColorAlpha(RED, 0.2);
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, water_colour);
}
if (data->tile_sprites[tilemap.tiles[i].tile_type] != NULL) if (data->tile_sprites[tilemap.tiles[i].tile_type] != NULL)
{ {
draw_sprite(data->tile_sprites[tilemap.tiles[i].tile_type], (Vector2){x,y}, false); draw_sprite(data->tile_sprites[tilemap.tiles[i].tile_type], (Vector2){x,y}, false);
@ -114,6 +98,12 @@ static void level_scene_render_func(Scene_t* scene)
Color water_colour = ColorAlpha(BLUE, 0.5); Color water_colour = ColorAlpha(BLUE, 0.5);
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, water_colour); DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, water_colour);
} }
if (!tilemap.tiles[i].moveable)
{
// Draw water tile
Color water_colour = ColorAlpha(RED, 0.2);
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, water_colour);
}
} }
char buffer[64] = {0}; char buffer[64] = {0};
@ -226,49 +216,6 @@ static void level_scene_render_func(Scene_t* scene)
(Vector2){data->game_rec.x, data->game_rec.y}, (Vector2){data->game_rec.x, data->game_rec.y},
WHITE WHITE
); );
Vector2 draw_pos = {data->game_rec.x, data->game_rec.y + data->game_rec.height + SELECTION_GAP};
const Color draw_colour[MAX_SPAWN_TYPE] = {BLACK, MAROON, ORANGE, ColorAlpha(RAYWHITE, 0.5), ColorAlpha(BLUE, 0.5), BROWN, GRAY, ColorAlpha(RAYWHITE, 0.5)};
for (uint8_t i = 0; i < MAX_SPAWN_TYPE; ++i)
{
if (i != current_spawn_selection)
{
DrawRectangle(draw_pos.x, draw_pos.y, SELECTION_TILE_SIZE, SELECTION_TILE_SIZE, draw_colour[i]);
switch (i)
{
case 3:
DrawRectangle(draw_pos.x, draw_pos.y + SELECTION_TILE_HALFSIZE, SELECTION_TILE_SIZE, SELECTION_TILE_HALFSIZE, RED);
break;
case 7:
{
Vector2 half_size = {SELECTION_TILE_HALFSIZE, SELECTION_TILE_HALFSIZE};
DrawCircleV(Vector2Add(draw_pos, half_size), half_size.x, GRAY);
}
break;
}
}
draw_pos.x += SELECTION_TILE_SIZE;
}
draw_pos.x = data->game_rec.x + current_spawn_selection * SELECTION_TILE_SIZE;
DrawRectangle(
draw_pos.x - 2, draw_pos.y - 2,
SELECTION_TILE_SIZE + 4, SELECTION_TILE_SIZE + 4, GREEN
);
DrawRectangle(draw_pos.x, draw_pos.y, SELECTION_TILE_SIZE, SELECTION_TILE_SIZE, draw_colour[current_spawn_selection]);
switch (current_spawn_selection)
{
case 3:
DrawRectangle(draw_pos.x, draw_pos.y + SELECTION_TILE_HALFSIZE, SELECTION_TILE_SIZE, SELECTION_TILE_HALFSIZE, RED);
break;
case 7:
{
const Vector2 half_size = {SELECTION_TILE_HALFSIZE, SELECTION_TILE_HALFSIZE};
DrawCircleV(Vector2Add(draw_pos, half_size), half_size.x, GRAY);
}
break;
}
// For DEBUG // For DEBUG
const int gui_x = data->game_rec.x + data->game_rec.width + 10; const int gui_x = data->game_rec.x + data->game_rec.width + 10;
sc_map_foreach_value(&scene->ent_manager.entities_map[PLAYER_ENT_TAG], p_ent) sc_map_foreach_value(&scene->ent_manager.entities_map[PLAYER_ENT_TAG], p_ent)
@ -334,18 +281,19 @@ static void toggle_block_system(Scene_t* scene)
Vector2 raw_mouse_pos = {GetMouseX(), GetMouseY()}; Vector2 raw_mouse_pos = {GetMouseX(), GetMouseY()};
raw_mouse_pos = Vector2Subtract(raw_mouse_pos, (Vector2){data->game_rec.x, data->game_rec.y}); raw_mouse_pos = Vector2Subtract(raw_mouse_pos, (Vector2){data->game_rec.x, data->game_rec.y});
if (
raw_mouse_pos.x < data->game_rec.width
&& raw_mouse_pos.y < data->game_rec.height
)
{
Vector2 mouse_pos = GetScreenToWorld2D(raw_mouse_pos, data->cam);
unsigned int tile_idx = get_tile_idx(mouse_pos.x, mouse_pos.y, &tilemap);
if (tile_idx >= MAX_N_TILES) return;
if (tile_idx == last_tile_idx) return;
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
{ {
if (
raw_mouse_pos.x > data->game_rec.width
|| raw_mouse_pos.y > data->game_rec.height
) return;
Vector2 mouse_pos = GetScreenToWorld2D(raw_mouse_pos, data->cam);
unsigned int tile_idx = get_tile_idx(mouse_pos.x, mouse_pos.y, &tilemap);
if (tile_idx >= MAX_N_TILES) return;
enum EntitySpawnSelection sel = (enum EntitySpawnSelection)current_spawn_selection; enum EntitySpawnSelection sel = (enum EntitySpawnSelection)current_spawn_selection;
if (tile_idx != last_tile_idx)
{
switch (sel) switch (sel)
{ {
case TOGGLE_TILE: case TOGGLE_TILE:
@ -409,16 +357,6 @@ static void toggle_block_system(Scene_t* scene)
} }
tilemap.tiles[tile_idx].solid = NOT_SOLID; tilemap.tiles[tile_idx].solid = NOT_SOLID;
break; break;
case TOGGLE_WATER:
if (tilemap.tiles[tile_idx].water_level == 0)
{
tilemap.tiles[tile_idx].water_level = MAX_WATER_LEVEL;
}
else
{
tilemap.tiles[tile_idx].water_level = 0;
}
break;
case SPAWN_CRATE: case SPAWN_CRATE:
spawn_crate(scene, tile_idx, false); spawn_crate(scene, tile_idx, false);
break; break;
@ -429,7 +367,6 @@ static void toggle_block_system(Scene_t* scene)
spawn_boulder(scene, tile_idx); spawn_boulder(scene, tile_idx);
break; break;
} }
if (tilemap.tiles[tile_idx].tile_type == SPIKES) if (tilemap.tiles[tile_idx].tile_type == SPIKES)
{ {
// Priority: Down, Up, Left, Right // Priority: Down, Up, Left, Right
@ -470,50 +407,34 @@ static void toggle_block_system(Scene_t* scene)
|| tilemap.tiles[tile_idx].tile_type == SPIKES || tilemap.tiles[tile_idx].tile_type == SPIKES
); );
} }
}
else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON))
{ {
tilemap.tiles[tile_idx].tile_type = EMPTY_TILE; if (
tilemap.tiles[tile_idx].solid = NOT_SOLID; raw_mouse_pos.x > data->game_rec.width
tilemap.tiles[tile_idx].water_level = 0; || raw_mouse_pos.y > data->game_rec.height
tilemap.tiles[tile_idx].moveable = true; ) return;
Vector2 mouse_pos = GetScreenToWorld2D(raw_mouse_pos, data->cam);
Entity_t* ent; unsigned int tile_idx = get_tile_idx(mouse_pos.x, mouse_pos.y, &tilemap);
unsigned int m_id; if (tile_idx >= MAX_N_TILES) return;
sc_map_foreach(&tilemap.tiles[tile_idx].entities_set, m_id, ent) if (tile_idx != last_tile_idx)
{ {
if (ent->m_tag == PLAYER_ENT_TAG) continue; if (tilemap.tiles[tile_idx].water_level == 0)
CTileCoord_t* p_tilecoord = get_component(
ent, CTILECOORD_COMP_T
);
for (size_t i = 0;i < p_tilecoord->n_tiles; ++i)
{ {
// Use previously store tile position tilemap.tiles[tile_idx].water_level = MAX_WATER_LEVEL;
// Clear from those positions
unsigned int tile_idx = p_tilecoord->tiles[i];
sc_map_del_64v(&(tilemap.tiles[tile_idx].entities_set), m_id);
} }
remove_entity(&scene->ent_manager, m_id); else
{
tilemap.tiles[tile_idx].water_level = 0;
}
last_tile_idx = tile_idx;
} }
} }
else else
{ {
last_tile_idx = MAX_N_TILES; last_tile_idx = MAX_N_TILES;
} }
return;
}
raw_mouse_pos = Vector2Subtract(raw_mouse_pos, (Vector2){0, data->game_rec.height});
if (
raw_mouse_pos.x < SELECTION_REGION_WIDTH
&& raw_mouse_pos.y < SELECTION_REGION_HEIGHT
)
{
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
{
current_spawn_selection = ((int)raw_mouse_pos.x / SELECTION_TILE_SIZE);
}
}
} }
void level_do_action(Scene_t* scene, ActionType_t action, bool pressed) void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)