- Timestamp:
- 2012-07-27 12:53:34 (11 years ago)
- Location:
- 2012/30/TinoS
- Files:
-
- 24 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/30/TinoS/Pong/Pong/Pong/Pong.cs
r3690 r3820 14 14 PhysicsObject maila1; 15 15 PhysicsObject maila2; 16 17 IntMeter pelaajan1Pisteet; 18 IntMeter pelaajan2Pisteet; 19 20 PhysicsObject vasenReuna; 21 PhysicsObject oikeaReuna; 22 23 16 24 public override void Begin() 17 25 { … … 19 27 AsetaOhjaimet(); 20 28 AloitaPeli(); 29 LisaaLaskurit(); 21 30 22 31 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); … … 33 42 Pallo.Hit(impulssi); 34 43 Pallo.Restitution = 1.0; 35 Level.CreateBorders(1.0, false); 36 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 37 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 44 45 PhysicsObject vasenReuna = Level.CreateLeftBorder(); 46 vasenReuna.Restitution = 1.0; 47 vasenReuna.IsVisible = false; 48 49 PhysicsObject oikeaReuna = Level.CreateRightBorder(); 50 oikeaReuna.Restitution = 1.0; 51 oikeaReuna.IsVisible = false; 52 53 54 vasenReuna.Restitution = 1.0; 55 vasenReuna.IsVisible = false; 56 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 57 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 38 58 Level.BackgroundColor = Color.Black; 39 59 Camera.ZoomToLevel(); 40 60 61 AddCollisionHandler(Pallo, KasittelePallonTormays); 62 41 63 } 42 64 void AloitaPeli() … … 59 81 { 60 82 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 61 Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1,nopeusYlos);62 Keyboard.Listen(Key.W, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero);83 Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 84 Keyboard.Listen(Key.W, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 63 85 Keyboard.Listen(Key.S, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 64 86 Keyboard.Listen(Key.S, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); … … 71 93 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 72 94 { 73 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 74 {maila.Velocity = Vector.Zero; 95 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 96 { 97 maila.Velocity = Vector.Zero; 75 98 return; 76 99 } 100 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 101 { 102 maila.Velocity = Vector.Zero; 103 return; 104 } 105 77 106 maila.Velocity = nopeus; 107 78 108 } 79 } 109 void LisaaLaskurit() 110 { 111 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 112 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 113 } 114 IntMeter LuoPisteLaskuri(double x, double y) 115 { 116 IntMeter laskuri = new IntMeter(0); 117 80 118 119 laskuri.MaxValue = 10; 120 Label naytto =new Label(); 121 naytto.BindTo(laskuri); 122 naytto.X = x; 123 naytto.Y = y; 124 naytto.TextColor = Color.White; 125 naytto.BorderColor = Level.BackgroundColor; 126 Add(naytto); 127 return laskuri; 128 } 129 void KasittelePallonTormays(PhysicsObject Pallo, PhysicsObject kohde) 130 { 131 if (kohde == oikeaReuna) 132 { 133 pelaajan1Pisteet.Value +=1; 134 } 135 else if (kohde == vasenReuna) 136 { 137 pelaajan2Pisteet.Value += 1; 138 } 139 } 140 } 141
Note: See TracChangeset
for help on using the changeset viewer.