- Timestamp:
- 2011-06-07 10:38:57 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/23/latakoso/Pong/Pong/Pong/Peli.cs
r1721 r1732 27 27 public override void Begin() 28 28 { 29 AsetaOhjaimet(); 30 ShowControlHelp(); 31 Timer.SingleShot(5, Alku); 32 } 33 34 void Alku() 35 { 36 ClearAll(); 29 37 LuoKentta(); 30 38 AsetaOhjaimet(); 39 Label tekija = new Label(); 40 tekija.TextColor = Color.White; 41 tekija.Text = "Lauri Kosonen"; 42 tekija.Y = Level.Top - 5; 43 Add(tekija); 31 44 LisaaLaskurit(); 32 AloitaPeli();45 Timer.SingleShot(1, AloitaPeli); 33 46 Pisteet2(); 34 47 Pisteet1(); 48 35 49 } 36 50 … … 40 54 pallo.Shape = Shape.Circle; 41 55 pallo.Color = Color.White; 42 pallo.X = -200;56 pallo.X = 0; 43 57 pallo.Y = 0; 44 58 pallo.Restitution = 1; … … 46 60 AddCollisionHandler(pallo, KasittelePallonTormays); 47 61 48 maila1 = LuoMaila(Level.Left + 2,0);49 maila2 = LuoMaila(Level.Right - 2, 0);62 maila1 = LuoMaila(Level.Left + 0,0); 63 maila2 = LuoMaila(Level.Right - 0, 0); 50 64 51 65 vasenReuna = Level.CreateLeftBorder(); … … 75 89 void AloitaPeli() 76 90 { 77 Vector impulssi = new Vector( 500,0);91 Vector impulssi = new Vector(Impulssi(),0); 78 92 pallo.Hit(impulssi); 93 } 94 95 int Impulssi() 96 { 97 if (pelaajan1Pisteet > pelaajan2Pisteet) 98 { 99 return 500; 100 } 101 else 102 { 103 return -500; 104 } 79 105 } 80 106 … … 102 128 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 103 129 104 Keyboard.Listen(Key. F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");130 Keyboard.Listen(Key.Space, ButtonState.Pressed, ResetPallo, "Palauta pallo keskelle. Älä käytä turhaan!"); 105 131 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 106 107 ControllerOne.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila1, nopeusYlos);108 ControllerOne.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero);109 ControllerOne.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila1, nopeusAlas);110 ControllerOne.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero);111 112 ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila2, nopeusYlos);113 ControllerTwo.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero);114 ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila2, nopeusAlas);115 ControllerTwo.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero);116 117 ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu");118 ControllerTwo.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu");119 132 } 120 133 … … 162 175 pelaajan1Pisteet.Value += 1; 163 176 Add(P1); 164 Muuta(); 165 Timer.SingleShot(1, PoistaP1); 177 Voitto(); 178 ResetPallo(); 179 Timer.SingleShot(1, PoistaP); 166 180 167 181 } … … 170 184 pelaajan2Pisteet.Value += 1; 171 185 Add(P2); 172 Muuta(); 173 Timer.SingleShot(1, PoistaP2); 186 Voitto(); 187 ResetPallo(); 188 Timer.SingleShot(1, PoistaP); 174 189 } 175 190 } … … 184 199 } 185 200 186 void PoistaP1() 187 { 188 // poistetaan p1 201 void PoistaP() 202 { 189 203 Remove(P1); 204 Remove(P2); 190 205 } 191 206 … … 199 214 } 200 215 201 void PoistaP2() 202 { 203 // poistetaan p2 204 Remove(P2); 205 206 } 207 208 void Muuta() 216 void Voitto() 209 217 { 210 218 if (pelaajan1Pisteet.Value == 10) 211 219 { 212 220 Remove(pallo); 221 pallo.Color = Color.Black; 213 222 Label P1voitto = new Label(); 214 223 P1voitto.Text = "Pelaaja 1 voitti pelin!"; … … 229 238 } 230 239 } 240 241 void ResetPallo() 242 { 243 pallo.X = 0; 244 pallo.Y = 0; 245 pallo.Velocity = Vector.Zero; 246 Timer.SingleShot(1, AloitaPeli); 247 } 231 248 }
Note: See TracChangeset
for help on using the changeset viewer.