Skip to content

Commit

Permalink
Swap the inactivated meteor with the last activated one
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanlangston authored Jan 4, 2024
1 parent 1c326a6 commit c6751ad
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/ViewModels/AsteroidsViewModel.zig
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create(
midMeteorsCount += 1;
}

// Swap the inactive meteor with the last active one
const temp = bigMeteors[i];
bigMeteors[i] = bigMeteors[bigMeteorsCount];
bigMeteors[bigMeteorsCount] = bigMeteors[i];

NewAlien();
},
.collide => {
Expand Down Expand Up @@ -268,6 +273,11 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create(
);
}

// Swap the inactive meteor with the last active one
const temp = bigMeteors[i];
bigMeteors[i] = bigMeteors[bigMeteorsCount];
bigMeteors[bigMeteorsCount] = bigMeteors[i];

mediumMeteors[@intCast(midMeteorsCount)].active = true;
midMeteorsCount += 1;
}
Expand Down Expand Up @@ -305,6 +315,11 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create(
);
}

// Swap the inactive meteor with the last active one
const temp = mediumMeteors[i];
mediumMeteors[i] = mediumMeteors[midMeteorsCount];
mediumMeteors[midMeteorsCount] = mediumMeteors[i];

smallMeteors[@intCast(smallMeteorsCount)].active = true;
smallMeteorsCount += 1;
}
Expand Down Expand Up @@ -349,6 +364,11 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create(
smallMeteorsCount += 1;
}

// Swap the inactive meteor with the last active one
const temp = mediumMeteors[i];
mediumMeteors[i] = mediumMeteors[midMeteorsCount];
mediumMeteors[midMeteorsCount] = mediumMeteors[i];

NewAlien();

nextShieldLevel -= 8;
Expand All @@ -375,6 +395,11 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create(
}
}

// Swap the inactive meteor with the last active one
const temp = smallMeteors[i];
smallMeteors[i] = smallMeteors[smallMeteorsCount];
smallMeteors[smallMeteorsCount] = smallMeteors[i];

NewAlien();
},
.collide => {
Expand Down Expand Up @@ -405,6 +430,11 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create(
}
}

// Swap the inactive meteor with the last active one
const temp = smallMeteors[i];
smallMeteors[i] = smallMeteors[smallMeteorsCount];
smallMeteors[smallMeteorsCount] = smallMeteors[i];

NewAlien();

nextShieldLevel -= 6;
Expand Down

0 comments on commit c6751ad

Please sign in to comment.