diff --git a/luennot/luento09/Pong/Pong.cs b/luennot/luento09/Pong/Pong.cs index 9e885fec5c1368aac29c171401b8018e290aca53..fd8c7c02f96e5c03a495eccf874b564b6b568d7e 100644 --- a/luennot/luento09/Pong/Pong.cs +++ b/luennot/luento09/Pong/Pong.cs @@ -1,27 +1,24 @@ using System; -using System.Collections.Generic; using Jypeli; -using Jypeli.Assets; -using Jypeli.Controls; -using Jypeli.Widgets; namespace Pong; public class Pong : PhysicsGame { - Vector nopeusYlos = new Vector(0, 200); - Vector nopeusAlas = new Vector(0, -200); + private readonly Vector nopeusYlos = new Vector(0, 200); + private readonly Vector nopeusAlas = new Vector(0, -200); - PhysicsObject pallo; - PhysicsObject maila1; - PhysicsObject maila2; + private PhysicsObject pallo; + private PhysicsObject maila1; + private PhysicsObject maila2; - PhysicsObject vasenReuna; - PhysicsObject oikeaReuna; + private PhysicsObject vasenReuna; + private PhysicsObject oikeaReuna; - IntMeter pelaajan1Pisteet; - IntMeter pelaajan2Pisteet; + private IntMeter pelaajan1Pisteet; + private IntMeter pelaajan2Pisteet; + public override void Begin() { LuoKentta(); @@ -30,7 +27,8 @@ public class Pong : PhysicsGame AloitaPeli(); } - void LuoKentta() + + private void LuoKentta() { pallo = new PhysicsObject(40.0, 40.0); pallo.Shape = Shape.Circle; @@ -70,7 +68,8 @@ public class Pong : PhysicsGame Camera.ZoomToLevel(); } - PhysicsObject LuoMaila(double x, double y) + + private PhysicsObject LuoMaila(double x, double y) { PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); maila.Shape = Shape.Rectangle; @@ -82,13 +81,15 @@ public class Pong : PhysicsGame return maila; } - void LisaaLaskurit() + + private void LisaaLaskurit() { pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); } - IntMeter LuoPisteLaskuri(double x, double y) + + private IntMeter LuoPisteLaskuri(double x, double y) { IntMeter laskuri = new IntMeter(0); laskuri.MaxValue = 10; @@ -105,7 +106,8 @@ public class Pong : PhysicsGame return laskuri; } - void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) + + private void KasittelePallonTormays(PhysicsObject p, PhysicsObject kohde) { if (kohde == oikeaReuna) { @@ -117,13 +119,15 @@ public class Pong : PhysicsGame } } - void AloitaPeli() + + private void AloitaPeli() { Vector impulssi = new Vector(500.0, 0.0); pallo.Hit(impulssi * pallo.Mass); } - void AsetaOhjaimet() + + private void AsetaOhjaimet() { Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); @@ -152,7 +156,8 @@ public class Pong : PhysicsGame ControllerTwo.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); } - void AsetaNopeus(PhysicsObject maila, Vector nopeus) + + private void AsetaNopeus(PhysicsObject maila, Vector nopeus) { if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) {