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

Commit

Permalink
fix: vehicle spawning behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
alestiago committed Mar 11, 2024
1 parent a6be451 commit ac2abcc
Showing 1 changed file with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ class VehicleSpawningBehavior extends Behavior<RoadLane>
FutureOr<void> onLoad() async {
await super.onLoad();

final world = ancestors().whereType<TrashyRoadWorld>().first;

for (var i = 0; i < parent.traffic; i++) {
var startPosition = (i / parent.traffic) * world.size.x;
var startPosition = (i / parent.traffic) * game.bounds!.bottomRight.x;

startPosition *= _minTrafficVariation +
(game.random.nextDouble() * (1 - _minTrafficVariation));
Expand All @@ -48,15 +46,12 @@ class VehicleSpawningBehavior extends Behavior<RoadLane>

@override
void update(double dt) {
final bounds = game.bounds;
if (bounds == null) return;

final vehicles = parent.children.whereType<Vehicle>();
for (final vehicle in vehicles) {
_vector2Cache
..setFrom(parent.position)
..add(vehicle.position);
final isWithinBound = bounds.isPointInside(_vector2Cache);
final isWithinBound = game.bounds!.isPointInside(_vector2Cache);
if (!isWithinBound) {
vehicle.position.setAll(0);
}
Expand Down

0 comments on commit ac2abcc

Please sign in to comment.