Delegate all audio management to the new audio package, then manage that through a new wolf3d class

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-15 14:33:58 +01:00
parent 070110adae
commit 6eb903cbaa
10 changed files with 249 additions and 81 deletions

View File

@@ -17,21 +17,19 @@ import 'package:wolf_dart/features/player/player.dart';
import 'package:wolf_dart/features/renderer/raycast_painter.dart';
import 'package:wolf_dart/features/renderer/weapon_painter.dart';
import 'package:wolf_dart/features/ui/hud.dart';
import 'package:wolf_dart/sprite_gallery.dart';
import 'package:wolf_dart/wolf_3d.dart';
class WolfRenderer extends StatefulWidget {
const WolfRenderer(
this.data, {
required this.difficulty,
required this.startingEpisode,
super.key,
this.difficulty = Difficulty.bringEmOn,
this.showSpriteGallery = false,
this.isShareware = true,
});
final WolfensteinData data;
final Difficulty difficulty;
final bool showSpriteGallery;
final bool isShareware;
final int startingEpisode;
@override
State<WolfRenderer> createState() => _WolfRendererState();
@@ -56,6 +54,9 @@ class _WolfRendererState extends State<WolfRenderer>
double damageFlashOpacity = 0.0;
late int _currentMapIndex;
late WolfLevel _currentLevel;
List<Entity> entities = [];
@override
@@ -64,7 +65,38 @@ class _WolfRendererState extends State<WolfRenderer>
_initGame();
}
void _loadLevel(int mapIndex) {
// Grab the specific level from the singleton
_currentLevel = Wolf3d.I.levels[mapIndex];
// TODO: Initialize player position, spawn enemies based on difficulty, etc.
debugPrint("Loaded Level: ${_currentLevel.name}");
}
void _onLevelCompleted() {
// When the player hits the elevator switch, advance the map
setState(() {
_currentMapIndex++;
// Check if they beat the episode (each episode is 10 levels)
int maxLevelForEpisode = (widget.startingEpisode * 10) + 9;
if (_currentMapIndex > maxLevelForEpisode) {
// TODO: Handle episode completion (show victory screen, return to menu)
debugPrint("Episode Completed!");
} else {
_loadLevel(_currentMapIndex);
}
});
}
Future<void> _initGame() async {
// 1. Calculate the starting index
_currentMapIndex = widget.startingEpisode * 10;
// 2. Load the initial level data
_loadLevel(_currentMapIndex);
// Get the first level out of the data class
activeLevel = widget.data.levels.first;
@@ -109,7 +141,7 @@ class _WolfRendererState extends State<WolfRenderer>
y + 0.5,
widget.difficulty,
widget.data.sprites.length,
isSharewareMode: widget.isShareware,
isSharewareMode: widget.data.version == GameVersion.shareware,
);
if (newEntity != null) {
@@ -402,10 +434,6 @@ class _WolfRendererState extends State<WolfRenderer>
return const Center(child: CircularProgressIndicator(color: Colors.teal));
}
if (widget.showSpriteGallery) {
return SpriteGallery(sprites: widget.data.sprites);
}
return Scaffold(
backgroundColor: Colors.black,
body: KeyboardListener(