gameplay: dosable power and a playable landscape layout

Two findings from actually playing:

1. Shot power was hard to set and impossible to read. It was derived from the
   absolute distance to the tank (250 world px = 100 %) and only shown through
   the size of the aim dots, so direction and power changed together.
   Aiming is now a slingshot: the drag length sets the power (260 px = 100 %),
   the drag direction sets the shot direction, with a 6 px dead zone. Feedback:
   a dashed rubber band to the finger, a charge bar under the active tank with
   quarter marks, and a HUD row with angle plus a power bar and percentage.

2. Landscape was unplayable. The camera used zoom = max(fitHeight, fitWidth),
   so a wide view zoomed in and cropped the world top and bottom - and the
   camera never panned vertically, which put both tanks off-screen. The camera
   now always fits the world height, centres the world when the view is wider,
   and the background continues into the letterbox (ridges tiled, ground edge
   extended, vignette follows the visible range). Controls and paddings are
   compact in landscape.

- new golden test landscape.png (840x420) shows both tanks and guards the bug;
  18 tests green.
- verified on the device in both orientations: shots fire, measured power 47 %
  and 54 % mid-gesture, no RenderFlex overflow in logcat, perf.sh still
  60.0 fps / 0.0 % jank (p90 16.9 ms).
- store screenshots re-captured with the new HUD and re-framed to 16:9;
  play-console.md release notes and "how to play" updated for 0.9.1.
- release 0.9.1 (14).
This commit is contained in:
2026-10-25 15:14:02 +01:00
parent 77226b1469
commit 254e0d2675
24 changed files with 977 additions and 73 deletions
+93 -14
View File
@@ -98,8 +98,10 @@ class SkyArt {
void _build() {
final rnd = math.Random(seed);
for (var i = 0; i < 16; i++) {
_stars.add(Offset(rnd.nextDouble() * kArtWorldWidth, rnd.nextDouble() * 430));
for (var i = 0; i < 22; i++) {
// Wider than the world: landscape letterboxes the sides with sky.
_stars.add(Offset(
-700 + rnd.nextDouble() * (kArtWorldWidth + 1400), rnd.nextDouble() * 430));
}
_ridges.addAll([
_Ridge(
@@ -153,28 +155,36 @@ class SkyArt {
void paint(Canvas canvas, {required double camX, required double viewWidth}) {
if (!_built) _build();
final left = camX - 12;
final right = camX + viewWidth + 12;
canvas.drawRect(
const Rect.fromLTWH(0, 0, kArtWorldWidth, kArtWorldHeight),
Rect.fromLTRB(left, 0, right, kArtWorldHeight),
_skyPaint,
);
_starPaint.color = const Color(0xFFDCE6F5).withValues(alpha: 0.22);
for (final s in _stars) {
final dx = s.dx + camX * 0.85;
if (dx < -40 || dx > kArtWorldWidth + 40) continue;
if (dx < left - 40 || dx > right + 40) continue;
canvas.drawCircle(Offset(dx, s.dy), 2.2, _starPaint);
}
_paintSun(canvas, Offset(camX + viewWidth * 0.66, 395));
// Tile the ridges so the horizon continues into the letterbox area.
for (final ridge in _ridges) {
canvas.save();
canvas.translate(camX * (1 - ridge.parallax), 0);
canvas.drawPath(ridge.path, ridge.fillPaint);
if (ridge.rim.a > 0.01) {
canvas.drawPath(ridge.path, ridge.rimPaint);
final base = camX * (1 - ridge.parallax);
for (final tile in const [-kArtWorldWidth, 0.0, kArtWorldWidth]) {
final shift = base + tile;
if (shift > right || shift + kArtWorldWidth < left) continue;
canvas.save();
canvas.translate(shift, 0);
canvas.drawPath(ridge.path, ridge.fillPaint);
if (ridge.rim.a > 0.01) {
canvas.drawPath(ridge.path, ridge.rimPaint);
}
canvas.restore();
}
canvas.restore();
}
}
@@ -598,23 +608,92 @@ void paintAim(
/// Edge darkening without a full-screen radial gradient: four cheap bands.
/// A single radial fill over 2048x1152 tripled the jank rate on the test device.
void paintVignette(Canvas canvas) {
const w = kArtWorldWidth;
void paintVignette(Canvas canvas, {required double left, required double right}) {
final w = right - left;
const h = kArtWorldHeight;
const band = 300.0;
const edge = Color(0x66000000);
const clear = Color(0x00000000);
canvas.drawRect(
const Rect.fromLTWH(0, 0, w, band),
Rect.fromLTWH(left, 0, w, band),
Paint()
..shader = ui.Gradient.linear(
const Offset(0, 0), const Offset(0, band), [edge, clear]),
);
canvas.drawRect(
const Rect.fromLTWH(0, h - band, w, band),
Rect.fromLTWH(left, h - band, w, band),
Paint()
..shader = ui.Gradient.linear(
const Offset(0, h - band), const Offset(0, h), [clear, edge]),
);
}
/// Charge bar under the active tank: the value the player is setting right now.
void paintPowerBar(Canvas canvas, Offset tankPos, double power) {
const w = 104.0;
const h = 9.0;
final rect = Rect.fromLTWH(tankPos.dx - w / 2, tankPos.dy + 12, w, h);
canvas.drawRRect(
RRect.fromRectAndRadius(rect, const Radius.circular(4)),
Paint()..color = Colors.black.withValues(alpha: 0.55),
);
final fill = power.clamp(0.0, 1.0);
final color = fill < 0.5
? Palette.solarBase
: fill < 0.85
? const Color(0xFFFF8A3D)
: Palette.stateDanger;
canvas.drawRRect(
RRect.fromRectAndRadius(
Rect.fromLTWH(rect.left, rect.top, w * fill, h),
const Radius.circular(4),
),
Paint()..color = color,
);
// Quarter marks make a value readable without text on the canvas.
for (var i = 1; i < 4; i++) {
final x = rect.left + w * i / 4;
canvas.drawLine(
Offset(x, rect.top + 1),
Offset(x, rect.bottom - 1),
Paint()
..color = Colors.black.withValues(alpha: 0.35)
..strokeWidth = 1,
);
}
canvas.drawRRect(
RRect.fromRectAndRadius(rect, const Radius.circular(4)),
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 1
..color = Colors.white.withValues(alpha: 0.28),
);
}
/// Rubber band from the barrel pivot to the finger while pulling back.
void paintPullBand(Canvas canvas, Offset pivot, Offset finger, double power) {
final band = Paint()
..color = Palette.solarLight.withValues(alpha: 0.45)
..strokeWidth = 3
..strokeCap = StrokeCap.round;
// Dashed, so it never competes with the trajectory hint.
final total = (finger - pivot).distance;
if (total < 4) return;
final dir = (finger - pivot) / total;
var travelled = 0.0;
while (travelled < total) {
final from = pivot + dir * travelled;
final to = pivot + dir * math.min(travelled + 12, total);
canvas.drawLine(from, to, band);
travelled += 22;
}
canvas.drawCircle(
finger,
14 + 10 * power,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 2
..color = Palette.solarLight.withValues(alpha: 0.5),
);
}
+75 -29
View File
@@ -101,8 +101,15 @@ class IronArcGame extends FlameGame {
double aimPower = 0.6;
bool _dragging = false;
/// Pull back to charge: full power at this many screen pixels of drag.
static const double _maxDragPx = 260;
Offset? _dragStart;
Offset? _dragCurrent;
double _zoom = 1;
double _camX = 0;
double _camY = 0;
bool _cameraReady = false;
int _terrainVersion = -1;
Path? _terrainFill;
@@ -196,19 +203,23 @@ class IronArcGame extends FlameGame {
void beginAim(Offset screen) {
if (!_match.isAiming) return;
_dragging = true;
_aimAt(screen);
_dragStart = screen;
_dragCurrent = screen;
}
/// Updates the aim while dragging.
void updateAim(Offset screen) {
if (!_dragging) return;
_aimAt(screen);
_dragCurrent = screen;
_aimFromDrag();
}
/// Fires if a drag produced a valid shot.
void releaseAim() {
if (!_dragging) return;
_dragging = false;
_dragStart = null;
_dragCurrent = null;
if (!_match.isAiming) return;
final angleMdeg = (aimAngle * 1000).round().clamp(1000, 89000);
final powerQ16 = (aimPower * 65536).round().clamp(3277, 65536);
@@ -225,17 +236,21 @@ class IronArcGame extends FlameGame {
_pushHud();
}
void _aimAt(Offset screen) {
final world = screenToWorld(screen);
final player = _match.current;
final tank = Offset(_match.tankX(player).toDouble(),
_match.tankY(player).toDouble() - 14);
final dx = world.dx - tank.dx;
final dy = world.dy - tank.dy;
final distance = math.sqrt(dx * dx + dy * dy);
aimPower = (distance / 250).clamp(0.05, 1.0);
final radians = math.atan2(-dy, dx.abs());
/// Slingshot semantics: pull away from the target, the shot leaves in the
/// opposite direction. The drag *length* sets the power; aiming at the finger
/// tip instead changed direction and power at the same time, which made the
/// power impossible to dose.
void _aimFromDrag() {
final start = _dragStart;
final now = _dragCurrent;
if (start == null || now == null) return;
final pull = now - start;
// Dead zone: a twitchy finger must not move the reticle.
if (pull.distance < 6) return;
final radians = math.atan2(pull.dy, pull.dx.abs());
aimAngle = (radians * 180 / math.pi).clamp(1.0, 89.0);
aimPower = (pull.distance / _maxDragPx).clamp(0.05, 1.0);
_pushHud();
}
@@ -246,28 +261,41 @@ class IronArcGame extends FlameGame {
void _updateCamera(double dt) {
if (size.y <= 0 || size.x <= 0) return;
// Fit height, but never crop the world horizontally more than necessary.
final zoomForHeight = size.y / kWorldHeight;
final zoomForWidth = size.x / kWorldWidth;
_zoom = math.max(zoomForHeight, zoomForWidth);
// The playfield must never be cropped vertically: a tank or a shot that
// leaves the screen makes the game unplayable. So the world height always
// fits. If the view is wider than the world (landscape), the world is
// centred and the sides are letterboxed with sky.
_zoom = size.y / kWorldHeight;
_camY = 0;
final viewW = _viewWidthWorld;
final focus = _match.isFlying
? (_match.projectile()?.x.toDouble() ??
_match.tankX(_match.current).toDouble())
: _match.tankX(_match.current).toDouble();
final desiredLeft = (focus - viewW / 2).clamp(0.0, math.max(0, kWorldWidth - viewW));
// Smooth follow; instant on first frame.
final t = _camX == 0 ? 1.0 : (dt * 5).clamp(0.0, 1.0);
_camX += (desiredLeft - _camX) * t;
_camX = _camX.clamp(0.0, math.max(0, kWorldWidth - viewW));
final bool worldFitsWidth = viewW >= kWorldWidth;
final double desiredLeft = worldFitsWidth
? (kWorldWidth - viewW) / 2
: (focus - viewW / 2).clamp(0.0, kWorldWidth - viewW);
if (!_cameraReady) {
_camX = desiredLeft;
_cameraReady = true;
} else {
final t = (dt * 5).clamp(0.0, 1.0);
_camX += (desiredLeft - _camX) * t;
}
if (!worldFitsWidth) {
_camX = _camX.clamp(0.0, kWorldWidth - viewW);
}
}
/// Screen -> world pixels.
Offset screenToWorld(Offset p) => Offset(p.dx / _zoom + _camX, p.dy / _zoom);
Offset screenToWorld(Offset p) => Offset(p.dx / _zoom + _camX, p.dy / _zoom + _camY);
/// World -> screen pixels.
Offset worldToScreen(Offset p) => Offset((p.dx - _camX) * _zoom, p.dy * _zoom);
Offset worldToScreen(Offset p) => Offset((p.dx - _camX) * _zoom, (p.dy - _camY) * _zoom);
// ------------------------------------------------------------- rendering
@@ -277,7 +305,7 @@ class IronArcGame extends FlameGame {
if (!isLoaded) return;
canvas.save();
canvas.scale(_zoom);
canvas.translate(-_camX, 0);
canvas.translate(-_camX, -_camY);
_drawSky(canvas);
_drawTerrain(canvas);
@@ -286,7 +314,7 @@ class IronArcGame extends FlameGame {
_drawProjectile(canvas);
if (_match.isAiming) _drawAim(canvas);
_drawImpact(canvas);
paintVignette(canvas);
paintVignette(canvas, left: _camX, right: _camX + _viewWidthWorld);
canvas.restore();
}
@@ -300,17 +328,22 @@ class IronArcGame extends FlameGame {
_terrainVersion = version;
final heights = _match.terrain();
_heightmap = heights;
final fill = Path()..moveTo(0, heights[0].toDouble());
final line = Path()..moveTo(0, heights[0].toDouble());
// Flat continuation outside the world so landscape letterboxing still
// shows ground instead of a hard edge.
const ext = 700.0;
final fill = Path()..moveTo(-ext, heights[0].toDouble());
final line = Path()..moveTo(-ext, heights[0].toDouble());
for (var i = 1; i < heights.length; i++) {
final x = i * kSamplePx.toDouble();
final y = heights[i].toDouble();
fill.lineTo(x, y);
line.lineTo(x, y);
}
line.lineTo(kWorldWidth + ext, heights[heights.length - 1].toDouble());
fill
..lineTo(kWorldWidth, kWorldHeight)
..lineTo(0, kWorldHeight)
..lineTo(kWorldWidth + ext, heights[heights.length - 1].toDouble())
..lineTo(kWorldWidth + ext, kWorldHeight)
..lineTo(-ext, kWorldHeight)
..close();
_terrainFill = fill;
_terrainLine = line;
@@ -333,6 +366,10 @@ class IronArcGame extends FlameGame {
hpFrac: _match.tankHp(player).clamp(0, kTankMaxHp) / kTankMaxHp,
isCurrent: player == _match.current && !_match.isPlayback,
);
// Charge bar sits under the tank that is about to fire.
if (player == _match.current && _match.isAiming) {
paintPowerBar(canvas, Offset(x, y), aimPower);
}
}
void _drawProjectile(Canvas canvas) {
@@ -355,6 +392,15 @@ class IronArcGame extends FlameGame {
dir: dir,
power: aimPower,
);
final finger = _dragCurrent;
if (_dragging && finger != null) {
paintPullBand(
canvas,
tankPivot(Offset(x, y)),
screenToWorld(finger),
aimPower,
);
}
}
void _drawImpact(Canvas canvas) {
+85 -9
View File
@@ -34,8 +34,18 @@ class Hud extends StatelessWidget {
const SizedBox(width: 4),
Text('${hud.wind > 0 ? '+' : ''}${hud.wind}',
style: const TextStyle(fontSize: 13)),
const SizedBox(width: 10),
Icon(Icons.straighten,
size: 14, color: const Color(0xFFA9B4C4)),
const SizedBox(width: 3),
Text('${hud.aimAngle.round()}°',
style: const TextStyle(fontSize: 13)),
],
),
// Power is the value players fight with - show it as a number
// *and* as a bar, not only through the size of the aim dots.
const SizedBox(height: 3),
_PowerMeter(power: hud.aimPower),
],
),
),
@@ -111,6 +121,7 @@ class Controls extends StatelessWidget {
required this.onReplay,
required this.onFlush,
required this.onAd,
this.compact = false,
});
final MatchSession session;
@@ -119,30 +130,52 @@ class Controls extends StatelessWidget {
final VoidCallback onFlush;
final VoidCallback onAd;
/// Landscape: the play area is short, so the controls lose their padding.
final bool compact;
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
_Action(icon: Icons.wifi_tethering, label: 'Online', onTap: onOnline),
_Action(icon: Icons.replay, label: 'Replay', onTap: onReplay),
_Action(
icon: Icons.wifi_tethering,
label: 'Online',
onTap: onOnline,
compact: compact),
_Action(
icon: Icons.replay,
label: 'Replay',
onTap: onReplay,
compact: compact),
_Action(
icon: Icons.cloud_upload,
label: session.queued > 0 ? 'Senden (${session.queued})' : 'Senden',
onTap: onFlush,
compact: compact,
),
_Action(icon: Icons.ondemand_video, label: 'Ad', onTap: onAd),
_Action(
icon: Icons.ondemand_video,
label: 'Ad',
onTap: onAd,
compact: compact),
],
);
}
}
class _Action extends StatelessWidget {
const _Action({required this.icon, required this.label, required this.onTap});
const _Action({
required this.icon,
required this.label,
required this.onTap,
this.compact = false,
});
final IconData icon;
final String label;
final VoidCallback onTap;
final bool compact;
@override
Widget build(BuildContext context) {
@@ -153,13 +186,14 @@ class _Action extends StatelessWidget {
borderRadius: BorderRadius.circular(18),
onTap: onTap,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
padding: EdgeInsets.symmetric(
horizontal: compact ? 10 : 14, vertical: compact ? 6 : 12),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(icon, size: 18),
const SizedBox(width: 6),
Text(label, style: const TextStyle(fontSize: 13)),
Icon(icon, size: compact ? 16 : 18),
SizedBox(width: compact ? 4 : 6),
Text(label, style: TextStyle(fontSize: compact ? 12 : 13)),
],
),
),
@@ -168,6 +202,48 @@ class _Action extends StatelessWidget {
}
}
/// Slim power bar with a percentage label, shared by the HUD.
class _PowerMeter extends StatelessWidget {
const _PowerMeter({required this.power});
final double power;
@override
Widget build(BuildContext context) {
final pct = (power.clamp(0.0, 1.0) * 100).round();
final color = pct < 50
? const Color(0xFFFFB347)
: pct < 85
? const Color(0xFFFF8A3D)
: const Color(0xFFFF5A5F);
return Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.bolt, size: 14, color: Color(0xFFA9B4C4)),
const SizedBox(width: 3),
SizedBox(
width: 74,
height: 6,
child: ClipRRect(
borderRadius: BorderRadius.circular(3),
child: LinearProgressIndicator(
value: power.clamp(0.0, 1.0),
minHeight: 6,
color: color,
backgroundColor: const Color(0xFF1B2C44),
),
),
),
const SizedBox(width: 5),
SizedBox(
width: 34,
child: Text('$pct %', style: const TextStyle(fontSize: 12)),
),
],
);
}
}
class _Pill extends StatelessWidget {
const _Pill({
required this.label,
@@ -216,7 +292,7 @@ class HintBubble extends StatelessWidget {
Widget build(BuildContext context) {
final text = hud.phase == 1
? 'Projektil im Flug…'
: 'Ziehen zum Zielen · Loslassen zum Schießen';
: 'Zurückziehen zum Spannen · Loslassen zum Schießen';
return Center(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),