Tweak wave times, fix Unit modification

This commit is contained in:
2024-02-13 15:55:14 +01:00
parent d8c7bb7074
commit 40712e13a9
4 changed files with 52 additions and 45 deletions

View File

@@ -9,7 +9,7 @@ ecs_entity_t entityCreateEmpty() {
}
ecs_entity_t entityCreateBaseUnit(const Position position, f32 size, Player player,
EntityType type, AnimType startAnim, Game *game) {
EntityType type, AnimType startAnim, Unit *unit, Game *game) {
BzTileset *tileset = &game->tileset;
BzTileID tileID = getEntityTile(type);
TextureRegion region = {
@@ -55,50 +55,55 @@ ecs_entity_t entityCreateBaseUnit(const Position position, f32 size, Player play
});
ecs_set(ECS, e, AIBlackboard, {.entity = e});
ecs_add_id(ECS, e, Selectable);
ecs_set(ECS, e, Unit, {
.attackElapsed = 0.0f,
.attackCooldown = 1.0f,
.minDamage = 1.0f,
.maxDamage = 2.0f,
.acceleration = 80.0f,
.maxSpeed = 15.0f,
.deceleration = 0.1f,
.unitType = type
});
Unit unitComp = {
.attackElapsed = 0.0f,
.attackCooldown = 1.0f,
.minDamage = 1.0f,
.maxDamage = 2.0f,
.acceleration = 80.0f,
.maxSpeed = 15.0f,
.deceleration = 0.1f,
.unitType = type
};
if (unit)
unitComp = *unit;
ecs_set_ptr(ECS, e, Unit, &unitComp);
ecs_set(ECS, e, ConsumePopCapacity, {1});
return e;
}
ecs_entity_t entityCreateSoldier(const Position position, Player player, Game *game) {
ecs_entity_t e = entityCreateBaseUnit(position, 10.0f, player, ENTITY_SOLDIER, ANIM_IDLE, game);
Unit unit = {0};
ecs_entity_t e = entityCreateBaseUnit(position, 10.0f, player, ENTITY_SOLDIER, ANIM_IDLE, &unit, game);
ecs_set(ECS, e, Health, {
.startHP = 40.0f,
.hp = 40.0f,
.lastChanged = -1000.0f
});
Unit *unit = ecs_get_mut(ECS, e, Unit);
unit->minDamage = 5.0f;
unit->maxDamage = 10.0f;
unit->attackCooldown = 1.0f;
unit.minDamage = 5.0f;
unit.maxDamage = 10.0f;
unit.attackCooldown = 1.0f;
ecs_set_ptr(ECS, e, Unit, &unit);
return e;
}
ecs_entity_t entityCreateWarrior(const Position position, Player player, Game *game) {
ecs_entity_t e = entityCreateBaseUnit(position, 10.0f, player, ENTITY_WARRIOR, ANIM_IDLE, game);
Unit unit = {0};
ecs_entity_t e = entityCreateBaseUnit(position, 10.0f, player, ENTITY_WARRIOR, ANIM_IDLE, &unit, game);
ecs_set(ECS, e, Health, {
.startHP = 80.0f,
.hp = 80.0f,
.lastChanged = -1000.0f
});
Unit *unit = ecs_get_mut(ECS, e, Unit);
unit->minDamage = 8.0f;
unit->maxDamage = 22.0f;
unit->attackCooldown = 1.8f;
unit.minDamage = 8.0f;
unit.maxDamage = 22.0f;
unit.attackCooldown = 1.8f;
ecs_set_ptr(ECS, e, Unit, &unit);
return e;
}
ecs_entity_t entityCreateWorker(const Position position, Player player, Game *game) {
BzTileset *tileset = &game->tileset;
ecs_entity_t e = entityCreateBaseUnit(position, 10.0f, player, ENTITY_WORKER, ANIM_IDLE, game);
Unit unit = {0};
ecs_entity_t e = entityCreateBaseUnit(position, 10.0f, player, ENTITY_WORKER, ANIM_IDLE, &unit, game);
ecs_set(ECS, e, Worker, {
.collectSpeed = 0.8f,
@@ -116,7 +121,8 @@ ecs_entity_t entityCreateWorker(const Position position, Player player, Game *ga
}
ecs_entity_t entityCreateSwarmGoblin(const Position position, Player player, Game *game) {
ecs_entity_t e = entityCreateBaseUnit(position, 10.0f, player, ENTITY_GOBLIN, ANIM_IDLE, game);
Unit unit = {0};
ecs_entity_t e = entityCreateBaseUnit(position, 10.0f, player, ENTITY_GOBLIN, ANIM_IDLE, &unit, game);
ecs_set(ECS, e, Swarm, {
.currWaypoint = 0,
});
@@ -126,16 +132,17 @@ ecs_entity_t entityCreateSwarmGoblin(const Position position, Player player, Gam
.lastChanged = -1000.0f
});
Unit *unit = ecs_get_mut(ECS, e, Unit);
unit->minDamage = 5.0f;
unit->maxDamage = 10.0f;
unit->attackCooldown = 1.0f;
unit->maxSpeed = 20.0f;
unit.minDamage = 5.0f;
unit.maxDamage = 10.0f;
unit.attackCooldown = 1.0f;
unit.maxSpeed = 20.0f;
ecs_set_ptr(ECS, e, Unit, &unit);
return e;
}
ecs_entity_t entityCreateSwarmOrc(const Position position, Player player, Game *game) {
ecs_entity_t e = entityCreateBaseUnit(position, 10.0f, player, ENTITY_ORC, ANIM_IDLE, game);
Unit unit = {0};
ecs_entity_t e = entityCreateBaseUnit(position, 10.0f, player, ENTITY_ORC, ANIM_IDLE, &unit, game);
ecs_set(ECS, e, Swarm, {
.currWaypoint = 0,
});
@@ -145,11 +152,11 @@ ecs_entity_t entityCreateSwarmOrc(const Position position, Player player, Game *
.lastChanged = -1000.0f
});
Unit *unit = ecs_get_mut(ECS, e, Unit);
unit->minDamage = 8.0f;
unit->maxDamage = 22.0f;
unit->attackCooldown = 1.8f;
unit->maxSpeed = 12.0f;
unit.minDamage = 8.0f;
unit.maxDamage = 22.0f;
unit.attackCooldown = 1.8f;
unit.maxSpeed = 12.0f;
ecs_set_ptr(ECS, e, Unit, &unit);
return e;
}

View File

@@ -7,7 +7,7 @@
ecs_entity_t entityCreateEmpty();
ecs_entity_t entityCreateBaseUnit(const Position position, f32 size, Player player,
EntityType type, AnimType startAnim, Game *game);
EntityType type, AnimType startAnim, Unit *unit, Game *game);
ecs_entity_t entityCreateSoldier(const Position position, Player player, Game *game);
ecs_entity_t entityCreateWarrior(const Position position, Player player, Game *game);
ecs_entity_t entityCreateWorker(const Position position, Player player, Game *game);

View File

@@ -122,20 +122,20 @@ void entityUpdateKinematic(ecs_iter_t *it) {
steering[i] = Vector2Normalize(steering[i]);
// velocity += steering * dt
Vector2 accel = Vector2Scale(steering[i], dt);
accel = Vector2Scale(accel, unit->acceleration);
accel = Vector2Scale(accel, unit[i].acceleration);
velocity[i] = Vector2Add(velocity[i], accel);
// Apply deceleration
if (Vector2LengthSqr(steering[i]) == 0) {
// velocity *= (1.0 - decel)
velocity[i] = Vector2Scale(velocity[i], 1.0 - unit->deceleration);
velocity[i] = Vector2Scale(velocity[i], 1.0 - unit[i].deceleration);
}
// Reset steering
steering[i] = Vector2Zero();
// Check for speeding and clip
const f32 maxSpeed = unit->maxSpeed;
const f32 maxSpeed = unit[i].maxSpeed;
if (Vector2Length(velocity[i]) > maxSpeed) {
velocity[i] = Vector2Normalize(velocity[i]);
velocity[i] = Vector2Scale(velocity[i], maxSpeed);

View File

@@ -8,12 +8,12 @@
EnemyWaves getDefaultWaves() {
static WaveData waves[NUM_WAVES] = {
{ 0, 0.0f, 5, 1.0f, 0, 5 * 60 },
{ 0, 0.0f, 20, 2.0f, 0, 1.5f * 60 },
{ 5, 0.2f, 30, 2.2f, 0, 30 },
{ 10, 0.5f, 40, 2.4f, 0, 20 },
{ 20, 1.0f, 60, 2.6f, 0, 20 },
{ 40, 1.4f, 80, 2.8f, 0, 10 },
{ 0, 0.0f, 5, 1.0f, 0, 8 * 60 },
{ 0, 0.0f, 20, 2.0f, 0, 3 * 60 },
{ 5, 0.2f, 30, 2.2f, 0, 60 },
{ 10, 0.5f, 40, 2.4f, 0, 40 },
{ 20, 1.0f, 60, 2.6f, 0, 30 },
{ 40, 1.4f, 80, 2.8f, 0, 20 },
{ 60, 1.5f, 100, 3.0f, 0, 10 },
{ 80, 1.6f, 120, 3.2f, 0, 10 },
{ 100, 1.8f, 160, 3.4f, 0, 5 },