Refactor coordinate system
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -2,7 +2,7 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:wolf_dart/classes/linear_coordinates.dart';
|
||||
import 'package:wolf_dart/classes/coordinate_2d.dart';
|
||||
import 'package:wolf_dart/classes/matrix.dart';
|
||||
import 'package:wolf_dart/features/difficulty/difficulty.dart';
|
||||
import 'package:wolf_dart/features/entities/collectible.dart';
|
||||
@@ -146,7 +146,7 @@ class _WolfRendererState extends State<WolfRenderer>
|
||||
pX >= currentLevel[0].length ||
|
||||
currentLevel[pY][pX] > 0) {
|
||||
double shortestDist = double.infinity;
|
||||
LinearCoordinates nearestSafeSpot = (x: 1.5, y: 1.5);
|
||||
Coordinate2D nearestSafeSpot = Coordinate2D(1.5, 1.5);
|
||||
|
||||
for (int y = 0; y < currentLevel.length; y++) {
|
||||
for (int x = 0; x < currentLevel[y].length; x++) {
|
||||
@@ -159,7 +159,7 @@ class _WolfRendererState extends State<WolfRenderer>
|
||||
|
||||
if (dist < shortestDist) {
|
||||
shortestDist = dist;
|
||||
nearestSafeSpot = (x: safeX, y: safeY);
|
||||
nearestSafeSpot = Coordinate2D(safeX, safeY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,7 +186,7 @@ class _WolfRendererState extends State<WolfRenderer>
|
||||
|
||||
// 2. Explicit State Updates
|
||||
player.updateWeaponSwitch();
|
||||
_applyMovementAndCollision(movement.dx, movement.dy);
|
||||
_applyMovementAndCollision(movement.x, movement.y);
|
||||
_updateEntities(elapsed);
|
||||
|
||||
// Explicit reassignment from a pure(r) function
|
||||
@@ -209,7 +209,7 @@ class _WolfRendererState extends State<WolfRenderer>
|
||||
}
|
||||
|
||||
// Returns movement deltas instead of modifying class variables
|
||||
({double dx, double dy}) _processInputs(Duration elapsed) {
|
||||
Coordinate2D _processInputs(Duration elapsed) {
|
||||
inputManager.update();
|
||||
|
||||
const double moveSpeed = 0.16;
|
||||
@@ -248,7 +248,7 @@ class _WolfRendererState extends State<WolfRenderer>
|
||||
);
|
||||
}
|
||||
|
||||
return (dx: dx, dy: dy);
|
||||
return Coordinate2D(dx, dy);
|
||||
}
|
||||
|
||||
// Now receives dx and dy explicitly
|
||||
@@ -277,7 +277,7 @@ class _WolfRendererState extends State<WolfRenderer>
|
||||
if (entity is Enemy) {
|
||||
entity.update(
|
||||
elapsedMs: elapsed.inMilliseconds,
|
||||
player: player.position,
|
||||
playerPosition: player.position,
|
||||
isWalkable: _isWalkable,
|
||||
onDamagePlayer: _takeDamage,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user