@@ -2,10 +2,10 @@ import 'dart:math' as math;
|
|||||||
|
|
||||||
import 'package:wolf_dart/classes/linear_coordinates.dart';
|
import 'package:wolf_dart/classes/linear_coordinates.dart';
|
||||||
import 'package:wolf_dart/features/entities/collectible.dart';
|
import 'package:wolf_dart/features/entities/collectible.dart';
|
||||||
import 'package:wolf_dart/features/player/weapon.dart';
|
import 'package:wolf_dart/features/weapon/weapons/knife.dart';
|
||||||
import 'package:wolf_dart/features/player/weapons/knife.dart';
|
import 'package:wolf_dart/features/weapon/weapons/machine_gun.dart';
|
||||||
import 'package:wolf_dart/features/player/weapons/machine_gun.dart';
|
import 'package:wolf_dart/features/weapon/weapons/pistol.dart';
|
||||||
import 'package:wolf_dart/features/player/weapons/pistol.dart';
|
import 'package:wolf_dart/features/weapon/weapons/weapon.dart';
|
||||||
|
|
||||||
class Player {
|
class Player {
|
||||||
// Spatial
|
// Spatial
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import 'package:wolf_dart/features/renderer/color_palette.dart';
|
|||||||
class WeaponPainter extends CustomPainter {
|
class WeaponPainter extends CustomPainter {
|
||||||
final List<List<int>> sprite;
|
final List<List<int>> sprite;
|
||||||
|
|
||||||
// 1. Initialize a reusable Paint object and disable anti-aliasing
|
// Initialize a reusable Paint object and disable anti-aliasing to keep the
|
||||||
// to keep the pixels perfectly sharp and chunky.
|
// pixels perfectly sharp and chunky.
|
||||||
final Paint _paint = Paint()
|
final Paint _paint = Paint()
|
||||||
..isAntiAlias = false
|
..isAntiAlias = false
|
||||||
..style = PaintingStyle.fill;
|
..style = PaintingStyle.fill;
|
||||||
@@ -14,7 +14,8 @@ class WeaponPainter extends CustomPainter {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void paint(Canvas canvas, Size size) {
|
void paint(Canvas canvas, Size size) {
|
||||||
// Calculate width and height separately in case the container isn't a perfect square
|
// Calculate width and height separately in case the container isn't a
|
||||||
|
// perfect square
|
||||||
double pixelWidth = size.width / 64;
|
double pixelWidth = size.width / 64;
|
||||||
double pixelHeight = size.height / 64;
|
double pixelHeight = size.height / 64;
|
||||||
|
|
||||||
@@ -30,8 +31,8 @@ class WeaponPainter extends CustomPainter {
|
|||||||
Rect.fromLTWH(
|
Rect.fromLTWH(
|
||||||
x * pixelWidth,
|
x * pixelWidth,
|
||||||
y * pixelHeight,
|
y * pixelHeight,
|
||||||
pixelWidth +
|
// Add a tiny 0.5 overlap to completely eliminate visual seams
|
||||||
0.5, // 2. Add a tiny 0.5 overlap to completely eliminate visual seams
|
pixelWidth + 0.5,
|
||||||
pixelHeight + 0.5,
|
pixelHeight + 0.5,
|
||||||
),
|
),
|
||||||
_paint,
|
_paint,
|
||||||
@@ -43,7 +44,7 @@ class WeaponPainter extends CustomPainter {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
bool shouldRepaint(covariant WeaponPainter oldDelegate) {
|
bool shouldRepaint(covariant WeaponPainter oldDelegate) {
|
||||||
// 3. ONLY repaint if the actual animation frame (sprite) has changed!
|
// ONLY repaint if the actual animation frame (sprite) has changed!
|
||||||
// This saves massive amounts of CPU when the player is just walking around.
|
// This saves massive amounts of CPU when the player is just walking around.
|
||||||
return oldDelegate.sprite != sprite;
|
return oldDelegate.sprite != sprite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import 'package:wolf_dart/features/player/weapon.dart';
|
import 'package:wolf_dart/features/weapon/weapons/weapon.dart';
|
||||||
|
|
||||||
class Knife extends Weapon {
|
class Knife extends Weapon {
|
||||||
Knife()
|
Knife()
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import 'package:wolf_dart/features/player/weapon.dart';
|
import 'package:wolf_dart/features/weapon/weapons/weapon.dart';
|
||||||
|
|
||||||
class MachineGun extends Weapon {
|
class MachineGun extends Weapon {
|
||||||
MachineGun()
|
MachineGun()
|
||||||
: super(
|
: super(
|
||||||
name: "Machine Gun",
|
name: "Machine Gun",
|
||||||
idleSprite: 413,
|
idleSprite: 413,
|
||||||
fireFrames: [414, 415], // Faster 2-frame loop
|
fireFrames: [414, 415],
|
||||||
damage: 20,
|
damage: 20,
|
||||||
msPerFrame: 80,
|
msPerFrame: 80,
|
||||||
);
|
);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import 'package:wolf_dart/features/player/weapon.dart';
|
import 'package:wolf_dart/features/weapon/weapons/weapon.dart';
|
||||||
|
|
||||||
class Pistol extends Weapon {
|
class Pistol extends Weapon {
|
||||||
Pistol()
|
Pistol()
|
||||||
Reference in New Issue
Block a user