WIP: Mapping sprite IDs (broken)

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-13 18:06:40 +01:00
parent af17a0aaf7
commit bf8d9d7eb1
7 changed files with 220 additions and 31 deletions

View File

@@ -5,11 +5,20 @@ import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:wolf_dart/classes/linear_coordinates.dart';
import 'package:wolf_dart/classes/matrix.dart';
import 'package:wolf_dart/classes/sprite.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';
class WolfRenderer extends StatefulWidget {
const WolfRenderer({super.key});
const WolfRenderer({
super.key,
this.showSpriteGallery = false,
this.isDemo = true,
});
final bool showSpriteGallery;
final bool isDemo;
@override
State<WolfRenderer> createState() => _WolfRendererState();
@@ -30,6 +39,8 @@ class _WolfRendererState extends State<WolfRenderer>
bool _isLoading = true;
bool _spaceWasPressed = false;
List<Sprite> entities = [];
// Track door animations
// Key is "X,Y" coordinate. Value is how far open it is (0.0 to 1.0)
Map<String, double> doorOffsets = {};
@@ -50,28 +61,49 @@ class _WolfRendererState extends State<WolfRenderer>
final Matrix<int> objectLevel = gameMap.levels[0].objectGrid;
// 1. SCAN FOR PLAYER SPAWN
// Adjusted mapping for WL1 Shareware
// These numbers represent the delta from the FIRST sprite chunk in VSWAP
Map<int, int> staticObjects = {
23: widget.isDemo ? 0 : 23, // Water Puddle
24: widget.isDemo ? 1 : 24, // Green Barrel
25: widget.isDemo ? 2 : 25, // Chairs
26: widget.isDemo ? 3 : 26, // Green Plant
27: widget.isDemo ? 4 : 27, // Skeleton / Bones
28: widget.isDemo ? 5 : 28, // Blue Lamp
29: widget.isDemo ? 6 : 29, // Chandelier
30: widget.isDemo ? 7 : 30, // Dog food
31: widget.isDemo ? 8 : 31, // White pillar
32: widget.isDemo ? 9 : 32, // Hanged man
50: widget.isDemo ? 42 : 95, // Standing Guard (Front-facing frame)
};
// 1. SCAN FOR PLAYER SPAWN & ENTITIES
for (int y = 0; y < 64; y++) {
for (int x = 0; x < 64; x++) {
int objId = objectLevel[y][x];
// In Wolf3D, IDs 19-22 represent the player's spawn point and facing direction.
// Player Spawn
if (objId >= 19 && objId <= 22) {
// Place the player perfectly in the center of the block
player = (x: x + 0.5, y: y + 0.5);
// Map the ID to standard radians
switch (objId) {
case 19:
playerAngle = 3 * math.pi / 2; // North (Facing up the Y-axis)
playerAngle = 3 * math.pi / 2;
case 20:
playerAngle = 0.0; // East (Facing right)
playerAngle = 0.0;
case 21:
playerAngle = math.pi / 2; // South (Facing down)
playerAngle = math.pi / 2;
case 22:
playerAngle = math.pi; // West (Facing left)
playerAngle = math.pi;
}
}
// NEW: Populate the Entities!
else if (staticObjects.containsKey(objId)) {
entities.add((
x: x + 0.5,
y: y + 0.5,
spriteIndex: staticObjects[objId]!,
));
}
}
}
@@ -236,6 +268,10 @@ class _WolfRendererState extends State<WolfRenderer>
return const Center(child: CircularProgressIndicator(color: Colors.teal));
}
if (widget.showSpriteGallery) {
return SpriteGallery(sprites: gameMap.sprites);
}
return Scaffold(
backgroundColor: Colors.black,
body: KeyboardListener(
@@ -253,6 +289,8 @@ class _WolfRendererState extends State<WolfRenderer>
playerAngle: playerAngle,
fov: fov,
doorOffsets: doorOffsets,
entities: entities,
sprites: gameMap.sprites,
),
);
},