- Timestamp:
- 2011-06-15 14:59:46 (10 years ago)
- Location:
- 2011/24/LeeviK/Pong/Pong
- Files:
-
- 13 added
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/24/LeeviK/Pong/Pong/Pong/Peli.cs
r1993 r2025 9 9 using Jypeli.Widgets; 10 10 11 12 class Natsi : PhysicsObject 13 { 14 public int Elamat = 3; 15 16 public Natsi(double leveys, double korkeus) 17 : base(leveys, korkeus) 18 { 19 } 20 } 21 22 11 23 public class Peli : PhysicsGame 12 24 { 13 25 Vector nopeusYlos = new Vector(0, 200); 14 26 Vector nopeusAlas = new Vector(0, -200); 15 27 List<Label> valikonKohdat; 28 29 GameObject crosshair; 16 30 PhysicsObject pelaaja; 17 31 AssaultRifle pelaajanAse; … … 21 35 Animation animaatio1; 22 36 Animation animaatio2; 37 SoundEffect aseAani = LoadSoundEffect("ThompsonFire1"); 38 ExplosionSystem explosionSystem2; 39 ExplosionSystem explosionSystem; 40 SoundEffect osumisAani = LoadSoundEffect("den_damage_32"); 41 Image crosshairkuva = LoadImage("crosshair kuva"); 42 Image jenkkiveri = LoadImage("jenkkiveri"); 23 43 24 44 public override void Begin() 25 45 { 26 LuoKentta();27 AsetaOhjaimet();28 ammoNaytto = LuoNaytto(Screen.Left + 60, Screen.Top - 60, pelaajanAse.Ammo);29 AloitaPeli(); 30 Mouse.IsCursorVisible = true; 31 Mouse.ListenMovement(0.1, KuunteleLiiketta, null);32 Image[] pelaajankuvat = LoadImages("jenkki lataus1", "jenkki lataus2", "jenkki lataus3", "jenkki lataus4", "jenkki lataus3", "jenkki lataus2", "jenkki lataus1", "jenkki lataus5", "jenkki lataus6", "jenkki lataus5");33 Image[] pelaajankuvat2 = LoadImages("jenkki2"); 34 animaatio1 = new Animation(pelaajankuvat);35 animaatio2 = new Animation(pelaajankuvat2); 36 pelaaja.Animation = animaatio1;37 pelaaja.Animation.FPS = 10;38 PhysicsObject natsi = new PhysicsObject(40, 40);46 Valikko(); 47 48 49 50 51 52 } 53 54 55 56 void LuoNatsi(double x, double y) 57 { 58 Natsi natsi = new Natsi(40, 40); 39 59 natsi.Shape = Shape.Circle; 40 Add(natsi); 60 natsi.Position = new Vector(x, y); 61 41 62 Image natsinKuva = LoadImage("NATSI"); 42 63 natsi.Image = natsinKuva; 43 64 natsi.Width = 155; 44 65 natsi.Height = 120; 66 45 67 FollowerBrain natsinAivot = new FollowerBrain(); 46 68 natsinAivot.Target = pelaaja; 47 natsinAivot.TargetFollowDistance = 1 00;48 natsinAivot.Speed = 300;69 natsinAivot.TargetFollowDistance = 1; 70 natsinAivot.Speed = 160; 49 71 natsinAivot.TargetClose += mitaTapahtuuKunOllaanLahella; 50 72 natsinAivot.FollowAlways = true; 51 52 53 54 Keyboard.Listen(Key.A, ButtonState.Down, LiikutaPelaajaa, "Liikuta pelaajaa vasemmalle", new Vector(-1000, 0)); 55 Keyboard.Listen(Key.D, ButtonState.Down, LiikutaPelaajaa, null, new Vector(1000, 0)); 56 Keyboard.Listen(Key.W, ButtonState.Down, LiikutaPelaajaa, null, new Vector(0, 1000)); 57 Keyboard.Listen(Key.S, ButtonState.Down, LiikutaPelaajaa, null, new Vector(0, -1000)); 58 Mouse.Listen(MouseButton.Left, ButtonState.Down, AmmuAseella, "Ammu", pelaaja, pelaajanAse); 59 Keyboard.Listen(Key.D1, ButtonState.Down, VaihdaAse, "VaihdaAse", pelaaja, pelaajanAse1); 60 Keyboard.Listen(Key.D2, ButtonState.Down, VaihdaAse, "VaihdaAse", pelaaja, pelaajanAse2); 73 natsinAivot.Active = true; 74 natsi.Brain = natsinAivot; 75 Add(natsi); 76 natsi.Angle = pelaaja.Angle; 77 Timer ajastin = new Timer(); 78 ajastin.Interval = 1.5; 79 ajastin.Trigger += KäännyPelaajaan; 80 ajastin.Start(); 81 ajastin.Tag = natsi; 61 82 } 62 83 … … 68 89 void LuoKentta() 69 90 { 91 92 crosshair = new GameObject(30.0, 30.0, Shape.Circle); 93 crosshair.Image = crosshairkuva; 94 Add(crosshair); 70 95 pelaaja = new PhysicsObject(200.0, 200.0); 71 96 pelaaja.Shape = Shape.Circle; … … 77 102 pelaaja.KineticFriction = 0.0; 78 103 Add(pelaaja); 104 explosionSystem2 = new ExplosionSystem(LoadImage("jenkkiveri"), 100); 79 105 pelaaja.Image = LoadImage("jenkki"); 80 106 pelaajanAse1 = new AssaultRifle(20, 0); 81 107 pelaajanAse = pelaajanAse1; 82 108 pelaaja.Add(pelaajanAse); 109 pelaajanAse.AttackSound = aseAani; 110 AddCollisionHandler(pelaaja, KasittelePelaajanTormays); 83 111 pelaajanAse.Ammo.Value = 30; 84 112 pelaajanAse.Ammo.MinValue = 0; … … 93 121 pelaajanAse2.ProjectileCollision = AmmusOsui; 94 122 95 96 Level.BackgroundColor = Color.Green; 97 Level.CreateBorders(); 123 MediaPlayer.Play("mus_17a_mystery"); 124 125 Level.BackgroundColor = Color.DarkGreen; 126 //Level.CreateBorders(); 98 127 Camera.Follow(pelaaja); 128 Add(explosionSystem); 129 explosionSystem.MinScale = 10; 130 explosionSystem.MaxScale = 50; 131 explosionSystem.MinLifetime = 0.1; 132 explosionSystem.MaxLifetime = 1; 133 Add(explosionSystem2); 134 explosionSystem2.MinScale = 10; 135 explosionSystem2.MaxScale = 50; 136 explosionSystem2.MinLifetime = 0.1; 137 explosionSystem2.MaxLifetime = 1; 138 99 139 } 100 140 … … 127 167 128 168 129 void AloitaPeli()130 {131 132 }133 134 169 void AsetaOhjaimet() 135 170 { 136 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 137 //Keyboard.Listen(Key.Left, ButtonState.Down, 171 Keyboard.Listen(Key.A, ButtonState.Down, LiikutaPelaajaa, "Liikuta pelaajaa vasemmalle", new Vector(-1000, 0)); 172 Keyboard.Listen(Key.D, ButtonState.Down, LiikutaPelaajaa, null, new Vector(1000, 0)); 173 Keyboard.Listen(Key.W, ButtonState.Down, LiikutaPelaajaa, null, new Vector(0, 1000)); 174 Keyboard.Listen(Key.S, ButtonState.Down, LiikutaPelaajaa, null, new Vector(0, -1000)); 175 Mouse.Listen(MouseButton.Left, ButtonState.Down, AmmuAseella, "Ammu", pelaaja, pelaajanAse); 176 Keyboard.Listen(Key.D1, ButtonState.Down, VaihdaAse, "VaihdaAse", pelaaja, pelaajanAse1); 177 Keyboard.Listen(Key.D2, ButtonState.Down, VaihdaAse, "VaihdaAse", pelaaja, pelaajanAse2); 178 138 179 } 139 180 … … 146 187 pelaaja.Angle = suunta.Angle + Angle.FromDegrees(180); 147 188 189 crosshair.X = Mouse.PositionOnWorld.X; 190 crosshair.Y = Mouse.PositionOnWorld.Y; 148 191 } 149 192 … … 162 205 { 163 206 ammus.Destroy(); 164 Explosion rajahdys = new Explosion(10 );207 Explosion rajahdys = new Explosion(100); 165 208 rajahdys.Position = ammus.Position; 209 rajahdys.Force = 90; 210 rajahdys.ShockwaveColor = Color.Red; 211 rajahdys.Sound = osumisAani; 166 212 Add(rajahdys); 167 } 213 214 if (kohde is Natsi) 215 { 216 Natsi natsi = (Natsi)kohde; 217 natsi.Elamat--; 218 if (natsi.Elamat < 1) 219 { 220 explosionSystem.AddEffect(natsi.Position, 100); 221 natsi.Destroy(); 222 } 223 } 224 } 225 168 226 void mitaTapahtuuKunOllaanLahella(object lahettajaAivot, EventArgs e) 169 227 { … … 174 232 pelaajanAse = (AssaultRifle)ase; 175 233 } 234 235 void KasittelePelaajanTormays(PhysicsObject pelaaja, PhysicsObject kohde) 236 { 237 pelaaja.Destroy(); 238 explosionSystem.AddEffect(pelaaja.Position, 100); 239 pelaaja.Destroy(); 240 241 242 243 244 } 245 void Valikko() 246 { 247 ClearAll(); 248 valikonKohdat = new List<Label>(); 249 250 Label kohta1 = new Label("Start zombie game"); 251 kohta1.Position = new Vector(0, 40); 252 valikonKohdat.Add(kohta1); 253 254 Label kohta2 = new Label("Exit Game"); 255 kohta2.Position = new Vector(0, -40); 256 valikonKohdat.Add(kohta2); 257 258 foreach (Label valikonKohta in valikonKohdat) 259 { 260 Add(valikonKohta); 261 } 262 263 Mouse.ListenOn(kohta1, MouseButton.Left, ButtonState.Pressed, AloitaPeli, null); 264 Mouse.ListenOn(kohta2, MouseButton.Left, ButtonState.Pressed, Poistu, null); 265 266 Mouse.IsCursorVisible = true; 267 Mouse.ListenMovement(1.0, ValikossaLiikkuminen, null); 268 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Poistu, ""); 269 } 270 void ValikossaLiikkuminen(AnalogState hiirenTila) 271 { 272 foreach (Label kohta in valikonKohdat) 273 { 274 if (Mouse.IsCursorOn(kohta)) 275 { 276 kohta.TextColor = Color.Gray; 277 } 278 else 279 { 280 kohta.TextColor = Color.Black; 281 } 282 283 } 284 } 285 void AloitaPeli() 286 { 287 ClearAll(); 288 explosionSystem = new ExplosionSystem(LoadImage("natsiveri"), 100); 289 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Valikko, "Palaa valikkoon"); 290 LuoKentta(); 291 AsetaOhjaimet(); 292 ammoNaytto = LuoNaytto(Screen.Left + 60, Screen.Top - 60, pelaajanAse.Ammo); 293 // AloitaPeli(); 294 Mouse.IsCursorVisible = true; 295 Mouse.ListenMovement(0.1, KuunteleLiiketta, null); 296 Image[] pelaajankuvat = LoadImages("jenkki lataus1", "jenkki lataus2", "jenkki lataus3", "jenkki lataus4", "jenkki lataus3", "jenkki lataus2", "jenkki lataus1", "jenkki lataus5", "jenkki lataus6", "jenkki lataus5"); 297 Image[] pelaajankuvat2 = LoadImages("jenkki2"); 298 animaatio1 = new Animation(pelaajankuvat); 299 animaatio2 = new Animation(pelaajankuvat2); 300 pelaaja.Animation = animaatio1; 301 pelaaja.Animation.FPS = 10; 302 303 for (int i = 0; i <5; i++) 304 { 305 LuoNatsi(RandomGen.NextDouble(Level.Left, Level.Right), RandomGen.NextDouble(Level.Bottom, Level.Top)); 306 } 307 308 } 309 310 void Poistu() 311 { 312 Exit(); 313 } 314 void KäännyPelaajaan( Timer sender ) 315 { 316 Natsi natsi = (Natsi)sender.Tag; 317 Vector suunta = (pelaaja.Position - natsi.Position).Normalize(); 318 natsi.Angle = suunta.Angle; 319 } 320 321 322 323 324 325 326 176 327 } -
2011/24/LeeviK/Pong/Pong/PongContent/PongContent.contentproj
r1993 r2025 57 57 </ItemGroup> 58 58 <ItemGroup> 59 <Compile Include="crosshair .png">60 <Name>crosshair </Name>59 <Compile Include="crosshair kuva.png"> 60 <Name>crosshair kuva</Name> 61 61 <Importer>TextureImporter</Importer> 62 62 <Processor>TextureProcessor</Processor> … … 107 107 <Importer>TextureImporter</Importer> 108 108 <Processor>TextureProcessor</Processor> 109 </Compile> 110 </ItemGroup> 111 <ItemGroup> 112 <Compile Include="mus_17a_mystery.mp3"> 113 <Name>mus_17a_mystery</Name> 114 <Importer>Mp3Importer</Importer> 115 <Processor>SongProcessor</Processor> 116 </Compile> 117 </ItemGroup> 118 <ItemGroup> 119 <Compile Include="Amb_M4_CountryExt_02.mp3"> 120 <Name>Amb_M4_CountryExt_02</Name> 121 <Importer>Mp3Importer</Importer> 122 <Processor>SongProcessor</Processor> 123 </Compile> 124 </ItemGroup> 125 <ItemGroup> 126 <Compile Include="natsiveri.png"> 127 <Name>natsiveri</Name> 128 <Importer>TextureImporter</Importer> 129 <Processor>TextureProcessor</Processor> 130 </Compile> 131 </ItemGroup> 132 <ItemGroup> 133 <Compile Include="den_damage_32.wav"> 134 <Name>den_damage_32</Name> 135 <Importer>WavImporter</Importer> 136 <Processor>SoundEffectProcessor</Processor> 137 </Compile> 138 </ItemGroup> 139 <ItemGroup> 140 <Compile Include="ThompsonFire1.wav"> 141 <Name>ThompsonFire1</Name> 142 <Importer>WavImporter</Importer> 143 <Processor>SoundEffectProcessor</Processor> 144 </Compile> 145 </ItemGroup> 146 <ItemGroup> 147 <Compile Include="wave.wav"> 148 <Name>wave</Name> 149 <Importer>WavImporter</Importer> 150 <Processor>SoundEffectProcessor</Processor> 151 </Compile> 152 </ItemGroup> 153 <ItemGroup> 154 <Compile Include="MG42Burst_01.wav"> 155 <Name>MG42Burst_01</Name> 156 <Importer>WavImporter</Importer> 157 <Processor>SoundEffectProcessor</Processor> 158 </Compile> 159 </ItemGroup> 160 <ItemGroup> 161 <Compile Include="MG42Burst_03.wav"> 162 <Name>MG42Burst_03</Name> 163 <Importer>WavImporter</Importer> 164 <Processor>SoundEffectProcessor</Processor> 165 </Compile> 166 </ItemGroup> 167 <ItemGroup> 168 <Compile Include="MG42Burst_02.wav"> 169 <Name>MG42Burst_02</Name> 170 <Importer>WavImporter</Importer> 171 <Processor>SoundEffectProcessor</Processor> 172 </Compile> 173 </ItemGroup> 174 <ItemGroup> 175 <Compile Include="MG42Fire5.wav"> 176 <Name>MG42Fire5</Name> 177 <Importer>WavImporter</Importer> 178 <Processor>SoundEffectProcessor</Processor> 179 </Compile> 180 </ItemGroup> 181 <ItemGroup> 182 <Compile Include="jenkkiveri.png"> 183 <Name>jenkkiveri</Name> 184 <Importer>TextureImporter</Importer> 185 <Processor>TextureProcessor</Processor> 186 </Compile> 187 </ItemGroup> 188 <ItemGroup> 189 <Compile Include="SpringfieldFire1.WAV"> 190 <Name>SpringfieldFire1</Name> 191 <Importer>WavImporter</Importer> 192 <Processor>SoundEffectProcessor</Processor> 109 193 </Compile> 110 194 </ItemGroup>
Note: See TracChangeset
for help on using the changeset viewer.