Changeset 7541
- Timestamp:
- 2016-06-28 11:27:42 (7 years ago)
- Location:
- 2016/26/RasmusL/Pong
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2016/26/RasmusL/Pong/Pong/Pong/Pong.cs
r7528 r7541 15 15 PhysicsObject maila1; 16 16 PhysicsObject maila2; 17 18 PhysicsObject vasenReuna; 19 PhysicsObject oikeaReuna; 20 21 IntMeter pelaajan1Pisteet; 22 IntMeter pelaajan2Pisteet; 17 23 public override void Begin() 18 24 { … … 20 26 AsetaOhjaimet(); 21 27 AloitaPeli(); 28 LisaaLaskurit(); 22 29 23 30 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 24 25 // TODO: Kirjoita ohjelmakoodisi tähän26 27 31 } 28 32 void LuoKentta() … … 30 34 pallo = new PhysicsObject(40.0, 40.0); 31 35 pallo.Shape = Shape.Circle; 32 Add(pallo);33 34 36 pallo.X = -200.0; 35 37 pallo.Y = 0.0; 38 pallo.Restitution = 1.0; 39 pallo.KineticFriction = 0.0; 40 pallo.MomentOfInertia = Double.PositiveInfinity; 41 Add(pallo); 42 AddCollisionHandler(pallo, KasittelePallonTormays); 36 43 37 44 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 38 45 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 39 46 40 Level.CreateBorders(1.0, false); 41 pallo.Restitution = 1.0; 42 Level.Background.Color = Color.Black; 47 vasenReuna = Level.CreateLeftBorder(); 48 vasenReuna.Restitution = 1.0; 49 vasenReuna.KineticFriction = 0.0; 50 vasenReuna.IsVisible = false; 51 52 oikeaReuna = Level.CreateRightBorder(); 53 oikeaReuna.Restitution = 1.0; 54 oikeaReuna.KineticFriction = 0.0; 55 oikeaReuna.IsVisible = false; 56 57 PhysicsObject ylaReuna = Level.CreateTopBorder(); 58 ylaReuna.Restitution = 1.0; 59 ylaReuna.KineticFriction = 0.0; 60 ylaReuna.IsVisible = false; 61 62 PhysicsObject alaReuna = Level.CreateBottomBorder(); 63 alaReuna.Restitution = 1.0; 64 alaReuna.IsVisible = false; 65 alaReuna.KineticFriction = 0.0; 66 67 Level.BackgroundColor = Color.Black; 68 43 69 Camera.ZoomToLevel(); 70 } // TODO: Kirjoita ohjelmakoodisi tähän 71 72 73 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 74 { 75 if (kohde == oikeaReuna) 76 { 77 pelaajan1Pisteet.Value += 1; 78 } 79 else if (kohde == vasenReuna) 80 { 81 pelaajan2Pisteet.Value += 1; 82 } 44 83 } 45 84 … … 97 136 } 98 137 138 void LisaaLaskurit() 139 { 140 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 141 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 142 } 143 144 IntMeter LuoPisteLaskuri(double x, double y) 145 { 146 IntMeter laskuri = new IntMeter(0); 147 laskuri.MaxValue = 10; 148 149 Label naytto = new Label(); 150 naytto.BindTo(laskuri); 151 naytto.X = x; 152 naytto.Y = y; 153 naytto.TextColor = Color.White; 154 naytto.Color = Level.Background.Color; 155 Add(naytto); 156 157 return laskuri; 158 159 } 160 161 void KasittelePallonTormaus(PhysicsObject pallo, PhysicsObject kohde) 162 { 163 if (kohde == oikeaReuna) 164 { 165 pelaajan1Pisteet.Value += 1; 166 } 167 else if (kohde == vasenReuna) 168 { 169 pelaajan2Pisteet.Value += 1; 170 } 171 } 172 99 173 }
Note: See TracChangeset
for help on using the changeset viewer.