From fc7433b98c63e5555b7574311888c6d5720b741f Mon Sep 17 00:00:00 2001
From: Kullberg Joonatan <joonatan.kullberg@gmail.com>
Date: Fri, 4 Apr 2025 10:58:43 +0300
Subject: [PATCH] bossfight trigger toimii paremmin

---
 .../Financial_Freedom/Financial_Freedom.cs    | 75 +++++++++++--------
 1 file changed, 43 insertions(+), 32 deletions(-)

diff --git a/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs b/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs
index e88c388..0a5cea0 100644
--- a/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs
+++ b/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs
@@ -242,10 +242,6 @@ public class  Financial_Freedom : PhysicsGame
     {
         if (pistelaskuri != null)
         {
-            if (pistelaskuri.Value >= 100000)
-            {
-                PlayerReachedBossCondition = true;
-            }
         }
     }
     
@@ -305,7 +301,7 @@ public class  Financial_Freedom : PhysicsGame
         PushButton kys = new PushButton(0,0,"");
         
         pelaa = new PushButton(nappiwidth, nappiheight, "Ota lainaa pankista ja lähde kasinolle");
-        pelaa.Position = new Vector(Screen.Left+400, 0);
+        pelaa.Position = new Vector(Screen.Left+400, 50);
         pelaa.Size = new Vector(750, 100);
         pelaa.TextScale = new Vector(2,2);
         pelaa.Clicked += delegate
@@ -318,7 +314,7 @@ public class  Financial_Freedom : PhysicsGame
         Add(pelaa);
 
         kys = new PushButton( nappiwidth, nappiheight, "Syöksy kuolemaasi");
-        kys.Position = new Vector(Screen.Right-400, -100); 
+        kys.Position = new Vector(Screen.Right-300, -150); 
         kys.Size = new Vector(500, 100);
         kys.TextScale = new Vector(2,2);
         kys.Clicked += delegate
@@ -384,7 +380,7 @@ public class  Financial_Freedom : PhysicsGame
         goal.Y = Screen.Top - 20;
         goal.BarColor = Color.Green;
         goal.BorderColor = Color.Gold;
-        Add(goal);
+        Add(goal);       
         
         pistelaskuri.MaxValue = tavoiteRaha;
     }
@@ -630,7 +626,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 mafiapomoille 100k$?";} return "Ulos"; }
+            case 6: {if(pistelaskuri.Value >= 100000){return "Kelpaisiko\nmafiapomoille\n100k$?";} return "Ulos"; }
             case 7: return "Mene kasinoon sisälle";
             default: return "Unknown";
         }
@@ -1769,6 +1765,18 @@ public class  Financial_Freedom : PhysicsGame
                 }
         }
         
+        PhysicsObject ptpallo = new PhysicsObject(1, 1, Shape.Circle);
+        
+        PisteAntaja(0, 200,  (0.25*tsplinko * yTs), ptpallo);
+        PisteAntaja(177, 150, (0.75*tsplinko * yTs), ptpallo);
+        PisteAntaja(-177, 150, (0.75*tsplinko * yTs), ptpallo);
+        PisteAntaja(316, 125, (2.5*tsplinko * yTs),ptpallo);
+        PisteAntaja(-316, 125, (2.5*tsplinko * yTs), ptpallo);
+        PisteAntaja(430, 100, (5*tsplinko * yTs), ptpallo);
+        PisteAntaja(-430, 100, (5*tsplinko * yTs), ptpallo);
+        PisteAntaja(520, 75, (20*tsplinko * yTs), ptpallo);
+        PisteAntaja(-520, 75, (20*tsplinko * yTs), ptpallo);
+        
         KerroinAlla(0, 0.25*tsplinko * yTs);
         KerroinAlla(177, 0.75*tsplinko * yTs);
         KerroinAlla(-177, 0.75*tsplinko * yTs);
@@ -1779,27 +1787,41 @@ public class  Financial_Freedom : PhysicsGame
         KerroinAlla(520, 25*tsplinko * yTs);
         KerroinAlla(-520, 25*tsplinko * yTs);
         
+        PhysicsObject ptbot = new PhysicsObject(Screen.Width*2, 10, Shape.Rectangle);
+        ptbot.Position = new Vector(0, Screen.Bottom+5); 
+        ptbot.MakeStatic();  
+        Add(ptbot);
+        
+        ptpallo.Collided += (rhapallo, pantajapalkki) => 
+        { 
+            if (rhapallo == ptpallo && pantajapalkki == ptbot) 
+            { 
+                ptpallo.Destroy();
+                peliKesken -= 1;
+            } 
+        };
+        
         Keyboard.Listen(Key.P, ButtonState.Pressed, async () => await VaihdaPanos(), "vaihtaa panoksen");
-        Keyboard.Listen(Key.Space, ButtonState.Down, ptpalloLuoja, "pudattaa pallon", this);
-        Keyboard.Listen(Key.PageDown, ButtonState.Down, ptpalloLuoja, "pudattaa pallon", this);
+        Keyboard.Listen(Key.Space, ButtonState.Down, ptpalloLuoja, "pudattaa pallon", this, ptpallo, ptbot);
+        Keyboard.Listen(Key.PageDown, ButtonState.Down, ptpalloLuoja, "pudattaa pallon", this, ptpallo, ptbot);
         
         
         TakaisinPV();
     }
-    
 
-    
+
     /// <summary>
     /// luo putoavan pallon ja palkin josta saa (ehkä) rahat takaisin
     /// </summary>
     /// <param name="peli"></param>
-    public void ptpalloLuoja(Game peli)
+    public void ptpalloLuoja(Game peli, PhysicsObject ptpallo, PhysicsObject ptbot)
     {
         if (pistelaskuri.Value >= panos)
         {
             peliKesken += 1;
             pistelaskuri.Value -= panos;
-            PhysicsObject ptpallo = new PhysicsObject(15, 15, Shape.Circle);
+            
+            ptpallo = new PhysicsObject(15, 15, Shape.Circle);
             ptpallo.Color=Color.Lime;
             ptpallo.Restitution = 0.35;
             ptpallo.X = RandomGen.NextDouble(-40,40);
@@ -1807,11 +1829,6 @@ public class  Financial_Freedom : PhysicsGame
             ptpallo.CollisionIgnoreGroup = 1; 
             peli.Add(ptpallo);
             
-            PhysicsObject ptbot = new PhysicsObject(Screen.Width*2, 10, Shape.Rectangle);
-            ptbot.Position = new Vector(0, Screen.Bottom+5); 
-            ptbot.MakeStatic();  
-            peli.Add(ptbot);
-            
             ptpallo.Collided += (rhapallo, pantajapalkki) => 
             { 
                 if (rhapallo == ptpallo && pantajapalkki == ptbot) 
@@ -1820,18 +1837,8 @@ public class  Financial_Freedom : PhysicsGame
                     peliKesken -= 1;
                 } 
             };
-            
-            PisteAntaja(0, 200,  (0.25*tsplinko * yTs), ptpallo);
-            PisteAntaja(177, 150, (0.75*tsplinko * yTs), ptpallo);
-            PisteAntaja(-177, 150, (0.75*tsplinko * yTs), ptpallo);
-            PisteAntaja(316, 125, (2.5*tsplinko * yTs),ptpallo);
-            PisteAntaja(-316, 125, (2.5*tsplinko * yTs), ptpallo);
-            PisteAntaja(430, 100, (5*tsplinko * yTs), ptpallo);
-            PisteAntaja(-430, 100, (5*tsplinko * yTs), ptpallo);
-            PisteAntaja(520, 75, (20*tsplinko * yTs), ptpallo);
-            PisteAntaja(-520, 75, (20*tsplinko * yTs), ptpallo);
-
         }
+        
         else
         {
             MessageDisplay.Add("Ei tarpeeksi rahaa panoksen asettamiseen.");
@@ -1849,7 +1856,7 @@ public class  Financial_Freedom : PhysicsGame
         Add(kerroinlabel);
     }
     
-    
+   
     /// <summary>
     /// luo annetun levyisen palkin joka antaa rahan takaisin annetulla kertoimella
     /// </summary>
@@ -3104,7 +3111,11 @@ public class  Financial_Freedom : PhysicsGame
     {
         peliKesken = 0;
         //if (pistelaskuri.Value > 10000) { ClearAll(); var mafiapomo = new Bossfight(); mafiapomo.Boss();}
-        if (pistelaskuri.Value > 100000){Exit();}
+        if (pistelaskuri.Value >= 100000)
+        {
+            PlayerReachedBossCondition = true;
+            Exit();
+        }
         else
         {
             ClearControls();
-- 
GitLab