Draw player dot

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-08-30 17:34:28 +02:00
parent d1b99c2af2
commit a6911411f9
+62 -7
View File
@@ -1,3 +1,5 @@
import "dart:math" as math;
import "package:flutter/material.dart";
// dart format off
@@ -33,7 +35,19 @@ class MainApp extends StatelessWidget {
spacing: mapSize / 1,
textDirection: TextDirection.ltr,
children: [
Flexible(child: Map()),
Flexible(
child: Center(
child: FittedBox(
fit: BoxFit.contain,
child: Stack(
children: [
Map(),
Player(),
],
),
),
),
),
Flexible(child: Background()),
],
),
@@ -42,6 +56,52 @@ class MainApp extends StatelessWidget {
}
}
// * Player
class Player extends StatefulWidget {
const new({super.key});
@override
State<Player> createState() => _PlayerState();
}
class _PlayerState extends State<Player> {
double playerAngle = 0;
double get playerDeltaX => math.cos(playerAngle) * 5;
double get playerDeltaY => math.sin(playerAngle) * 5;
Offset playerPosition = const Offset(1.5 * mapSize, 1.5 * mapSize);
@override
Widget build(BuildContext context) {
return CustomPaint(
painter: PlayerPainter(offset: playerPosition),
);
}
}
class PlayerPainter extends CustomPainter {
final Offset offset;
const new({
required this.offset,
});
@override
void paint(Canvas canvas, Size size) {
final paintYelow = Paint()..color = Colors.yellow;
canvas.drawRect(
Rect.fromLTWH(offset.dx, offset.dy, 8, 8),
paintYelow,
);
}
@override
bool shouldRepaint(covariant oldDelegate) => false;
@override
bool shouldRebuildSemantics(covariant oldDelegate) => false;
}
// * Map
class Map extends StatelessWidget {
const new({super.key});
@@ -51,10 +111,7 @@ class Map extends StatelessWidget {
const double width = mapX * mapSize / 1;
const double height = mapY * mapSize / 1;
return const Center(
child: FittedBox(
fit: BoxFit.contain,
child: CustomPaint(
return const CustomPaint(
size: Size(width, height),
painter: MapPainter(
mapData: map,
@@ -62,8 +119,6 @@ class Map extends StatelessWidget {
mapY: mapY,
tileSize: mapSize / 1,
),
),
),
);
}
}