198 lines
8.3 KiB
C++
198 lines
8.3 KiB
C++
#if defined(__clang__)
|
|
#pragma once
|
|
#include "feely_pona_unity.h"
|
|
#endif
|
|
|
|
static void FP_Entity_AddDebugEditorFlags(FP_Game *game, FP_GameEntityHandle handle)
|
|
{
|
|
FP_GameEntity *entity = FP_Game_GetEntity(game, handle);
|
|
if (!FP_Game_IsNilEntity(entity)) {
|
|
entity->flags |= FP_GameEntityFlag_Clickable;
|
|
entity->flags |= FP_GameEntityFlag_MoveByKeyboard;
|
|
entity->flags |= FP_GameEntityFlag_MoveByMouse;
|
|
entity->flags |= FP_GameEntityFlag_MoveByGamepad;
|
|
}
|
|
}
|
|
|
|
static Dqn_f32 FP_Entity_CalcSpriteScaleForDesiredHeight(FP_Game *game, FP_Meters height, Dqn_Rect sprite_rect)
|
|
{
|
|
Dqn_f32 sprite_in_meters = FP_Game_PixelsToMetersNx1(game, sprite_rect.size.y);
|
|
Dqn_f32 result = height.meters / sprite_in_meters;
|
|
return result;
|
|
}
|
|
|
|
static FP_GameEntityHandle FP_Entity_CreateWaypointF(FP_Game *game, Dqn_V2 pos, DQN_FMT_STRING_ANNOTATE char const *fmt, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
FP_GameEntity *entity = FP_Game_MakeEntityPointerFV(game, fmt, args);
|
|
FP_GameEntityHandle result = entity->handle;
|
|
va_end(args);
|
|
|
|
entity->local_pos = pos;
|
|
entity->local_hit_box_size = Dqn_V2_InitNx1(32);
|
|
FP_Entity_AddDebugEditorFlags(game, entity->handle);
|
|
entity->flags |= FP_GameEntityFlag_MobSpawnerWaypoint;
|
|
|
|
FP_GameShape *shape = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes);
|
|
shape->type = FP_GameShapeType_Circle;
|
|
shape->circle_radius = 16.f;
|
|
shape->render_mode = TELY_RenderShapeMode_Line;
|
|
shape->colour = TELY_COLOUR_BLUE_CADET_V4;
|
|
return result;
|
|
}
|
|
|
|
static FP_GameEntityHandle FP_Entity_CreateClinger(FP_Game *game, Dqn_V2 pos, DQN_FMT_STRING_ANNOTATE char const *fmt, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
FP_GameEntity *entity = FP_Game_MakeEntityPointerFV(game, fmt, args);
|
|
FP_GameEntityHandle result = entity->handle;
|
|
va_end(args);
|
|
|
|
entity->type = FP_EntityType_Clinger;
|
|
entity->hp = 1;
|
|
entity->is_dying = false;
|
|
entity->base_acceleration_per_s.meters = 8.f;
|
|
entity->local_pos = pos;
|
|
entity->sprite_height.meters = 1.6f;
|
|
entity->attack_cooldown_ms = 1000;
|
|
|
|
entity->local_hit_box_size = FP_Game_MetersToPixelsNx2(game, 0.4f, entity->sprite_height.meters * .5f);
|
|
FP_Entity_AddDebugEditorFlags(game, entity->handle);
|
|
entity->flags |= FP_GameEntityFlag_NonTraversable;
|
|
entity->flags |= FP_GameEntityFlag_Attackable;
|
|
return result;
|
|
}
|
|
|
|
static FP_GameEntityHandle FP_Entity_CreateSmoochie(FP_Game *game, Dqn_V2 pos, DQN_FMT_STRING_ANNOTATE char const *fmt, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
FP_GameEntity *entity = FP_Game_MakeEntityPointerFV(game, fmt, args);
|
|
FP_GameEntityHandle result = entity->handle;
|
|
va_end(args);
|
|
|
|
entity->type = FP_EntityType_Smoochie;
|
|
entity->base_acceleration_per_s.meters = 8.f;
|
|
entity->hp = 1;
|
|
entity->is_dying = false;
|
|
entity->local_pos = pos;
|
|
entity->sprite_height.meters = 1.6f;
|
|
entity->attack_cooldown_ms = 1000;
|
|
entity->local_hit_box_size = FP_Game_MetersToPixelsNx2(game, 0.4f, entity->sprite_height.meters * .6f);
|
|
FP_Entity_AddDebugEditorFlags(game, entity->handle);
|
|
entity->flags |= FP_GameEntityFlag_NonTraversable;
|
|
entity->flags |= FP_GameEntityFlag_Attackable;
|
|
return result;
|
|
}
|
|
|
|
static FP_GameEntityHandle FP_Entity_CreateWallAtTile(FP_Game *game, Dqn_String8 name, Dqn_V2I tile_pos, Dqn_V2I size_in_tiles)
|
|
{
|
|
Dqn_V2 size = Dqn_V2_InitV2I(size_in_tiles * DQN_CAST(int32_t) game->tile_size);
|
|
Dqn_V2 world_pos = FP_Game_TilePosToWorldPos(game, tile_pos);
|
|
world_pos += size * .5f;
|
|
|
|
FP_GameEntity *entity = FP_Game_MakeEntityPointerF(game, name.data);
|
|
FP_GameEntityHandle result = entity->handle;
|
|
entity->local_pos = world_pos;
|
|
entity->local_hit_box_size = Dqn_V2_InitV2I(size_in_tiles * DQN_CAST(int32_t)game->tile_size);
|
|
FP_Entity_AddDebugEditorFlags(game, entity->handle);
|
|
entity->flags |= FP_GameEntityFlag_NonTraversable;
|
|
|
|
FP_GameShape *wall = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes);
|
|
wall->type = FP_GameShapeType_Rect;
|
|
wall->p2 = entity->local_hit_box_size;
|
|
wall->colour = TELY_COLOUR_GREEN_DARK_KHAKI_V4;
|
|
return result;
|
|
}
|
|
|
|
static FP_GameEntityHandle FP_Entity_CreateMobSpawner(FP_Game *game, Dqn_V2 pos, Dqn_usize spawn_cap, char const *fmt, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
FP_GameEntity *entity = FP_Game_MakeEntityPointerFV(game, fmt, args);
|
|
FP_GameEntityHandle result = entity->handle;
|
|
va_end(args);
|
|
|
|
entity->local_pos = pos;
|
|
entity->local_hit_box_size = Dqn_V2_InitNx1(32);
|
|
FP_Entity_AddDebugEditorFlags(game, result);
|
|
entity->flags |= FP_GameEntityFlag_MobSpawner;
|
|
|
|
entity->spawn_cap = spawn_cap;
|
|
entity->spawn_list = FP_SentinelList_Init<FP_GameEntityHandle>(game->chunk_pool);
|
|
|
|
FP_GameShape *shape = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes);
|
|
shape->type = FP_GameShapeType_Rect;
|
|
shape->p1 = {};
|
|
shape->p2 = entity->local_hit_box_size;
|
|
shape->render_mode = TELY_RenderShapeMode_Line;
|
|
shape->colour = TELY_COLOUR_BLUE_CADET_V4;
|
|
return result;
|
|
}
|
|
|
|
static FP_GameEntityHandle FP_Entity_CreateTerry(FP_Game *game, Dqn_V2 pos, DQN_FMT_STRING_ANNOTATE char const *fmt, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
FP_GameEntity *entity = FP_Game_MakeEntityPointerFV(game, fmt, args);
|
|
FP_GameEntityHandle result = entity->handle;
|
|
va_end(args);
|
|
|
|
entity->type = FP_EntityType_Terry;
|
|
entity->local_pos = pos;
|
|
entity->base_acceleration_per_s.meters = 16.f;
|
|
entity->sprite_height.meters = 1.8f;
|
|
entity->attack_cooldown_ms = 500;
|
|
entity->local_hit_box_size = FP_Game_MetersToPixelsNx2(game, 0.5f, entity->sprite_height.meters * .6f);
|
|
FP_Entity_AddDebugEditorFlags(game, result);
|
|
entity->flags |= FP_GameEntityFlag_NonTraversable;
|
|
entity->flags |= FP_GameEntityFlag_Attackable;
|
|
entity->flags |= FP_GameEntityFlag_CameraTracking;
|
|
return result;
|
|
}
|
|
|
|
static FP_GameEntityHandle FP_Entity_CreateMerchant(FP_Game *game, Dqn_V2 pos, DQN_FMT_STRING_ANNOTATE char const *fmt, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
FP_GameEntity *entity = FP_Game_MakeEntityPointerFV(game, fmt, args);
|
|
FP_GameEntityHandle result = entity->handle;
|
|
va_end(args);
|
|
|
|
entity->type = FP_EntityType_Merchant;
|
|
entity->local_pos = pos;
|
|
entity->local_hit_box_size = Dqn_V2_InitNx2(50, 50);
|
|
entity->sprite_height.meters = 3.66f;
|
|
FP_Entity_AddDebugEditorFlags(game, result);
|
|
entity->flags |= FP_GameEntityFlag_NonTraversable;
|
|
|
|
return result;
|
|
}
|
|
|
|
static FP_GameEntityHandle FP_Entity_CreateClubTerry(FP_Game *game, Dqn_V2 pos, DQN_FMT_STRING_ANNOTATE char const *fmt, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
FP_GameEntity *entity = FP_Game_MakeEntityPointerFV(game, fmt, args);
|
|
FP_GameEntityHandle result = entity->handle;
|
|
va_end(args);
|
|
|
|
entity->type = FP_EntityType_ClubTerry;
|
|
entity->local_pos = pos;
|
|
entity->sprite_height.meters = 4.f;
|
|
|
|
TELY_AssetSpriteAnimation *sprite_anim = TELY_Asset_GetSpriteAnimation(&game->club_terry_sprite_sheet, g_anim_names.club_terry_alive);
|
|
Dqn_Rect sprite_rect = game->club_terry_sprite_sheet.rects.data[sprite_anim->index];
|
|
Dqn_f32 size_scale = FP_Entity_CalcSpriteScaleForDesiredHeight(game, entity->sprite_height, sprite_rect);
|
|
Dqn_V2 sprite_rect_scaled = sprite_rect.size * size_scale;
|
|
|
|
entity->local_hit_box_size = Dqn_V2_InitNx2(sprite_rect_scaled.w, sprite_rect_scaled.h - (sprite_rect_scaled.h * .4f));
|
|
FP_Entity_AddDebugEditorFlags(game, result);
|
|
entity->flags |= FP_GameEntityFlag_NonTraversable;
|
|
|
|
return result;
|
|
}
|
|
|