Changeset 8171
- Timestamp:
- 2016-07-27 15:01:17 (7 years ago)
- Location:
- 2016/30/PyryS
- Files:
-
- 47 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2016/30/PyryS/Pinkiponki/Pinkiponki/Pinkiponki/Pinkiponki.cs
r8087 r8171 11 11 Vector nopeusYlos = new Vector(0, 200); 12 12 Vector nopeusAlas = new Vector(0, -200); 13 Vector lahtonopeus = new Vector(-500.0, 100.0); 14 15 16 const int pistemaksimi = 10; 13 17 14 18 … … 17 21 PhysicsObject maila2; 18 22 23 PhysicsObject vasenReuna; 24 PhysicsObject oikeaReuna; 25 26 Level.Background.color taustavari = Color.Black; 27 28 const double PALLO_MIN_NOPEUS = 550; 29 19 30 IntMeter P1Pisteet; 20 31 IntMeter P2Pisteet; … … 24 35 Ohjaimet(); 25 36 LisääLaskurit(); 26 AloitaPeli();27 28 29 37 Timer.SingleShot(5.0, AloitaPeli); 38 39 40 30 41 } 31 42 … … 35 46 Add(pallo); 36 47 pallo.Shape = Shape.Circle; 37 pallo.X = -300.0;48 pallo.X = 0.0; 38 49 pallo.Y = 0.0; 39 pallo.Restitution = 1. 0;50 pallo.Restitution = 1.1; 40 51 41 52 maila1 = LuoMaila(Level.Left + 20.0, 0.0); … … 44 55 AddCollisionHandler(pallo, KasittelePallonTormays); 45 56 46 PhysicsObjectvasenReuna = Level.CreateLeftBorder();57 vasenReuna = Level.CreateLeftBorder(); 47 58 vasenReuna.Restitution = 1.0; 48 59 vasenReuna.IsVisible = true; 49 60 50 PhysicsObjectoikeaReuna = Level.CreateRightBorder();61 oikeaReuna = Level.CreateRightBorder(); 51 62 oikeaReuna.Restitution = 1.0; 52 63 vasenReuna.IsVisible = true; … … 62 73 63 74 64 Level.Background.Color = Color.Black;75 Level.Background.Color = taustavari; 65 76 66 77 Camera.ZoomToLevel(); … … 68 79 void AloitaPeli() 69 80 { 70 Vector impulssi = new Vector(500.0, 0.0);81 Vector impulssi = lahtonopeus; 71 82 pallo.Hit(impulssi); 72 83 } … … 90 101 Keyboard.Listen(Key.S, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 91 102 103 92 104 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "P2 maila ylös", maila2, nopeusYlos); 93 105 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); … … 102 114 { 103 115 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 104 {maila.Velocity = Vector.Zero; 116 { 117 maila.Velocity = Vector.Zero; 105 118 return; 106 } 107 108 { 119 } 120 109 121 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 110 { maila.Velocity = Vector.Zero; 122 { 123 maila.Velocity = Vector.Zero; 111 124 return; 112 125 } 113 }126 114 127 maila.Velocity = nopeus; 128 129 if (maila == maila2 && Keyboard.IsShiftDown()) 130 { 131 maila2.Velocity = nopeus * 2.0; 132 } 133 if ( maila == maila1 && Keyboard.IsCtrlDown()) 134 { 135 maila1.Velocity = nopeus * 2.0; 136 } 137 138 139 115 140 } 116 141 … … 118 143 { 119 144 P1Pisteet = LuoLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 145 P1Pisteet.UpperLimit += delegate { LopetaPeli("P1 voitti pelin"); }; 146 120 147 P2Pisteet = LuoLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 121 } 148 P2Pisteet.UpperLimit += delegate { LopetaPeli("P2 voitti pelin"); }; 149 150 151 } 152 122 153 IntMeter LuoLaskuri(double x, double y) 123 154 { 124 155 IntMeter laskuri = new IntMeter(0); 125 laskuri.MaxValue = 10;156 laskuri.MaxValue = pistemaksimi; 126 157 127 158 Label naytto = new Label(); … … 139 170 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 140 171 { 141 if 172 if (kohde == oikeaReuna) 142 173 { 143 174 P1Pisteet.Value += 1; … … 148 179 } 149 180 } 181 182 183 protected override void Update(Time time) 184 { 185 if (pallo != null && Math.Abs(pallo.Velocity.X) < PALLO_MIN_NOPEUS) 186 { 187 pallo.Velocity = new Vector(pallo.Velocity.X * 1.1, pallo.Velocity.Y); 188 } 189 190 base.Update(time); 191 } 192 193 void LopetaPeli(String viesti) 194 { 195 MessageWindow voittofanfaari = new MessageWindow(viesti); 196 Add(voittofanfaari); 197 198 IsPaused = true; 199 voittofanfaari.Closed += delegate { Exit(); }; 200 } 201 202 150 203 }
Note: See TracChangeset
for help on using the changeset viewer.