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:
2026-03-13 20:07:44 +01:00
parent 7835a6051e
commit bca8d10964
10 changed files with 110 additions and 52 deletions

View File

@@ -3,13 +3,12 @@ import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:wolf_dart/classes/decorative.dart';
import 'package:wolf_dart/classes/difficulty.dart';
import 'package:wolf_dart/classes/enemy.dart';
import 'package:wolf_dart/classes/entity.dart';
import 'package:wolf_dart/classes/linear_coordinates.dart';
import 'package:wolf_dart/classes/matrix.dart';
import 'package:wolf_dart/features/enemies/brown_guard.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/entity_registry.dart';
import 'package:wolf_dart/features/map/wolf_map.dart';
import 'package:wolf_dart/features/renderer/raycast_painter.dart';
import 'package:wolf_dart/sprite_gallery.dart';
@@ -88,34 +87,17 @@ class _WolfRendererState extends State<WolfRenderer>
case 22:
playerAngle = math.pi;
}
} // 1. POPULATE DECORATIONS & DEAD BODIES
else if (Decorative.isDecoration(objId)) {
int spriteIdx = Decorative.getSpriteIndex(objId);
if (spriteIdx >= 0 && spriteIdx < gameMap.sprites.length) {
entities.add(
Decorative(
x: x + 0.5,
y: y + 0.5,
spriteIndex: spriteIdx,
mapId: objId,
// NEW: Dynamically assign the state!
state: objId == 124 ? EntityState.dead : EntityState.staticObj,
),
);
}
} else if (BrownGuard.isSpawnableForDifficulty(
objId,
widget.difficulty.level,
)) {
if (50 < gameMap.sprites.length) {
entities.add(
BrownGuard(
x: x + 0.5,
y: y + 0.5,
angle: Enemy.getInitialAngle(objId),
mapId: objId,
),
);
} else {
Entity? newEntity = EntityRegistry.spawn(
objId,
x + 0.5,
y + 0.5,
widget.difficulty.level,
gameMap.sprites.length,
);
if (newEntity != null) {
entities.add(newEntity);
}
}
}