From c6751ad0c6e15a4531762a7062c68fb34143c76e Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 4 Jan 2024 10:14:27 -0500 Subject: [PATCH] Swap the inactivated meteor with the last activated one --- src/ViewModels/AsteroidsViewModel.zig | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/ViewModels/AsteroidsViewModel.zig b/src/ViewModels/AsteroidsViewModel.zig index dee35c8..88af6fa 100644 --- a/src/ViewModels/AsteroidsViewModel.zig +++ b/src/ViewModels/AsteroidsViewModel.zig @@ -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 => { @@ -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; } @@ -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; } @@ -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; @@ -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 => { @@ -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;