Changeset 1017
- Timestamp:
- 2010-06-19 23:25:08 (13 years ago)
- Location:
- 2010/23/hniemi/ShootEmUp
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/23/hniemi/ShootEmUp/ShootEmUp/Alus.cs
r1012 r1017 33 33 /// </summary> 34 34 public IntMeter HpMeter {get { return hp; }} 35 35 36 public LisaData Data 37 { 38 get { return (LisaData)this.Tag; } 39 set { this.Tag = value; } 40 } 41 36 42 /// <summary> 37 43 /// Luo aluksen … … 49 55 this.hp = new IntMeter(hp); 50 56 this.AddedToGame += LoadWeapon; 57 58 LisaData ase = new LisaData(); ; 59 ase.Damage = 1; 60 ase.Rajahtaa = false; 61 ase.Tyyppi = "oma"; 62 this.Tag = ase; 51 63 } 52 64 53 65 private void LoadWeapon() 54 66 { 55 56 67 this.SetWeapon(new Beam(5, 35, Game.LoadImage("sade") )); 57 68 } … … 91 102 public void Shoot(Timer sender) 92 103 { 93 //this.Position = new Vector(0, 0);94 //Game.Add(this.Shoot());95 104 this.Shoot(); 96 105 } -
2010/23/hniemi/ShootEmUp/ShootEmUp/Muodostelma.cs
r1007 r1017 45 45 if (alukset != null){this.alukset = alukset;} 46 46 else { this.alukset = new List<Alus>(); } 47 if (reitti != null && reitti.Count > 0) lahtopiste = new Vector(0, + 900);//reitti[0];47 if (reitti != null && reitti.Count > 0) lahtopiste = new Vector(0, +500); 48 48 49 49 this.kellottaja = ajastin; … … 57 57 aivot.Path = reitti; 58 58 aivot.Speed = movingSpeed; 59 //((PathFollowerBrain)alus.Brain).Add(reitti.ToArray());60 //((PathFollowerBrain)alus.Brain).MovingSpeed = movingSpeed;61 59 alus.Position = lahtopiste; 62 60 } -
2010/23/hniemi/ShootEmUp/ShootEmUp/Peli.cs
r1012 r1017 5 5 using System.Collections.Generic; 6 6 7 8 7 namespace ShootEmUp 9 8 { 9 /// <summary> 10 /// ShootEmUp-peli 11 /// 12 /// Pelin ideana on ampua viholisia niin kauan kuin niitä tulee. 13 /// </summary> 10 14 public class Peli : PhysicsGame 11 15 { 12 16 #region Julistukset 13 14 15 17 //Liikkumisnopeudet 16 18 private const double NOPEUS = 300; … … 21 23 //Kentän rakenne 22 24 private Alus pelaajaAlus; 23 private PhysicsObject vasenLaita; 24 private PhysicsObject oikeaLaita; 25 private PhysicsObject pohja; 26 private PhysicsObject katto; 25 private PhysicsObject[] seinat = new PhysicsObject[4]; 27 26 private PhysicsObject exitZone; 28 27 29 28 private GameObject[] tahdet; 30 29 31 //Viholliset 30 //Viholliset (vihollinen1.png, vihollinen2.png...) 32 31 private const int VIHOLLISKUVIA = 4; 33 32 … … 37 36 private IntMeter lives = new IntMeter(3); 38 37 private TextDisplay[] aseNimet; 39 private Weapon[] weapons; 40 41 private bool bossmode = true; 42 38 private ShmupWeapon[] weapons; 39 40 //Menu 41 private int valittu = 0; 42 private string[] menutekstit; 43 private Action[] menutapahtumat; 44 private TextDisplay[] menu; 45 private Color tekstinVari = Color.White; 46 private Color tekstiValittuVari = Color.Yellow; 47 48 /** 49 * Boss-Mode 50 * Loppuvastuksen testaamista varten. Hyppää normaalien vastusten yli 51 * suoraan loppuvastuksen takaisin. Tarkoituksena myös jossain 52 * vaiheessa olla yhtenä "pelityyppinä" 53 */ 54 private bool bossmode = false; 43 55 #endregion 44 56 … … 62 74 for (int i = 0; i < tahdet.Length; i++) 63 75 { 64 tahdet[i].Y -= 30;76 tahdet[i].Y -= 20; 65 77 if (tahdet[i].Y < Level.Bottom - 40) tahdet[i].Y = Level.Top + 100; 66 78 } 67 79 } 68 69 80 base.Update(time); 70 81 } … … 80 91 { 81 92 ClearAll(); 93 94 if (kentanNumero == 0) 95 { 96 NaytaMenu(); 97 return; 98 } 99 82 100 Level.Width = 600; 83 101 Level.Height = 800; 84 102 103 Level.BackgroundColor = Color.Black; 85 104 Camera.Move(new Vector(250, 0)); 86 //Camera.Zoom(0.2); 105 //Camera.Zoom(0.9); 106 107 LuoPelaaja(); 108 LataaHUD(); 109 LataaKontrollit(pelaajaAlus); 110 LataaSeinat(); 111 LataaTausta(kentanNumero); 112 LataaViholliset(20, 4,10); 87 113 88 //Laidat 114 } 115 116 /// <summary> 117 /// Luo näytölle valikon ja kontrollit sen käyttöön 118 /// </summary> 119 void NaytaMenu() 120 { 121 Level.BackgroundColor = Color.Black; 122 menu = new TextDisplay[2]; 123 menutapahtumat = new Action[2]; 124 menutapahtumat[1] = Exit; 125 menutapahtumat[0] = AloitaPeli; 126 menutekstit = new string[2]; 127 menutekstit[0] = "Start"; 128 menutekstit[1] = "Exit"; 129 130 for (int i = 0; i < menu.Length; i++) 131 { 132 menu[i] = new TextDisplay(); 133 menu[i].Text = menutekstit[i]; 134 menu[i].AutoSize = true; 135 menu[i].TextColor = tekstinVari; 136 137 138 menu[i].Position = new Vector(0, +100 - i*40); 139 Add(menu[i]); 140 } 141 menu[valittu].TextColor = tekstiValittuVari; 142 LataaMenukontrollit(); 143 } 144 145 /// <summary> 146 /// Kasvattaa kentän numeroa ja lataa seuraavan kentän 147 /// Tähän tulee myös muut toiminnot (pisteiden säilyttäminen yms); 148 /// </summary> 149 void SeuraavaKentta() 150 { 151 kentannro++; 152 LataaKentta(kentannro); 153 } 154 155 void AloitaPeli() 156 { 157 lives.Value = 3; 158 kentannro = 0; 159 SeuraavaKentta(); 160 } 161 162 /// <summary> 163 /// Lataa seinät ja kulmat, sekä ns "tappoalueen"; 164 /// Kulmille ei lisätä törmäystunnistusta 165 /// </summary> 166 void LataaSeinat() 167 { 168 //Laitojen tagi 89 169 LisaData tieto = new LisaData(); 90 170 tieto.Tyyppi = "seina"; 91 tieto.Rajahtaa = true;92 tieto.Damage = 5;93 171 94 172 PhysicsObject[] kulmat = new PhysicsObject[4]; 95 173 174 //Lisää samassa silmukassa kulmat ja seinät 96 175 for (int i = 0; i < kulmat.Length; i++) 97 176 { … … 101 180 kulmat[i].Angle = Angle.Degrees(i * 90); 102 181 Add(kulmat[i]); 103 } 104 kulmat[3].Position = new Vector(Level.Left - 30, Level.Top+30); 105 kulmat[2].Position = new Vector(Level.Right + 30, Level.Top + 30); 182 183 seinat[i] = PhysicsObject.CreateStaticObject(1, 1); 184 seinat[i].Tag = tieto; 185 seinat[i].Image = LoadImage("seina/seinaOikea"); 186 seinat[i].Angle = Angle.Degrees(90 * i); 187 seinat[i].Size = new Vector(Level.Height, 60); 188 Add(seinat[i]); 189 } 190 191 //Sijoittaa kulmat ja seinät. 106 192 kulmat[0].Position = new Vector(Level.Left - 30, Level.Bottom - 30); 107 193 kulmat[1].Position = new Vector(Level.Right + 30, Level.Bottom - 30); 108 109 110 //Seinät 111 Level.BackgroundColor = Color.Black; 112 113 vasenLaita = Level.CreateLeftBorder(); 114 vasenLaita.Image = LoadImage("seina/seinaOikea"); 115 vasenLaita.Angle = Angle.Degrees(270); 116 vasenLaita.Tag = tieto; 117 118 oikeaLaita = Level.CreateRightBorder(); 119 oikeaLaita.Image = LoadImage("seina/seinaOikea"); 120 oikeaLaita.Angle = Angle.Degrees(90); 121 oikeaLaita.Tag = tieto; 122 123 pohja = Level.CreateBottomBorder(); 124 pohja.Image = LoadImage("seina/seinaOikea"); 125 pohja.Angle = Angle.Degrees(0); 126 pohja.Size = new Vector(pohja.Width - 120, pohja.Height); 127 pohja.Tag = tieto; 128 129 katto = Level.CreateTopBorder(); 130 katto.Image = LoadImage("seina/seinaOikea"); 131 katto.Angle = Angle.Degrees(180); 132 katto.Size = new Vector(katto.Width - 120, katto.Height); 133 katto.Tag = tieto; 194 kulmat[2].Position = new Vector(Level.Right + 30, Level.Top + 30); 195 kulmat[3].Position = new Vector(Level.Left - 30, Level.Top + 30); 196 seinat[0].Y = Level.Bottom - (seinat[0].Height / 2); 197 seinat[1].X = Level.Right + (seinat[1].Height / 2); 198 seinat[2].Y = Level.Top + (seinat[2].Height / 2); 199 seinat[3].X = Level.Left - (seinat[3].Height / 2); 134 200 135 201 //Exit-alueen tekeminen. 136 202 exitZone = PhysicsObject.CreateStaticObject(Level.Width, 200); 137 exitZone. Position = new Vector(Level.Center.X, Level.Bottom - exitZone.Size.Y / 2 - 5);203 exitZone.Y = Level.Bottom - (exitZone.Height / 2); 138 204 exitZone.Tag = tieto; 139 205 exitZone.IsVisible = false; 140 206 Add(exitZone); 141 142 143 LuoPelaaja();144 LataaHUD();145 LataaKontrollit(pelaajaAlus);146 LataaTausta(kentanNumero);147 LataaViholliset(20, 4,10);148 149 207 } 150 208 … … 183 241 aseNimet[1].Text = "Missile"; 184 242 aseNimet[2].Text = "Photon"; 185 243 186 244 Timer purkkaAjastin = new Timer(); 187 245 purkkaAjastin.Interval = 0.01; … … 192 250 } 193 251 252 /// <summary> 253 /// Purkkakorjaus aseen vaihtamiseen. Vaihtaa aluksen asetta alussa, 254 /// jotta ampuminen toimii. 255 /// </summary> 256 /// <param name="sender"></param> 194 257 void Purkkakorjaus(Timer sender) 195 258 { 196 VaihdaAsetta( 1);259 VaihdaAsetta(OLETUSASE+1); 197 260 } 198 261 … … 208 271 GameObject tahti = new GameObject(3, 3); 209 272 tahti.Color = Color.White; 273 tahti.Shape = Shapes.Circle; 210 274 tahti.Position = new Vector(RandomGen.NextDouble(Level.Left, Level.Right), 211 275 RandomGen.NextDouble(Level.Top +20, Level.Top + 2000)); 212 276 tahdet[i] = tahti; 213 214 277 Add(tahti); 215 278 } … … 224 287 pelaajaAlus = new Alus(60, 55, 10); 225 288 pelaajaAlus.Shape = Shapes.Triangle; 226 227 289 pelaajaAlus.Animation = new Animation(LoadImages("sankarialus/sankarialusThrust1", "sankarialus/sankarialusThrust2")); 228 290 pelaajaAlus.Animation.Start(); 229 291 230 LisaData tieto = new LisaData(); 231 tieto.Tyyppi = "oma"; 232 tieto.Rajahtaa = true; 233 tieto.Damage = 5; 234 pelaajaAlus.Tag = tieto; 235 292 pelaajaAlus.Data.Rajahtaa = true; 293 pelaajaAlus.Data.Tyyppi = "oma"; 294 pelaajaAlus.Data.Damage = 5; 295 236 296 pelaajaAlus.Angle += Angle.Degrees(90); 237 297 238 298 pelaajaAlus.IgnoresCollisionResponse = false; 239 299 pelaajaAlus.Y = Level.Bottom + 40; 240 pelaajaAlus.KineticFriction = 1.0; 241 pelaajaAlus.Mass = 100000; 242 243 weapons = new Weapon[3]; 244 245 //LoadImage("sade"); 246 300 301 weapons = new ShmupWeapon[3]; 247 302 weapons[0] = new Beam(5, 35, LoadImage("sade")); 248 ((ShmupWeapon)weapons[0]).ProjectileCollision = AmmusOsuu;249 weapons[0].Position = new Vector(0, -40);250 303 weapons[1] = new Missile(15, 30, LoadImage("ohjus")); 251 ((ShmupWeapon)weapons[1]).ProjectileCollision = AmmusOsuu;252 253 304 weapons[2] = new Photon(15, 15, LoadImage("photon")); 254 ((ShmupWeapon)weapons[2]).ProjectileCollision = AmmusOsuu; 255 305 256 306 for (int i = 0; i < weapons.Length; i++) 257 307 { 308 weapons[i].ProjectileCollision = AmmusOsuu; 258 309 weapons[i].IsVisible = false; 310 weapons[i].Position = new Vector(0, -42); 259 311 pelaajaAlus.Add(weapons[i]); 260 312 } 261 313 262 314 Add(pelaajaAlus); 263 264 265 315 AddCollisionHandler(pelaajaAlus, PelaajaTormaa); 266 316 } … … 291 341 292 342 /// <summary> 343 /// Lataa menun kontrollit 344 /// </summary> 345 void LataaMenukontrollit() 346 { 347 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Sulkee pelin"); 348 Keyboard.Listen(Key.Up, ButtonState.Pressed, MenuMove, "Liikuttaa valintaa ylös", -1); 349 Keyboard.Listen(Key.Down, ButtonState.Pressed, MenuMove, "Liikuttaa valintaa alas", +1); 350 Keyboard.Listen(Key.Enter, ButtonState.Pressed, MenuSelect, "Valitse"); 351 } 352 353 /// <summary> 354 /// Liikuttaa menuvalintaa, ja tarkastaa ettei se mene yli menun 355 /// </summary> 356 /// <param name="askelmaara"></param> 357 void MenuMove(int askelmaara) 358 { 359 valittu += askelmaara; 360 if (valittu < 0) valittu = menutekstit.Length - 1; 361 if (valittu >= menutekstit.Length) valittu = 0; 362 for (int i = 0; i < menu.Length; i++) 363 { 364 menu[i].TextColor = tekstinVari; 365 } 366 367 menu[valittu].TextColor = tekstiValittuVari; 368 } 369 370 /// <summary> 371 /// Valitsee valitun toiminnon menusta 372 /// </summary> 373 void MenuSelect() 374 { 375 menutapahtumat[valittu](); 376 } 377 378 /// <summary> 293 379 /// Liikuttaa alusta haluttuun suuntaan 294 380 /// </summary> … … 307 393 } 308 394 395 /// <summary> 396 /// Vaihtaa pelaajan asetta. 397 /// </summary> 398 /// <param name="aseenNumero">Aseen numero, johon vaihdetaan</param> 309 399 void VaihdaAsetta(int aseenNumero) 310 400 { 311 if (aseenNumero > 0 && aseenNumero < 4)401 if (aseenNumero > 0 && aseenNumero < weapons.Length+1) 312 402 { 313 403 pelaajaAlus.SetWeapon(weapons[aseenNumero-1]); … … 327 417 { 328 418 alus.Shoot(); 329 //Add(alus.Shoot());330 419 } 331 420 … … 354 443 vihollistenTuloajat.Add(new AikaTapahtuma(0, LahetaLoppupomo, 1, 20)); 355 444 } 445 446 //Lisää jokaiselle muodostelmalle lähettäjän 356 447 foreach (AikaTapahtuma tapahtuma in vihollistenTuloajat) 357 448 { … … 377 468 Image vihollisenKuva = LoadImage("loppuvastus" + 1); 378 469 alukset.Add(LuoVihollinen(vihollisenKuva, 400)); 379 alukset[0].Position = new Vector(0, Level.Top + 200);470 alukset[0].Position = new Vector(0, Level.Top + 0); 380 471 alukset[0].Angle = Angle.Degrees(270); 381 472 Add(alukset[0]); 382 383 //ase.ProjectileCollision = AmmusOsuu;384 473 385 474 Timer Purkkakorjaus = new Timer(); … … 511 600 } 512 601 513 if (kohde == vasenLaita)602 if (kohde == seinat[3]) 514 603 { 515 604 tormaaja.X = Level.Left + tormaaja.Height / 2 + 1; … … 517 606 } 518 607 519 if (kohde == oikeaLaita)608 if (kohde == seinat[1]) 520 609 { 521 610 tormaaja.X = Level.Right - tormaaja.Height / 2 - 1; 522 611 tormaaja.StopHorizontal(); 523 612 } 524 if (kohde == katto)613 if (kohde == seinat[2]) 525 614 { 526 615 tormaaja.Y = Level.Top - tormaaja.Width / 2 - 1; 527 616 tormaaja.StopVertical(); 528 617 } 529 if (kohde == pohja)618 if (kohde == seinat[0]) 530 619 { 531 620 tormaaja.Y = Level.Bottom + tormaaja.Width/2 +1;
Note: See TracChangeset
for help on using the changeset viewer.