Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
feat: make birds move at random speeds£
Browse files Browse the repository at this point in the history
  • Loading branch information
OlliePugh committed Mar 12, 2024
1 parent 9b775ea commit 5349c0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import 'package:trashy_road/src/game/game.dart';
class BirdFlyingBehavior extends Behavior<Bird>
with HasGameReference<TrashyRoadGame> {
/// The speed multiplier for the bird.
static const birdSpeedMultiplier = 80;
static const birdSpeedMultiplier = 30;

@override
void update(double dt) {
super.update(dt);

final distanceCovered = birdSpeedMultiplier * dt;
final distanceCovered = birdSpeedMultiplier * dt * parent.speed;

final direction = parent.isFlyingRight ? 1 : -1;
parent.position.x += distanceCovered * direction;
Expand Down
11 changes: 9 additions & 2 deletions packages/trashy_road/lib/src/game/entities/bird/bird.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:trashy_road/src/game/game.dart';
export 'behaviors/behaviors.dart';

class Bird extends PositionedEntity with ZIndex {
Bird._({required this.isFlyingRight})
Bird._({required this.isFlyingRight, required this.speed})
: super(
scale: Vector2.all(0.5),
behaviors: [
Expand All @@ -33,8 +33,9 @@ class Bird extends PositionedEntity with ZIndex {

factory Bird.randomize() {
final isFlyingRight = random.nextBool();
final speed = minSpeed + random.nextDouble() * (maxSpeed - minSpeed);

return Bird._(isFlyingRight: isFlyingRight);
return Bird._(isFlyingRight: isFlyingRight, speed: speed);
}

static List<Bird> randomAmount() {
Expand All @@ -48,9 +49,15 @@ class Bird extends PositionedEntity with ZIndex {
/// The maximum amount of birds that are loaded into a map.
static const maxAmountOfBirds = 5;

static const maxSpeed = 3.0;
static const minSpeed = 1.0;

/// Whether the bird is flying right.
final bool isFlyingRight;

/// Speed Multiplier
final double speed;

@override
int get zIndex => 100000;
}

0 comments on commit 5349c0e

Please sign in to comment.