Changeset 1599 for 2010/31/alisa@ala-konni.fi/Table Pong/Peli.cs
- Timestamp:
- 2010-08-04 14:59:22 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/31/alisa@ala-konni.fi/Table Pong/Peli.cs
r1536 r1599 9 9 Vector nopeusAlas = new Vector(0, -200); 10 10 11 IntMeter pelaajan1Pisteet; 12 IntMeter pelaajan2Pisteet; 13 11 14 PhysicsObject pallo; 12 15 PhysicsObject maila1; 13 16 PhysicsObject maila2; 17 18 PhysicsObject vasenReuna; 19 PhysicsObject oikeaReuna; 14 20 15 21 protected override void Begin() … … 18 24 AloitaPeli(); 19 25 AsetaOhjaimet(); 26 LisaaLaskurit(); 27 20 28 } 21 29 … … 30 38 Add(pallo); 31 39 40 AddCollisionHandler(pallo, KasittelePallonTormays); 41 32 42 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 33 43 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 34 44 35 Level.CreateBorders(1.0, false); 45 vasenReuna = Level.CreateLeftBorder(); 46 vasenReuna.Restitution = 1.0; 47 vasenReuna.IsVisible = false; 48 49 oikeaReuna = Level.CreateRightBorder(); 50 oikeaReuna.Restitution = 1.0; 51 oikeaReuna.IsVisible = false; 52 53 PhysicsObject ylaReuna = Level.CreateTopBorder(); 54 ylaReuna.Restitution = 1.0; 55 ylaReuna.IsVisible = false; 56 57 PhysicsObject alaReuna = Level.CreateBottomBorder(); 58 alaReuna.Restitution = 1.0; 59 alaReuna.IsVisible = false; 60 61 62 36 63 Level.BackgroundColor = Color.Black; 37 64 Camera.ZoomToLevel(); … … 60 87 { 61 88 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 62 Keyboard.Listen(Key.W, ButtonState.Down, LiikutaMailaaYlos, "Pelaaja 1: Liikuta mailaa ylös"); 63 Keyboard.Listen(Key.W, ButtonState.Released, PysaytaMaila, null); 89 Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, new Vector(0, 500)); 90 Keyboard.Listen(Key.W, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 91 Keyboard.Listen(Key.S, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, new Vector (0, -500)); 92 Keyboard.Listen(Key.S, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 93 94 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, new Vector (0, 500)); 95 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 96 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, new Vector (0, -500)); 97 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 98 99 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 100 64 101 65 102 } … … 67 104 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 68 105 { 106 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 107 { 108 maila.Velocity = Vector.Zero; 109 return; 110 } 111 112 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 113 { 114 maila.Velocity = Vector.Zero; 115 return; 116 } 69 117 maila.Velocity = nopeus; 70 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 IntMeter LuoPisteLaskuri(double x, double y) 127 { 128 IntMeter laskuri = new IntMeter(0); 129 laskuri.MaxValue = 10; 130 Label naytto = new Label(); 131 naytto.BindTo(laskuri); 132 naytto.X = x; 133 naytto.Y = y; 134 naytto.TextColor = Color.White; 135 Add(naytto); 136 137 return laskuri; 138 } 139 140 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 141 { 142 if (kohde == oikeaReuna) 143 { 144 pelaajan1Pisteet.Value += 1; 145 } 146 else if (kohde == vasenReuna) 147 { 148 pelaajan2Pisteet.Value += 1; 149 } 150 151 } 152 71 153 72 154 }
Note: See TracChangeset
for help on using the changeset viewer.