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:
42
lib/features/entities/decorative.dart
Normal file
42
lib/features/entities/decorative.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:wolf_dart/features/entities/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;
|
||||
}
|
||||
|
||||
static Decorative? trySpawn(
|
||||
int objId,
|
||||
double x,
|
||||
double y,
|
||||
int difficultyLevel,
|
||||
) {
|
||||
if (isDecoration(objId)) {
|
||||
return Decorative(
|
||||
x: x,
|
||||
y: y,
|
||||
spriteIndex: getSpriteIndex(objId),
|
||||
mapId: objId,
|
||||
state: objId == 124 ? EntityState.dead : EntityState.staticObj,
|
||||
);
|
||||
}
|
||||
|
||||
// Not a decoration!
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user