Changeset 9048
- Timestamp:
- 2017-07-24 13:11:36 (6 years ago)
- Location:
- 2017/30/LeoL/Pong/Pong/Pong
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
2017/30/LeoL/Pong/Pong/Pong/Pong.cs
r9039 r9048 13 13 14 14 PhysicsObject pallo; 15 16 15 PhysicsObject maila1; 17 16 PhysicsObject maila2; 17 18 PhysicsObject VasenReuna; 19 PhysicsObject OikeaReuna; 20 21 IntMeter pelaajan1Pisteet; 22 IntMeter pelaajan2Pisteet; 18 23 public override void Begin() 19 24 { 20 25 // TODO: Kirjoita ohjelmakoodisi tähän 21 26 22 luokentta(); 23 asetaohjaimet(); 27 LuoKentta(); 28 AsetaOhjaimet(); 29 LisaaLaskurit(); 24 30 AloitaPeli(); 25 31 … … 28 34 } 29 35 30 void luokentta()36 void LuoKentta() 31 37 { 32 38 pallo = new PhysicsObject(40.0, 40.0); … … 35 41 pallo.X = -200.0; 36 42 pallo.Y = 0.0; 43 AddCollisionHandler(pallo, KasittelePallonTormays); 44 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 45 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 37 46 38 LuoMaila(Level.Left + 20.0, 0.0); 39 LuoMaila(Level.Right - 20.0, 0.0); 40 41 42 Level.CreateBorders(1.0, false); 47 PhysicsObject yläReuna = Level.CreateTopBorder(); 48 yläReuna.Restitution = 1.0; 49 yläReuna.IsVisible = false; 50 PhysicsObject AlaReuna = Level.CreateBottomBorder(); 51 AlaReuna.Restitution = 1.0; 52 AlaReuna.IsVisible = false; 53 OikeaReuna = Level.CreateRightBorder(); 54 OikeaReuna.Restitution = 1.0; 55 OikeaReuna.IsVisible = false; 56 VasenReuna = Level.CreateLeftBorder(); 57 VasenReuna.Restitution = 1.0; 58 VasenReuna.IsVisible = false; 43 59 pallo.Restitution = 1.0; 44 60 Level.Background.Color = Color.Black; 45 61 Camera.ZoomToLevel(); 62 63 46 64 } 47 65 void AloitaPeli() … … 60 78 return maila; 61 79 } 62 void asetaohjaimet()80 void AsetaOhjaimet() 63 81 { 64 82 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); … … 77 95 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 78 96 { 97 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 98 { 99 maila.Velocity = Vector.Zero; 100 return; 101 } 102 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 103 { 104 maila.Velocity = Vector.Zero; 105 return; 106 } 107 108 109 79 110 maila.Velocity = nopeus; 111 } 112 113 void LisaaLaskurit() 114 { 115 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 116 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 117 } 118 IntMeter LuoPisteLaskuri(double x, double y) 119 { 120 IntMeter laskuri = new IntMeter(0); 121 laskuri.MaxValue = 10; 122 123 Label naytto = new Label(); 124 naytto.BindTo(laskuri); 125 naytto.X = x; 126 naytto.Y = y; 127 naytto.TextColor = Color.White; 128 naytto.BorderColor = Level.Background.Color; 129 naytto.Color = Level.Background.Color; 130 Add(naytto); 131 132 return laskuri; 133 } 134 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 135 { 136 if (kohde == OikeaReuna) 137 { 138 pelaajan1Pisteet.Value += 1; 139 } 140 else if (kohde == VasenReuna) 141 { 142 pelaajan2Pisteet.Value += 1; 143 } 144 80 145 } 81 146
Note: See TracChangeset
for help on using the changeset viewer.