- Timestamp:
- 2010-07-27 11:25:47 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/30/mikmatla/Pong/Peli.cs
r1285 r1308 6 6 public class Peli : PhysicsGame 7 7 { 8 Vector nopeusYlos = new Vector(0, 200.0);9 Vector nopeusAlas = new Vector( 0, - 200.0);8 Vector nopeusYlos = new Vector(0, 300.0); 9 Vector nopeusAlas = new Vector( 0, -300.0); 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 } 22 28 23 29 void LuoKentta() 24 30 { 25 26 31 Pallo = new PhysicsObject(40.0, 40.0); 27 32 Pallo.Shape = Shapes.Circle; … … 34 39 maila2 = LuoMaila(Level.Right - 30.0, 0.0); 35 40 36 Level.CreateBorders(1.0, false); 41 AddCollisionHandler(Pallo, KasittelePallonTormays); 42 43 vasenReuna = Level.CreateLeftBorder(); 44 vasenReuna.Restitution = 1.0; 45 vasenReuna.IsVisible = false; 46 PhysicsObject ylaReuna = Level.CreateTopBorder(); 47 ylaReuna.Restitution = 1.0; 48 ylaReuna.IsVisible = false; 49 oikeaReuna = Level.CreateRightBorder(); 50 oikeaReuna.Restitution = 1.0; 51 oikeaReuna.IsVisible = false; 52 PhysicsObject alaReuna = Level.CreateBottomBorder(); 53 alaReuna.Restitution = 1.0; 54 alaReuna.IsVisible = false; 55 56 oikeaReuna.IgnoresCollisionResponse = true; 57 vasenReuna.IgnoresCollisionResponse = true; 58 37 59 Level.BackgroundColor = Color.YellowGreen; 38 60 39 61 Camera.ZoomToLevel(); 62 } 63 64 void LuoPallo() 65 { 66 Pallo = new PhysicsObject(40.0, 40.0); 67 Pallo.Shape = Shapes.Circle; 68 Pallo.X = 0.0; 69 Pallo.Y = 0.0; 70 Pallo.Restitution = 1.0; 71 Add(Pallo); 40 72 } 41 73 … … 76 108 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 77 109 { 110 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 111 { 112 maila.Velocity = Vector.Zero; 113 return; 114 } 115 116 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 117 { 118 maila.Velocity = Vector.Zero; 119 return; 120 } 121 78 122 maila.Velocity = nopeus; 79 123 } 124 125 void LisaaLaskurit() 126 { 127 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top -100.0); 128 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 129 } 130 131 IntMeter LuoPisteLaskuri(double x, double y) 132 { 133 IntMeter laskuri = new IntMeter(3); 134 laskuri.MinValue = 1; 135 Label naytto = new Label(); 136 naytto.BindTo(laskuri); 137 naytto.X = x; 138 naytto.Y = y; 139 naytto.TextColor = Color.White; 140 Add(naytto); 141 return laskuri; 142 } 143 144 void KasittelePallonTormays(PhysicsObject Pallo, PhysicsObject kohde) 145 { 146 if (kohde == oikeaReuna) 147 { 148 PalloKeskelle(Pallo); 149 pelaajan2Pisteet.Value -= 1; 150 } 151 else if (kohde == vasenReuna) 152 { 153 PalloKeskelle(Pallo); 154 pelaajan1Pisteet.Value -= 1; 155 } 156 } 157 158 private void PalloKeskelle(PhysicsObject Pallo) 159 { 160 Pallo.Velocity = new Vector(0, 0); 161 Pallo.X = 0; 162 Pallo.Y = 0; 163 AloitaPeli(); 164 } 80 165 }
Note: See TracChangeset
for help on using the changeset viewer.