- Timestamp:
- 2012-06-12 12:27:52 (7 years ago)
- Location:
- 2012/24/AtteJ/Pong
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/24/AtteJ/Pong/Pong/Pong/Pong.cs
r2922 r2941 15 15 PhysicsObject maila1; 16 16 PhysicsObject maila2; 17 PhysicsObject VasenReuna; 18 PhysicsObject OikeaReuna; 19 IntMeter Pelaajan1Pisteet; 20 IntMeter Pelaajan2Pisteet; 17 21 public override void Begin() 18 22 { 19 23 LuoKentta(); 20 24 Ohjaimet(); 25 LisaaLaskurit(); 21 26 AloitaPeli(); 22 27 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); … … 33 38 pallo.X = 0.0; 34 39 pallo.Y = 0.0; 35 pallo.Restitution = 1.0; 36 Level.CreateBorders(1.0, false); 40 pallo.Restitution = 1.0; 41 42 VasenReuna = Level.CreateLeftBorder(); 43 VasenReuna.Restitution = 1.0; 44 VasenReuna.IsVisible = false; 45 46 OikeaReuna = Level.CreateRightBorder(); 47 OikeaReuna.Restitution = 1.0; 48 OikeaReuna.IsVisible = false; 49 50 PhysicsObject AlaReuna = Level.CreateBottomBorder(); 51 AlaReuna.Restitution = 1.0; 52 AlaReuna.IsVisible = false; 53 54 PhysicsObject YläReuna = Level.CreateTopBorder(); 55 YläReuna.Restitution = 1.0; 56 YläReuna.IsVisible = false; 57 37 58 Level.BackgroundColor = Color.Black; 38 59 … … 40 61 maila1 = Mailat(Level.Left + 20.0, 0.0); 41 62 maila2 = Mailat(Level.Right - 20.0, 0.0); 63 64 MessageDisplay.TextColor = Color.White; 65 66 AddCollisionHandler(pallo, KasittelePallonTormays); 42 67 } 43 68 void AloitaPeli() … … 63 88 Keyboard.Listen ( Key.A, ButtonState.Released, MailojenNopeus, null, maila1, Vector.Zero); 64 89 Keyboard.Listen ( Key.Z, ButtonState.Down, MailojenNopeus, "Pelaaja 1 , liikuta mailaa alas", maila1, NopeusAlas); 65 Keyboard.Listen ( Key.Z, ButtonState.Released, MailojenNopeus, null, Vector.Zero);90 Keyboard.Listen ( Key.Z, ButtonState.Released, MailojenNopeus, null, maila1, Vector.Zero); 66 91 67 92 Keyboard.Listen ( Key.Up, ButtonState.Down, MailojenNopeus, "Pelaaja 2, liikuta mailaa ylös", maila2, NopeusYlos); 68 Keyboard.Listen(Key. Down, ButtonState.Released, MailojenNopeus, null, Vector.Zero);69 Keyboard.Listen ( Key.Down, ButtonState. Pressed, MailojenNopeus, "Pelaaja 2, liikuta mailaasi alas", maila2,NopeusYlos);70 Keyboard.Listen ( Key.Down, ButtonState.Released, MailojenNopeus, null, Vector.Zero);93 Keyboard.Listen(Key.Up, ButtonState.Released, MailojenNopeus, null, maila2, Vector.Zero); 94 Keyboard.Listen ( Key.Down, ButtonState.Down, MailojenNopeus, "Pelaaja 2, liikuta mailaasi alas", maila2,NopeusAlas); 95 Keyboard.Listen ( Key.Down, ButtonState.Released, MailojenNopeus, null, maila2, Vector.Zero); 71 96 72 97 Keyboard.Listen ( Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli" ); … … 74 99 void MailojenNopeus(PhysicsObject maila, Vector nopeus) 75 100 { 101 102 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 103 { 104 maila.Velocity = Vector.Zero; 105 return; 106 } 107 108 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 109 { 110 maila.Velocity = Vector.Zero; 111 return; 112 } 76 113 maila.Velocity = nopeus; 114 77 115 } 116 void LisaaLaskurit() 117 { 118 Pelaajan1Pisteet = LuoPisteLaskuri (Screen.Left + 100, Screen.Top - 100); 119 Pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100, Screen.Top - 100); 120 } 121 IntMeter LuoPisteLaskuri(double x, double y) 122 { 123 IntMeter Laskuri = new IntMeter(0); 124 Laskuri.MaxValue = 10; 125 Label naytto = new Label(); 126 naytto.BindTo(Laskuri); 127 naytto.X = x; 128 naytto.Y = y; 129 naytto.TextColor = Color.White; 130 naytto.BorderColor = Level.BackgroundColor; 131 naytto.Color = Level.BackgroundColor; 132 Add(naytto); 133 return Laskuri; 134 } 135 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 136 { 137 if (kohde == OikeaReuna) 138 { 139 Pelaajan1Pisteet.Value += 1; 140 } 141 else if (kohde == VasenReuna) 142 { 143 Pelaajan2Pisteet.Value += 1; 144 } 145 } 146 78 147 } 79 148
Note: See TracChangeset
for help on using the changeset viewer.