- Timestamp:
- 2013-06-25 12:48:45 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/26/RoopeR/Pong/Pong/Pong/Pong.cs
r4197 r4211 9 9 public class Pong : PhysicsGame 10 10 { 11 Vector nopeusYlos = new Vector(0, 200); 12 Vector nopeusAlas = new Vector(0, -200); 11 13 PhysicsObject pallo; 12 14 15 PhysicsObject maila1; 16 PhysicsObject maila2; 17 IntMeter pelaajan1Pisteet; 18 IntMeter pelaajan2Pisteet; 13 19 public override void Begin() 14 20 { 15 21 LuoKentta(); 16 22 Aloitapeli(); 23 LisaaLaskurit(); 17 24 AsetaOhjaimet(); 18 25 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); … … 26 33 pallo = new PhysicsObject(40, 40); 27 34 pallo.Shape = Shape.Circle; 28 pallo.Restitution = 1.0;35 pallo.Restitution = 2.0; 29 36 Add(pallo); 30 31 LuoMaila(Level.Left + 20.0, 0.0);32 LuoMaila(Level.Right - 20.0, 0.0);37 AddCollisionHandler(pallo, KasittelePallonTormays); 38 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 39 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 33 40 34 41 Level.BackgroundColor = Color.Blue; 35 Level.CreateBorders(1.0, false); 42 PhysicsObject vasenReuna = Level.CreateLeftBorder(); 43 vasenReuna.Restitution = 1.0; 44 vasenReuna.IsVisible= false; 36 45 37 Camera.ZoomToLevel( );46 Camera.ZoomToLevel(-10.5); 38 47 39 48 } … … 44 53 } 45 54 46 voidLuoMaila(double x, double y)55 PhysicsObject LuoMaila(double x, double y) 47 56 { 48 57 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); … … 52 61 maila.Y = y; 53 62 Add(maila); 63 return maila; 54 64 } 55 65 56 66 void AsetaOhjaimet() 57 67 { 58 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 59 Keyboard.Listen(Key.A, ButtonState.Down, LiikutaMaila1Ylos, "Pelaaja 1: Liikuta mailaa ylös"); 60 Keyboard.Listen(Key.A, ButtonState.Released, PysaytaMaila1, null); 68 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "pelaaja !: Liikuta mailaa ylos", maila1, nopeusYlos); 69 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 70 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 71 Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 72 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 73 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 74 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 75 76 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 77 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylos", maila2, nopeusYlos); 78 61 79 } 62 void LiikutaMailaaYlos(PhysicsObject maila) 63 Vector nopeus = new Vector(0, -200); 64 maila.Velocity= nopeus; 65 } 66 void LiikutaMailaaAlas(PhysicsObject maila) 80 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 81 { 82 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 83 { 84 maila.Velocity = Vector.Zero; 85 return; 86 } 87 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 88 { 89 maila.Velocity = Vector.Zero; 90 return; 91 } 92 maila.Velocity = nopeus; 93 94 } 95 96 void LisaaLaskurit() 97 { 98 pelaajan1Pisteet = LuoPistelaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 99 pelaajan2Pisteet = LuoPistelaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 100 } 101 IntMeter LuoPistelaskuri(double x, double y) 102 { 103 IntMeter laskuri = new IntMeter(0); 104 laskuri.MaxValue = 10; 105 Label naytto = new Label(); 106 naytto.X = x; 107 naytto.Y = y; 108 naytto.BindTo(laskuri); 109 naytto.TextColor = Color.Emerald; 110 naytto.BorderColor = Level.BackgroundColor; 111 //naytto.Color = Level.BackgroundColor; 112 Add(naytto); 113 return laskuri; 114 } 115 } 116 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 67 117 { 118 if (kohde== oikeaReuna) 119 } 120 pelaajan1pisteet.Value+=1; 121 } 122 else if (kohde== vasenReuna) 123 { 124 pelaajan2Pisteet.Value+=1; 125 } 126 }
Note: See TracChangeset
for help on using the changeset viewer.