- Timestamp:
- 2011-06-29 15:00:52 (12 years ago)
- Location:
- 2011/26/EliasH
- Files:
-
- 17 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/26/EliasH/Pong/Pong/Pong/Peli.cs
r2239 r2322 16 16 PhysicsObject maila2; 17 17 18 PhysicsObject vasenReuna; 19 PhysicsObject oikeaReuna; 20 21 IntMeter pelaajan1Pisteet; 22 IntMeter pelaajan2Pisteet; 23 18 24 public override void Begin() 19 25 { 20 26 LuoKentta(); 21 27 AsetaOhjaimet(); 28 LisaaLaskurit(); 22 29 AloitaPeli(); 23 30 } … … 29 36 pallo.Y = 0.0; 30 37 pallo.Restitution = 1.0; 38 pallo.KineticFriction = 0.0; 39 pallo.MomentOfInertia = Double.PositiveInfinity; 31 40 Add(pallo); 41 AddCollisionHandler(pallo, KasittelePallonTormays); 32 42 33 43 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 34 44 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 35 45 46 vasenReuna = Level.CreateLeftBorder(); 47 vasenReuna.Restitution = 1.0; 48 vasenReuna.KineticFriction = 0.0; 49 vasenReuna.IsVisible = false; 50 oikeaReuna = Level.CreateRightBorder(); 51 oikeaReuna.Restitution = 1.0; 52 oikeaReuna.KineticFriction = 0.0; 53 oikeaReuna.IsVisible = false; 54 PhysicsObject ylaReuna = Level.CreateTopBorder(); 55 ylaReuna.Restitution = 1.0; 56 ylaReuna.KineticFriction = 0.0; 57 ylaReuna.IsVisible = false; 58 PhysicsObject alaReuna = Level.CreateBottomBorder(); 59 alaReuna.Restitution = 1.0; 60 alaReuna.KineticFriction = 0.0; 61 alaReuna.IsVisible = false; 36 62 37 Level.CreateBorders(1.0, false);38 63 Level.BackgroundColor = Color.Black; 39 64 … … 47 72 maila.Y = y; 48 73 maila.Restitution = 1.0; 74 maila.KineticFriction = 0.0; 49 75 Add(maila); 50 76 return maila; … … 71 97 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 72 98 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 73 99 74 100 } 75 101 … … 86 112 return; 87 113 } 88 maila.Velocity = nopeus; 89 114 maila.Velocity = nopeus; 115 } 90 116 91 117 118 void LisaaLaskurit() 119 { 120 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 121 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 122 } 92 123 124 IntMeter LuoPisteLaskuri(double x, double y) 125 { 126 IntMeter laskuri = new IntMeter(0); 127 laskuri.MaxValue = 10; 128 Label naytto = new Label(); 129 naytto.BindTo(laskuri); 130 naytto.X = x; 131 naytto.Y = y; 132 naytto.TextColor = Color.White; 133 naytto.BorderColor = Level.BackgroundColor; 134 naytto.Color = Level.BackgroundColor; 135 Add(naytto); 136 return laskuri; 137 } 93 138 139 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 140 { 141 if (kohde == oikeaReuna) 142 { 143 pelaajan1Pisteet.Value += 1; 144 } 145 else if (kohde == vasenReuna) 146 { 147 pelaajan2Pisteet.Value += 1; 148 } 94 149 95 96 97 void LuoPisteLaskuri(double x, double y) 98 { } 99 } 150 } 151 }
Note: See TracChangeset
for help on using the changeset viewer.