De-coupled remaining aspects of game into packages

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-15 16:17:27 +01:00
parent 026e6d8cb4
commit 57d394e911
41 changed files with 522 additions and 44 deletions

View File

@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
import 'package:wolf_dart/features/renderer/renderer.dart';
import 'package:wolf_dart/wolf_3d.dart';
import 'package:wolf_3d_flutter/wolf_3d.dart';
import 'package:wolf_3d_renderer/wolf_3d_renderer.dart';
class DifficultyScreen extends StatefulWidget {
const DifficultyScreen({

View File

@@ -1,7 +1,7 @@
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/features/screens/difficulty_screen.dart';
import 'package:wolf_dart/wolf_3d.dart';
class EpisodeScreen extends StatefulWidget {
const EpisodeScreen({super.key});

View File

@@ -1,7 +1,7 @@
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/features/screens/episode_screen.dart';
import 'package:wolf_dart/wolf_3d.dart';
class GameSelectScreen extends StatelessWidget {
const GameSelectScreen({super.key});

View File

@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:wolf_3d_flutter/wolf_3d.dart';
import 'package:wolf_dart/game_select_screen.dart';
import 'package:wolf_dart/wolf_3d.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();

View File

@@ -1,7 +1,7 @@
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_dart/features/renderer/color_palette.dart';
import 'package:wolf_3d_renderer/color_palette.dart';
class SpriteGallery extends StatelessWidget {
final List<Sprite> sprites;

View File

@@ -0,0 +1,7 @@
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
abstract class EngineAudio {
void playLevelMusic(WolfLevel level);
void stopMusic();
// You can easily add things like void playSoundEffect(SoundId id); later!
}

View File

@@ -0,0 +1,11 @@
import 'package:wolf_3d_entities/wolf_3d_entities.dart';
class EngineInput {
bool isMovingForward = false;
bool isMovingBackward = false;
bool isTurningLeft = false;
bool isTurningRight = false;
bool isInteracting = false;
bool isFiring = false;
WeaponType? requestedWeapon;
}

View File

@@ -1,4 +1,3 @@
// No flutter imports allowed!
import 'dart:math' as math;
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
@@ -11,17 +10,19 @@ class WolfEngine {
required this.difficulty,
required this.startingEpisode,
required this.onGameWon,
required this.audio,
});
final WolfensteinData data;
final Difficulty difficulty;
final int startingEpisode;
final EngineAudio audio;
// Standard Dart function instead of Flutter's VoidCallback
final void Function() onGameWon;
// Managers
final InputManager inputManager = InputManager();
final DoorManager doorManager = DoorManager();
final PushwallManager pushwallManager = PushwallManager();
@@ -46,10 +47,10 @@ class WolfEngine {
}
// Expect standard Dart Duration. The host app is responsible for the loop.
void tick(Duration elapsed) {
void tick(Duration elapsed, EngineInput input) {
if (!isInitialized) return;
final inputResult = _processInputs(elapsed);
final inputResult = _processInputs(elapsed, input);
doorManager.update(elapsed);
pushwallManager.update(elapsed, currentLevel);
@@ -94,8 +95,7 @@ class WolfEngine {
doorManager.initDoors(currentLevel);
pushwallManager.initPushwalls(currentLevel, objectLevel);
// TODO: Consider abstracting audio so the engine doesn't depend on Wolf3d singleton
Wolf3d.I.audio.playLevelMusic(activeLevel);
audio.playLevelMusic(activeLevel);
for (int y = 0; y < 64; y++) {
for (int x = 0; x < 64; x++) {
@@ -144,7 +144,7 @@ class WolfEngine {
}
void _onLevelCompleted({bool isSecretExit = false}) {
Wolf3d.I.audio.stopMusic();
audio.stopMusic();
final currentEpisode = data.episodes[_currentEpisodeIndex];
@@ -169,37 +169,39 @@ class WolfEngine {
}
}
({Coordinate2D movement, double dAngle}) _processInputs(Duration elapsed) {
inputManager.update();
({Coordinate2D movement, double dAngle}) _processInputs(
Duration elapsed,
EngineInput input,
) {
const double moveSpeed = 0.14;
const double turnSpeed = 0.10;
Coordinate2D movement = const Coordinate2D(0, 0);
double dAngle = 0.0;
if (inputManager.requestedWeapon != null) {
player.requestWeaponSwitch(inputManager.requestedWeapon!);
// Read directly from the passed-in EngineInput object
if (input.requestedWeapon != null) {
player.requestWeaponSwitch(input.requestedWeapon!);
}
if (inputManager.isFiring) {
if (input.isFiring) {
player.fire(elapsed.inMilliseconds);
} else {
player.releaseTrigger();
}
if (inputManager.isTurningLeft) dAngle -= turnSpeed;
if (inputManager.isTurningRight) dAngle += turnSpeed;
if (input.isTurningLeft) dAngle -= turnSpeed;
if (input.isTurningRight) dAngle += turnSpeed;
Coordinate2D forwardVec = Coordinate2D(
math.cos(player.angle),
math.sin(player.angle),
);
if (inputManager.isMovingForward) movement += forwardVec * moveSpeed;
if (inputManager.isMovingBackward) movement -= forwardVec * moveSpeed;
if (input.isMovingForward) movement += forwardVec * moveSpeed;
if (input.isMovingBackward) movement -= forwardVec * moveSpeed;
if (inputManager.isInteracting) {
if (input.isInteracting) {
int targetX = (player.x + math.cos(player.angle)).toInt();
int targetY = (player.y + math.sin(player.angle)).toInt();

View File

@@ -3,6 +3,8 @@
/// More dartdocs go here.
library;
export 'src/engine_audio.dart';
export 'src/engine_input.dart';
export 'src/managers/door_manager.dart';
export 'src/managers/pushwall_manager.dart';
export 'src/player/player.dart';

View File

@@ -11,6 +11,7 @@ resolution: workspace
dependencies:
wolf_3d_data_types: any
wolf_3d_entities: any
wolf_3d_input: any
dev_dependencies:
lints: ^6.0.0

31
packages/wolf_3d_flutter/.gitignore vendored Normal file
View File

@@ -0,0 +1,31 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.flutter-plugins-dependencies
/build/
/coverage/

View File

@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
version:
revision: "ff37bef603469fb030f2b72995ab929ccfc227f0"
channel: "stable"
project_type: package

View File

@@ -0,0 +1,3 @@
## 0.0.1
* TODO: Describe initial release.

View File

@@ -0,0 +1 @@
TODO: Add your license here.

View File

@@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/to/develop-packages).
-->
TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
## Features
TODO: List what your package can do. Maybe include images, gifs, or videos.
## Getting started
TODO: List prerequisites and provide or point to information on how to
start using the package.
## Usage
TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
```dart
const like = 'sample';
```
## Additional information
TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.

View File

@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

View File

@@ -0,0 +1,15 @@
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
import 'package:wolf_3d_engine/wolf_3d_engine.dart';
import 'package:wolf_3d_flutter/wolf_3d.dart';
class FlutterAudioAdapter implements EngineAudio {
@override
void playLevelMusic(WolfLevel level) {
Wolf3d.I.audio.playLevelMusic(level);
}
@override
void stopMusic() {
Wolf3d.I.audio.stopMusic();
}
}

View File

@@ -0,0 +1,5 @@
/// A Calculator.
class Calculator {
/// Returns [value] plus 1.
int addOne(int value) => value + 1;
}

View File

@@ -0,0 +1,60 @@
name: wolf_3d_flutter
description: "A new Flutter package project."
version: 0.0.1
homepage:
environment:
sdk: ^3.11.1
flutter: ">=1.17.0"
resolution: workspace
dependencies:
flutter:
sdk: flutter
wolf_3d_data: any
wolf_3d_data_types: any
wolf_3d_synth: any
wolf_3d_engine: any
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^6.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/to/asset-from-package
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/to/resolution-aware-images
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/to/font-from-package

31
packages/wolf_3d_input/.gitignore vendored Normal file
View File

@@ -0,0 +1,31 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.flutter-plugins-dependencies
/build/
/coverage/

View File

@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
version:
revision: "ff37bef603469fb030f2b72995ab929ccfc227f0"
channel: "stable"
project_type: package

View File

@@ -0,0 +1,3 @@
## 0.0.1
* TODO: Describe initial release.

View File

@@ -0,0 +1 @@
TODO: Add your license here.

View File

@@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/to/develop-packages).
-->
TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
## Features
TODO: List what your package can do. Maybe include images, gifs, or videos.
## Getting started
TODO: List prerequisites and provide or point to information on how to
start using the package.
## Usage
TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
```dart
const like = 'sample';
```
## Additional information
TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.

View File

@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

View File

@@ -0,0 +1,57 @@
name: wolf_3d_input
description: "A new Flutter package project."
version: 0.0.1
homepage:
environment:
sdk: ^3.11.1
flutter: ">=1.17.0"
resolution: workspace
dependencies:
flutter:
sdk: flutter
wolf_3d_entities: any
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^6.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/to/asset-from-package
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/to/resolution-aware-images
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/to/font-from-package

31
packages/wolf_3d_renderer/.gitignore vendored Normal file
View File

@@ -0,0 +1,31 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.flutter-plugins-dependencies
/build/
/coverage/

View File

@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
version:
revision: "ff37bef603469fb030f2b72995ab929ccfc227f0"
channel: "stable"
project_type: package

View File

@@ -0,0 +1,3 @@
## 0.0.1
* TODO: Describe initial release.

View File

@@ -0,0 +1 @@
TODO: Add your license here.

View File

@@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/to/develop-packages).
-->
TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
## Features
TODO: List what your package can do. Maybe include images, gifs, or videos.
## Getting started
TODO: List prerequisites and provide or point to information on how to
start using the package.
## Usage
TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
```dart
const like = 'sample';
```
## Additional information
TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.

View File

@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

View File

@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
import 'package:wolf_3d_engine/wolf_3d_engine.dart';
import 'package:wolf_3d_entities/wolf_3d_entities.dart';
import 'package:wolf_dart/features/renderer/color_palette.dart';
import 'package:wolf_3d_renderer/color_palette.dart';
class RaycasterPainter extends CustomPainter {
final Level map;
@@ -358,11 +358,7 @@ class RaycasterPainter extends CustomPainter {
double endY = startY + stepY + 0.5;
if (endY > 0 && startY < size.height) {
canvas.drawLine(
Offset(drawX, startY),
Offset(drawX, endY),
paint,
);
canvas.drawLine(Offset(drawX, startY), Offset(drawX, endY), paint);
}
startY += stepY;
}

View File

@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
import 'package:wolf_dart/features/renderer/color_palette.dart';
import 'package:wolf_3d_renderer/color_palette.dart';
class WeaponPainter extends CustomPainter {
final Sprite? sprite;

View File

@@ -5,10 +5,10 @@ import 'package:flutter/scheduler.dart';
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
import 'package:wolf_3d_engine/wolf_3d_engine.dart';
import 'package:wolf_3d_entities/wolf_3d_entities.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/wolf_3d.dart';
import 'package:wolf_3d_input/wolf_3d_input.dart';
import 'package:wolf_3d_renderer/hud.dart';
import 'package:wolf_3d_renderer/raycast_painter.dart';
import 'package:wolf_3d_renderer/weapon_painter.dart';
class WolfRenderer extends StatefulWidget {
const WolfRenderer(
@@ -84,19 +84,13 @@ class _WolfRendererState extends State<WolfRenderer>
// 3. DEEP COPY the wall grid! If we don't do this, destroying walls/doors
// will permanently corrupt the map data in the Wolf3d singleton.
currentLevel = List.generate(
64,
(y) => List.from(activeLevel.wallGrid[y]),
);
currentLevel = List.generate(64, (y) => List.from(activeLevel.wallGrid[y]));
final Level objectLevel = activeLevel.objectGrid;
// 4. Initialize Managers
doorManager.initDoors(currentLevel);
pushwallManager.initPushwalls(currentLevel, objectLevel);
// 5. Play Music
Wolf3d.I.audio.playLevelMusic(activeLevel);
// 6. Spawn Player and Entities
for (int y = 0; y < 64; y++) {
for (int x = 0; x < 64; x++) {
@@ -146,8 +140,6 @@ class _WolfRendererState extends State<WolfRenderer>
}
void _onLevelCompleted({bool isSecretExit = false}) {
Wolf3d.I.audio.stopMusic();
setState(() {
final currentEpisode = widget.data.episodes[_currentEpisodeIndex];

View File

@@ -0,0 +1,60 @@
name: wolf_3d_renderer
description: "A new Flutter package project."
version: 0.0.1
homepage:
environment:
sdk: ^3.11.1
flutter: ">=1.17.0"
resolution: workspace
dependencies:
flutter:
sdk: flutter
wolf_3d_data_types: any
wolf_3d_engine: any
wolf_3d_entities: any
wolf_3d_input: any
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^6.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/to/asset-from-package
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/to/resolution-aware-images
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/to/font-from-package

View File

@@ -12,6 +12,9 @@ dependencies:
wolf_3d_synth: any
wolf_3d_engine: any
wolf_3d_entities: any
wolf_3d_renderer: any
wolf_3d_input: any
wolf_3d_flutter: any
flutter:
sdk: flutter
@@ -32,3 +35,6 @@ workspace:
- packages/wolf_3d_synth/
- packages/wolf_3d_engine/
- packages/wolf_3d_entities/
- packages/wolf_3d_renderer/
- packages/wolf_3d_input/
- packages/wolf_3d_flutter/