- Timestamp:
- 2013-07-04 14:46:34 (10 years ago)
- Location:
- 2013/27/AkseliJ/Levypallo/Levypallo
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/27/AkseliJ/Levypallo/Levypallo/Levypallo/Kuutio.cs
r4406 r4431 11 11 12 12 internal int health; 13 internal int x; 14 internal int y; 13 15 14 16 public static Color[] healthvarit = { Color.Green, Color.Red, Color.Purple, Color.Yellow, Color.Brown }; 15 17 16 public Kuutio(int indexY, int indexX, int health )18 public Kuutio(int indexY, int indexX, int health, int x, int y) 17 19 : base(100, 100) 18 20 { … … 20 22 21 23 22 24 this.x = x; 25 this.y = y; 23 26 this.health = health; 24 27 Color = healthvarit[health - 1]; -
2013/27/AkseliJ/Levypallo/Levypallo/Levypallo/Levypallo.cs
r4406 r4431 22 22 internal PhysicsObject levy; 23 23 internal bool palloKiinni = true; 24 public int elamat = 3; 24 public int elamat; 25 public int taso = 0; 26 private double previousY; 25 27 26 28 //Vakiot … … 35 37 instance = this; 36 38 39 AsetaKontrolliKuuntelijat(); 37 40 AsetaPerusKuuntelijat(); 41 elamat = 3; 38 42 ValmisteleTausta(); 39 43 LuoPallo(); 44 AsetaFysiikkaKuuntelijat(); 40 45 LuoLevy(); 41 46 LuoKentta(); 47 48 //Gravity = new Vector(0, -150); 49 50 51 } 52 private void Aloita() 53 { 54 55 elamat = 3; 56 TyhjennaKentta(); 57 ValmisteleTausta(); 58 LuoPallo(); 42 59 AsetaFysiikkaKuuntelijat(); 43 AsetaKontrolliKuuntelijat(); 44 Gravity = new Vector(0, -150); 45 46 60 LuoLevy(); 61 LuoKentta(); 62 63 } 64 65 private void TyhjennaKentta() 66 { 67 kentta = null; 68 ClearGameObjects(); 69 47 70 } 48 71 … … 50 73 { 51 74 base.Update(time); 52 taulu.Text = " LEVYPALLO SCORE: \n" + Score.ToString()+"\n"+"Elämiä jäljellä:\n"+elamat;75 taulu.Text = "Taso: " + ((int)(taso + 1)) + "\nLEVYPALLO SCORE: \n" + Score.ToString() + "\n" + "Elämiä jäljellä:\n" + elamat; 53 76 if (!palloKiinni) 54 77 { … … 56 79 pallo.Velocity = pallo.Velocity.Normalize() * Pallon_nopeus; 57 80 } 58 else { pallo.Velocity = levy.Velocity; 59 pallo.StopAngular(); 60 pallo.Angle = Angle.Zero; 61 62 } 63 if (pallo.Y <= Level.Bottom + 30) { 81 else 82 { 83 pallo.Velocity = levy.Velocity; 84 pallo.StopAngular(); 85 pallo.Angle = Angle.Zero; 86 87 } 88 if (pallo.Y <= Level.Bottom + 30) 89 { 64 90 65 91 palloKiinni = true; … … 70 96 } 71 97 98 previousY = pallo.Y; 99 taulu.Text = "Taso: " +((int)( taso + 1 ))+ "\nLEVYPALLO SCORE: \n" + Score.ToString() + "\n" + "Elämiä jäljellä:\n" + elamat; 100 72 101 if (elamat <= 0) 73 102 { … … 78 107 Add(l); 79 108 Pause(); 109 110 111 } 112 113 } 114 115 private string ArvioiTulos() 116 { 117 return "Sait "+Score+" pistettä."; 118 } 119 120 private void AsetaFysiikkaKuuntelijat() 121 { 122 AddCollisionHandler<PhysicsObject, Kuutio>(pallo, "kuutio", KuutioonIskee); 123 } 124 125 private void KuutioonIskee(PhysicsObject bollen, Kuutio k) 126 { 127 Score += (int)(50 + (0.5 * ((double)taso))); 128 k.health--; 129 130 Explosion kaboom = new Explosion(100); 131 kaboom.X = k.X; 132 kaboom.Y = k.Y; 133 kaboom.UseShockWave = false; 134 Add(kaboom); 135 if (k.health > 0) 136 { 137 k.Color = Kuutio.healthvarit[k.health - 1]; 138 } 139 if (k.health <= 0) 140 { 141 142 k.Destroy(); 143 kentta[k.x, k.y] = null; 80 144 81 82 } 83 84 } 85 86 private string ArvioiTulos() 87 { 88 if (Score < 1000) 89 return "EI VOI OLLA TOTTA! Vain "+Score+" pistettä!?!?! Miten se on mahdollista?"; 90 91 else if (Score < 2000) 92 93 return Score + " pisteitä ei ole kovin häävi. Yritä kuitenkin uudelleen!"; 94 95 96 97 else if (Score > 4000) { 98 99 return "Vaikuttavaa! Mistä sait nuo taidot? "+Score+" on aika hyvä tulos :)"; 100 } 101 else if (Score > 8000) { 102 103 return "ANTAKAA APLODIT UUDELLE LEVYPALLOMESTARILLE! "+Score+" PISTETTÄ!"; 104 105 } 106 107 return "Hmm... Ihan ok - "+Score+" pistettä."; 108 } 109 110 private void AsetaFysiikkaKuuntelijat() 111 { 112 AddCollisionHandler(pallo, "kuutio", KuutioonIskee); 113 } 114 115 private void KuutioonIskee(PhysicsObject bollen, PhysicsObject kuutio) 116 { 117 118 if (kuutio is Kuutio) 119 { 120 121 Score += 50; 122 Kuutio cube = kuutio as Kuutio; 123 cube.health--; 145 for (int i = 0; i < kentta.GetLength(0); i++) 146 { 147 for (int j = 0; j < kentta.GetLength(1); j++) 148 { 149 if (kentta[i, j] != null) 150 { 151 152 return; 153 } 154 } 155 } 156 if (taso >= 4) { 157 158 Label l = new Label(600, 400, "Onneksi olkoon!\nLäpäisit pelin!"); 159 l.TextScale = new Vector(6, 6); 160 l.TextColor = Color.Pink; 161 Add(l); 162 MessageDisplay.Add(ArvioiTulos()); 163 Pause(); 124 164 125 165 126 127 Explosion KABOOOOOOOOOOM = new Explosion(100); 128 KABOOOOOOOOOOM.X = cube.X; 129 KABOOOOOOOOOOM.Y = cube.Y; 130 KABOOOOOOOOOOM.UseShockWave = false; 131 Add(KABOOOOOOOOOOM); 132 if (cube.health <= 0) cube.Destroy(); 133 134 135 if(cube.health > 0) 136 cube.Color = Kuutio.healthvarit[cube.health - 1]; 137 138 166 } 167 taso++; 168 TyhjennaKentta(); 169 Aloita(); 170 139 171 } 140 172 } … … 142 174 private void AsetaKontrolliKuuntelijat() 143 175 { 144 Keyboard.Listen<Key, ButtonState>(Key.Left, ButtonState.Down, NappiYlos, null, Key.Left, ButtonState.Down);145 Keyboard.Listen<Key, ButtonState>(Key.Right, ButtonState.Down, NappiYlos, null, Key.Right, ButtonState.Down);146 Keyboard.Listen<Key, ButtonState>(Key.Space, ButtonState.Pressed, NappiYlos, null, Key.Space, ButtonState.Pressed);176 Keyboard.Listen<Key, ButtonState>(Key.Left, ButtonState.Down, NappiYlos, "Liiku vasemmalle", Key.Left, ButtonState.Down); 177 Keyboard.Listen<Key, ButtonState>(Key.Right, ButtonState.Down, NappiYlos, "Liiku oikealle", Key.Right, ButtonState.Down); 178 Keyboard.Listen<Key, ButtonState>(Key.Space, ButtonState.Pressed, NappiYlos, "Laukaise pallo", Key.Space, ButtonState.Pressed); 147 179 Keyboard.Listen<Key, ButtonState>(Key.Right, ButtonState.Up, NappiYlos, null, Key.Right, ButtonState.Up); 148 180 Keyboard.Listen<Key, ButtonState>(Key.Left, ButtonState.Up, NappiYlos, null, Key.Left, ButtonState.Up); 149 Keyboard.Listen<Key, ButtonState>(Key.K, ButtonState.Pressed, NappiYlos, null, Key.K, ButtonState.Pressed); 181 Keyboard.Listen<Key, ButtonState>(Key.K, ButtonState.Pressed, NappiYlos, "Palauta pallo lähtöalustalle (maksaa yhden elämän)", Key.K, ButtonState.Pressed); 182 ShowControlHelp(); 150 183 } 151 184 … … 153 186 { 154 187 //Oletusleveys 250 155 levy = PhysicsObject.CreateStaticObject(250, 40); 188 double leveys = 250 - 50 * taso; 189 levy = PhysicsObject.CreateStaticObject(leveys, 40); 156 190 levy.Color = Color.Yellow; 157 191 levy.X = 0; … … 160 194 levy.Tag = "levy"; 161 195 Add(levy); 162 163 } 164 165 private void NappiYlos(Key nappi, ButtonState tila) { 166 167 if (tila == ButtonState.Down) { 168 169 if (nappi == Key.Left) { 196 197 } 198 199 private void NappiYlos(Key nappi, ButtonState tila) 200 { 201 202 if (tila == ButtonState.Down) 203 { 204 205 if (nappi == Key.Left) 206 { 170 207 if (levy.Left - 5 < Level.Left) ; 171 208 else 172 levy.Velocity = new Vector(-325, 0);209 levy.Velocity = new Vector(-400, 0); 173 210 return; 174 175 } 176 else if (nappi == Key.Right) { 211 212 } 213 else if (nappi == Key.Right) 214 { 177 215 178 216 if (levy.Right > Level.Right) ; 179 217 else 180 218 { 181 levy.Velocity = new Vector( 325, 0);219 levy.Velocity = new Vector(400, 0); 182 220 return; 183 221 } 184 185 } 186 187 222 223 } 224 225 188 226 } 189 227 if (tila == ButtonState.Pressed) … … 192 230 if (nappi == Key.Space && palloKiinni) 193 231 { 194 palloKiinni = false; 232 palloKiinni = false;+ 195 233 pallo.IgnoresCollisionResponse = false; 196 234 bool rnd = RandomGen.NextBool(); … … 198 236 else pallo.Velocity = new Vector(-300, 300); 199 237 } 200 else if (nappi == Key.K && !palloKiinni) { 201 202 palloKiinni = true; 203 pallo.X = levy.X; 238 else if (nappi == Key.K && !palloKiinni) 239 { 240 241 /*palloKiinni = true; 242 //pallo.X = levy.X; 204 243 pallo.Y = Level.Bottom + 70; 205 244 pallo.IgnoresCollisionResponse = true; 206 elamat--; 207 208 } 209 210 211 245 elamat--;*/ 246 Label l = new Label(600, 400, "Onneksi olkoon!\nLäpäisit pelin!"); 247 l.TextScale = new Vector(6, 6); 248 l.TextColor = Color.Pink; 249 Add(l); 250 MessageDisplay.Add(ArvioiTulos()); 251 Pause(); 252 253 } 254 255 256 212 257 } 213 258 214 259 levy.Velocity = Vector.Zero; 215 260 216 261 } 217 262 … … 233 278 234 279 235 kentta[i, j] = new Kuutio(((int)Level.Bottom / 100) + i, (((int)Level.Left / 100) + j), RandomGen.NextInt(1, 6) );280 kentta[i, j] = new Kuutio(((int)Level.Bottom / 100) + i, (((int)Level.Left / 100) + j), RandomGen.NextInt(1, 6), i, j); 236 281 } 237 282 else kentta[i, j] = null; … … 248 293 pallo.Color = Color.YellowGreen; 249 294 pallo.Y = Level.Bottom + 70; 250 pallo.X = 0;251 pallo.Shape = Shape. Octagon;295 pallo.X = 0; 296 pallo.Shape = Shape.Circle; 252 297 pallo.Restitution = 1.5; 253 298 pallo.IgnoresGravity = true; … … 265 310 Camera.ZoomToLevel(); 266 311 taulu = new Label(400, 400); 267 taulu.Y = Screen.Top - 50;312 taulu.Y = Screen.Top - 70; 268 313 //taulu.X:n paras arvo tähän asti on 325 269 314 taulu.X = Screen.Right - 325; … … 285 330 } 286 331 287 332 288 333 } -
2013/27/AkseliJ/Levypallo/Levypallo/LevypalloContent/LevypalloContent.contentproj
r4351 r4431 52 52 </Compile> 53 53 </ItemGroup> 54 <ItemGroup> 55 <Compile Include="Vihreapalikka.png"> 56 <Name>Vihreapalikka</Name> 57 <Importer>TextureImporter</Importer> 58 <Processor>TextureProcessor</Processor> 59 </Compile> 60 </ItemGroup> 54 61 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 55 62 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Note: See TracChangeset
for help on using the changeset viewer.