Trying to figure out issue with sprites loading improperly. Broken, still.

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-14 23:20:03 +01:00
parent 1ec891d9a0
commit 8ea7642c8b
12 changed files with 242 additions and 320 deletions

View File

@@ -1,42 +1,28 @@
import 'dart:math' as math;
import 'package:wolf_dart/classes/coordinate_2d.dart';
import 'package:wolf_dart/features/difficulty/difficulty.dart';
import 'package:wolf_dart/features/entities/enemies/enemy.dart';
import 'package:wolf_dart/features/entities/entity.dart';
import 'package:wolf_dart/features/entities/map_objects.dart';
class Mutant extends Enemy {
static const double speed = 0.045;
static const double speed = 0.04;
bool _hasFiredThisCycle = false;
static EnemyType get type => EnemyType.mutant;
Mutant({
required super.x,
required super.y,
required super.angle,
required super.mapId,
}) : super(
spriteIndex: EnemyType.mutant.spriteBaseIdx,
spriteIndex: type.spriteBaseIdx,
state: EntityState.idle,
) {
health = 45;
damage = 10;
}
static Mutant? trySpawn(int objId, double x, double y, Difficulty _) {
if (EnemyType.mutant.claimsMapId(objId)) {
bool isPatrolling = objId >= EnemyType.mutant.mapBaseId + 18;
return Mutant(
x: x,
y: y,
angle: MapObject.getAngle(objId),
mapId: objId,
)..state = isPatrolling ? EntityState.patrolling : EntityState.idle;
}
return null;
}
@override
({Coordinate2D movement, double newAngle}) update({
required int elapsedMs,
@@ -48,7 +34,6 @@ class Mutant extends Enemy {
Coordinate2D movement = const Coordinate2D(0, 0);
double newAngle = angle;
// Mutants don't make wake-up noises in the original game!
checkWakeUp(
elapsedMs: elapsedMs,
playerPosition: playerPosition,
@@ -62,6 +47,7 @@ class Mutant extends Enemy {
newAngle = angleToPlayer;
}
// Calculate angle diff for the octant logic
double diff = angleToPlayer - newAngle;
while (diff <= -math.pi) {
diff += 2 * math.pi;
@@ -69,80 +55,31 @@ class Mutant extends Enemy {
while (diff > math.pi) {
diff -= 2 * math.pi;
}
int octant = ((diff + (math.pi / 8)) / (math.pi / 4)).floor() % 8;
if (octant < 0) octant += 8;
switch (state) {
case EntityState.idle:
spriteIndex = EnemyType.mutant.spriteBaseIdx + octant;
break;
EnemyAnimation currentAnim = switch (state) {
EntityState.patrolling => EnemyAnimation.walking,
EntityState.attacking => EnemyAnimation.attacking,
EntityState.pain => EnemyAnimation.pain,
EntityState.dead => isDying ? EnemyAnimation.dying : EnemyAnimation.dead,
_ => EnemyAnimation.idle,
};
case EntityState.patrolling:
if (distance > 0.8) {
double moveX = math.cos(angleToPlayer) * speed;
double moveY = math.sin(angleToPlayer) * speed;
movement = getValidMovement(
Coordinate2D(moveX, moveY),
isWalkable,
tryOpenDoor,
);
}
spriteIndex = type.getSpriteFromAnimation(
animation: currentAnim,
elapsedMs: elapsedMs,
lastActionTime: lastActionTime,
angleDiff: diff,
);
int walkFrame = (elapsedMs ~/ 150) % 4;
spriteIndex =
(EnemyType.mutant.spriteBaseIdx + 8) + (walkFrame * 8) + octant;
if (distance < 6.0 && elapsedMs - lastActionTime > 1000) {
if (hasLineOfSight(playerPosition, isWalkable)) {
state = EntityState.attacking;
lastActionTime = elapsedMs;
_hasFiredThisCycle = false;
}
}
break;
case EntityState.attacking:
int timeShooting = elapsedMs - lastActionTime;
if (timeShooting < 150) {
spriteIndex = EnemyType.mutant.spriteBaseIdx + 46; // Aiming
} else if (timeShooting < 300) {
spriteIndex = EnemyType.mutant.spriteBaseIdx + 47; // Firing
if (!_hasFiredThisCycle) {
onDamagePlayer(damage);
_hasFiredThisCycle = true;
}
} else if (timeShooting < 450) {
spriteIndex = EnemyType.mutant.spriteBaseIdx + 48; // Recoil
} else {
state = EntityState.patrolling;
lastActionTime = elapsedMs;
}
break;
case EntityState.pain:
spriteIndex = EnemyType.mutant.spriteBaseIdx + 44;
if (elapsedMs - lastActionTime > 250) {
state = EntityState.patrolling;
lastActionTime = elapsedMs;
}
break;
case EntityState.dead:
if (isDying) {
int deathFrame = (elapsedMs - lastActionTime) ~/ 150;
if (deathFrame < 4) {
spriteIndex = (EnemyType.mutant.spriteBaseIdx + 40) + deathFrame;
} else {
spriteIndex = EnemyType.mutant.spriteBaseIdx + 45;
isDying = false;
}
} else {
spriteIndex = EnemyType.mutant.spriteBaseIdx + 45;
}
break;
default:
break;
if (state == EntityState.attacking) {
int time = elapsedMs - lastActionTime;
if (time >= 150 && !_hasFiredThisCycle) {
onDamagePlayer(damage);
_hasFiredThisCycle = true;
} else if (time >= 300) {
state = EntityState.patrolling;
lastActionTime = elapsedMs;
}
}
return (movement: movement, newAngle: newAngle);