Changeset 1322 for 2010/30/tieenyky/Pong/Peli.cs
- Timestamp:
- 2010-07-27 13:28:35 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/30/tieenyky/Pong/Peli.cs
r1304 r1322 10 10 11 11 PhysicsObject pallo; 12 13 12 PhysicsObject maila1; 14 13 PhysicsObject maila2; 14 15 PhysicsObject vasenReuna; 16 PhysicsObject oikeaReuna; 17 18 IntMeter pelaajan1Pisteet; 19 IntMeter pelaajan2Pisteet; 15 20 16 21 protected override void Begin() … … 18 23 LuoKentta(); 19 24 AsetaOhjaimet(); 25 LisaaLaskurit(); 20 26 AloitaPeli(); 21 27 } … … 23 29 void LuoKentta() 24 30 { 31 vasenReuna = Level.CreateLeftBorder(); 25 32 pallo = new PhysicsObject(40.0, 40.0); 26 33 pallo.Shape = Shapes.Circle; … … 28 35 pallo.Restitution = 1.0; 29 36 Add( pallo ); 30 37 AddCollisionHandler(pallo, KasittelePallonTormays); 31 38 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 32 39 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 33 40 oikeaReuna = Level.CreateRightBorder(); 34 41 Level.CreateBorders(1.0, false); 35 Level.BackgroundColor = Color.Black; 36 42 Level.BackgroundColor = Color.Black; 37 43 Camera.ZoomToLevel(); 38 44 MessageDisplay.TextColor = Color.Red; 39 45 } 40 46 … … 75 81 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 76 82 { 83 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 84 { 85 maila.Velocity = Vector.Zero; 86 return; 87 } 88 89 if ( (nopeus.Y > 0) && (maila.Top > Level.Top) ) 90 { 91 maila.Velocity = Vector.Zero; 92 return; 93 } 77 94 maila.Velocity = nopeus; 78 95 } 79 96 97 void LisaaLaskurit() 98 { 99 pelaajan1Pisteet = LuoPisteLaskuri( Screen.Left + 100.0, Screen.Top - 100.0 ); 100 pelaajan2Pisteet = LuoPisteLaskuri( Screen.Right - 100.0, Screen.Top - 100.0 ); 101 } 102 103 104 IntMeter LuoPisteLaskuri(double x, double y) 105 { 106 IntMeter laskuri = new IntMeter(0); 107 laskuri.MaxValue = 10; 108 Label naytto = new Label(); 109 naytto.BindTo(laskuri); 110 naytto.X = x; 111 naytto.Y = y; 112 naytto.TextColor = Color.White; 113 Add(naytto); 114 return laskuri; 115 } 116 117 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 118 { 119 if (kohde == oikeaReuna) 120 { 121 pelaajan1Pisteet.Value += 1; 122 } 123 else if (kohde == vasenReuna) 124 { 125 pelaajan2Pisteet.Value += 1; 126 } 127 } 128 129 130 80 131 }
Note: See TracChangeset
for help on using the changeset viewer.