From d7cf33ccc457f296e7af322743ee10405f089bea Mon Sep 17 00:00:00 2001 From: josisaku <josisaku@jyu.fi> Date: Sat, 5 Apr 2025 22:18:46 +0300 Subject: [PATCH] movement --- .../Financial_Freedom/Bossfight.cs | 101 +++++++++++++++--- 1 file changed, 84 insertions(+), 17 deletions(-) diff --git a/Financial_Freedom/Financial_Freedom/Bossfight.cs b/Financial_Freedom/Financial_Freedom/Bossfight.cs index 63a8af3..22f6fdc 100644 --- a/Financial_Freedom/Financial_Freedom/Bossfight.cs +++ b/Financial_Freedom/Financial_Freedom/Bossfight.cs @@ -26,7 +26,7 @@ public class Bossfight : PhysicsGame private PlatformCharacter2 boss; private IntMeter bossHealth; private IntMeter teroHealth; - private Timer projectileTimer; + private Timer bossAttackTimer; private Timer bossMovementTimer; private double bossMoveSpeed = 150; @@ -35,6 +35,9 @@ public class Bossfight : PhysicsGame private Weapon rifle = new AssaultRifle(20, 5); private bool startBoss = false; + private bool isBossMoving = false; + private Vector bossMovementDirection = Vector.Zero; + private double bossMovementDuration = 0; private GameObject bossHealthBar; private GameObject playerHealthBar; @@ -51,6 +54,8 @@ public class Bossfight : PhysicsGame bottomWall = PhysicsObject.CreateStaticObject(Level.Width, 200.0); bottomWall.Y = Level.Bottom + 25.0; + bottomWall.Restitution = 0.2; + bottomWall.KineticFriction = 0.4; bottomWall.Color = Color.Gray; bottomWall.Tag = "reuna"; bottomWall.MakeStatic(); @@ -113,6 +118,8 @@ public class Bossfight : PhysicsGame { PhysicsObject platform = new PhysicsObject(200, 40); platform.Position = new Vector(Screen.Left+i*(Screen.Width/6), -50); + platform.Restitution = 0.1; + platform.KineticFriction = 0.3; platform.Color = Color.Green; platform.MakeStatic(); Add(platform); @@ -123,10 +130,10 @@ public class Bossfight : PhysicsGame { tero = new PlatformCharacter(75, 120); tero.Image = LoadImage("tero.png"); - tero.Position = new Vector(0, -200); + tero.Position = new Vector(0, 0); tero.Mass = 10.0; - tero.CollisionIgnoreGroup = 1; + tero.CollisionIgnoreGroup = 2; rifle = new AssaultRifle(150, 100); rifle.Image = LoadImage("ch661.png"); @@ -141,7 +148,7 @@ public class Bossfight : PhysicsGame tero.Add(rifle); teroHealth = new IntMeter(teroHealthValue, 0, teroHealthValue); - bossHealth.LowerLimit += BossDeath; + teroHealth.LowerLimit += TeroDeath; BarGauge terohpPalkki = new BarGauge(60, Screen.Width/4); terohpPalkki.Y = Screen.BottomSafe + terohpPalkki.Width/2+25; terohpPalkki.X = Screen.LeftSafe + terohpPalkki.Height/2+25; @@ -151,7 +158,7 @@ public class Bossfight : PhysicsGame terohpPalkki.Color = Color.Black; terohpPalkki.BarColor = Color.Green; - Label bossHealthLabel = new Label(600, 200) + Label teroHealthLabel = new Label(600, 200) { Text = "Tero", TextScale = new Vector(2,2), @@ -161,7 +168,7 @@ public class Bossfight : PhysicsGame }; Add(terohpPalkki); - terohpPalkki.Add(bossHealthLabel); + terohpPalkki.Add(teroHealthLabel); } private void CreateBoss() @@ -169,9 +176,9 @@ public class Bossfight : PhysicsGame boss = new PlatformCharacter2(120, 240); boss.Shape = Shape.Rectangle; boss.Color = Color.Red; - boss.Position = new Vector(600, 300); + boss.Position = new Vector(600, 100); boss.CollisionIgnoreGroup = 2; - boss.Mass = 1.0; + boss.Mass = 10.0; Add(boss); bossHealth = new IntMeter(bossHealthValue, 1, bossHealthValue); @@ -199,6 +206,7 @@ public class Bossfight : PhysicsGame } public void BossDeath(){Exit();} + public void TeroDeath(){Exit();} private void TeroProjectileHit(PhysicsObject projectile, PhysicsObject target) { @@ -251,9 +259,9 @@ public class Bossfight : PhysicsGame private void StartBossBehavior() { // Projectile attack pattern - projectileTimer = new Timer(1.5); - projectileTimer.Timeout += ShootProjectiles; - projectileTimer.Start(); + bossAttackTimer = new Timer(1.5); + bossAttackTimer.Timeout += BossAttack; + bossAttackTimer.Start(); // Movement pattern bossMovementTimer = new Timer(0.5); @@ -265,18 +273,76 @@ public class Bossfight : PhysicsGame private void MoveBoss() { - int i = RandomNumberGenerator.GetInt32(0, 4); + if (isBossMoving) return; // Prevent overlapping movements + int i = RandomNumberGenerator.GetInt32(0, 5); switch (i) { - case 0: boss.Jump(600); break; - case 1: boss.X += 75.0; break; - case 2: boss.X -= 75.0; break; - case 3: boss.X += 150.0;break; - case 4: boss.X -= 150.0; break; + case 0: + boss.Jump(600000); + break; + case 1: + StartMovement(new Vector(12, 0), 1.0); + break; + case 2: + StartMovement(new Vector(-12, 0), 1.0); + break; + case 3: + StartMovement(new Vector(18, 0), 0.7); + break; + case 4: + StartMovement(new Vector(-18, 0), 0.7); + break; } } + private void StartMovement(Vector direction, double duration) + { + isBossMoving = true; + bossMovementDirection = direction; + bossMovementDuration = duration; + + Timer movementTimer = new Timer(0.01); + movementTimer.Timeout += () => + { + boss.X += bossMovementDirection.X; + bossMovementDuration -= 0.01; + + if (bossMovementDuration <= 0) + { + movementTimer.Stop(); + isBossMoving = false; + } + }; + movementTimer.Start(); + } + + + private void BossAttack() + { + int i = RandomNumberGenerator.GetInt32(0, 3); + + switch (i) + { + case 0: + ShootProjectiles(); + break; + case 1: + + break; + case 2: + + break; + case 3: + + break; + case 4: + + break; + } + } + + private void ShootProjectiles() { for (int i = 0; i < 3; i++) @@ -327,6 +393,7 @@ public class Bossfight : PhysicsGame bullet.Velocity *= bulletVel; bullet.MaximumLifetime = TimeSpan.FromSeconds(bulletLifespan); bullet.IgnoresGravity = false; + bullet.Mass = 1.0; bullet.Tag = "PlayerProjectile"; bullet.CollisionIgnoreGroup = 1; } -- GitLab