55 lines
1.7 KiB
C
55 lines
1.7 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "entityprefabplayer.h"
|
|
#include "entity/entitymanager.h"
|
|
#include "entity/component/display/entityposition.h"
|
|
#include "entity/component/display/entityrenderable.h"
|
|
#include "entity/component/physics/entityphysics.h"
|
|
#include "entity/component/trigger/entitytrigger.h"
|
|
#include "display/color.h"
|
|
|
|
errorret_t entityPrefabPlayerApply(
|
|
entitymanager_t *mgr,
|
|
const entityid_t entityId
|
|
) {
|
|
componentid_t posComp = entityAddComponent(
|
|
mgr, entityId, COMPONENT_TYPE_POSITION
|
|
);
|
|
vec3 startPos = { 0.0f, 5.0f, 0.0f };
|
|
entityPositionSetLocalPosition(mgr, entityId, posComp, startPos);
|
|
|
|
componentid_t renderComp = entityAddComponent(
|
|
mgr, entityId, COMPONENT_TYPE_RENDERABLE
|
|
);
|
|
entityRenderableSetColor(
|
|
mgr, entityId, renderComp, color4b(255, 80, 80, 255)
|
|
);
|
|
|
|
entityAddComponent(mgr, entityId, COMPONENT_TYPE_PLAYER);
|
|
|
|
componentid_t physComp = entityAddComponent(
|
|
mgr, entityId, COMPONENT_TYPE_PHYSICS
|
|
);
|
|
entityPhysicsSetBodyType(mgr, entityId, physComp, PHYSICS_BODY_DYNAMIC);
|
|
entityPhysicsSetCollideMask(mgr, entityId, physComp, 0x3);
|
|
|
|
// Interact box: a little larger than the player's own body, so nearby
|
|
// interactable entities overlap it without needing to touch the player
|
|
// exactly (see entityPlayerTryInteract()).
|
|
componentid_t interactComp = entityAddComponent(
|
|
mgr, entityId, COMPONENT_TYPE_TRIGGER
|
|
);
|
|
physicsshape_t interactShape = {
|
|
.type = PHYSICS_SHAPE_CUBE,
|
|
.data.cube.halfExtents = { 1.0f, 1.0f, 1.0f }
|
|
};
|
|
entityTriggerSetShape(mgr, entityId, interactComp, interactShape);
|
|
|
|
errorOk();
|
|
}
|