diff --git a/Financial_Freedom/Financial_Freedom/Bossfight.cs b/Financial_Freedom/Financial_Freedom/Bossfight.cs index c78f13a0c57691a7df1debbff3c8b74c0bfa0e6c..b0387739b84fa921f8c2e778e7f8646e65d7112b 100644 --- a/Financial_Freedom/Financial_Freedom/Bossfight.cs +++ b/Financial_Freedom/Financial_Freedom/Bossfight.cs @@ -1,4 +1,5 @@ using System; +using System.Security.Cryptography; using FarseerPhysics.Dynamics; using FarseerPhysics.Dynamics.Joints; using Jypeli; @@ -9,11 +10,22 @@ using Jypeli.Widgets; public class Bossfight : PhysicsGame { + private const int teroHealthValue = 100; + private const int terofireRate = 10; + private const int teroAmmoValue = terofireRate; + + private const int bulletVel = 7; + private const int bulletSize = 2; + private const int bulletLifespan = 1; + + private const int bossHealthValue = 100; + const int teroDamageToBoss = 1; + private PlatformCharacter tero; private AssaultRifle playerWeapon; private PlatformCharacter2 boss; private IntMeter bossHealth; - private IntMeter playerHealth; + private IntMeter teroHealth; private Timer projectileTimer; private Timer bossMovementTimer; private double bossMoveSpeed = 150; @@ -25,21 +37,25 @@ public class Bossfight : PhysicsGame private bool startBoss = false; private GameObject bossHealthBar; - private GameObject bossHealthBackground; private GameObject playerHealthBar; - private GameObject playerHealthBackground; + private GameObject cursor; + private Image cursorImage; public override void Begin() { IsFullScreen = true; Level.Size = new Vector(5000, 1500); // Larger level for sidescrolling + + CustomCursor(); bottomWall = PhysicsObject.CreateStaticObject(Level.Width, 200.0); - bottomWall.Y = Level.Bottom + 100.0; + bottomWall.Y = Level.Bottom + 25.0; bottomWall.Color = Color.Gray; bottomWall.Tag = "reuna"; + bottomWall.MakeStatic(); Add(bottomWall); + Level.CreateBorders(1.0, true); Level.CreateLeftBorder(1.0, true).Tag = "reuna"; Level.CreateRightBorder(1.0, true).Tag = "reuna"; @@ -55,52 +71,28 @@ public class Bossfight : PhysicsGame Camera.StayInLevel = true; CreatePlatforms(); - CreateHealthBars(); - SetupCollisions(); - SetupControls(); StartBossBehavior(); + + SetupControls(); } - - private void CreateHealthBars() - { - // Boss health bar background - bossHealthBackground = new Widget(Screen.Width -100, 50); - bossHealthBackground.Color = Color.Gray; - bossHealthBackground.Position = new Vector(0, Screen.Top - 75); - Add(bossHealthBackground); - // Boss health bar foreground - bossHealthBar = new Widget(Screen.Width -100, 50); - bossHealthBar.Color = Color.Red; - bossHealthBar.Position = bossHealthBackground.Position; - Label bossHealthLabel = new Label(600, 200) - { - Text = "Boss Health", - TextScale = new Vector(2,2), - TextColor = Color.White, - Position = new Vector(0,0) - - }; - Add(bossHealthBar); - bossHealthBar.Add(bossHealthLabel); + public void CustomCursor() + { + // Add this at the start of the Begin() method + Mouse.IsCursorVisible = false; + cursorImage = LoadImage("scope.png"); - // Player health bar background - playerHealthBackground = new Widget(300, 30); - playerHealthBackground.Color = Color.Gray; - playerHealthBackground.Position = new Vector(Screen.Left + 170, Screen.Top - 50); - Add(playerHealthBackground); - - // Player health bar foreground - playerHealthBar = new Widget(300, 30); - playerHealthBar.Color = Color.Green; - playerHealthBar.Position = playerHealthBackground.Position; - Add(playerHealthBar); + // Create custom cursor + cursor = new GameObject(100, 100); + cursor.Image = cursorImage; + Add(cursor); } - + protected override void Update(Time time) { base.Update(time); - if (bossHealth != null && playerHealth != null) {UpdateHealthBars();} + + cursor.Position = Mouse.PositionOnWorld; // Get mouse position relative to the player Vector mousePos = Mouse.PositionOnWorld; @@ -110,29 +102,9 @@ public class Bossfight : PhysicsGame float angle = (float)Math.Atan2(direction.Y, direction.X); rifle.Angle = Angle.FromRadians(angle); - if (rifle.Ammo.Value == 0){Timer.SingleShot(5.0, () => rifle.Ammo.Value = 30);} + if (rifle.Ammo.Value == 0){Timer.SingleShot(3.0, () => rifle.Ammo.Value = teroAmmoValue);} } - private void UpdateHealthBars() - { - if (bossHealthBar != null && bossHealthBackground != null) - UpdateHealthBar(bossHealth, bossHealthBar, bossHealthBackground); - - if (playerHealthBar != null && playerHealthBackground != null) - UpdateHealthBar(playerHealth, playerHealthBar, playerHealthBackground); - } - - private void UpdateHealthBar(IntMeter meter, GameObject bar, GameObject background) - { - if (meter == null || bar == null || background == null) return; - - double healthPercent = (double)meter.Value / meter.MaxValue; - bar.Width = background.Width * healthPercent; - bar.Position = new Vector( - background.Left + (bar.Width / 2), - background.Position.Y - ); - } private void CreatePlatforms() { @@ -149,28 +121,47 @@ public class Bossfight : PhysicsGame public void CreatePlayer() { - rifle = new AssaultRifle(100, 66); - rifle.Image = LoadImage("ch661.png"); - tero = new PlatformCharacter(75, 120); - tero.Shape = Shape.Rectangle; - tero.Color = Color.Blue; + tero.Image = LoadImage("tero.png"); tero.Position = new Vector(0, -200); - playerHealth = new IntMeter(100, 0, 100); - + tero.Mass = 10.0; - tero.Weapon = rifle; - tero.Weapon.Ammo.Value = 25; - tero.Weapon.FireRate = 50; tero.CollisionIgnoreGroup = 1; - playerHealth = new IntMeter(100, 0, 100); - tero.Image = LoadImage("tero.png"); - tero.Weapon.ProjectileCollision += OnProjectileHit; + rifle = new AssaultRifle(150, 100); + rifle.Image = LoadImage("ch661.png"); + + tero.Weapon = rifle; + tero.Weapon.Ammo.Value = teroAmmoValue; + tero.Weapon.FireRate = terofireRate; + tero.Weapon.ProjectileCollision += TeroProjectileHit; tero.Weapon.Tag = "PlayerProjectile"; Add(tero); tero.Add(rifle); + + teroHealth = new IntMeter(teroHealthValue, 0, teroHealthValue); + bossHealth.LowerLimit += BossDeath; + BarGauge terohpPalkki = new BarGauge(60, Screen.Width/4); + terohpPalkki.Y = Screen.BottomSafe + terohpPalkki.Width/2+25; + terohpPalkki.X = Screen.LeftSafe + terohpPalkki.Height/2+25; + terohpPalkki.Angle -= Angle.FromRadians(Math.PI / 2); + terohpPalkki.BindTo(teroHealth); + terohpPalkki.BorderColor = Color.Black; + terohpPalkki.Color = Color.Black; + terohpPalkki.BarColor = Color.Green; + + Label bossHealthLabel = new Label(600, 200) + { + Text = "Tero", + TextScale = new Vector(2,2), + TextColor = Color.White, + Position = terohpPalkki.Position + + }; + + Add(terohpPalkki); + terohpPalkki.Add(bossHealthLabel); } private void CreateBoss() @@ -180,30 +171,42 @@ public class Bossfight : PhysicsGame boss.Color = Color.Red; boss.Position = new Vector(600, 300); boss.CollisionIgnoreGroup = 2; - boss.Mass = 10.0; - bossHealth = new IntMeter(500, 0, 300); + boss.Mass = 1.0; Add(boss); - } - - private void SetupCollisions() - { - // Player projectiles hitting boss - //AddCollisionHandler(boss, tero.Weapon.Shoot(), OnProjectileHit); - - // Boss projectiles hitting player - AddCollisionHandler(tero, typeof(PhysicsObject), OnPlayerHitByProjectile); + bossHealth = new IntMeter(bossHealthValue, 1, bossHealthValue); + bossHealth.LowerLimit += BossDeath; + BarGauge bosshpPalkki = new BarGauge(60, Screen.Width-100); + bosshpPalkki.Y = Screen.TopSafe - bosshpPalkki.Width/2-25; + bosshpPalkki.Angle -= Angle.FromRadians(Math.PI / 2); + bosshpPalkki.BindTo(bossHealth); + bosshpPalkki.BorderColor = Color.Black; + bosshpPalkki.Color = Color.Black; + bosshpPalkki.BarColor = Color.Red; + + Label bossHealthLabel = new Label(600, 200) + { + Text = "Dimitri (Diddler) Smirnov", + TextScale = new Vector(2,2), + TextColor = Color.White, + Position = bosshpPalkki.Position + + }; + + Add(bosshpPalkki); + bosshpPalkki.Add(bossHealthLabel); } + + public void BossDeath(){Exit();} - private void OnProjectileHit(PhysicsObject projectile, PhysicsObject target) + private void TeroProjectileHit(PhysicsObject projectile, PhysicsObject target) { if (projectile.Tag as string == "PlayerProjectile" && target == boss) { - bossHealth.Value -= 1; + bossHealth.Value -= teroDamageToBoss; projectile.Destroy(); ShowBossDamageEffect(); - CheckBossDefeat(); } if (projectile.Tag as string == "PlayerProjectile" && target.Tag.ToString() == "reuna") @@ -213,11 +216,11 @@ public class Bossfight : PhysicsGame } - private void OnPlayerHitByProjectile(PhysicsObject projectile, PhysicsObject target) + private void BossProjectileHit(PhysicsObject projectile, PhysicsObject target) { if (projectile.Tag as string == "BossProjectile" && target == tero) { - playerHealth.Value -= 20; + teroHealth.Value -= 20; projectile.Destroy(); ShowPlayerDamageEffect(); CheckPlayerDeath(); @@ -236,18 +239,9 @@ public class Bossfight : PhysicsGame Timer.SingleShot(0.2, () => tero.Color = Color.Blue); } - private void CheckBossDefeat() - { - if (bossHealth.Value <= 0) - { - MessageDisplay.Add("VICTORY!"); - Exit(); - } - } - private void CheckPlayerDeath() { - if (playerHealth.Value <= 0) + if (teroHealth.Value <= 0) { MessageDisplay.Add("GAME OVER"); Exit(); @@ -262,7 +256,7 @@ public class Bossfight : PhysicsGame projectileTimer.Start(); // Movement pattern - bossMovementTimer = new Timer(3.0); + bossMovementTimer = new Timer(0.5); bossMovementTimer.Timeout += MoveBoss; bossMovementTimer.Start(); @@ -271,7 +265,16 @@ public class Bossfight : PhysicsGame private void MoveBoss() { + int i = RandomNumberGenerator.GetInt32(0, 4); + 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; + } } private void ShootProjectiles() @@ -290,31 +293,29 @@ public class Bossfight : PhysicsGame // Add velocity towards player Vector direction = (tero.Position - boss.Position).Normalize(); - projectile.Velocity = direction * 300; + projectile.Velocity = direction * 3000; Add(projectile); Timer.SingleShot(5.0, projectile.Destroy); } } - - private void SetupControls() { Keyboard.Listen(Key.A, ButtonState.Down, () => tero.X -= 12, "Move left"); Keyboard.Listen(Key.D, ButtonState.Down, () => tero.X += 12, "Move right"); - Keyboard.Listen(Key.W, ButtonState.Down, () => tero.Jump(500.0), "Jump"); + Keyboard.Listen(Key.W, ButtonState.Pressed, () => tero.Jump(500.0), "Jump"); // Safe shooting Mouse.Listen(MouseButton.Left, ButtonState.Down, () => { - ShootWeapon(rifle); + TeroShootWeapon(rifle); }, "Shoot"); Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Quit"); } - void ShootWeapon(Weapon weapon) { + void TeroShootWeapon(Weapon weapon) { if (weapon == null) { Console.WriteLine("Weapon is null!"); // Log error @@ -322,13 +323,12 @@ public class Bossfight : PhysicsGame } PhysicsObject bullet = weapon.Shoot(); if (bullet != null) { - bullet.Size *= 1 ; // Customize projectile size - bullet.Velocity *= 12; - bullet.MaximumLifetime = TimeSpan.FromSeconds(1); + bullet.Size *= bulletSize; // Customize projectile size + bullet.Velocity *= bulletVel; + bullet.MaximumLifetime = TimeSpan.FromSeconds(bulletLifespan); bullet.IgnoresGravity = false; bullet.Tag = "PlayerProjectile"; bullet.CollisionIgnoreGroup = 1; } } - } \ No newline at end of file diff --git a/Financial_Freedom/Financial_Freedom/Content/scope.png b/Financial_Freedom/Financial_Freedom/Content/scope.png new file mode 100644 index 0000000000000000000000000000000000000000..95cb5e465b89532c034f6c104796c4f7709fc781 Binary files /dev/null and b/Financial_Freedom/Financial_Freedom/Content/scope.png differ diff --git a/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs b/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs index 0a5cea0c747f55058827f072cbc2980f808a9cd7..8e4a77cbe5f3493a359082a74cfc44e7586a9b6e 100644 --- a/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs +++ b/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs @@ -263,7 +263,7 @@ public class Financial_Freedom : PhysicsGame Level.Background.Image = LoadImage("dia1.png"); Level.Background.Width = Screen.Width; Level.Background.Height = Screen.Height; - Keyboard.Listen(Key.Space, ButtonState.Pressed, () => + Keyboard.Listen(Key.Space, ButtonState.Pressed, () => { if (i < 11) { @@ -278,6 +278,13 @@ public class Financial_Freedom : PhysicsGame } }, "seuraava dia"); + Keyboard.Listen(Key.B, ButtonState.Pressed, () => + { + PlayerReachedBossCondition = true; + Exit(); + }, "BossFight Skip"); + + } public async Task Valikko() // lore @@ -626,7 +633,7 @@ public class Financial_Freedom : PhysicsGame case 3: return "Ruletti"; case 4: return "Slots"; case 5: return "Coinflip"; - case 6: {if(pistelaskuri.Value >= 100000){return "Kelpaisiko\nmafiapomoille\n100k$?";} return "Ulos"; } + case 6: {if(pistelaskuri.Value >= 1000000){return "Kelpaisiko\nmafiapomoille\n1M$?";} return "Ulos"; } case 7: return "Mene kasinoon sisälle"; default: return "Unknown"; } @@ -3111,7 +3118,7 @@ public class Financial_Freedom : PhysicsGame { peliKesken = 0; //if (pistelaskuri.Value > 10000) { ClearAll(); var mafiapomo = new Bossfight(); mafiapomo.Boss();} - if (pistelaskuri.Value >= 100000) + if (pistelaskuri.Value >= 1000000) { PlayerReachedBossCondition = true; Exit(); diff --git a/Financial_Freedom/Financial_Freedom/Financial_Freedom.csproj b/Financial_Freedom/Financial_Freedom/Financial_Freedom.csproj index b3362f4da639a14e8425c48024c0abedc1e3f2ed..76f858853cb8a79d2b21acad75146d20003dda9d 100644 --- a/Financial_Freedom/Financial_Freedom/Financial_Freedom.csproj +++ b/Financial_Freedom/Financial_Freedom/Financial_Freedom.csproj @@ -395,6 +395,9 @@ <None Update="Content\ch661.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Update="Content\scope.png"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> </ItemGroup> <ItemGroup>