- Timestamp:
- 2016-06-14 13:59:46 (7 years ago)
- Location:
- 2016/24/OliverK
- Files:
-
- 143 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2016/24/OliverK/Pong/Pong/Pong/Pong.cs
r7277 r7287 17 17 18 18 PhysicsObject pallo; 19 20 21 22 23 19 PhysicsObject maila1; 24 20 PhysicsObject maila2; 25 21 22 PhysicsObject vasenReuna; 23 PhysicsObject oikeaReuna; 26 24 25 IntMeter pelaajan1Pisteet; 26 IntMeter pelaajan2Pisteet; 27 27 28 28 public override void Begin() … … 31 31 AsetaOhjaimet(); 32 32 AloitaPeli(); 33 LisaaLaskurit(); 33 34 34 35 … … 54 55 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 55 56 57 Keyboard.Listen(Key.Right, ButtonState.Pressed, hidasta, "Hidasta palloa"); 58 Keyboard.Listen(Key.Left, ButtonState.Pressed, nopeuta, "Nopeuta palloa"); 59 60 56 61 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 57 62 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 58 63 } 64 65 void hidasta() { 66 pallo.Velocity /=2; 67 68 } 69 void nopeuta() 70 { 71 pallo.Velocity *= 3.1; 72 } 73 74 59 75 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 60 76 { … … 65 81 maila.Velocity = Vector.Zero; return; 66 82 } 67 if ((nopeus.Y > 0) && (maila.Top > Level.Top))83 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 68 84 { 69 85 maila.Velocity = Vector.Zero; return; … … 74 90 75 91 } 92 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 93 { 94 if (kohde == oikeaReuna) 95 { 96 pelaajan1Pisteet.Value += 1; 97 } 98 else if (kohde == vasenReuna) 99 { 100 pelaajan2Pisteet.Value += 1; 101 } 102 } 103 76 104 void LuoKentta() 77 105 { … … 80 108 Add(pallo); 81 109 82 110 AddCollisionHandler(pallo, KasittelePallonTormays); 83 111 84 112 … … 86 114 pallo.X = -200.0; 87 115 pallo.Y = 0.0; 116 117 118 vasenReuna = Level.CreateLeftBorder(); 119 vasenReuna.Restitution = 1.0; 120 vasenReuna.KineticFriction = 0.0; 121 vasenReuna.IsVisible = false; 122 123 oikeaReuna = Level.CreateRightBorder(); 124 oikeaReuna.Restitution = 1.0; 125 oikeaReuna.KineticFriction = 0.0; 126 oikeaReuna.IsVisible = false; 127 128 PhysicsObject ylaReuna = Level.CreateTopBorder(); 129 ylaReuna.Restitution = 1.0; 130 ylaReuna.KineticFriction = 0.0; 131 ylaReuna.IsVisible = false; 132 133 PhysicsObject alaReuna = Level.CreateBottomBorder(); 134 alaReuna.Restitution = 1.0; 135 alaReuna.IsVisible = false; 136 alaReuna.KineticFriction = 0.0; 88 137 89 138 … … 91 140 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 92 141 93 Level.CreateBorders(1.0, false);142 94 143 Level.Background.Color = Color.Red; 95 144 … … 107 156 return maila; 108 157 } 158 void LisaaLaskurit() 159 { 160 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 161 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 162 // ... 163 } 164 IntMeter LuoPisteLaskuri(double x, double y) 165 { 166 IntMeter laskuri = new IntMeter(0); 167 laskuri.MaxValue = 100; 168 169 Label naytto = new Label(); 170 naytto.BindTo(laskuri); 171 naytto.X = x; 172 naytto.Y = y; 173 naytto.TextColor = Color.White; 174 naytto.BorderColor = Level.Background.Color; 175 naytto.Color = Level.Background.Color; 176 Add(naytto); 177 178 return laskuri; 179 } 109 180 }
Note: See TracChangeset
for help on using the changeset viewer.