diff --git a/assets/GAMEMAPS.WL6 b/assets/GAMEMAPS.WL6 new file mode 100644 index 0000000..76aef9d Binary files /dev/null and b/assets/GAMEMAPS.WL6 differ diff --git a/assets/MAPHEAD.WL6 b/assets/MAPHEAD.WL6 new file mode 100644 index 0000000..6ef824d Binary files /dev/null and b/assets/MAPHEAD.WL6 differ diff --git a/assets/VSWAP.WL6 b/assets/VSWAP.WL6 new file mode 100644 index 0000000..1860799 Binary files /dev/null and b/assets/VSWAP.WL6 differ diff --git a/lib/features/map/vswap_parser.dart b/lib/features/map/vswap_parser.dart index 7194115..b502a6e 100644 --- a/lib/features/map/vswap_parser.dart +++ b/lib/features/map/vswap_parser.dart @@ -43,7 +43,7 @@ class VswapParser { /// Extracts the compiled scaled sprites from VSWAP.WL1 static List> parseSprites(ByteData vswap) { int chunks = vswap.getUint16(0, Endian.little); - int spriteStart = vswap.getUint16(2, Endian.little); // 64 + int spriteStart = vswap.getUint16(2, Endian.little); int soundStart = vswap.getUint16(4, Endian.little); List offsets = []; diff --git a/lib/features/map/wolf_map.dart b/lib/features/map/wolf_map.dart index 73dbf4b..f01c7b8 100644 --- a/lib/features/map/wolf_map.dart +++ b/lib/features/map/wolf_map.dart @@ -18,7 +18,7 @@ class WolfMap { ); /// Asynchronously loads the map files and parses them into a new WolfMap instance. - static Future load() async { + static Future loadDemo() async { // 1. Load the binary data final mapHead = await rootBundle.load("assets/MAPHEAD.WL1"); final gameMaps = await rootBundle.load("assets/GAMEMAPS.WL1"); @@ -36,4 +36,24 @@ class WolfMap { parsedSprites, ); } + + /// Asynchronously loads the map files and parses them into a new WolfMap instance. + static Future load() async { + // 1. Load the binary data + final mapHead = await rootBundle.load("assets/MAPHEAD.WL6"); + final gameMaps = await rootBundle.load("assets/GAMEMAPS.WL6"); + final vswap = await rootBundle.load("assets/VSWAP.WL6"); + + // 2. Parse the data using the parser we just built + final parsedLevels = WolfMapParser.parseMaps(mapHead, gameMaps); + final parsedTextures = VswapParser.parseWalls(vswap); + final parsedSprites = VswapParser.parseSprites(vswap); + + // 3. Return the populated instance! + return WolfMap._( + parsedLevels, + parsedTextures, + parsedSprites, + ); + } } diff --git a/lib/classes/color_palette.dart b/lib/features/renderer/color_palette.dart similarity index 100% rename from lib/classes/color_palette.dart rename to lib/features/renderer/color_palette.dart diff --git a/lib/features/renderer/raycast_painter.dart b/lib/features/renderer/raycast_painter.dart index 2972a1c..03fe119 100644 --- a/lib/features/renderer/raycast_painter.dart +++ b/lib/features/renderer/raycast_painter.dart @@ -1,10 +1,10 @@ import 'dart:math' as math; import 'package:flutter/material.dart'; -import 'package:wolf_dart/classes/color_palette.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/renderer/color_palette.dart'; class RaycasterPainter extends CustomPainter { final Matrix map; @@ -209,10 +209,8 @@ class RaycasterPainter extends CustomPainter { // THE Z-BUFFER CHECK! // Only draw if the sprite is closer to the camera than the wall at this pixel column if (transformY < zBuffer[stripe]) { - int texX = ((stripe - drawStartX) * 64 / spriteWidth).toInt().clamp( - 0, - 63, - ); + double texXDouble = (stripe - drawStartX) * 64 / spriteWidth; + int texX = texXDouble.toInt().clamp(0, 63); double startY = (size.height / 2) - (spriteHeight / 2); double stepY = spriteHeight / 64.0; diff --git a/lib/features/renderer/renderer.dart b/lib/features/renderer/renderer.dart index 1d0e486..580dd1f 100644 --- a/lib/features/renderer/renderer.dart +++ b/lib/features/renderer/renderer.dart @@ -49,34 +49,18 @@ class _WolfRendererState extends State @override void initState() { super.initState(); - _initGame(); + _initGame(demo: widget.isDemo); } - Future _initGame() async { - // 1. Load the entire WAD/WL1 data - gameMap = await WolfMap.load(); + Future _initGame({bool demo = true}) async { + // 1. Load the entire WL1 (demo)/WL6 (retail) data + gameMap = demo ? await WolfMap.loadDemo() : await WolfMap.load(); // 2. Extract Level 1 (E1M1) currentLevel = gameMap.levels[0].wallGrid; final Matrix objectLevel = gameMap.levels[0].objectGrid; - // Adjusted mapping for WL1 Shareware - // These numbers represent the delta from the FIRST sprite chunk in VSWAP - Map 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++) { @@ -97,12 +81,26 @@ class _WolfRendererState extends State } } // NEW: Populate the Entities! - else if (staticObjects.containsKey(objId)) { - entities.add(( - x: x + 0.5, - y: y + 0.5, - spriteIndex: staticObjects[objId]!, - )); + else if (objId >= 23 && objId <= 70) { + int calculatedSpriteIndex = objId - 21; + + // Safety bounds check to prevent crashes on custom/corrupt maps + if (calculatedSpriteIndex >= 0 && + calculatedSpriteIndex < gameMap.sprites.length) { + entities.add(( + x: x + 0.5, + y: y + 0.5, + spriteIndex: calculatedSpriteIndex, + )); + } + } else if (objId == 124) { + if (95 < gameMap.sprites.length) { + entities.add(( + x: x + 0.5, + y: y + 0.5, + spriteIndex: 95, + )); + } } } } diff --git a/lib/main.dart b/lib/main.dart index f964c8a..af2da65 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,7 +6,7 @@ void main() { const MaterialApp( home: WolfRenderer( showSpriteGallery: false, - isDemo: true, + isDemo: false, ), ), ); diff --git a/lib/sprite_gallery.dart b/lib/sprite_gallery.dart index 72b2d3f..903c164 100644 --- a/lib/sprite_gallery.dart +++ b/lib/sprite_gallery.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:wolf_dart/classes/color_palette.dart'; import 'package:wolf_dart/classes/matrix.dart'; +import 'package:wolf_dart/features/renderer/color_palette.dart'; class SpriteGallery extends StatelessWidget { final List> sprites;