Fix dead guard not spawning at the beginning of the level

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-15 16:27:59 +01:00
parent 20755e93ed
commit da00c5237f
6 changed files with 7 additions and 3 deletions

View File

@@ -0,0 +1,93 @@
import 'package:flutter/material.dart';
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
import 'package:wolf_3d_flutter/wolf_3d.dart';
import 'package:wolf_3d_renderer/wolf_3d_renderer.dart';
class DifficultyScreen extends StatefulWidget {
const DifficultyScreen({
super.key,
});
@override
State<DifficultyScreen> createState() => _DifficultyScreenState();
}
class _DifficultyScreenState extends State<DifficultyScreen> {
bool get isShareware => Wolf3d.I.activeGame.version == GameVersion.shareware;
@override
void dispose() {
Wolf3d.I.audio.stopMusic();
super.dispose();
}
void _startGame(Difficulty difficulty, {bool showGallery = false}) {
Wolf3d.I.audio.stopMusic();
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (_) => WolfRenderer(
Wolf3d.I.activeGame,
difficulty: difficulty,
startingEpisode: Wolf3d.I.activeEpisode,
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.red[900],
onPressed: () => _startGame(Difficulty.bringEmOn, showGallery: true),
child: const Icon(Icons.bug_report, color: Colors.white),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'HOW TOUGH ARE YOU?',
style: TextStyle(
color: Colors.red,
fontSize: 32,
fontWeight: FontWeight.bold,
fontFamily: 'Courier',
),
),
const SizedBox(height: 40),
// --- Difficulty Buttons ---
ListView.builder(
shrinkWrap: true,
itemCount: Difficulty.values.length,
itemBuilder: (context, index) {
final Difficulty difficulty = Difficulty.values[index];
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blueGrey[900],
foregroundColor: Colors.white,
minimumSize: const Size(300, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
),
onPressed: () => _startGame(difficulty),
child: Text(
difficulty.title,
style: const TextStyle(fontSize: 18),
),
),
);
},
),
],
),
),
);
}
}

View File

@@ -0,0 +1,83 @@
import 'package:flutter/material.dart';
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
import 'package:wolf_3d_flutter/wolf_3d.dart';
import 'package:wolf_dart/screens/difficulty_screen.dart';
class EpisodeScreen extends StatefulWidget {
const EpisodeScreen({super.key});
@override
State<EpisodeScreen> createState() => _EpisodeScreenState();
}
class _EpisodeScreenState extends State<EpisodeScreen> {
@override
void initState() {
super.initState();
Wolf3d.I.audio.playMenuMusic();
}
void _selectEpisode(int index) {
Wolf3d.I.setActiveEpisode(index);
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => DifficultyScreen(),
),
);
}
@override
Widget build(BuildContext context) {
final List<Episode> episodes = Wolf3d.I.activeGame.episodes;
return Scaffold(
backgroundColor: Colors.black,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'WHICH EPISODE TO PLAY?',
style: TextStyle(
color: Colors.red,
fontSize: 32,
fontWeight: FontWeight.bold,
fontFamily: 'Courier',
),
),
const SizedBox(height: 40),
ListView.builder(
shrinkWrap: true,
itemCount: episodes.length,
itemBuilder: (context, index) {
final Episode episode = episodes[index];
return Padding(
padding: const EdgeInsets.symmetric(
vertical: 8.0,
horizontal: 32.0,
),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blueGrey[900],
foregroundColor: Colors.white,
minimumSize: const Size(300, 60),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
),
onPressed: () => _selectEpisode(index),
child: Text(
episode.name,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 18),
),
),
);
},
),
],
),
),
);
}
}

View File

@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
import 'package:wolf_3d_flutter/wolf_3d.dart';
import 'package:wolf_dart/screens/episode_screen.dart';
class GameSelectScreen extends StatelessWidget {
const GameSelectScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: Wolf3d.I.availableGames.length,
itemBuilder: (context, i) {
final WolfensteinData data = Wolf3d.I.availableGames[i];
final GameVersion version = data.version;
return Card(
child: ListTile(
title: Text(version.name),
onTap: () {
Wolf3d.I.setActiveGame(data);
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const EpisodeScreen(),
),
);
},
),
);
},
),
);
}
}

View File

@@ -0,0 +1,79 @@
import 'package:flutter/material.dart';
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
import 'package:wolf_3d_entities/wolf_3d_entities.dart';
import 'package:wolf_3d_renderer/color_palette.dart';
class SpriteGallery extends StatelessWidget {
final List<Sprite> sprites;
const SpriteGallery({super.key, required this.sprites});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Sprite Gallery"),
automaticallyImplyLeading: true,
),
backgroundColor: Colors.black,
body: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 8, // 8 sprites per row
),
itemCount: sprites.length,
itemBuilder: (context, index) {
// --- Check which enemy owns this sprite ---
String label = "Idx: $index";
for (final enemy in EnemyType.values) {
if (enemy.claimsSpriteIndex(index)) {
// Appends the enum name (e.g., "guard", "dog")
label += "\n${enemy.name}";
break;
}
}
return Column(
children: [
Text(
label,
style: const TextStyle(color: Colors.white, fontSize: 10),
textAlign: TextAlign.center,
),
Expanded(
child: CustomPaint(
painter: SingleSpritePainter(sprite: sprites[index]),
size: const Size(64, 64),
),
),
],
);
},
),
);
}
}
class SingleSpritePainter extends CustomPainter {
final Sprite sprite;
SingleSpritePainter({required this.sprite});
@override
void paint(Canvas canvas, Size size) {
double pixelSize = size.width / 64;
for (int x = 0; x < 64; x++) {
for (int y = 0; y < 64; y++) {
int colorByte = sprite[x][y];
if (colorByte != 255) {
// Skip transparency
canvas.drawRect(
Rect.fromLTWH(x * pixelSize, y * pixelSize, pixelSize, pixelSize),
Paint()..color = ColorPalette.vga[colorByte],
);
}
}
}
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}