- Timestamp:
- 2016-06-20 14:12:55 (7 years ago)
- Location:
- 2016/25/MatiasA/Pong 03/Pong 03/Pong_03
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
2016/25/MatiasA/Pong 03/Pong 03/Pong_03/Pong_03.cs
r7468 r7469 12 12 Vector nopeusYlos = new Vector(0, 200); 13 13 Vector nopeusalas = new Vector(0, -200); 14 const double PALLON_MIN_NOPEUS = 10000; 14 15 IntMeter pelaajan1Pisteet; 16 IntMeter pelaajan2Pisteet; 17 18 const double PALLON_MIN_NOPEUS = 10000000; 15 19 PhysicsObject maila1; 16 20 PhysicsObject maila2; 21 IntMeter pelaajan1pisteet; 22 IntMeter pelaajan2pisteet; 23 24 PhysicsObject vasenReuna; 25 PhysicsObject oikeaReuna; 26 17 27 18 28 public override void Begin() … … 21 31 AsetaOhjaimet(); 22 32 LisaaLaskurit(); 23 Aloitapeli(); 24 33 AloitaPeli(); 25 34 26 35 … … 39 48 } 40 49 50 51 41 52 void LuoKentta() 42 53 { 54 vasenReuna = Level.CreateLeftBorder(); 55 vasenReuna.Restitution = 1.0; 56 vasenReuna.IsVisible = false; 57 58 oikeaReuna = Level.CreateRightBorder(); 59 oikeaReuna.Restitution = 1.0; 60 oikeaReuna.IsVisible = false; 61 62 PhysicsObject ylaReuna = Level.CreateTopBorder(); 63 ylaReuna.Restitution = 1.0; 64 ylaReuna.IsVisible = false; 65 66 PhysicsObject alaReuna = Level.CreateBottomBorder(); 67 alaReuna.Restitution = 1.0; 68 alaReuna.IsVisible = false; 69 43 70 pallo = new PhysicsObject(50, 50); 44 71 pallo.Shape = Shape.Circle; … … 48 75 pallo.Y = 0.0; 49 76 pallo.Restitution = 1.0; 77 AddCollisionHandler(pallo, KasittelePallonTormays); 50 78 51 79 52 maila1= LuoMaila(Level.Left + 20.0, 0.0);53 maila2= LuoMaila(Level.Right - 20.0, 0.0);80 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 81 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 54 82 55 83 … … 58 86 } 59 87 60 void Aloita peli()88 void AloitaPeli() 61 89 { 62 90 Vector impulssi = new Vector(500.0, 0.0); … … 64 92 } 65 93 66 67 94 95 68 96 69 97 void AsetaOhjaimet() … … 73 101 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "pelaaja 1", maila1, nopeusalas); 74 102 Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 75 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, 103 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 76 104 77 105 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); … … 99 127 100 128 } 101 102 103 104 129 130 131 132 PhysicsObject LuoMaila(double x, double y) 105 133 { 106 134 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 120.0); … … 111 139 Add(maila); 112 140 return maila; 113 } 114 void LiikutaMailaaYlos(PhysicsObject maila) 115 { 116 141 } 142 void LiikutaMailaaYlos(PhysicsObject maila) 143 { 117 144 118 }119 120 void LisaaLaskurit()121 {122 145 123 146 } 124 147 148 void LisaaLaskurit() 149 { 150 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 151 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 152 } 125 153 154 IntMeter LuoPisteLaskuri(double x, double y) 155 { 156 IntMeter laskuri = new IntMeter(0); 157 laskuri.MaxValue = 10; 126 158 127 159 Label naytto = new Label(); 160 naytto.BindTo(laskuri); 161 naytto.X = x; 162 naytto.Y = y; 163 naytto.TextColor = Color.White; 164 naytto.BorderColor = Level.BackgroundColor; 165 naytto.Color = Level.BackgroundColor; 166 Add(naytto); 128 167 129 130 131 132 168 return laskuri; 169 } 170 171 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 172 { 173 if (kohde == oikeaReuna) 174 { 175 pelaajan1Pisteet.Value += 1; 176 } 177 else if (kohde == vasenReuna) 178 { 179 pelaajan2Pisteet.Value += 1; 180 } 181 } 133 182 } 134 183
Note: See TracChangeset
for help on using the changeset viewer.