Changeset 2507
- Timestamp:
- 2011-08-02 14:59:43 (8 years ago)
- Location:
- 2011/31/AkuH
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/31/AkuH/Pong/Pong/Peli.cs
r2474 r2507 10 10 { 11 11 PhysicsObject pallo; 12 IntMeter Pelaajan1Pisteet; 13 IntMeter Pelaajan2Pisteet; 14 Vector nopeusYlos = new Vector(0, 200); 15 Vector nopeusAlas = new Vector(0, -200); 12 16 13 public override void Begin() 17 PhysicsObject maila1; 18 PhysicsObject maila2; 19 20 PhysicsObject vasenreuna; 21 PhysicsObject oikeareuna; 22 23 public override void Begin() 14 24 { 15 25 LuoKentta(); 16 26 AsetaOhjaimet(); 17 // TODO: Kirjoita ohjelmakoodisi tähän 27 // TODO: Kirjoita ohjelmakoodisi tähän 28 18 29 AloitaPeli(); 30 LisaaLaskurit(); 19 31 20 21 32 33 34 35 36 22 37 } 23 38 … … 30 45 pallo.Y = 0.0; 31 46 32 LuoMaila(Level.Left + 20.0, 0.0);33 LuoMaila(Level.Right - 20.0, 0.0);47 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 48 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 34 49 35 Level.CreateBorders(1.0, false); 50 vasenreuna = Level.CreateLeftBorder(); 51 vasenreuna.Restitution = 1.0; 52 vasenreuna.IsVisible = false; 53 oikeareuna = Level.CreateRightBorder(); 54 oikeareuna.Restitution = 1.0; 55 oikeareuna.IsVisible = false; 56 PhysicsObject ylaReuna = Level.CreateTopBorder(); 57 ylaReuna.Restitution = 1.0; 58 ylaReuna.IsVisible = false; 59 PhysicsObject alaReuna = Level.CreateBottomBorder(); 60 alaReuna.Restitution = 1.0; 61 alaReuna.IsVisible = false; 36 62 pallo.Restitution = 1.0; 37 Level.BackgroundColor = Color.Black; 63 64 Level.BackgroundColor = Color.DarkRed; 38 65 Camera.ZoomToLevel(); 39 66 40 67 AddCollisionHandler(pallo, KasittelePallonTormays); 41 68 42 69 } … … 47 74 pallo.Hit(impulssi); 48 75 } 49 void LuoMaila(double x, double y) 76 77 PhysicsObject LuoMaila(double x, double y) 50 78 { 51 79 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); … … 56 84 Add(maila); 57 85 58 86 return maila; 59 87 } 60 88 61 89 void AsetaOhjaimet() 62 90 { 91 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 92 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 93 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusAlas); 94 Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 95 96 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 97 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 98 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusAlas); 99 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 100 101 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "NäytäOhjeet"); 63 102 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 64 103 65 Keyboard.Listen(Key.A, ButtonState.Down, LiikutaMailaaYlos, "Pelaaja 1: Liikuta mailaa ylös"); 104 105 } 106 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 107 { 108 maila.Velocity = nopeus; 109 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 110 { 111 maila.Velocity = Vector.Zero; 112 return; 113 } 114 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 115 { 116 maila.Velocity = Vector.Zero; 117 return; 118 119 } 120 121 maila.Velocity = nopeus; 66 122 } 67 123 68 }69 70 124 71 125 126 127 128 IntMeter LuoPisteLaskuri(double x, double y) 129 { 130 IntMeter laskuri = new IntMeter(0); 131 laskuri.MaxValue = 10; 132 Label naytto = new Label(); 133 naytto.BindTo(laskuri); 134 naytto.X = x; 135 naytto.Y = y; 136 naytto.TextColor = Color.DarkCyan; 137 naytto.BorderColor = Level.BackgroundColor; 138 naytto.Color = Level.BackgroundColor; 139 Add(naytto); 140 return laskuri; 141 } 142 void LisaaLaskurit() 143 { 144 Pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 145 Pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 146 } 147 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 148 { 149 if (kohde == oikeareuna) 150 Pelaajan1Pisteet.Value += 1; 151 152 else if (kohde == vasenreuna) 153 Pelaajan2Pisteet.Value += 1; 154 } 155 }
Note: See TracChangeset
for help on using the changeset viewer.