Skip to content

Commit

Permalink
fix: Color, powerup and ship parameter fixes (#84)
Browse files Browse the repository at this point in the history
Some general fixes
  • Loading branch information
spydon authored Jul 3, 2023
1 parent 0d5542e commit ab36227
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 30 deletions.
21 changes: 9 additions & 12 deletions lib/game/components/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<LightRunnersGame> {
with HasGameReference<LightRunnersGame>, HasPaint {
late Rect clipArea;
late List<ShadedTriangle> mesh;

Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}

Expand All @@ -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();
Expand Down
4 changes: 1 addition & 3 deletions lib/game/components/bullet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<LightRunnersGame> {
final int ownerPlayerNumber;
final Vector2 velocity;
Expand All @@ -19,7 +17,7 @@ class Bullet extends CircleComponent with HasGameReference<LightRunnersGame> {
required this.velocity,
required this.color,
}) : super(
radius: velocity.length / 32,
radius: velocity.length / 50,
anchor: Anchor.center,
paint: GamePalette.bulletPaints[ownerPlayerNumber],
);
Expand Down
9 changes: 5 additions & 4 deletions lib/game/components/powerup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
}
8 changes: 4 additions & 4 deletions lib/game/components/ship.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -208,7 +208,7 @@ class Ship extends SpriteComponent
..scale(engineStrength);
drag
..setFrom(velocity)
..scaleTo(_drag)
..scaleTo(dragFactor)
..scale(-1);
acceleration
..setFrom(engine)
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion lib/game/components/spotlight.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions lib/ui/palette.dart
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
}

0 comments on commit ab36227

Please sign in to comment.