Changeset 8851
- Timestamp:
- 2017-07-03 15:01:29 (6 years ago)
- Location:
- 2017/27/TuukkaH/Pong
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2017/27/TuukkaH/Pong/Pong/Pong/Pong.cs
r8828 r8851 18 18 PhysicsObject maila2; 19 19 20 PhysicsObject vasenReuna; 21 PhysicsObject oikeaReuna; 22 23 IntMeter pelaajan1Pisteet; 24 IntMeter pelaajan2Pisteet; 25 26 20 27 public override void Begin() 21 28 { 22 29 LuoKentta(); 23 30 AsetaOhjaimet(); 31 LisaaLaskurit(); 24 32 AloitaPeli(); 25 33 } 26 27 34 void LuoKentta() 28 35 { … … 32 39 pallo.Y = 0.0; 33 40 pallo.Restitution = 1.0; 41 Add(pallo); 34 42 pallo.Color = Color.Ultramarine; 35 Add (pallo);43 AddCollisionHandler(pallo, KasittelePallonTormays); 36 44 37 45 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 38 46 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 39 47 40 Level.CreateBorders(1.0, false); 48 vasenReuna = Level.CreateLeftBorder(); 49 vasenReuna.Restitution = 1.0; 50 vasenReuna.IsVisible = false; 51 52 oikeaReuna = Level.CreateRightBorder(); 53 oikeaReuna.Restitution = 1.0; 54 oikeaReuna.IsVisible = false; 55 56 PhysicsObject ylaReuna = Level.CreateTopBorder(); 57 ylaReuna.Restitution = 1.0; 58 ylaReuna.IsVisible = false; 59 60 PhysicsObject alaReuna = Level.CreateBottomBorder(); 61 alaReuna.Restitution = 1.0; 62 alaReuna.IsVisible = false; 63 41 64 Level.Background.Color = Color.Aqua; 42 65 43 66 Camera.ZoomToLevel(); 67 68 } 69 void LisaaLaskurit() 70 { 71 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 72 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); // ... 73 } 74 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 75 { 76 if (kohde == oikeaReuna) 77 { 78 pelaajan1Pisteet.Value += 1; 79 } 80 else if (kohde == vasenReuna) 81 { 82 pelaajan2Pisteet.Value += 1; 83 } 44 84 } 45 85 … … 57 97 } 58 98 59 void AloitaPeli() 60 { 61 Vector impulssi = new Vector(500.0, 0.0); 62 pallo.Hit(impulssi); 63 } 99 64 100 65 101 void AsetaOhjaimet() … … 78 114 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 79 115 } 80 81 116 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 82 117 { 118 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 119 { 120 maila.Velocity = Vector.Zero; 121 return; 122 } 123 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 124 { 125 maila.Velocity = Vector.Zero; 126 return; 127 } 128 83 129 maila.Velocity = nopeus; 84 130 } 131 IntMeter LuoPisteLaskuri(double x, double y) 132 { 133 IntMeter laskuri = new IntMeter(0); 134 laskuri.MaxValue = 10; 135 136 Label naytto = new Label(); 137 naytto.BindTo(laskuri); 138 naytto.X = x; 139 naytto.Y = y; 140 naytto.TextColor = Color.Ultramarine; 141 naytto.BorderColor = Level.Background.Color; 142 naytto.Color = Level.Background.Color; 143 Add(naytto); 144 145 return laskuri; 146 } 147 148 void AloitaPeli() 149 { 150 Vector impulssi = new Vector(500.0, 0.0); 151 pallo.Hit(impulssi); 152 } 153 85 154 }
Note: See TracChangeset
for help on using the changeset viewer.