- Timestamp:
- 2015-06-22 14:36:53 (8 years ago)
- Location:
- 2015/26/AkseliP/Pong/Pong
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2015/26/AkseliP/Pong/Pong/Pong/Pong/Pong.cs
r6126 r6133 11 11 Vector nopeusYlos = new Vector(0, 200); 12 12 Vector nopeusAlas = new Vector(0, -200); 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 19 24 public override void Begin() … … 24 29 AsetaOhjaimet(); 25 30 AloitaPeli(); 31 LisaaLaskurit(); 26 32 27 33 28 34 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 29 35 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); … … 35 41 Add(pallo); 36 42 pallo.Restitution = 1.0; 37 Level.CreateBorders(1.0, false); 43 AddCollisionHandler(pallo, kasittelepallontormays); 44 vasenReuna = Level.CreateLeftBorder(); 45 vasenReuna.Restitution = 1.0; 46 vasenReuna.IsVisible = false; 38 47 39 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 48 oikeaReuna = Level.CreateRightBorder(); 49 oikeaReuna.Restitution = 1.0; 50 oikeaReuna.IsVisible = false; 51 52 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 40 53 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 41 54 … … 44 57 pallo.Y = 0.0; 45 58 46 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);47 maila.Shape = Shape.Rectangle;48 maila.X = Level.Left + 20.0;49 maila.Y = 0.0;50 maila.Restitution = 1.0;51 Add(maila);52 59 53 60 Camera.ZoomToLevel(); … … 60 67 61 68 } 62 void LuoMaila(double x, double y) 69 70 PhysicsObject LuoMaila(double x, double y) 63 71 { 64 72 … … 75 83 void AsetaOhjaimet() 76 84 { 77 Keyboard.Listen(Key.A, ButtonState.Released, PysaytaMaila1, null); 78 Keyboard.Listen(Key.A, ButtonState.Down, LiikutaMaila1Ylos, "Pelaaja 1: Liikuta mailaa ylös"); 85 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 86 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 87 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "pelaaja 1:Liikuta mailaa nopeusAlas", maila1, nopeusAlas); 88 Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 79 89 80 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "lopeta peli"); 90 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 91 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 92 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 93 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 94 95 96 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 97 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "lopeta peli"); 81 98 } 99 82 100 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 83 101 { 102 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 103 { 104 maila.Velocity = Vector.Zero; 105 return; 106 } 107 84 108 maila.Velocity = nopeus; 85 109 110 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 111 { 112 maila.Velocity = Vector.Zero; 113 return; 114 } 115 116 maila.Velocity = nopeus; 117 } 118 119 120 void LisaaLaskurit() 121 { 122 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 123 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 124 125 126 } 127 128 129 IntMeter LuoPisteLaskuri(double x, double y) 130 { 131 IntMeter laskuri = new IntMeter(0); 132 laskuri.MaxValue = 10; 133 134 135 136 Label naytto = new Label(); 137 naytto.BindTo(laskuri); 138 naytto.X = x; 139 naytto.Y = y; 140 naytto.TextColor = Color.White; 141 naytto.BorderColor = Level.Background.Color; 142 naytto.Color = Level.Background.Color; 143 Add(naytto); 144 145 146 return laskuri; 147 } 148 void kasittelepallontormays(PhysicsObject pallo, PhysicsObject kohde) 149 { 150 if (kohde == oikeaReuna) 151 { 152 pelaajan1Pisteet.Value += 1; 153 } 154 else if (kohde == vasenReuna) 155 { 156 pelaajan2Pisteet.Value += 1; 157 } 158 } 86 159 87 160 } 88 161 89 162 90
Note: See TracChangeset
for help on using the changeset viewer.