Break out spawnable entities and use a registry to spawn them.
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
import 'package:wolf_dart/classes/entity.dart';
|
||||
|
||||
class Decorative extends Entity {
|
||||
Decorative({
|
||||
required super.x,
|
||||
required super.y,
|
||||
required super.spriteIndex,
|
||||
required super.mapId,
|
||||
super.state = EntityState.staticObj, // Defaults to static
|
||||
});
|
||||
|
||||
// Checks if the Map ID belongs to a standard decoration
|
||||
static bool isDecoration(int objId) {
|
||||
return (objId >= 23 && objId <= 70) || objId == 124;
|
||||
}
|
||||
|
||||
// Safely calculates the VSWAP sprite index for standard decorations
|
||||
static int getSpriteIndex(int objId) {
|
||||
if (objId == 124) return 95; // Dead guard
|
||||
return objId - 21;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
enum Difficulty {
|
||||
canIPlayDaddy(0, "Can I play, Daddy?"),
|
||||
dontHurtMe(1, "Don't hurt me."),
|
||||
bringEmOn(2, "Bring em' on!"),
|
||||
iAmDeathIncarnate(3, "I am Death incarnate!"),
|
||||
;
|
||||
|
||||
final String title;
|
||||
final int level;
|
||||
|
||||
const Difficulty(this.level, this.title);
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:wolf_dart/classes/entity.dart';
|
||||
import 'package:wolf_dart/classes/linear_coordinates.dart';
|
||||
|
||||
abstract class Enemy extends Entity {
|
||||
Enemy({
|
||||
required super.x,
|
||||
required super.y,
|
||||
required super.spriteIndex,
|
||||
super.angle,
|
||||
super.state,
|
||||
super.mapId,
|
||||
super.lastActionTime,
|
||||
});
|
||||
|
||||
// Decodes the Map ID to figure out which way the enemy is facing
|
||||
static double getInitialAngle(int objId) {
|
||||
int normalizedId = (objId - 108) % 36;
|
||||
int direction = normalizedId % 4; // 0=East, 1=North, 2=West, 3=South
|
||||
|
||||
switch (direction) {
|
||||
case 0:
|
||||
return 0.0;
|
||||
case 1:
|
||||
return 3 * math.pi / 2;
|
||||
case 2:
|
||||
return math.pi;
|
||||
case 3:
|
||||
return math.pi / 2;
|
||||
default:
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
// The enemy can now check its own line of sight!
|
||||
bool hasLineOfSight(
|
||||
LinearCoordinates player,
|
||||
bool Function(int x, int y) isWalkable,
|
||||
) {
|
||||
double dx = player.x - x;
|
||||
double dy = player.y - y;
|
||||
double distance = math.sqrt(dx * dx + dy * dy);
|
||||
|
||||
// 1. FOV Check
|
||||
double angleToPlayer = math.atan2(dy, dx);
|
||||
double diff = angle - angleToPlayer;
|
||||
|
||||
while (diff <= -math.pi) {
|
||||
diff += 2 * math.pi;
|
||||
}
|
||||
while (diff > math.pi) {
|
||||
diff -= 2 * math.pi;
|
||||
}
|
||||
|
||||
if (diff.abs() > math.pi / 2) return false;
|
||||
|
||||
// 2. Map Check
|
||||
double dirX = dx / distance;
|
||||
double dirY = dy / distance;
|
||||
double stepSize = 0.2;
|
||||
for (double i = 0; i < distance; i += stepSize) {
|
||||
int checkX = (x + dirX * i).toInt();
|
||||
int checkY = (y + dirY * i).toInt();
|
||||
|
||||
if (!isWalkable(checkX, checkY)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Update signature is cleaner now
|
||||
void update({
|
||||
required int elapsedMs,
|
||||
required LinearCoordinates player,
|
||||
required bool Function(int x, int y) isWalkable,
|
||||
required void Function(int damage) onDamagePlayer,
|
||||
});
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
enum EntityState { staticObj, idle, patrolling, shooting, pain, dead }
|
||||
|
||||
class Entity {
|
||||
double x;
|
||||
double y;
|
||||
int spriteIndex;
|
||||
double angle;
|
||||
EntityState state;
|
||||
int mapId;
|
||||
int lastActionTime;
|
||||
|
||||
Entity({
|
||||
required this.x,
|
||||
required this.y,
|
||||
required this.spriteIndex,
|
||||
this.angle = 0.0,
|
||||
this.state = EntityState.staticObj,
|
||||
this.mapId = 0,
|
||||
this.lastActionTime = 0,
|
||||
});
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
typedef Sprite = ({double x, double y, int spriteIndex});
|
||||
Reference in New Issue
Block a user