Fixed pistol and knife sprites for retail. Added firing mechanism.
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -16,7 +16,7 @@ class DifficultyScreen extends StatelessWidget {
|
|||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (_) => const WolfRenderer(
|
builder: (_) => const WolfRenderer(
|
||||||
difficulty: Difficulty.bringEmOn,
|
difficulty: Difficulty.bringEmOn,
|
||||||
// isDemo: true,
|
isDemo: false,
|
||||||
showSpriteGallery: true,
|
showSpriteGallery: true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -120,14 +120,11 @@ class Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void fire(int currentTime) {
|
void fire(int currentTime) {
|
||||||
|
// Only spend ammo if the weapon isn't a knife
|
||||||
bool shotFired = currentWeapon.fire(currentTime, currentAmmo: ammo);
|
bool shotFired = currentWeapon.fire(currentTime, currentAmmo: ammo);
|
||||||
|
|
||||||
// If it was a gun (not a knife) and it fired, consume ammo
|
|
||||||
if (shotFired && currentWeapon is! Knife) {
|
if (shotFired && currentWeapon is! Knife) {
|
||||||
ammo--;
|
ammo--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: We'll add Raycast hit detection here next!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateWeapon(int currentTime) {
|
void updateWeapon(int currentTime) {
|
||||||
|
|||||||
@@ -16,16 +16,13 @@ abstract class Weapon {
|
|||||||
required this.idleSprite,
|
required this.idleSprite,
|
||||||
required this.fireFrames,
|
required this.fireFrames,
|
||||||
required this.damage,
|
required this.damage,
|
||||||
this.msPerFrame = 100, // Speed of animation
|
this.msPerFrame = 100,
|
||||||
});
|
});
|
||||||
|
|
||||||
int get currentSprite =>
|
int get currentSprite =>
|
||||||
state == WeaponState.idle ? idleSprite : fireFrames[frameIndex];
|
state == WeaponState.idle ? idleSprite : fireFrames[frameIndex];
|
||||||
|
|
||||||
bool get isFiring => state == WeaponState.firing;
|
/// Core firing logic. Returns true if a bullet was spent.
|
||||||
|
|
||||||
/// The main entry point for the player to use the gun.
|
|
||||||
/// Returns true if a bullet was actually spent.
|
|
||||||
bool fire(int currentTime, {required int currentAmmo}) {
|
bool fire(int currentTime, {required int currentAmmo}) {
|
||||||
if (state == WeaponState.idle && currentAmmo > 0) {
|
if (state == WeaponState.idle && currentAmmo > 0) {
|
||||||
state = WeaponState.firing;
|
state = WeaponState.firing;
|
||||||
|
|||||||
@@ -5,14 +5,13 @@ class Knife extends Weapon {
|
|||||||
: super(
|
: super(
|
||||||
name: "Knife",
|
name: "Knife",
|
||||||
idleSprite: 416,
|
idleSprite: 416,
|
||||||
fireFrames: [417, 418, 419],
|
fireFrames: [417, 418, 419, 420],
|
||||||
damage: 15,
|
damage: 15,
|
||||||
msPerFrame: 120,
|
msPerFrame: 120,
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool fire(int currentTime, {required int currentAmmo}) {
|
bool fire(int currentTime, {required int currentAmmo}) {
|
||||||
// Knife doesn't need ammo!
|
|
||||||
if (state == WeaponState.idle) {
|
if (state == WeaponState.idle) {
|
||||||
state = WeaponState.firing;
|
state = WeaponState.firing;
|
||||||
frameIndex = 0;
|
frameIndex = 0;
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ class Pistol extends Weapon {
|
|||||||
Pistol()
|
Pistol()
|
||||||
: super(
|
: super(
|
||||||
name: "Pistol",
|
name: "Pistol",
|
||||||
idleSprite: 408,
|
idleSprite: 421,
|
||||||
fireFrames: [409, 410, 411, 412],
|
fireFrames: [422, 423, 424, 425],
|
||||||
damage: 20,
|
damage: 20,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import 'package:wolf_dart/features/entities/entity_registry.dart';
|
|||||||
import 'package:wolf_dart/features/map/wolf_map.dart';
|
import 'package:wolf_dart/features/map/wolf_map.dart';
|
||||||
import 'package:wolf_dart/features/player/player.dart';
|
import 'package:wolf_dart/features/player/player.dart';
|
||||||
import 'package:wolf_dart/features/renderer/raycast_painter.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/features/ui/hud.dart';
|
||||||
import 'package:wolf_dart/sprite_gallery.dart';
|
import 'package:wolf_dart/sprite_gallery.dart';
|
||||||
|
|
||||||
@@ -55,6 +56,9 @@ class _WolfRendererState extends State<WolfRenderer>
|
|||||||
Map<String, double> doorOffsets = {};
|
Map<String, double> doorOffsets = {};
|
||||||
Map<String, int> doorStates = {}; // 1 = opening, 2 = fully open
|
Map<String, int> doorStates = {}; // 1 = opening, 2 = fully open
|
||||||
|
|
||||||
|
double moveStepX = 0;
|
||||||
|
double moveStepY = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -191,6 +195,10 @@ class _WolfRendererState extends State<WolfRenderer>
|
|||||||
const double moveSpeed = 0.12;
|
const double moveSpeed = 0.12;
|
||||||
const double turnSpeed = 0.08;
|
const double turnSpeed = 0.08;
|
||||||
|
|
||||||
|
// Reset steps each tick before calculation
|
||||||
|
moveStepX = 0;
|
||||||
|
moveStepY = 0;
|
||||||
|
|
||||||
// 1. ANIMATE DOORS
|
// 1. ANIMATE DOORS
|
||||||
doorStates.forEach((key, state) {
|
doorStates.forEach((key, state) {
|
||||||
if (state == 1) {
|
if (state == 1) {
|
||||||
@@ -203,8 +211,6 @@ class _WolfRendererState extends State<WolfRenderer>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
double moveStepX = 0;
|
|
||||||
double moveStepY = 0;
|
|
||||||
final pressedKeys = HardwareKeyboard.instance.logicalKeysPressed;
|
final pressedKeys = HardwareKeyboard.instance.logicalKeysPressed;
|
||||||
|
|
||||||
if (pressedKeys.contains(LogicalKeyboardKey.keyW)) {
|
if (pressedKeys.contains(LogicalKeyboardKey.keyW)) {
|
||||||
@@ -300,12 +306,12 @@ class _WolfRendererState extends State<WolfRenderer>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Fire weapon
|
// 5. Weapon
|
||||||
bool isCtrlPressed = pressedKeys.contains(LogicalKeyboardKey.controlLeft);
|
player.currentWeapon.update(elapsed.inMilliseconds);
|
||||||
if (isCtrlPressed) {
|
|
||||||
|
if (pressedKeys.contains(LogicalKeyboardKey.controlLeft)) {
|
||||||
player.fire(elapsed.inMilliseconds);
|
player.fire(elapsed.inMilliseconds);
|
||||||
}
|
}
|
||||||
player.updateWeapon(elapsed.inMilliseconds);
|
|
||||||
|
|
||||||
// Fade out the damage flash smoothly
|
// Fade out the damage flash smoothly
|
||||||
if (damageFlashOpacity > 0) {
|
if (damageFlashOpacity > 0) {
|
||||||
@@ -357,6 +363,40 @@ class _WolfRendererState extends State<WolfRenderer>
|
|||||||
sprites: gameMap.sprites,
|
sprites: gameMap.sprites,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
// Weapon Viewmodel
|
||||||
|
Positioned(
|
||||||
|
bottom: -20,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
child: Center(
|
||||||
|
child: Transform.translate(
|
||||||
|
offset: Offset(
|
||||||
|
0,
|
||||||
|
// Bobbing math: only moves if velocity is > 0
|
||||||
|
(moveStepX.abs() + moveStepY.abs()) > 0
|
||||||
|
? math.sin(
|
||||||
|
DateTime.now()
|
||||||
|
.millisecondsSinceEpoch /
|
||||||
|
100,
|
||||||
|
) *
|
||||||
|
12
|
||||||
|
: 0,
|
||||||
|
),
|
||||||
|
child: SizedBox(
|
||||||
|
width: 500,
|
||||||
|
height: 500,
|
||||||
|
child: CustomPaint(
|
||||||
|
painter: WeaponPainter(
|
||||||
|
sprite:
|
||||||
|
gameMap.sprites[player
|
||||||
|
.currentWeapon
|
||||||
|
.currentSprite],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
if (damageFlashOpacity > 0)
|
if (damageFlashOpacity > 0)
|
||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
child: Container(
|
child: Container(
|
||||||
@@ -370,6 +410,7 @@ class _WolfRendererState extends State<WolfRenderer>
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// HUD
|
// HUD
|
||||||
Hud(player: player),
|
Hud(player: player),
|
||||||
],
|
],
|
||||||
|
|||||||
29
lib/features/renderer/weapon_painter.dart
Normal file
29
lib/features/renderer/weapon_painter.dart
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:wolf_dart/features/renderer/color_palette.dart';
|
||||||
|
|
||||||
|
class WeaponPainter extends CustomPainter {
|
||||||
|
final List<List<int>> sprite;
|
||||||
|
WeaponPainter({required this.sprite});
|
||||||
|
|
||||||
|
@override
|
||||||
|
void paint(Canvas canvas, Size size) {
|
||||||
|
double pixelSize = size.width / 64;
|
||||||
|
final paint = Paint();
|
||||||
|
for (int x = 0; x < 64; x++) {
|
||||||
|
for (int y = 0; y < 64; y++) {
|
||||||
|
int colorByte = sprite[x][y];
|
||||||
|
if (colorByte != 255) {
|
||||||
|
// Transparency check
|
||||||
|
paint.color = ColorPalette.vga[colorByte];
|
||||||
|
canvas.drawRect(
|
||||||
|
Rect.fromLTWH(x * pixelSize, y * pixelSize, pixelSize, pixelSize),
|
||||||
|
paint,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool shouldRepaint(covariant WeaponPainter oldDelegate) => true;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user