Changeset 1017 for 2010/23


Ignore:
Timestamp:
2010-06-19 23:25:08 (13 years ago)
Author:
hniemi
Message:

Lisätty aloitusmenu ja järkevöitetty rakennetta.

Location:
2010/23/hniemi/ShootEmUp
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 2010/23/hniemi/ShootEmUp/ShootEmUp/Alus.cs

    r1012 r1017  
    3333        /// </summary> 
    3434        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         
    3642        /// <summary> 
    3743        /// Luo aluksen 
     
    4955            this.hp = new IntMeter(hp); 
    5056            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; 
    5163        } 
    5264 
    5365        private void LoadWeapon() 
    5466        { 
    55  
    5667            this.SetWeapon(new Beam(5, 35, Game.LoadImage("sade") )); 
    5768        } 
     
    91102        public void Shoot(Timer sender) 
    92103        { 
    93             //this.Position = new Vector(0, 0); 
    94             //Game.Add(this.Shoot()); 
    95104            this.Shoot(); 
    96105        } 
  • 2010/23/hniemi/ShootEmUp/ShootEmUp/Muodostelma.cs

    r1007 r1017  
    4545            if (alukset != null){this.alukset = alukset;} 
    4646            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); 
    4848 
    4949            this.kellottaja = ajastin; 
     
    5757                aivot.Path = reitti; 
    5858                aivot.Speed = movingSpeed; 
    59                 //((PathFollowerBrain)alus.Brain).Add(reitti.ToArray()); 
    60                 //((PathFollowerBrain)alus.Brain).MovingSpeed = movingSpeed; 
    6159                alus.Position = lahtopiste; 
    6260            } 
  • 2010/23/hniemi/ShootEmUp/ShootEmUp/Peli.cs

    r1012 r1017  
    55using System.Collections.Generic; 
    66 
    7  
    87namespace ShootEmUp 
    98{ 
     9    /// <summary> 
     10    /// ShootEmUp-peli 
     11    ///  
     12    /// Pelin ideana on ampua viholisia niin kauan kuin niitä tulee. 
     13    /// </summary> 
    1014    public class Peli : PhysicsGame 
    1115    { 
    1216        #region Julistukset 
    13          
    14          
    1517        //Liikkumisnopeudet 
    1618        private const double NOPEUS = 300; 
     
    2123        //Kentän rakenne 
    2224        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]; 
    2726        private PhysicsObject exitZone; 
    2827 
    2928        private GameObject[] tahdet; 
    3029 
    31         //Viholliset 
     30        //Viholliset (vihollinen1.png, vihollinen2.png...) 
    3231        private const int VIHOLLISKUVIA = 4; 
    3332 
     
    3736        private IntMeter lives = new IntMeter(3); 
    3837        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; 
    4355        #endregion 
    4456 
     
    6274                for (int i = 0; i < tahdet.Length; i++) 
    6375                { 
    64                     tahdet[i].Y -= 30; 
     76                    tahdet[i].Y -= 20; 
    6577                    if (tahdet[i].Y < Level.Bottom - 40) tahdet[i].Y = Level.Top + 100; 
    6678                } 
    6779            } 
    68  
    6980            base.Update(time); 
    7081        } 
     
    8091        { 
    8192            ClearAll(); 
     93 
     94            if (kentanNumero == 0) 
     95            {  
     96                NaytaMenu(); 
     97                return; 
     98            } 
     99 
    82100            Level.Width = 600; 
    83101            Level.Height = 800; 
    84102 
     103            Level.BackgroundColor = Color.Black; 
    85104            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); 
    87113             
    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 
    89169            LisaData tieto = new LisaData(); 
    90170            tieto.Tyyppi = "seina"; 
    91             tieto.Rajahtaa = true; 
    92             tieto.Damage = 5; 
    93171 
    94172            PhysicsObject[] kulmat = new PhysicsObject[4]; 
    95173 
     174            //Lisää samassa silmukassa kulmat ja seinät 
    96175            for (int i = 0; i < kulmat.Length; i++) 
    97176            { 
     
    101180                kulmat[i].Angle = Angle.Degrees(i * 90); 
    102181                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. 
    106192            kulmat[0].Position = new Vector(Level.Left - 30, Level.Bottom - 30); 
    107193            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); 
    134200 
    135201            //Exit-alueen tekeminen. 
    136202            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); 
    138204            exitZone.Tag = tieto; 
    139205            exitZone.IsVisible = false; 
    140206            Add(exitZone); 
    141  
    142              
    143             LuoPelaaja(); 
    144             LataaHUD(); 
    145             LataaKontrollit(pelaajaAlus); 
    146             LataaTausta(kentanNumero); 
    147             LataaViholliset(20, 4,10); 
    148              
    149207        } 
    150208 
     
    183241            aseNimet[1].Text = "Missile"; 
    184242            aseNimet[2].Text = "Photon"; 
    185  
     243             
    186244            Timer purkkaAjastin = new Timer(); 
    187245            purkkaAjastin.Interval = 0.01; 
     
    192250        } 
    193251 
     252        /// <summary> 
     253        /// Purkkakorjaus aseen vaihtamiseen. Vaihtaa aluksen asetta alussa, 
     254        /// jotta ampuminen toimii. 
     255        /// </summary> 
     256        /// <param name="sender"></param> 
    194257        void Purkkakorjaus(Timer sender) 
    195258        { 
    196             VaihdaAsetta(1); 
     259            VaihdaAsetta(OLETUSASE+1); 
    197260        } 
    198261 
     
    208271                GameObject tahti = new GameObject(3, 3); 
    209272                tahti.Color = Color.White; 
     273                tahti.Shape = Shapes.Circle; 
    210274                tahti.Position = new Vector(RandomGen.NextDouble(Level.Left, Level.Right), 
    211275                                            RandomGen.NextDouble(Level.Top +20, Level.Top + 2000)); 
    212276                tahdet[i] = tahti; 
    213  
    214277                Add(tahti); 
    215278            } 
     
    224287            pelaajaAlus = new Alus(60, 55, 10); 
    225288            pelaajaAlus.Shape = Shapes.Triangle; 
    226              
    227289            pelaajaAlus.Animation = new Animation(LoadImages("sankarialus/sankarialusThrust1", "sankarialus/sankarialusThrust2")); 
    228290            pelaajaAlus.Animation.Start(); 
    229291 
    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             
    236296            pelaajaAlus.Angle += Angle.Degrees(90); 
    237297 
    238298            pelaajaAlus.IgnoresCollisionResponse = false; 
    239299            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]; 
    247302            weapons[0] = new Beam(5, 35, LoadImage("sade")); 
    248             ((ShmupWeapon)weapons[0]).ProjectileCollision = AmmusOsuu; 
    249             weapons[0].Position = new Vector(0, -40); 
    250303            weapons[1] = new Missile(15, 30, LoadImage("ohjus")); 
    251             ((ShmupWeapon)weapons[1]).ProjectileCollision = AmmusOsuu; 
    252  
    253304            weapons[2] = new Photon(15, 15, LoadImage("photon")); 
    254             ((ShmupWeapon)weapons[2]).ProjectileCollision = AmmusOsuu; 
    255  
     305             
    256306            for (int i = 0; i < weapons.Length; i++) 
    257307            { 
     308                weapons[i].ProjectileCollision = AmmusOsuu; 
    258309                weapons[i].IsVisible = false; 
     310                weapons[i].Position = new Vector(0, -42); 
    259311                pelaajaAlus.Add(weapons[i]); 
    260312            } 
    261313 
    262314            Add(pelaajaAlus); 
    263              
    264              
    265315            AddCollisionHandler(pelaajaAlus, PelaajaTormaa); 
    266316        } 
     
    291341 
    292342        /// <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> 
    293379        /// Liikuttaa alusta haluttuun suuntaan 
    294380        /// </summary> 
     
    307393        } 
    308394 
     395        /// <summary> 
     396        /// Vaihtaa pelaajan asetta. 
     397        /// </summary> 
     398        /// <param name="aseenNumero">Aseen numero, johon vaihdetaan</param> 
    309399        void VaihdaAsetta(int aseenNumero) 
    310400        { 
    311             if (aseenNumero > 0 && aseenNumero < 4) 
     401            if (aseenNumero > 0 && aseenNumero < weapons.Length+1) 
    312402            { 
    313403                pelaajaAlus.SetWeapon(weapons[aseenNumero-1]); 
     
    327417        { 
    328418            alus.Shoot(); 
    329             //Add(alus.Shoot()); 
    330419        } 
    331420 
     
    354443                vihollistenTuloajat.Add(new AikaTapahtuma(0, LahetaLoppupomo, 1, 20)); 
    355444            } 
     445 
     446            //Lisää jokaiselle muodostelmalle lähettäjän 
    356447            foreach (AikaTapahtuma tapahtuma in vihollistenTuloajat) 
    357448            { 
     
    377468            Image vihollisenKuva = LoadImage("loppuvastus" + 1); 
    378469            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); 
    380471            alukset[0].Angle = Angle.Degrees(270); 
    381472            Add(alukset[0]); 
    382  
    383             //ase.ProjectileCollision = AmmusOsuu; 
    384473 
    385474            Timer Purkkakorjaus = new Timer(); 
     
    511600            } 
    512601 
    513             if (kohde == vasenLaita) 
     602            if (kohde == seinat[3]) 
    514603            { 
    515604                tormaaja.X = Level.Left + tormaaja.Height / 2 + 1; 
     
    517606            } 
    518607 
    519             if (kohde == oikeaLaita) 
     608            if (kohde == seinat[1]) 
    520609            { 
    521610                tormaaja.X = Level.Right - tormaaja.Height / 2 - 1; 
    522611                tormaaja.StopHorizontal(); 
    523612            } 
    524             if (kohde == katto) 
     613            if (kohde == seinat[2]) 
    525614            { 
    526615                tormaaja.Y = Level.Top - tormaaja.Width / 2 - 1; 
    527616                tormaaja.StopVertical(); 
    528617            } 
    529             if (kohde == pohja) 
     618            if (kohde == seinat[0]) 
    530619            { 
    531620                tormaaja.Y = Level.Bottom + tormaaja.Width/2 +1; 
Note: See TracChangeset for help on using the changeset viewer.