Files
simian/scripts/ball.as
nick bc99a1e53c
CI / build-and-test (push) Successful in 2m41s
Sync Docs to Gitea Wiki / Sync docs to Gitea wiki (push) Successful in 11s
feat: Globals value store as well
2026-03-13 14:50:53 +13:00

51 lines
1.4 KiB
ActionScript 3

// Class-based entity script: one `EntityScript` instance per entity.
// Implements Init/Update/Shutdown so the engine will instantiate it per-entity.
class EntityScript
{
float baseX;
float baseY;
float baseZ;
[group["Movement"]][desc["Phase accumulator for the sine wave"]][editable][range[0,1]]float phase;
// per-instance movement parameters (can be tuned per-entity)
[group["Movement"]][desc["Bounce height"]][editable][range[0,10]]float amplitude = 2.5f;
[group["Movement"]][desc["Cycles per second"]][editable][range[0,10]]float speed = 2.5f;
[group["State"]][desc["Debug animation state"]][editable][options[Idle,Walk,Run]] int state = 0;
EntityScript()
{
baseX = 0.0f;
baseY = 0.0f;
baseZ = 0.0f;
phase = 0.0f;
}
void Init(uint entity)
{
if (!ECS::IsValid(entity)) return;
if (!ECS::HasTransform(entity))
ECS::AddTransform(entity, 0.0f, 0.0f, 0.0f);
ECS::GetPosition(entity, baseX, baseY, baseZ);
phase = 0.0f;
}
void Update(uint entity, float dt)
{
if (!ECS::IsValid(entity)) return;
if (!ECS::HasTransform(entity)) return;
phase += dt;
float offset = Math::Sin(phase * speed + float(entity) * 0.1f) * amplitude;
ECS::SetPosition(entity, baseX, baseY + offset, baseZ);
ECS::SetRotationEuler(entity, 0.0f, phase * 50.0f * dt, 0.0f);
}
void Shutdown(uint entity)
{
// nothing to clean up per-instance for this simple example
}
}