Add weapons
This commit is contained in:
@@ -141,6 +141,31 @@ void entityFollowPath(ecs_iter_t *it) {
|
||||
}
|
||||
}
|
||||
|
||||
static void entityUpdateArm(ecs_entity_t armEntity, Position pos, Velocity vel,
|
||||
Rotation rot, Orientation orient) {
|
||||
if (!armEntity) return;
|
||||
const Arm arm = *ecs_get(ECS, armEntity, Arm);
|
||||
|
||||
Vector2 v = {arm.extended, 0.0f};
|
||||
v = Vector2Rotate(v, orient + arm.offset);
|
||||
v = Vector2Add(v, pos);
|
||||
ecs_set_ptr(ECS, armEntity, Position, &v);
|
||||
}
|
||||
void entityUpdateArms(ecs_iter_t *it) {
|
||||
Position *position = ecs_field(it, Position, 1);
|
||||
Velocity *velocity = ecs_field(it, Velocity, 2);
|
||||
Rotation *rotation = ecs_field(it, Rotation, 3);
|
||||
Orientation *orientation = ecs_field(it, Orientation, 4);
|
||||
Arms *arms = ecs_field(it, Arms, 5);
|
||||
|
||||
for (i32 i = 0; i < it->count; i++) {
|
||||
entityUpdateArm(arms[i].primary, position[i], velocity[i],
|
||||
rotation[i], orientation[i]);
|
||||
entityUpdateArm(arms[i].secondary, position[i], velocity[i],
|
||||
rotation[i], orientation[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void renderColliders(ecs_iter_t *it) {
|
||||
Position *pos = ecs_field(it, Position, 1);
|
||||
Size *size = ecs_field(it, Size, 2);
|
||||
@@ -152,19 +177,27 @@ void renderColliders(ecs_iter_t *it) {
|
||||
}
|
||||
}
|
||||
|
||||
void renderRotationDirection(ecs_iter_t *it) {
|
||||
void renderOrientationDirection(ecs_iter_t *it) {
|
||||
Position *pos = ecs_field(it, Position, 1);
|
||||
Rotation *rot = ecs_field(it, Rotation, 2);
|
||||
Orientation *orientation = ecs_field(it, Orientation, 2);
|
||||
|
||||
for (i32 i = 0; i < it->count; i++) {
|
||||
Vector2 v = {10.0f, 0.0f};
|
||||
v = Vector2Rotate(v, rot[i]);
|
||||
Vector2 v = {6.0f, 0.0f};
|
||||
v = Vector2Rotate(v, orientation[i]);
|
||||
v = Vector2Add(v, pos[i]);
|
||||
DrawCircle(v.x, v.y, 1.0f, RED);
|
||||
DrawLine(pos->x, pos->y, v.x, v.y, RED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void renderArmPosition(ecs_iter_t *it) {
|
||||
Position *pos = ecs_field(it, Position, 1);
|
||||
Arm *arm = ecs_field(it, Arm, 2);
|
||||
|
||||
for (i32 i = 0; i < it->count; i++) {
|
||||
DrawCircle(pos[i].x, pos[i].y, 1.5f, ORANGE);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void renderDebugPath(ecs_iter_t *it) {
|
||||
Path *path = ecs_field(it, Path, 1);
|
||||
|
||||
@@ -124,7 +124,12 @@ void inputUnitAction(Game *game, InputState *input) {
|
||||
while (ecs_iter_next(&it)) {
|
||||
for (i32 i = 0; i < it.count; i++) {
|
||||
const ecs_entity_t entity = it.entities[i];
|
||||
entitySetPath(entity, target, game);
|
||||
clearActions(entity, game);
|
||||
addAction(entity, game, &(const Action) {
|
||||
.type = ACTION_MOVE_TO,
|
||||
.as.moveTo.target = target,
|
||||
.as.moveTo.proximityThreshold = 6.0f,
|
||||
});
|
||||
}
|
||||
}
|
||||
ecs_defer_end(ECS);
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "../game_state.h"
|
||||
|
||||
ecs_entity_t renderCollidersSystem;
|
||||
ecs_entity_t renderOrientDirSystem;
|
||||
ecs_entity_t renderArmPositionSystem;
|
||||
ecs_entity_t renderDebugPathSystem;
|
||||
|
||||
ECS_DTOR(SpatialGridID, gridID, {
|
||||
@@ -43,6 +45,7 @@ void setupSystems() {
|
||||
|
||||
ECS_SYSTEM(ECS, entityMoveToTarget, EcsOnUpdate, Position, Velocity, TargetPosition, Steering);
|
||||
ECS_SYSTEM(ECS, entityFollowPath, EcsOnUpdate, Path);
|
||||
ECS_SYSTEM(ECS, entityUpdateArms, EcsOnUpdate, Position, Velocity, Rotation, Orientation, Arms);
|
||||
|
||||
ECS_SYSTEM(ECS, handleUnitActionsSystem, EcsOnUpdate, UnitAction);
|
||||
ECS_SYSTEM(ECS, updateUnitAISystem, EcsOnUpdate, UnitAI, UnitAction);
|
||||
@@ -56,9 +59,14 @@ void setupSystems() {
|
||||
ECS_SYSTEM(ECS, renderDebugPath, EcsOnUpdate, Path);
|
||||
|
||||
ECS_SYSTEM(ECS, renderColliders, EcsOnUpdate, Position, Size);
|
||||
ECS_SYSTEM(ECS, renderRotationDirection, EcsOnUpdate, Position, Rotation);
|
||||
ECS_SYSTEM(ECS, renderOrientationDirection, EcsOnUpdate, Position, Orientation);
|
||||
ECS_SYSTEM(ECS, renderArmPosition, EcsOnUpdate, Position, Arm);
|
||||
|
||||
renderDebugPathSystem = renderDebugPath;
|
||||
renderOrientDirSystem = renderOrientationDirection;
|
||||
renderArmPositionSystem = renderArmPosition;
|
||||
renderCollidersSystem = renderColliders;
|
||||
|
||||
ecs_enable(ECS, renderOrientDirSystem, false);
|
||||
ecs_enable(ECS, renderArmPositionSystem, false);
|
||||
}
|
||||
|
||||
@@ -101,6 +101,15 @@ void entityMoveToTarget(ecs_iter_t *it);
|
||||
*/
|
||||
void entityFollowPath(ecs_iter_t *it);
|
||||
|
||||
/*
|
||||
* 1. Position
|
||||
* 2. Velocity
|
||||
* 3. Rotation
|
||||
* 4. Orientation
|
||||
* 5. Arms
|
||||
*/
|
||||
void entityUpdateArms(ecs_iter_t *it);
|
||||
|
||||
|
||||
/*
|
||||
* 1: Position
|
||||
@@ -110,9 +119,15 @@ void renderColliders(ecs_iter_t *it);
|
||||
|
||||
/*
|
||||
* 1: Position
|
||||
* 2: Rotation
|
||||
* 2: Orientation
|
||||
*/
|
||||
void renderRotationDirection(ecs_iter_t *it);
|
||||
void renderOrientationDirection(ecs_iter_t *it);
|
||||
|
||||
/*
|
||||
* 1. Position
|
||||
* 2. Arm
|
||||
*/
|
||||
void renderArmPosition(ecs_iter_t *it);
|
||||
|
||||
/*
|
||||
* 1: Path
|
||||
@@ -161,6 +176,8 @@ void drawPlayerInputUI();
|
||||
**********************************/
|
||||
|
||||
extern ecs_entity_t renderCollidersSystem;
|
||||
extern ecs_entity_t renderOrientDirSystem;
|
||||
extern ecs_entity_t renderArmPositionSystem;
|
||||
extern ecs_entity_t renderDebugPathSystem;
|
||||
|
||||
void setupSystems();
|
||||
|
||||
Reference in New Issue
Block a user