Changeset 2531
- Timestamp:
- 2011-08-03 14:55:53 (12 years ago)
- Location:
- 2011/31/JereK/Serades/Serades
- Files:
-
- 9 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/31/JereK/Serades/Serades/Serades/Peli.cs
r2498 r2531 14 14 new Vector(-450,-350)}; 15 15 Image olionkuva = LoadImage("alus"); 16 Image karttakuva = LoadImage("kartta"); 16 17 Image vihokuva = LoadImage("vihollinen"); 17 18 PhysicsObject alus; 19 LaserGun pyssy; 18 Image taustakuva = LoadImage("taustakuva"); 19 Image oliokuva = LoadImage("alus2"); 20 Image pomonkuva = LoadImage("boss"); 21 PhysicsObject pelaaja1; 22 PhysicsObject pelaaja2; 23 LaserGun pelaaja1Pyssy; 24 LaserGun pelaaja2Pyssy; 25 List<Label> valikonKohdat; 26 27 28 List<PhysicsObject> viholliset = new List<PhysicsObject>(); 29 30 int taso = 1; 31 20 32 PhysicsObject beam = new PhysicsObject(new RaySegment(Vector.Zero, Vector.UnitX, 10)); 21 33 22 34 23 35 public override void Begin() 24 25 { 36 { 37 Valikko(); 38 } 39 40 void Valikko() 41 { 42 ClearAll(); 43 Camera.ZoomToLevel(); 44 Level.Background.Image = taustakuva; 45 Level.Background.FitToLevel(); 46 valikonKohdat = new List<Label>(); 47 48 Label kohta1 = new Label("Aloita peli yhdellä pelaajalla."); 49 kohta1.Position = new Vector(0, 40); 50 valikonKohdat.Add(kohta1); 51 52 Label kohta2 = new Label("Aloita peli kahdella pelaajalla."); 53 kohta2.Position = new Vector(0, 0); 54 valikonKohdat.Add(kohta2); 55 56 Label kohta3 = new Label("Lopeta ja poistu pelistä."); 57 kohta3.Position = new Vector(0, -40); 58 valikonKohdat.Add(kohta3); 59 60 foreach (Label valikonKohta in valikonKohdat) 61 { 62 Add(valikonKohta); 63 } 64 65 Mouse.ListenOn(kohta1, MouseButton.Left, ButtonState.Pressed, AloitaPeli, null); 66 Mouse.ListenOn(kohta2, MouseButton.Left, ButtonState.Pressed, AloitaKaksinpeli, null); 67 Mouse.ListenOn(kohta3, MouseButton.Left, ButtonState.Pressed, Exit, null); 68 69 Mouse.IsCursorVisible = true; 70 Mouse.ListenMovement(1.0, ValikossaLiikkuminen, null); 71 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, ""); 72 } 73 74 void ValikossaLiikkuminen(AnalogState a) 75 { 76 foreach (Label kohta in valikonKohdat) 77 { 78 if (Mouse.IsCursorOn(kohta)) 79 { 80 kohta.TextColor = Color.White; 81 } 82 else 83 { 84 kohta.TextColor = Color.OrangeRed; 85 } 86 87 } 88 89 } 90 91 92 93 void LuoAlus() 94 { 95 pelaaja1 = new PhysicsObject(30, 30); 96 Add(pelaaja1); 97 pelaaja1.LinearDamping = 0.96; 98 pelaaja1.Image = olionkuva; 99 pelaaja1Pyssy = new LaserGun(20, 5); 100 pelaaja1Pyssy.ProjectileCollision = LaserSadeOsuu; 101 pelaaja1Pyssy.InfiniteAmmo = true; 102 pelaaja1.Add(pelaaja1Pyssy); 103 pelaaja1.IgnoresExplosions = true; 104 pelaaja1Pyssy.Angle = pelaaja1Pyssy.Angle + Angle.FromDegrees(90); 105 beam.Color = Color.Blue; 106 } 107 108 void AsetaPelaaja2() 109 { 110 pelaaja2 = new PhysicsObject(30, 30); 111 Add(pelaaja2); 112 pelaaja2.LinearDamping = 0.96; 113 pelaaja2.Image = oliokuva; 114 pelaaja2Pyssy = new LaserGun(20, 5); 115 pelaaja2Pyssy.ProjectileCollision = LaserSadeOsuu; 116 pelaaja2Pyssy.InfiniteAmmo = true; 117 pelaaja2.IgnoresExplosions = true; 118 pelaaja2.Add(pelaaja2Pyssy); 119 pelaaja2Pyssy.Angle = pelaaja2Pyssy.Angle + Angle.FromDegrees(90); 120 beam.Color = Color.Blue; 121 pelaaja2.X = 30; 122 } 123 124 void SeuraavaTaso() 125 { 126 taso++; 127 128 if (taso < 2) 129 { 130 MessageDisplay.Add("Seuraava aalto alkaa!!"); 131 Timer.SingleShot(3, AloitaAalto); 132 } 133 else 134 { 135 MessageDisplay.Add("VAROKAA POMOA"); 136 Timer.SingleShot(3, AloitaPomotaistelu); 137 } 138 } 139 140 void AloitaPomotaistelu() 141 { 142 PhysicsObject Pomo = new PhysicsObject(200, 100); 143 Pomo.Image = pomonkuva; 144 Add(Pomo); 145 Pomo.X = 450; 146 Pomo.Y = 350; 147 148 PlasmaCannon plasmaTykki = new PlasmaCannon(20, 5); 149 Pomo.Add(plasmaTykki); 150 plasmaTykki.PlasmaParticleCollision = PlasmaPalloOsuu; 151 152 153 } 154 155 void AloitaAalto() 156 { 157 Timer ajastin = new Timer(); 158 ajastin.Interval = 3.0 - (taso / 10.0); 159 ajastin.Timeout += LuoVihollinen; 160 161 ajastin.Start(2); 162 } 163 164 void Aloitakaksin() 165 { 166 Timer ajastin = new Timer(); 167 ajastin.Interval = 1.0 - (taso / 10.0); 168 ajastin.Timeout += LuoVihollinen; 169 ajastin.Start(30); 170 } 171 172 void AsetaOhjaimet() 173 { 174 Keyboard.Listen(Key.Left, ButtonState.Down, 175 Kaanna, null, 10.0, pelaaja1); 176 Keyboard.Listen(Key.Right, ButtonState.Down, 177 Kaanna, null, -10.0, pelaaja1); 178 Keyboard.Listen(Key.Up, ButtonState.Down, 179 Kaasu, null, pelaaja1); 180 Keyboard.Listen(Key.Down, ButtonState.Down, 181 Kaasu, null, pelaaja1); 182 Keyboard.Listen(Key.RightControl, ButtonState.Pressed, Ammu, null, pelaaja1Pyssy); 183 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Valikko, ""); 184 } 185 186 void AsetaKakkosohjaimet() 187 { 188 Keyboard.Listen(Key.A, ButtonState.Down, 189 Kaanna, null, 10.0, pelaaja2); 190 Keyboard.Listen(Key.D, ButtonState.Down, 191 Kaanna, null, -10.0, pelaaja2); 192 Keyboard.Listen(Key.W, ButtonState.Down, 193 Kaasu, null, pelaaja2); 194 Keyboard.Listen(Key.S, ButtonState.Down, 195 Kaasu, null, pelaaja2); 196 Keyboard.Listen(Key.LeftControl, ButtonState.Pressed, Ammu, null, pelaaja2Pyssy); 197 } 198 199 void Ammu(Weapon pyssy) 200 { 201 PhysicsObject ammus = pyssy.Shoot(); 202 if (ammus != null) AddCollisionHandler(ammus, LaserSadeOsuu); 203 } 204 205 206 void Kaasu(PhysicsObject alus) 207 { 208 alus.Push(Vector.FromLengthAndAngle(400, alus.Angle + Angle.FromDegrees(90))); 209 } 210 211 void Kaanna(double nopeus, PhysicsObject alus) 212 { 213 alus.AngularAcceleration = nopeus; 214 } 215 216 void LuoVihollinen() 217 { 218 for (int i = 0; i < 4; i++) 219 { 220 PhysicsObject vihollinen = new PhysicsObject(40, 40); 221 vihollinen.X = 450; 222 vihollinen.Y = 350; 223 vihollinen.Position = vihollistenAloitukset[i]; 224 vihollinen.Image = vihokuva; 225 //AddCollisionHandler(vihollinen, LaserSadeOsuu); 226 vihollinen.Tag = "vihollinen"; 227 228 FollowerBrain seuraajanAivot = new FollowerBrain(); 229 seuraajanAivot.Target = pelaaja1; 230 seuraajanAivot.Speed = 50; 231 seuraajanAivot.TargetFollowDistance = 600; 232 seuraajanAivot.FollowAlways = true; 233 seuraajanAivot.TargetCloseDistance = 1; 234 seuraajanAivot.StopWhenTargetClose = false; 235 seuraajanAivot.TargetClose += mitaTapahtuuKunOllaanLahella; 236 vihollinen.Brain = seuraajanAivot; 237 seuraajanAivot.Active = true; 238 Add(vihollinen); 239 240 viholliset.Add(vihollinen); 241 } 242 } 243 244 void mitaTapahtuuKunOllaanLahella(object lahettajaAivot, EventArgs e) 245 { 246 //TODO 247 } 248 249 void LaserSadeOsuu(PhysicsObject ammus, PhysicsObject kohde) 250 { 251 ammus.Destroy(); 252 Explosion rajahdys = new Explosion(50); 253 rajahdys.Position = ammus.Position; 254 Add(rajahdys); 255 256 if (kohde.Tag.ToString() == "vihollinen") 257 { 258 kohde.Destroy(); 259 if (viholliset.Contains(kohde)) { 260 viholliset.Remove(kohde); 261 if (viholliset.Count == 0) { SeuraavaTaso(); } 262 } 263 } 264 } 265 266 void PlasmaPalloOsuu(PhysicsObject pallo, PhysicsObject kohde) 267 { 268 if (kohde.Tag.ToString() == "pelaaja") 269 { 270 kohde.Destroy(); 271 } 272 } 273 274 void AloitaPeli() 275 { 276 ClearAll(); 277 MessageDisplay.TextColor = Color.OrangeRed; 278 26 279 LuoAlus(); 27 280 Level.CreateBorders(); 28 281 Camera.ZoomToLevel(); 29 Level.Background.CreateStars( 5000);282 Level.Background.CreateStars(2000); 30 283 AsetaOhjaimet(); 31 MessageDisplay.Add("haa");32 MessageDisplay.TextColor = Color.White; 284 // MessageDisplay.Add("Test"); 285 33 286 MessageDisplay.MessageTime = new TimeSpan(0, 0, 10); 34 287 //tekstikentta.X = Screen.Left + 100; 35 288 //tekstikentta.Y = Screen.Top - 100; 36 289 AloitaAalto(); 37 beam.Color = Color.Green; 38 } 39 40 void LuoAlus() 41 { 42 alus = new PhysicsObject(30, 30); 43 Add(alus); 44 alus.LinearDamping = 0.96; 45 alus.Image = olionkuva; 46 pyssy = new LaserGun(20, 5); 47 pyssy.LaserCollision = LaserSadeOsuu; 48 pyssy.ProjectileCollision = LaserSadeOsuu; 49 alus.Add(pyssy); 50 pyssy.Angle = pyssy.Angle + Angle.FromDegrees(90); 51 } 52 53 54 55 void AloitaAalto() 56 { 57 Timer ajastin = new Timer(); 58 ajastin.Interval = 5.0; 59 ajastin.Timeout += LuoVihollinen; 60 ajastin.Start(3); 61 } 62 63 void AsetaOhjaimet() 64 { 65 Keyboard.Listen(Key.Left, ButtonState.Down, 66 Kaanna, null, 10.0); 67 Keyboard.Listen(Key.Right, ButtonState.Down, 68 Kaanna, null, -10.0); 69 Keyboard.Listen(Key.Up, ButtonState.Down, 70 Kaasu, null); 71 Keyboard.Listen(Key.Down, ButtonState.Down, 72 Kaasu, null); 73 Keyboard.Listen(Key.LeftControl, ButtonState.Pressed,Ammu, null); 74 } 75 76 void Ammu() 77 { 78 pyssy.Shoot(); 79 beam.Color = Color.Blue; 80 } 81 82 83 void Kaasu() 84 { 85 alus.Push(Vector.FromLengthAndAngle(400,alus.Angle + Angle.FromDegrees(90))); 86 } 87 88 void Kaanna(double nopeus) 89 { 90 alus.AngularAcceleration = nopeus; 91 } 92 93 void LuoVihollinen() 94 { 95 for (int i = 0; i < 4; i++) 96 { 97 PhysicsObject vihollinen = new PhysicsObject(40, 40); 98 vihollinen.X = 450; 99 vihollinen.Y = 350; 100 vihollinen.Position = vihollistenAloitukset[i]; 101 vihollinen.Image = vihokuva; 102 AddCollisionHandler(vihollinen, LaserSadeOsuu); 103 104 105 FollowerBrain seuraajanAivot = new FollowerBrain(); 106 seuraajanAivot.Target = alus; 107 seuraajanAivot.Speed = 20; 108 seuraajanAivot.TargetFollowDistance = 600; 109 seuraajanAivot.FollowAlways = true; 110 seuraajanAivot.TargetCloseDistance = 1; 111 seuraajanAivot.StopWhenTargetClose = false; 112 seuraajanAivot.TargetClose += mitaTapahtuuKunOllaanLahella; 113 vihollinen.Brain = seuraajanAivot; 114 seuraajanAivot.Active = true; 115 Add(vihollinen); 116 117 118 119 } 120 } 121 122 void mitaTapahtuuKunOllaanLahella(object lahettajaAivot, EventArgs e) 123 { 124 //TODO 125 } 126 127 void LaserSadeOsuu(PhysicsObject ammus, PhysicsObject kohde) 128 { 129 ammus.Destroy(); 130 Explosion rajahdys = new Explosion(10); 131 rajahdys.Position = ammus.Position; 132 Add(rajahdys); 133 } 134 290 beam.Color = Color.Red; 291 292 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Valikko, "Palaa valikkoon"); 293 } 294 295 void AloitaKaksinpeli() 296 { 297 ClearAll(); 298 MessageDisplay.TextColor = Color.OrangeRed; 299 LuoAlus(); 300 AsetaPelaaja2(); 301 AsetaOhjaimet(); 302 AsetaKakkosohjaimet(); 303 Level.CreateBorders(); 304 Camera.ZoomToLevel(); 305 Level.Background.Image = taustakuva; 306 Level.Background.CreateStars(2000); 307 Aloitakaksin(); 308 } 135 309 } 136 137 138 139 140 -
2011/31/JereK/Serades/Serades/Serades/Serades.csproj
r2498 r2531 117 117 <ItemGroup> 118 118 <Content Include="alus.png" /> 119 <Content Include="alus2.png" /> 120 <Content Include="boss.png" /> 119 121 <Content Include="Game.ico" /> 120 122 <Content Include="GameThumbnail.png" /> 123 <Content Include="kartta.png" /> 124 <Content Include="taustakuva.png" /> 121 125 <Content Include="vihollinen.png" /> 122 126 </ItemGroup> -
2011/31/JereK/Serades/Serades/SeradesContent/SeradesContent.contentproj
r2498 r2531 51 51 </Compile> 52 52 </ItemGroup> 53 <ItemGroup> 54 <Compile Include="vihollinen.png"> 55 <Name>vihollinen</Name> 56 <Importer>TextureImporter</Importer> 57 <Processor>TextureProcessor</Processor> 58 </Compile> 59 </ItemGroup> 60 <ItemGroup> 61 <Compile Include="kartta.png"> 62 <Name>kartta</Name> 63 <Importer>TextureImporter</Importer> 64 <Processor>TextureProcessor</Processor> 65 </Compile> 66 </ItemGroup> 67 <ItemGroup> 68 <Compile Include="taustakuva.png"> 69 <Name>taustakuva</Name> 70 <Importer>TextureImporter</Importer> 71 <Processor>TextureProcessor</Processor> 72 </Compile> 73 </ItemGroup> 74 <ItemGroup> 75 <Compile Include="alus2.png"> 76 <Name>alus2</Name> 77 <Importer>TextureImporter</Importer> 78 <Processor>TextureProcessor</Processor> 79 </Compile> 80 </ItemGroup> 81 <ItemGroup> 82 <Compile Include="boss.png"> 83 <Name>boss</Name> 84 <Importer>TextureImporter</Importer> 85 <Processor>TextureProcessor</Processor> 86 </Compile> 87 </ItemGroup> 53 88 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 54 89 <!-- 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.