- Timestamp:
- 2015-06-30 10:34:33 (8 years ago)
- Location:
- 2015/27/JaakkoS/Pong/Pong
- Files:
-
- 29 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2015/27/JaakkoS/Pong/Pong/Pong/Pong.cs
r6524 r6558 13 13 14 14 PhysicsObject pallo; 15 16 15 PhysicsObject maila1; 17 16 PhysicsObject maila2; 17 18 PhysicsObject vasenReuna; 19 PhysicsObject oikeaReuna; 18 20 19 21 IntMeter pelaajan1Pisteet; … … 42 44 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 43 45 44 Level.CreateBorders(1.0, false); 46 vasenReuna = Level.CreateLeftBorder(); 47 vasenReuna.Restitution = 1.0; 48 vasenReuna.IsVisible = false; 49 50 oikeaReuna = Level.CreateRightBorder(); 51 oikeaReuna.Restitution = 1.0; 52 oikeaReuna.IsVisible = false; 53 54 PhysicsObject alaReuna = Level.CreateBottomBorder(); 55 alaReuna.Restitution = 1.0; 56 alaReuna.IsVisible = false; 57 58 PhysicsObject ylaReuna = Level.CreateTopBorder(); 59 ylaReuna.Restitution = 1.0; 60 ylaReuna.IsVisible = false; 61 45 62 Level.Background.Color = Color.Black; 46 63 Camera.ZoomToLevel(); 47 64 48 65 AddCollisionHandler(pallo, KasittelePallonTormays); 49 66 } 50 67 … … 67 84 return maila; 68 85 } 86 69 87 void AsetaOhjaimet() 70 88 { … … 82 100 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 83 101 } 102 84 103 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 85 104 { 86 if ((nopeus.Y > 0) && (maila.Top > Level.Top))105 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 87 106 { 88 107 maila.Velocity = Vector.Zero; 89 108 return; 90 109 } 91 if ((nopeus.Y > 0) && (maila.Bottom > Level.Bottom)) 110 111 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 92 112 { 93 113 maila.Velocity = Vector.Zero; … … 97 117 maila.Velocity = nopeus; 98 118 } 119 99 120 void LisaaLaskurit() 100 121 { 101 122 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 102 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right +100.0, Screen.Top - 100.0);123 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 103 124 } 104 IntMeter LisaaPisteLaskurit() 125 126 IntMeter LuoPisteLaskuri(double x, double y) 105 127 { 106 128 IntMeter laskuri = new IntMeter(0); … … 119 141 return laskuri; 120 142 } 143 144 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 145 { 146 if (kohde == oikeaReuna) 147 { 148 pelaajan1Pisteet.Value += 1; 149 } 150 else if (kohde == vasenReuna) 151 { 152 pelaajan2Pisteet.Value += 1; 153 } 154 } 121 155 } 122 156
Note: See TracChangeset
for help on using the changeset viewer.