Draw player position line a bit better

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-08-30 17:39:45 +02:00
parent a6911411f9
commit 3fee462c35
+16 -4
View File
@@ -69,30 +69,42 @@ class _PlayerState extends State<Player> {
double get playerDeltaX => math.cos(playerAngle) * 5;
double get playerDeltaY => math.sin(playerAngle) * 5;
Offset get playerDelta => Offset(playerDeltaX, playerDeltaY);
Offset playerPosition = const Offset(1.5 * mapSize, 1.5 * mapSize);
@override
Widget build(BuildContext context) {
return CustomPaint(
painter: PlayerPainter(offset: playerPosition),
painter: PlayerPainter(offset: playerPosition, delta: playerDelta),
);
}
}
class PlayerPainter extends CustomPainter {
final Offset offset;
final Offset delta;
const new({
required this.offset,
required this.delta,
});
@override
void paint(Canvas canvas, Size size) {
final paintYelow = Paint()..color = Colors.yellow;
// Player dot
canvas.drawRect(
Rect.fromLTWH(offset.dx, offset.dy, 8, 8),
paintYelow,
Paint()..color = Colors.yellow,
);
// Player direction line
canvas.drawLine(
offset + const Offset(4, 4),
delta * 5,
Paint()
..color = Colors.yellow
..strokeWidth = 2,
);
}