Changeset 6521
- Timestamp:
- 2015-06-29 14:48:17 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2015/27/TeemuH/Pong/Pong/Pong/Pong.cs
r6489 r6521 9 9 public class Pong : PhysicsGame 10 10 { 11 Vector nope ysYlos = new Vector(0, 200);11 Vector nopeusYlos = new Vector(0, 200); 12 12 Vector nopeusAlas = new Vector(0, -200); 13 14 PhysicsObject pallo; 13 15 PhysicsObject maila1; 14 16 PhysicsObject maila2; 15 17 16 PhysicsObject pallo; 18 PhysicsObject vasenReuna; 19 PhysicsObject oikeaReuna; 20 21 IntMeter pelaajan1Pisteet; 22 IntMeter pelaajan2Pisteet; 17 23 18 24 public override void Begin() … … 20 26 LuoKentta(); 21 27 AsetaOhjaimet(); 22 LuoKentta(); 28 LisaaLaskurit(); 29 AloitaPeli(); 30 31 23 32 24 33 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); … … 31 40 Add(pallo); 32 41 pallo.Shape = Shape.Circle; 42 43 44 45 ; 33 46 pallo.X = -200.0; 34 47 pallo.Y = 0.0; 35 48 Vector impulssi = new Vector(500.0, 0.0); 36 49 pallo.Hit(impulssi); 37 maila1 = LuoMaila(Level1.Left + 20.0, 0.0); 50 AddCollisionHandler(pallo, KasittelePallonTormays); 51 52 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 38 53 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 39 54 40 41 Level.CreateBorders(1.0, false); 55 56 vasenReuna = Level.CreateLeftBorder(); 57 vasenReuna.Restitution = 1.0; 58 vasenReuna.IsVisible = false; 59 60 oikeaReuna = Level.CreateRightBorder(); 61 oikeaReuna.Restitution = 1.0; 62 oikeaReuna.IsVisible = false; 63 64 PhysicsObject ylaReuna = Level.CreateTopBorder(); 65 ylaReuna.Restitution = 1.0; 66 ylaReuna.IsVisible = false; 67 68 PhysicsObject alaReuna = Level.CreateTopBorder(); 69 alaReuna.Restitution = 1.0; 70 alaReuna.IsVisible = false; 71 72 73 42 74 pallo.Restitution = 1.0; 43 75 44 LuoMaila(Level.Left + 20.0, 0.0); 45 LuoMaila(Level.Right - 20.0, 0.0); 76 46 77 47 78 Level.CreateBorders(1.0, false); 48 Level.Background.Color = Color. Black;79 Level.Background.Color = Color.LightBlue; 49 80 50 81 Camera.ZoomToLevel(); … … 59 90 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 60 91 } 61 92 PhysicsObject LuoMaila(double x, double y) 62 93 { 63 94 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); … … 66 97 maila.Y = y; 67 98 maila.Restitution = 1.0; 99 maila.Color = Color.Pink; 100 68 101 Add(maila); 69 102 return maila; … … 72 105 { 73 106 74 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, ", maila1, nopeusYlos)"; 75 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 107 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 108 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 109 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja1: Liikuta mailaa alas", maila1, nopeusAlas); 110 Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 76 111 77 Keyborad.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 112 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 113 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 114 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus,"Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 115 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 116 117 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 118 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 119 120 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 78 121 } 79 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 80 { 81 maila.Velocity=nopeus; 122 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 123 { 124 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 125 { 126 maila.Velocity = Vector.Zero; 127 return; 128 } 129 if ((nopeus.Y >0) && (maila.Top > Level.Top)) 130 { 131 maila.Velocity = Vector.Zero; 132 return; 133 134 } 135 maila.Velocity = nopeus; 136 137 } 138 void LiikutaMailaaYlos(PhysicsObject Maila) 139 { 140 Vector nopeus = new Vector(0, 200); 141 maila1.Velocity = nopeus; 142 } 143 void LiikutaMailaaAlas(PhysicsObject maila1) 144 { 145 Vector nopeus = new Vector(0, -200); 146 maila1.Velocity = nopeus; 147 148 } 149 void PysaytaMaila(PhysicsObject maila) 150 { 151 Vector nopeus = Vector.Zero; 152 maila.Velocity = nopeus; 153 154 } 155 void LisaaLaskurit() 156 { 157 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 158 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 159 160 } 161 IntMeter LuoPisteLaskuri(double x, double y) 162 { 163 IntMeter laskuri = new IntMeter(0); 164 laskuri.MaxValue = 10; 165 166 Label naytto = new Label(); 167 naytto.BindTo(laskuri); 168 naytto.X = x; 169 naytto.Y = y; 170 naytto.TextColor = Color.Brown; 171 naytto.BorderColor = Level.Background.Color; 172 naytto.Color = Level.Background.Color; 173 Add(naytto); 174 175 return laskuri; 176 } 177 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 178 { 179 if (kohde == oikeaReuna) 180 { 181 pelaajan1Pisteet.Value += 1; 182 } 183 else if (kohde == vasenReuna) 184 { 185 pelaajan2Pisteet.Value += 1; 186 187 } 188 pallo.Color = Color.Purple; 189 } 82 190 } 83 }
Note: See TracChangeset
for help on using the changeset viewer.