From ab3622746732518116a4a7f43f1aa8c176a4a839 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Mon, 3 Jul 2023 21:27:37 +0200 Subject: [PATCH] fix: Color, powerup and ship parameter fixes (#84) Some general fixes --- lib/game/components/background.dart | 21 +++++++++------------ lib/game/components/bullet.dart | 4 +--- lib/game/components/powerup.dart | 9 +++++---- lib/game/components/ship.dart | 8 ++++---- lib/game/components/spotlight.dart | 2 +- lib/ui/palette.dart | 7 +------ 6 files changed, 21 insertions(+), 30 deletions(-) diff --git a/lib/game/components/background.dart b/lib/game/components/background.dart index 4260125..40b5a32 100644 --- a/lib/game/components/background.dart +++ b/lib/game/components/background.dart @@ -9,24 +9,23 @@ import 'package:lightrunners/game/lightrunners_game.dart'; import 'package:lightrunners/ui/palette.dart'; import 'package:lightrunners/utils/delaunay.dart'; import 'package:lightrunners/utils/flame_utils.dart'; -import 'package:lightrunners/utils/triangle2.dart'; const _margin = 200.0; const _numberShades = 5; const _shadeStep = 0.1; const _colorMoveSpeed = 30; -final _emptyColor = GamePalette.black.brighten(_numberShades * _shadeStep); +final _emptyColor = GamePalette.black.brighten(0.1); -final _r = Random(); +final _random = Random(); typedef ShadedTriangle = ({ - Triangle2 triangle, + Path path, int shadeLevel, }); class Background extends PositionComponent - with HasGameReference { + with HasGameReference, HasPaint { late Rect clipArea; late List mesh; @@ -57,8 +56,8 @@ class Background extends PositionComponent .map((e) => e.translateBy(delta)) .map( (triangle) => ( - triangle: triangle, - shadeLevel: _r.nextInt(_numberShades), + path: triangle.toPath(), + shadeLevel: _random.nextInt(_numberShades), ), ) .toList(); @@ -79,9 +78,8 @@ class Background extends PositionComponent canvas.clipRect(clipArea); for (final t in mesh) { - final shadedColor = currentColor.darken(t.shadeLevel * _shadeStep); - final path = t.triangle.toPath(); - canvas.drawPath(path, Paint()..color = shadedColor); + final shadedColor = currentColor.brighten(t.shadeLevel * _shadeStep); + canvas.drawPath(t.path, paint..color = shadedColor); } } @@ -91,10 +89,9 @@ class Background extends PositionComponent if (maxScore == 0) { return _fromColor(_emptyColor); } - const defaultBrightening = _numberShades / 2 * _shadeStep; final colors = sortedShips .takeWhile((ship) => ship.score == maxScore) - .map((ship) => ship.paint.color.brighten(defaultBrightening)) + .map((ship) => ship.paint.color.darken(0.75)) .toList(); return colors.map(_fromColor).reduce((value, element) => value + element) / colors.length.toDouble(); diff --git a/lib/game/components/bullet.dart b/lib/game/components/bullet.dart index 2bbf771..7299399 100644 --- a/lib/game/components/bullet.dart +++ b/lib/game/components/bullet.dart @@ -6,8 +6,6 @@ import 'package:flame/experimental.dart'; import 'package:lightrunners/game/game.dart'; import 'package:lightrunners/ui/ui.dart'; -const bulletRadius = 8.0; - class Bullet extends CircleComponent with HasGameReference { final int ownerPlayerNumber; final Vector2 velocity; @@ -19,7 +17,7 @@ class Bullet extends CircleComponent with HasGameReference { required this.velocity, required this.color, }) : super( - radius: velocity.length / 32, + radius: velocity.length / 50, anchor: Anchor.center, paint: GamePalette.bulletPaints[ownerPlayerNumber], ); diff --git a/lib/game/components/powerup.dart b/lib/game/components/powerup.dart index 514206f..ab6b3bd 100644 --- a/lib/game/components/powerup.dart +++ b/lib/game/components/powerup.dart @@ -12,7 +12,7 @@ import 'package:lightrunners/game/game.dart'; enum PowerUpType { speed('invertase.png'), shots('flame.png'), - secret('melos.png'), + drag('melos.png'), weight('widgetbook.png'); const PowerUpType(this.asset); @@ -80,9 +80,10 @@ class PowerUp extends SpriteComponent case PowerUpType.speed: ship.engineStrength *= 2; case PowerUpType.weight: - ship.weightFactor *= 2; - case PowerUpType.secret: - // Does absolutely nothing, very mysterious! + ship.weightFactor *= 1.5; + ship.size.scale(1.5); + case PowerUpType.drag: + ship.dragFactor *= 0.7; } } } diff --git a/lib/game/components/ship.dart b/lib/game/components/ship.dart index 29cce24..756051f 100644 --- a/lib/game/components/ship.dart +++ b/lib/game/components/ship.dart @@ -100,9 +100,9 @@ class Ship extends SpriteComponent late final String spritePath; double engineStrength = 125.0; - double bulletSpeed = 300.0; + double bulletSpeed = 400.0; double weightFactor = 1.0; - final double _drag = 5.0; + double dragFactor = 5.0; final Vector2 velocity = Vector2.zero(); final Vector2 drag = Vector2.zero(); @@ -208,7 +208,7 @@ class Ship extends SpriteComponent ..scale(engineStrength); drag ..setFrom(velocity) - ..scaleTo(_drag) + ..scaleTo(dragFactor) ..scale(-1); acceleration ..setFrom(engine) @@ -262,7 +262,7 @@ class Ship extends SpriteComponent if (other.ownerPlayerNumber == playerNumber) { return; } - velocity.add(other.velocity..scale(0.1)); + velocity.add(other.velocity..scale(0.2)); other.removeFromParent(); } else if (other is Ship && playerNumber < other.playerNumber) { _nextVelocity.setFrom(other.velocity.scaled(other.weightFactor)); diff --git a/lib/game/components/spotlight.dart b/lib/game/components/spotlight.dart index 7e93f84..608db6c 100644 --- a/lib/game/components/spotlight.dart +++ b/lib/game/components/spotlight.dart @@ -9,7 +9,7 @@ import 'package:lightrunners/game/components/ship.dart'; import 'package:lightrunners/game/lightrunners_game.dart'; import 'package:lightrunners/utils/utils.dart'; -const _spotlightRadius = 35.0; //pixels +const _spotlightRadius = 45.0; // pixels const _spotlightSpeed = 50.0; // pixels per second const _targetChangeProbability = 0.05; // per [_targetChangePeriod] const _targetChangePeriod = 0.5; // seconds diff --git a/lib/ui/palette.dart b/lib/ui/palette.dart index 2d57afd..9250c7f 100644 --- a/lib/ui/palette.dart +++ b/lib/ui/palette.dart @@ -1,7 +1,5 @@ import 'dart:ui'; -import 'package:lightrunners/game/components/bullet.dart'; - class GamePalette { static const red = Color(0xFFE03232); static const orange = Color(0xFFE07B32); @@ -28,9 +26,6 @@ class GamePalette { static final bulletPaints = shipValues.map((color) { return Paint() ..color = color - ..maskFilter = const MaskFilter.blur( - BlurStyle.normal, - bulletRadius / 2, - ); + ..maskFilter = const MaskFilter.blur(BlurStyle.normal, 3); }).toList(growable: false); }