Changeset 7747 for 2016/27/PaavoH/Pong/Pong/Pong/Pong.cs
- Timestamp:
- 2016-07-05 10:38:53 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2016/27/PaavoH/Pong/Pong/Pong/Pong.cs
r7713 r7747 16 16 17 17 PhysicsObject maila1; 18 18 19 PhysicsObject maila2; 20 21 PhysicsObject vasenReuna; 22 PhysicsObject oikeaReuna; 23 24 IntMeter pelaajan1Pisteet; 25 IntMeter pelaajan2Pisteet; 26 19 27 public override void Begin() 20 28 { … … 22 30 LuoKentta(); 23 31 AsetaOhjaimet(); 32 LisaaLaskurit(); 24 33 AloitaPeli(); 25 34 … … 36 45 pallo.Y = 0.0; 37 46 38 Level.CreateBorders(1.0, false); 47 vasenReuna = Level.CreateLeftBorder(); 48 vasenReuna.Restitution = 1.0; 49 vasenReuna.IsVisible = false; 50 oikeaReuna = Level.CreateRightBorder(); 51 oikeaReuna.Restitution = 1.0; 52 oikeaReuna.IsVisible = false; 53 PhysicsObject ylaReuna = Level.CreateTopBorder(); 54 ylaReuna.Restitution = 1.0; 55 ylaReuna.IsVisible = false; 56 57 PhysicsObject alaReuna = Level.CreateBottomBorder(); 58 alaReuna.Restitution = 1.0; 59 alaReuna.IsVisible = false; 39 60 pallo.Restitution = 1.0; 40 61 Level.Background.Color = Color.DarkTurquoise; 41 62 Camera.ZoomToLevel(); 42 63 43 PhysicsObject maila2 = PhysicsObject.CreateStaticObject(20.0, 100.0); 44 maila2.Shape = Shape.Rectangle; 45 maila2.X = Level.Left + 20.0; 46 maila2.Y = 0.0; 47 maila2.Restitution = 1.0; 48 Add(maila2); 64 49 65 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 50 66 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 67 AddCollisionHandler(pallo, KasittelePallonTormays); 51 68 } 52 69 PhysicsObject LuoMaila(double x, double y) … … 84 101 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 85 102 { 103 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 104 105 { 106 maila.Velocity = Vector.Zero; 107 return; 108 } 86 109 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 87 110 { … … 91 114 maila.Velocity = nopeus; 92 115 } 116 117 void LisaaLaskurit() 118 { 119 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 120 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 121 122 } 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.Background.Color; 134 naytto.Color = Level.Background.Color; 135 Add(naytto); 136 return laskuri; 137 } 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 } 149 150 } 93 151 } 94 void LisaaLaskurit()95 {96 // ...97 }98 }99 IntMeter LuoPisteLaskuri()100 {101 IntMeter laskuri = new IntMeter(0);102 laskuri.MaxValue = 10;103 return laskuri;104 }105 }
Note: See TracChangeset
for help on using the changeset viewer.