Changeset 2032
- Timestamp:
- 2011-06-15 15:03:21 (12 years ago)
- Location:
- 2011/24/LauriK/Call of garden Modern carrotfare 2
- Files:
-
- 7 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/24/LauriK/Call of garden Modern carrotfare 2/Call of garden Modern carrotfare 2/Peli.cs
r2002 r2032 14 14 15 15 PlatformCharacter porkkana; 16 PlatformCharacter tomaatti; 16 PhysicsObject hautakivi; 17 PhysicsObject kuolluttomaatti; 18 PhysicsObject lipas; 19 20 IntMeter panoslaskuri; 21 IntMeter pistelaskuri; 17 22 18 23 Image[] pelaajanKuva = LoadImages("porkkana"); … … 20 25 21 26 Image pelaajanKuvaKuolleena = LoadImage("rip"); 22 27 23 28 Image[] vihollisenKuva = LoadImages("tomaatti"); 24 29 Image[] vihollisenKuvaPeilattu; 30 31 Image vihollisenKuvaKuolleena = LoadImage("tomaattikuolleena"); 32 33 Image lippaanKuva = LoadImage("Lipas2"); 34 35 ExplosionSystem rajahdys; 36 int pMaxMaara = 50; 25 37 26 38 public override void Begin() 27 39 { 40 ClearAll(); 41 28 42 pelaajanKuvaPeilattu = Image.Mirror(pelaajanKuva); 29 43 vihollisenKuvaPeilattu = Image.Mirror(vihollisenKuva); 44 45 30 46 Gravity = new Vector(0, -1000); 31 47 … … 34 50 35 51 Camera.Follow(porkkana); 52 36 53 Camera.ZoomFactor = 1.2; 37 54 Camera.StayInLevel = true; 55 56 LuoPanosLaskuri(); 57 LuoPisteLaskuri(); 38 58 } 39 59 … … 42 62 TileMap kentta = TileMap.FromFile("kentta1.txt"); 43 63 kentta['#'] = lisaaTaso; 64 kentta['K'] = lisaaTaso2; 44 65 kentta['N'] = lisaaPelaaja; 45 66 kentta['E'] = lisaaTomaatti; 67 kentta['L'] = LuoLipas; 46 68 kentta.Insert(RUUDUN_KOKO, RUUDUN_KOKO); 47 69 Level.CreateBorders(); 48 } 70 71 rajahdys = new ExplosionSystem(LoadImage("rajahdys"), pMaxMaara); 72 rajahdys.MaxLifetime = 1.0; 73 rajahdys.MaxScale = 0.1; 74 Add(rajahdys); 75 } 76 49 77 PhysicsObject lisaaTaso() 50 78 { … … 54 82 } 55 83 84 PhysicsObject lisaaTaso2() 85 { 86 PhysicsObject taso2 = PhysicsObject.CreateStaticObject(RUUDUN_KOKO, RUUDUN_KOKO); 87 taso2.Color = Color.Gray; 88 return taso2; 89 } 90 56 91 PlatformCharacter lisaaPelaaja() 57 92 { … … 59 94 porkkana.Mass = 4.0; 60 95 61 porkkana.Weapon = new AssaultRifle( 40, 20);62 porkkana.Weapon.Ammo.Value = 500;96 porkkana.Weapon = new AssaultRifle(50, 30); 97 porkkana.Weapon.Ammo.Value = 10; 63 98 porkkana.Weapon.Y = -10; 64 99 porkkana.Weapon.X = 0; 65 100 porkkana.Weapon.ProjectileCollision = AmmusOsui; 66 101 102 AddCollisionHandler(porkkana, LippaaseenOsuma); 103 67 104 porkkana.RightWalkingAnimation = new Animation(pelaajanKuva); 68 105 porkkana.LeftWalkingAnimation = new Animation(pelaajanKuvaPeilattu); … … 72 109 PlatformCharacter lisaaTomaatti() 73 110 { 74 tomaatti = new PlatformCharacter(40, 40);111 PlatformCharacter tomaatti = new PlatformCharacter(40, 40); 75 112 tomaatti.Mass = 4.0; 113 114 tomaatti.Tag = "Vihollinen"; 76 115 77 116 FollowerBrain SeuraajanAivot = new FollowerBrain(); 78 117 tomaatti.Brain = SeuraajanAivot; 79 118 SeuraajanAivot.Target = porkkana; 80 SeuraajanAivot.Speed = 300;119 SeuraajanAivot.Speed = 100; 81 120 SeuraajanAivot.TargetFollowDistance = 1000; 82 121 SeuraajanAivot.TargetCloseDistance = 50; 83 122 SeuraajanAivot.StopWhenTargetClose = false; 84 SeuraajanAivot.TargetClose += MitaTapahtuuKunOllaanLahella;123 AddCollisionHandler(tomaatti, TomaattiOsui); 85 124 86 125 tomaatti.RightWalkingAnimation = new Animation(vihollisenKuva); … … 95 134 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); 96 135 97 Keyboard.Listen(Key.Left, ButtonState.Down, liikuta, " Liikkuu vasemmalle", porkkana, -nopeus);98 Keyboard.Listen(Key.Right, ButtonState.Down, liikuta, " Liikkuu vasemmalle", porkkana, nopeus);136 Keyboard.Listen(Key.Left, ButtonState.Down, liikuta, "Pelaaja liikkuu vasemmalle", porkkana, -nopeus); 137 Keyboard.Listen(Key.Right, ButtonState.Down, liikuta, "Pelaaja liikkuu vasemmalle", porkkana, nopeus); 99 138 Keyboard.Listen(Key.Up, ButtonState.Pressed, hyppaa, "Pelaaja hyppää", porkkana, hyppyNopeus); 100 139 … … 102 141 Keyboard.Listen(Key.W, ButtonState.Down, TahtaaYlos, "Tähtää ylös rynnäkkökiväärillä"); 103 142 Keyboard.Listen(Key.S, ButtonState.Down, TahtaaAlas, "Tähtää alas rynnäkkökiväärillä"); 104 105 ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä"); 106 143 Keyboard.Listen(Key.Q, ButtonState.Pressed, HeitaKranaatti, "Heitä kranaatti"); 144 145 ControllerOne.Listen(Button.Start, ButtonState.Pressed, Exit, "Poistu pelistä"); 146 ControllerOne.Listen(Button.Back, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 147 107 148 ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, liikuta, "Pelaaja liikkuu vasemmalle", porkkana, -nopeus); 108 149 ControllerOne.Listen(Button.DPadRight, ButtonState.Down, liikuta, "Pelaaja liikkuu oikealle", porkkana, nopeus); 109 150 ControllerOne.Listen(Button.A, ButtonState.Pressed, hyppaa, "Pelaaja hyppää", porkkana, hyppyNopeus); 151 152 ControllerOne.Listen(Button.RightTrigger, ButtonState.Down, AmmuAseella, "Ammu rynnäkkökiväärillä"); 153 ControllerOne.Listen(Button.DPadUp,ButtonState.Down, TahtaaYlos, "Tähtää ylös rynnäkkökiväärillä"); 154 ControllerOne.Listen(Button.DPadDown, ButtonState.Down, TahtaaAlas, "Tähtää alas rynnäkkökiväärillä"); 155 ControllerOne.Listen(Button.LeftTrigger, ButtonState.Pressed, HeitaKranaatti, "Heitä kranaatti"); 110 156 } 111 157 … … 128 174 { 129 175 ammus.Size *= 5; 130 ammus.MaximumLifetime = TimeSpan.FromSeconds(1.0); 131 } 132 } 176 ammus.MaximumLifetime = TimeSpan.FromSeconds(1.5); 177 } 178 } 179 133 180 void TahtaaYlos() 134 181 { … … 144 191 145 192 } 193 146 194 void TahtaaAlas() 147 195 { … … 155 203 } 156 204 } 205 157 206 void AmmusOsui(PhysicsObject ammus, PhysicsObject kohde) 158 207 { 159 208 160 if (kohde == tomaatti)209 if (kohde.Tag.ToString() == "Vihollinen") 161 210 { 162 211 ammus.Destroy(); 163 212 kohde.Brain = null; 213 TomaattiKuoli(kohde); 164 214 kohde.IgnoresCollisionResponse = true; 165 //kohde.Destroy(); 215 rajahdys.AddEffect(kohde.Position, 50); 216 166 217 } 167 218 if (kohde == porkkana) 168 219 { 169 ammus.Destroy();170 tomaatti.Brain = null;171 kohde.IgnoresCollisionResponse = true;172 220 LopetaPeli(); 173 174 } 175 176 } 177 void TomaattiOsui(PlatformCharacter tomaatti, PhysicsObject kohde) 178 { 179 if (kohde == porkkana) 180 { 181 182 183 } 184 } 185 186 187 221 } 222 223 } 224 188 225 void LopetaPeli() 189 226 { 190 227 porkkana.Stop(); 191 228 229 porkkana.Destroy(); 230 231 LuoHautakivi(); 232 192 233 Label lopetus = new Label(); 193 234 lopetus.Position = Screen.Center; … … 196 237 Add(lopetus); 197 238 lopetus.Text = " Game over.\n" + 198 "Jos haluat aloittaa alusta, paina enter . Jos taas haluat lopettaa, paina Esc.";239 "Jos haluat aloittaa alusta, paina enter/A. Jos taas haluat lopettaa, paina Esc/start."; 199 240 200 241 ClearControls(); … … 203 244 Keyboard.Listen(Key.Enter, ButtonState.Pressed, Begin, null); 204 245 205 ControllerOne.Listen(Button.A, ButtonState.Down, Exit, "Poistu pelistä"); 206 ControllerOne.Listen(Button.B, ButtonState.Down, Begin, null); 207 } 208 void MitaTapahtuuKunOllaanLahella(object SeuraajanAivot, EventArgs e) 209 { 210 tomaatti.Stop(); 211 tomaatti.Brain.Active = false; 212 porkkana.Image = pelaajanKuvaKuolleena; 213 LopetaPeli(); 214 } 215 216 } 217 218 246 ControllerOne.Listen(Button.A, ButtonState.Down, Begin, "Poistu pelistä"); 247 ControllerOne.Listen(Button.Start, ButtonState.Down, Exit, null); 248 } 249 250 void LuoHautakivi() 251 { 252 hautakivi = new PhysicsObject(40, 40); 253 hautakivi.Mass = 100000000000.0; 254 255 hautakivi.Image = pelaajanKuvaKuolleena; 256 257 hautakivi.Position = porkkana.Position; 258 Add(hautakivi); 259 260 } 261 262 void TomaattiKuoli(PhysicsObject tomaatti) 263 { 264 tomaatti.Destroy(); 265 266 pistelaskuri.Value += 100; 267 268 kuolluttomaatti = new PhysicsObject(50, 50); 269 kuolluttomaatti.Mass = 4.0; 270 271 kuolluttomaatti.IgnoresCollisionResponse = true; 272 273 kuolluttomaatti.IgnoresGravity = true; 274 275 kuolluttomaatti.Image = vihollisenKuvaKuolleena; 276 277 kuolluttomaatti.Position = tomaatti.Position; 278 Add(kuolluttomaatti); 279 280 LuoLipas(kuolluttomaatti.X - 50, kuolluttomaatti.Y); 281 } 282 283 void TomaattiOsui(PhysicsObject tomaatti, PhysicsObject kohde) 284 { 285 if (kohde == porkkana) 286 { 287 tomaatti.Stop(); 288 tomaatti.Brain.Active = false; 289 290 LopetaPeli(); 291 } 292 293 } 294 295 void LuoPanosLaskuri() 296 { 297 panoslaskuri = new IntMeter(0); 298 299 Label panosnaytto = new Label(); 300 panosnaytto.X = Screen.Right - 100; 301 panosnaytto.Y = Screen.Top - 100; 302 panosnaytto.TextColor = Color.Red; 303 304 panosnaytto.BindTo(porkkana.Weapon.Ammo); 305 Add(panosnaytto); 306 307 Label panosteksti = new Label("Panoksia jäljellä: "); 308 panosteksti.X = Screen.Right - 200; 309 panosteksti.Y = Screen.Top - 100; 310 panosteksti.TextColor = Color.Red; 311 312 Add(panosteksti); 313 } 314 315 void LuoPisteLaskuri() 316 { 317 pistelaskuri = new IntMeter(0); 318 319 Label pistenaytto = new Label(); 320 pistenaytto.X = Screen.Right - 100; 321 pistenaytto.Y = Screen.Top - 150; 322 pistenaytto.TextColor = Color.Red; 323 324 pistenaytto.BindTo(pistelaskuri); 325 Add(pistenaytto); 326 327 Label pisteteksti = new Label("Pisteitä: "); 328 pisteteksti.X = Screen.Right - 200; 329 pisteteksti.Y = Screen.Top - 150; 330 pisteteksti.TextColor = Color.Red; 331 332 Add(pisteteksti); 333 } 334 335 PhysicsObject LuoLipas() 336 { 337 lipas = new PhysicsObject(20, 20); 338 lipas.Mass = 2.0; 339 340 lipas.Image = lippaanKuva; 341 342 lipas.Tag = "Lipas"; 343 344 Add(lipas); 345 return lipas; 346 } 347 348 void LuoLipas(double x, double y) 349 { 350 LuoLipas().Position = new Vector(x,y); 351 } 352 353 void LippaaseenOsuma(PhysicsObject porkkana, PhysicsObject kohde) 354 { 355 if (kohde.Tag.ToString() == "Lipas") 356 { 357 ((PlatformCharacter)porkkana).Weapon.Ammo.Value +=10; 358 kohde.Destroy(); 359 } 360 } 361 362 void HeitaKranaatti() 363 { 364 Grenade kranaatti = new Grenade(4.0); 365 kranaatti.X = porkkana.X + 10; 366 kranaatti.Y = porkkana.Y + 10; 367 Add(kranaatti); 368 Vector kranaatinlento = Vector.FromLengthAndAngle(100.0, porkkana.Weapon.Angle); 369 kranaatti.Hit(kranaatinlento); 370 } 371 } -
2011/24/LauriK/Call of garden Modern carrotfare 2/Call of garden Modern carrotfare 2/kentta1.txt
r2002 r2032 1 *2 ##3 1 4 * *5 ## ##6 2 7 * * 8 ## ## ## 9 10 * * * * 11 ## ## ## ## 12 13 * * * * 14 ## ## ## ## ## 15 16 N E 17 ###################### 3 4 5 K 6 K 7 K 8 K K 9 K KKKKKKKKKKKKKKKKKKKK 10 K K 11 K K 12 K K 13 K K 14 K K 15 N E K EEEEEEEEEEEEEEEEEEEEEEEEE 16 ########################################################################################## -
2011/24/LauriK/Call of garden Modern carrotfare 2/Call of garden Modern carrotfare 2Content/Call of garden Modern carrotfare 2Content.contentproj
r2002 r2032 70 70 </Compile> 71 71 </ItemGroup> 72 <ItemGroup> 73 <Compile Include="Tomaattikuolleena.png"> 74 <Name>Tomaattikuolleena</Name> 75 <Importer>TextureImporter</Importer> 76 <Processor>TextureProcessor</Processor> 77 </Compile> 78 </ItemGroup> 79 <ItemGroup> 80 <Compile Include="Lipas2.png"> 81 <Name>Lipas2</Name> 82 <Importer>TextureImporter</Importer> 83 <Processor>TextureProcessor</Processor> 84 </Compile> 85 </ItemGroup> 86 <ItemGroup> 87 <Compile Include="rajahdys.png"> 88 <Name>rajahdys</Name> 89 <Importer>TextureImporter</Importer> 90 <Processor>TextureProcessor</Processor> 91 </Compile> 92 </ItemGroup> 72 93 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 73 94 <!-- 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.