Skip to content

Commit

Permalink
feat: Better bullets (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzanardo authored Jun 18, 2023
1 parent 2fd240f commit 28ae8da
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
9 changes: 5 additions & 4 deletions lib/game/components/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ class Background extends PositionComponent with HasGameRef<LightRunnersGame> {
});
mesh = Delaunay.triangulate(points)
.map((e) => e.translateBy(delta))
.map((triangle) => (
triangle: triangle,
shadeLevel: _r.nextInt(_numberShades),
),
.map(
(triangle) => (
triangle: triangle,
shadeLevel: _r.nextInt(_numberShades),
),
)
.toList();
}
Expand Down
22 changes: 18 additions & 4 deletions lib/game/components/bullet.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import 'dart:ui';

import 'package:flame/collisions.dart';
import 'package:flame/components.dart';
import 'package:flame/experimental.dart';
import 'package:flame/palette.dart';
import 'package:lightrunners/game/game.dart';

class Bullet extends CircleComponent with HasGameReference<LightRunnersGame> {
static final _paint = BasicPalette.white.paint();
final int ownerPlayerNumber;
final Vector2 velocity;
final Color color;

static const _radius = 8.0;

Bullet({
required this.ownerPlayerNumber,
required super.position,
required this.velocity,
}) : super(radius: 2.0, anchor: Anchor.center, paint: _paint);
required this.color,
}) : super(
radius: _radius,
anchor: Anchor.center,
paint: Paint()
..color = color
..maskFilter = const MaskFilter.blur(
BlurStyle.normal,
_radius / 2,
),
);

@override
Future<void> onLoad() async {
Expand All @@ -29,7 +42,8 @@ class Bullet extends CircleComponent with HasGameReference<LightRunnersGame> {
..setFrom(velocity)
..scale(dt);
position.add(_velocityTmp);
if (!game.cameraComponent.canSee(this)) {

if (!game.playArea.contains(position.toOffset())) {
removeFromParent();
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/game/components/ship.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Ship extends SpriteComponent
ownerPlayerNumber: playerNumber,
position: position + (move..scaled(size.length)),
velocity: bulletVector * _bulletSpeed,
color: paint.color,
),
);
}
Expand Down

0 comments on commit 28ae8da

Please sign in to comment.