Add spawn entity selection via mouse
Changelog: - Add row below game scene to select spawning entity - Add mouse release logic to select spawning entity - Update render order for tile - order: 'moveable' -> tile -> water levelscene_man
parent
f206d3c981
commit
9859854baa
|
@ -24,6 +24,13 @@ enum EntitySpawnSelection {
|
||||||
#define MAX_SPAWN_TYPE 8
|
#define MAX_SPAWN_TYPE 8
|
||||||
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;
|
||||||
|
@ -70,6 +77,13 @@ 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);
|
||||||
|
@ -100,12 +114,6 @@ 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};
|
||||||
|
@ -219,11 +227,46 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
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)
|
for (uint8_t i = 0; i < MAX_SPAWN_TYPE; ++i)
|
||||||
{
|
{
|
||||||
DrawRectangle(data->game_rec.x + i * 32, data->game_rec.y + data->game_rec.height + 5, 32, 32, (i == current_spawn_selection) ? GREEN : RAYWHITE );
|
if (i != current_spawn_selection)
|
||||||
sprintf(buffer, "%u", i);
|
{
|
||||||
DrawText(buffer, data->game_rec.x + i * 32, data->game_rec.y + data->game_rec.height + 5, 12, BLACK);
|
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
|
||||||
|
@ -457,6 +500,19 @@ static void toggle_block_system(Scene_t* scene)
|
||||||
{
|
{
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue