Skip to content

Commit

Permalink
Meteors spawn closer to player
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanlangston committed Dec 29, 2023
1 parent 0332119 commit b3a3882
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/Models/Meteor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@ pub const Meteor = struct {
var vely: f32 = undefined;

var posx: f32 = (Shared.Random.Get().float(f32) * (screenSize.x - 150)) + 150;
while (offscreen) {
const radiusX = if (offscreen) activeRadiusX else 100;
while (true) {
const visibleX = posx - player.position.x;
if (visibleX > activeRadiusX or visibleX < -activeRadiusX) {
if (visibleX > radiusX or visibleX < -radiusX) {
break;
}
posx = (Shared.Random.Get().float(f32) * (screenSize.x - 150)) + 150;
}

var posy: f32 = (Shared.Random.Get().float(f32) * (screenSize.y - 150)) + 150;
while (offscreen) {
const radiusY = if (offscreen) activeRadiusY else 100;
while (true) {
const visibleY = posy - player.position.y;
if (visibleY > activeRadiusY or visibleY < -activeRadiusY) {
if (visibleY > radiusY or visibleY < -radiusY) {
break;
}
posy = (Shared.Random.Get().float(f32) * (screenSize.y - 150)) + 150;
Expand Down
6 changes: 3 additions & 3 deletions src/ViewModels/AsteroidsViewModel.zig
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,19 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create(
while (initialMeteorCount < totalStartingMeteors) {
switch (Shared.Random.Get().intRangeAtMost(u2, 0, 2)) {
2 => {
bigMeteors[@intCast(bigMeteorsCount)].RandomizePositionAndSpeed(player, screenSize, true);
bigMeteors[@intCast(bigMeteorsCount)].RandomizePositionAndSpeed(player, screenSize, false);
bigMeteors[@intCast(bigMeteorsCount)].active = true;
initialMeteorCount += 4;
bigMeteorsCount += 1;
},
1 => {
mediumMeteors[@intCast(midMeteorsCount)].RandomizePositionAndSpeed(player, screenSize, true);
mediumMeteors[@intCast(midMeteorsCount)].RandomizePositionAndSpeed(player, screenSize, false);
mediumMeteors[@intCast(midMeteorsCount)].active = true;
initialMeteorCount += 2;
midMeteorsCount += 1;
},
else => {
smallMeteors[@intCast(smallMeteorsCount)].RandomizePositionAndSpeed(player, screenSize, true);
smallMeteors[@intCast(smallMeteorsCount)].RandomizePositionAndSpeed(player, screenSize, false);
smallMeteors[@intCast(smallMeteorsCount)].active = true;
initialMeteorCount += 1;
smallMeteorsCount += 1;
Expand Down

0 comments on commit b3a3882

Please sign in to comment.