Changeset 2700 for 2012/JAO/Tero/Pong/Pong/Pong/Pong.cs
- Timestamp:
- 2012-04-16 14:22:13 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/JAO/Tero/Pong/Pong/Pong/Pong.cs
r2694 r2700 13 13 14 14 PhysicsObject pallo; 15 16 15 PhysicsObject maila1; 17 16 PhysicsObject maila2; 17 18 PhysicsObject vasenReuna; 19 PhysicsObject oikeaReuna; 20 21 IntMeter pelaajan1Pisteet; 22 IntMeter pelaajan2Pisteet; 18 23 19 24 public override void Begin() 20 25 { 21 26 LuoKentta(); 27 MessageDisplay.TextColor = Color.White; 22 28 AsetaOhjaimet(); 29 LisaaLaskurit(); 23 30 AloitaPeli(); 24 31 } 32 33 void LisaaLaskurit() 34 { 35 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 36 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 37 } 38 39 IntMeter LuoPisteLaskuri(double x, double y) 40 { 41 IntMeter laskuri = new IntMeter(0); 42 laskuri.MaxValue = 10; 43 Label naytto = new Label(); 44 naytto.BindTo(laskuri); 45 naytto.X = x; 46 naytto.Y = y; 47 naytto.TextColor = Color.White; 48 naytto.BorderColor = Level.BackgroundColor; 49 naytto.Color = Level.BackgroundColor; 50 Add(naytto); 51 return laskuri; 52 } 53 25 54 26 55 void AsetaOhjaimet() 27 56 { 28 57 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 29 Keyboard.Listen(Key.A, ButtonState.Down, LiikutaMailaaYlos, "Pelaaja 1: Liikuta mailaa ylös"); 30 Keyboard.Listen(Key.A, ButtonState.Released, PysaytaMaila, null); 58 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 59 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 60 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 61 Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 62 63 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 64 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 65 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 66 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 67 68 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 69 31 70 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 32 71 } … … 34 73 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 35 74 { 75 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 76 { 77 maila.Velocity = Vector.Zero; 78 return; 79 } 80 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 81 { 82 maila.Velocity = Vector.Zero; 83 return; 84 } 85 36 86 maila.Velocity = nopeus; 37 87 } … … 44 94 pallo.Y = 0.0; 45 95 pallo.Restitution = 1.0; 96 pallo.KineticFriction = 0.0; 97 pallo.MomentOfInertia = Double.PositiveInfinity; 46 98 Add( pallo ); 99 AddCollisionHandler(pallo, KasittelePallonTormays); 47 100 48 LuoMaila(Level.Left + 20.0, 0.0);49 LuoMaila(Level.Right - 20.0, 0.0);101 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 102 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 50 103 51 Level.CreateBorders( 1.0, false ); 104 vasenReuna = Level.CreateLeftBorder(); 105 vasenReuna.Restitution = 1.0; 106 vasenReuna.KineticFriction = 0.0; 107 vasenReuna.IsVisible = false; 108 oikeaReuna = Level.CreateRightBorder(); 109 oikeaReuna.Restitution = 1.0; 110 oikeaReuna.KineticFriction = 0.0; 111 oikeaReuna.IsVisible = false; 112 PhysicsObject ylaReuna = Level.CreateTopBorder(); 113 ylaReuna.Restitution = 1.0; 114 ylaReuna.KineticFriction = 0.0; 115 ylaReuna.IsVisible = false; 116 PhysicsObject alaReuna = Level.CreateBottomBorder(); 117 alaReuna.Restitution = 1.0; 118 alaReuna.IsVisible = false; 119 alaReuna.KineticFriction = 0.0; 52 120 Level.BackgroundColor = Color.Black; 53 121 … … 57 125 } 58 126 127 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 128 { 129 if (kohde == oikeaReuna) 130 { 131 pelaajan1Pisteet.Value += 1; 132 Timer.SingleShot(0.5, AloitaPeli); 133 } 134 else if (kohde == vasenReuna) 135 { 136 pelaajan2Pisteet.Value += 1; 137 Timer.SingleShot(0.5, AloitaPeli); 138 } 139 } 140 59 141 void AloitaPeli() 60 142 { 143 pallo.X = 0.0; 144 pallo.Y = 0.0; 145 pallo.Stop(); 61 146 Vector impulssi = new Vector( 500.0, 0.0 ); 62 147 pallo.Hit( impulssi );
Note: See TracChangeset
for help on using the changeset viewer.