Add spawning urchin in editor

main
En Yi 2024-09-23 21:55:06 +08:00
parent 8a731637f7
commit b275caf795
2 changed files with 52 additions and 3 deletions

View File

@ -1,3 +1,4 @@
#include "EC.h"
#include "scene_impl.h"
#include "game_systems.h"
#include "water_flow.h"
@ -28,13 +29,20 @@ enum EntitySpawnSelection {
SPAWN_BOULDER,
SPAWN_WATER_RUNNER,
SPAWN_LEVEL_END,
SPAWN_URCHIN,
};
#define MAX_SPAWN_TYPE 16
#define MAX_SPAWN_TYPE 17
static unsigned int current_spawn_selection = 0;
static bool metal_toggle = false;
static bool crate_activation = false;
#define MAX_URCHIN_SPAWN_SPD 20
#define URCHIN_SPAWN_UI_RADIUS 40
#define URCHIN_VELOCITY_SCALE 10
static Vector2 urchin_spawn_vec = {0,0};
#define SELECTION_TILE_SIZE 32
#define SELECTION_TILE_HALFSIZE (SELECTION_TILE_SIZE >> 1)
#define SELECTION_GAP 5
@ -77,6 +85,7 @@ static char* get_spawn_selection_string(enum EntitySpawnSelection sel)
case SPAWN_BOULDER: return "boulder";
case SPAWN_WATER_RUNNER: return "water runner";
case SPAWN_LEVEL_END: return "level end";
case SPAWN_URCHIN: return "urchin";
default: return "unknown";
}
}
@ -134,6 +143,31 @@ static void level_scene_render_func(Scene_t* scene)
sprintf(buffer, "Camera mode: %s", data->camera.mode == CAMERA_FOLLOW_PLAYER ? "FOLLOW" : "FREE");
DrawText(buffer, draw_pos.x, draw_pos.y, 20, BLACK);
draw_pos.x = game_rec.x + game_rec.width - 50 - URCHIN_SPAWN_UI_RADIUS;
draw_pos.y = game_rec.y + game_rec.height + SELECTION_GAP + URCHIN_SPAWN_UI_RADIUS;
// Draw Urchin spawn info
DrawCircleV(draw_pos, 40, RED);
// HACK: because this ui is not stored, need to perform the mouse check here
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
{
Vector2 click_pos = Vector2Subtract(
scene->mouse_pos, draw_pos
);
float mag = Vector2Length(click_pos);
if (mag <= URCHIN_SPAWN_UI_RADIUS)
{
urchin_spawn_vec = Vector2Scale(
Vector2Normalize(click_pos),
mag
);
}
}
DrawCircleV(
Vector2Add(urchin_spawn_vec, draw_pos),
4, BLUE
);
// For DEBUG
const int gui_x = game_rec.x + game_rec.width + 10;
int gui_y = 15;
@ -746,7 +780,19 @@ static void toggle_block_system(Scene_t* scene, ActionType_t action, bool presse
if (p_ent != NULL)
{
p_ent->position.x = (tile_idx % tilemap.width) * tilemap.tile_size + (tilemap.tile_size >> 1);
p_ent->position.y = (tile_idx / tilemap.width) * tilemap.tile_size + (tilemap.tile_size >> 1);;
p_ent->position.y = (tile_idx / tilemap.width) * tilemap.tile_size + (tilemap.tile_size >> 1);
}
}
break;
case SPAWN_URCHIN:
{
Entity_t* p_ent = create_urchin(&scene->ent_manager);
if (p_ent != NULL)
{
p_ent->position.x = (tile_idx % tilemap.width) * tilemap.tile_size + (tilemap.tile_size >> 1);
p_ent->position.y = (tile_idx / tilemap.width) * tilemap.tile_size + (tilemap.tile_size >> 1);
CTransform_t* p_ct = get_component(p_ent, CTRANSFORM_COMP_T);
p_ct->velocity = Vector2Scale(urchin_spawn_vec, URCHIN_VELOCITY_SCALE);
}
}
break;
@ -1392,6 +1438,9 @@ void init_sandbox_scene(LevelScene_t* scene)
case SPAWN_LEVEL_END:
DrawCircleV(Vector2Add(draw_pos, half_size), half_size.x, GREEN);
break;
case SPAWN_URCHIN:
DrawCircleV(Vector2Add(draw_pos, half_size), half_size.x, RED);
break;
}
draw_pos.x += SELECTION_TILE_SIZE;

View File

@ -267,7 +267,7 @@ Entity_t* create_urchin(EntityManager_t* ent_manager)
CHitBoxes_t* p_hitbox = add_component(p_urchin, CHITBOXES_T);
p_hitbox->n_boxes = 1;
p_hitbox->boxes[0] = (Rectangle){3, 3, 26, 26};
p_hitbox->atk = 3;
p_hitbox->atk = 2;
CSprite_t* p_cspr = add_component(p_urchin, CSPRITE_T);
p_cspr->sprites = item_sprite_map;