Changeset 4640 for 2013


Ignore:
Timestamp:
2013-07-24 15:06:04 (10 years ago)
Author:
anlakane
Message:

Laitettu Sandboxissa palikat menemään ruudukkoon. Lisätty helikopteri ja tehty siihen nousu ja lasku. Helikopteri kasvaa liikaa toisella nousulla.

Location:
2013/30/MiskaK/MW2(My Warfare 2)
Files:
7 added
7 edited

Legend:

Unmodified
Added
Removed
  • 2013/30/MiskaK/MW2(My Warfare 2)/MW2(My Warfare 2)/MW2(My Warfare 2)/Aseet.cs

    r4507 r4640  
    144144        minigun.Pelaajan2AseKuva = pelaaja2minigunKuva; 
    145145        minigun.UsesTracers = true; 
     146        minigun.TracerBrightness = 20.0; 
     147        minigun.TracerLength = 0.4; 
    146148        return minigun; 
    147149    } 
  • 2013/30/MiskaK/MW2(My Warfare 2)/MW2(My Warfare 2)/MW2(My Warfare 2)/Elävä.cs

    r4507 r4640  
    2323        this.Elamat.LowerLimit += this.Kuoli; 
    2424    } 
     25 
     26    public Elava(double width, double height, double elamat) 
     27        : base(width, height) 
     28    { 
     29        this.Elamat = new DoubleMeter(elamat); 
     30        this.Elamat.MinValue = 0; 
     31        this.Elamat.LowerLimit += this.Kuoli; 
     32    } 
    2533} 
  • 2013/30/MiskaK/MW2(My Warfare 2)/MW2(My Warfare 2)/MW2(My Warfare 2)/MW2(My Warfare 2).csproj

    r4532 r4640  
    122122    <Compile Include="Elävä.cs" /> 
    123123    <Compile Include="GameOfLife.cs" /> 
     124    <Compile Include="Helikopteri.cs" /> 
    124125    <Compile Include="Kentta.cs" /> 
    125126    <Compile Include="Kerattava.cs" /> 
  • 2013/30/MiskaK/MW2(My Warfare 2)/MW2(My Warfare 2)/MW2(My Warfare 2)/MW2_My_Warfare_2_.cs

    r4580 r4640  
    137137    /// </summary> 
    138138    public override void Begin() 
    139     {    
     139    { 
    140140        SoitaMusiikkia(0); // valikkotheme valikkoon 
    141141        LuoAlkuValikko(); 
     
    11021102        }); 
    11031103    } 
     1104 
     1105    void LuoHelikopteri(Vector paikka) 
     1106    { 
     1107        Helikopteri kopteri = new Helikopteri(73, 233, 50, false); // 211, 171 
     1108        kopteri.Position = paikka; 
     1109        Add(kopteri, 2); 
     1110 
     1111#if DEBUG 
     1112        Keyboard.Listen(Key.I, ButtonState.Pressed, kopteri.NouseIlmaan, null); 
     1113        Keyboard.Listen(Key.U, ButtonState.Pressed, kopteri.AloitaLaskeutuminen, null); 
     1114#endif 
     1115    } 
     1116 
     1117    /// <summary> 
     1118    /// Asetetaan pelaajan lisäämät seinät siten, että se eivät mene sisäkkäin. 
     1119    /// </summary> 
     1120    /// <param name="realPos">Paikka, johon seinää yritetään lisätä.</param> 
     1121    void SijoitaKentanosaRuudukkoon(Vector mousePos) 
     1122    { 
     1123        int merkki = Math.Sign(mousePos.X); 
     1124        double x = mousePos.X - mousePos.X % Vakiot.KENTAN_RUUDUN_LEVEYS + merkki * Vakiot.KENTAN_RUUDUN_LEVEYS / 2; 
     1125        merkki = Math.Sign(mousePos.Y); 
     1126        double y = mousePos.Y - (mousePos.Y % Vakiot.KENTAN_RUUDUN_KORKEUS) + merkki * Vakiot.KENTAN_RUUDUN_KORKEUS / 2; 
     1127 
     1128        Vector posRuudukossa = new Vector(x, y); 
     1129 
     1130        LuoTuhoutuvaKentanOsa(posRuudukossa, 50, 50, null, kivenKuva, "kivi", 20, 1.0, 1.0); 
     1131    } 
     1132 
    11041133    #endregion 
    11051134 
     
    16601689    { 
    16611690        // Tavallinen zombi 
    1662         Vihollinen zombi = new Vihollinen(normaaliZombiKuva.Width / 1.2, normaaliZombiKuva.Height / 1.2, normaaliZombiKuva, 20, 4, 100, pelaajat, false, false, this, peli); 
     1691        Vihollinen zombi = new Vihollinen(normaaliZombiKuva.Width / 1.2, normaaliZombiKuva.Height / 1.2, normaaliZombiKuva, 20, 12, 100, pelaajat, false, false, this, peli); // nopeus oli 4 
    16631692        peli.LisaaVihollinenPeliin(zombi); 
    16641693 
     
    16981727            } 
    16991728            else vihu.Position = ArvoSpawnausPaikkaKentanLaidoilta(Vakiot.PALJONKO_VIHOLLISET_SPAWNAAVAT_KENTAN_RAJOJEN_ULKOPUOLELLE); 
    1700              
     1729 
    17011730            peli.VihollisetKentalla.Add(vihu); 
    17021731        } 
     
    17741803        pelaaja.ValittuAseNaytto.Text = pelaaja.ValittuAse.AseenNimi; 
    17751804        pelaaja.TappojenMaaraNaytto = LuoTappoNaytto(pelaaja.ValittuAseNaytto.Position); 
    1776         AddCollisionHandler<Pelaaja, Vihollinen>(pelaaja, delegate(Pelaaja p, Vihollinen v) { Damagea(pelaaja, v.TuhovoimaElaviaKohtaan);}); 
     1805        AddCollisionHandler<Pelaaja, Vihollinen>(pelaaja, delegate(Pelaaja p, Vihollinen v) { Damagea(pelaaja, v.TuhovoimaElaviaKohtaan); }); 
    17771806        if (kaytetaankoLaseria) 
    17781807        { 
     
    20572086                Partikkelit.AddParticleEffect(Partikkelit.PuuPartikkelit, new Vector(a.X, a.Y), 40); 
    20582087            }); 
     2088        AddCollisionHandler<PhysicsObject, Helikopteri>( 
     2089            ammus, delegate(PhysicsObject a, Helikopteri kopteri) 
     2090            { 
     2091                if (kopteri.OnkoIlmassa) return; 
     2092 
     2093                Damagea(kopteri, pelaaja.ValittuAse.TuhovoimaElaviaVastaan); 
     2094                Partikkelit.AddParticleEffect(Partikkelit.KipinaPartikkelit, new Vector(a.X, a.Y), 40); 
     2095                a.Destroy(); 
     2096            }); 
     2097 
    20592098        AddCollisionHandler<PhysicsObject, PhysicsObject>( 
    20602099            ammus, "piikkilanka", delegate(PhysicsObject a, PhysicsObject piikkilanka) 
     
    20692108                a.NeedsUpdateCall = false; 
    20702109            }); 
     2110 
    20712111 
    20722112    } 
     
    24082448 
    24092449        }, null); 
     2450        Keyboard.Listen(Key.O, ButtonState.Pressed, LuoHelikopteri, null, pelaajat[0].tahtain.Position); 
    24102451#endif 
    24112452 
     
    24432484    void AsetaSandboxOhjaimet() 
    24442485    { 
    2445         Keyboard.Listen(Key.Space, ButtonState.Pressed, delegate { LuoTuhoutuvaKentanOsa(pelaajat[0].tahtain.Position, 50, 50, null, kivenKuva, "kivi", 20, 1.0, 1.0); }, null); 
     2486        Keyboard.Listen(Key.Space, ButtonState.Pressed, delegate { SijoitaKentanosaRuudukkoon(pelaajat[0].tahtain.Position); }, null); 
    24462487        Keyboard.Listen(Key.K, ButtonState.Pressed, delegate { LuoKillBall(pelaajat[0].tahtain.Position); }, null); 
    24472488        Keyboard.Listen(Key.T, ButtonState.Pressed, delegate { LuoTynnyri(pelaajat[0].tahtain.Position, 50.0, 50.0, null); }, null); 
    24482489        Keyboard.Listen(Key.Delete, ButtonState.Pressed, RemoveAllEntities, null); 
    2449         ControllerOne.Listen(Button.B, ButtonState.Pressed, delegate { LuoTuhoutuvaKentanOsa(pelaajat[1].tahtain.Position, 50, 50, null, kivenKuva, "kivi", 20, 1.0, 1.0); }, null); 
     2490        ControllerOne.Listen(Button.B, ButtonState.Pressed, delegate { SijoitaKentanosaRuudukkoon(pelaajat[1].tahtain.Position); }, null); 
    24502491    } 
    24512492 
  • 2013/30/MiskaK/MW2(My Warfare 2)/MW2(My Warfare 2)/MW2(My Warfare 2)Content/MW2(My Warfare 2)Content.contentproj

    r4580 r4640  
    14981498    </Compile> 
    14991499  </ItemGroup> 
     1500  <ItemGroup> 
     1501    <Compile Include="kopteri_ilmanlapoja.png"> 
     1502      <Name>kopteri_ilmanlapoja</Name> 
     1503      <Importer>TextureImporter</Importer> 
     1504      <Processor>TextureProcessor</Processor> 
     1505    </Compile> 
     1506    <Compile Include="kopteri_ilmassa1.png"> 
     1507      <Name>kopteri_ilmassa1</Name> 
     1508      <Importer>TextureImporter</Importer> 
     1509      <Processor>TextureProcessor</Processor> 
     1510    </Compile> 
     1511    <Compile Include="kopteri_ilmassa2.png"> 
     1512      <Name>kopteri_ilmassa2</Name> 
     1513      <Importer>TextureImporter</Importer> 
     1514      <Processor>TextureProcessor</Processor> 
     1515    </Compile> 
     1516    <Compile Include="kopteri_ilmassa3.png"> 
     1517      <Name>kopteri_ilmassa3</Name> 
     1518      <Importer>TextureImporter</Importer> 
     1519      <Processor>TextureProcessor</Processor> 
     1520    </Compile> 
     1521    <Compile Include="kopteri_ilmassa4.png"> 
     1522      <Name>kopteri_ilmassa4</Name> 
     1523      <Importer>TextureImporter</Importer> 
     1524      <Processor>TextureProcessor</Processor> 
     1525    </Compile> 
     1526    <Compile Include="kopteri_lavat.png"> 
     1527      <Name>kopteri_lavat</Name> 
     1528      <Importer>TextureImporter</Importer> 
     1529      <Processor>TextureProcessor</Processor> 
     1530    </Compile> 
     1531  </ItemGroup> 
     1532  <ItemGroup> 
     1533    <Compile Include="kopteri_laskeutumisalusta.png"> 
     1534      <Name>kopteri_laskeutumisalusta</Name> 
     1535      <Importer>TextureImporter</Importer> 
     1536      <Processor>TextureProcessor</Processor> 
     1537    </Compile> 
     1538  </ItemGroup> 
    15001539  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    15011540  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
  • 2013/30/MiskaK/MW2(My Warfare 2)/Paranneltu Jypeli/GameObjects/GameObject/GameObject.cs

    r4507 r4640  
    4848    { 
    4949        public List<Listener> AssociatedListeners { get; private set; } 
     50        Timer fadeTimer; 
    5051 
    5152        #region Destroyable 
     
    149150                oscillators.Update( time ); 
    150151        } 
     152 
     153        /// <summary> 
     154        /// Näkeekö olio toisen. 
     155        /// </summary> 
     156        /// <param name="obj">Toinen olio</param> 
     157        /// <returns></returns> 
     158        public bool SeesObject(GameObject obj) 
     159        { 
     160            return Game.Instance.GetFirstObject(obstacle => obstacle != this && obstacle != obj && !(obstacle is Widget) && obstacle.IsBlocking(this.Position, obj.Position)) == null; 
     161        } 
     162 
     163        /// <summary> 
     164        /// Näkeekö olio toisen. 
     165        /// </summary> 
     166        /// <param name="obj">Toinen olio</param> 
     167        /// <param name="isObstacle">Ehto sille mikä lasketaan esteeksi</param> 
     168        /// <returns></returns> 
     169        public bool SeesObject(GameObject obj, Predicate<GameObject> isObstacle) 
     170        { 
     171            return Game.Instance.GetFirstObject(obstacle => obstacle != this && obstacle != obj && isObstacle(obstacle) && obstacle.IsBlocking(this.Position, obj.Position)) == null; 
     172        } 
     173 
     174        /// <summary> 
     175        /// Näkeekö olio toisen. 
     176        /// </summary> 
     177        /// <param name="obj">Toinen olio</param> 
     178        /// <param name="obstacleTag">Tagi esteelle</param> 
     179        /// <returns></returns> 
     180        public bool SeesObject(GameObject obj, object obstacleTag) 
     181        { 
     182            return SeesObject(obj, o => o.Tag == obstacleTag); 
     183        } 
     184 
     185        /// <summary> 
     186        /// Näkeekö olio paikkaan. 
     187        /// </summary> 
     188        /// <param name="targetPosition">Paikka</param> 
     189        /// <returns></returns> 
     190        public bool SeesTarget(Vector targetPosition) 
     191        { 
     192            return Game.Instance.GetFirstObject(obstacle => obstacle != this && !(obstacle is Widget) && obstacle.IsBlocking(this.Position, targetPosition)) == null; 
     193        } 
     194 
     195        /// <summary> 
     196        /// Näkeekö olio paikkaan. 
     197        /// </summary> 
     198        /// <param name="targetPosition">Paikka</param> 
     199        /// <param name="isObstacle">Ehto sille mikä lasketaan esteeksi</param> 
     200        /// <returns></returns> 
     201        public bool SeesTarget(Vector targetPosition, Predicate<GameObject> isObstacle) 
     202        { 
     203            return Game.Instance.GetFirstObject(obstacle => obstacle != this && isObstacle(obstacle) && obstacle.IsBlocking(this.Position, targetPosition)) == null; 
     204        } 
     205 
     206        /// <summary> 
     207        /// Näkeekö olio paikkaan. 
     208        /// </summary> 
     209        /// <param name="targetPosition">Paikka</param> 
     210        /// <param name="obstacleTag">Tagi esteelle</param> 
     211        /// <returns></returns> 
     212        public bool SeesTarget(Vector targetPosition, object obstacleTag) 
     213        { 
     214            return SeesTarget(targetPosition, o => o.Tag == obstacleTag); 
     215        } 
     216 
     217        /// <summary> 
     218        /// Onko olio kahden paikan välissä. 
     219        /// </summary> 
     220        /// <param name="obj">Olio</param> 
     221        /// <param name="pos1">Paikka 1</param> 
     222        /// <param name="pos2">Paikka 2</param> 
     223        /// <returns></returns> 
     224        public bool IsBlocking(Vector pos1, Vector pos2) 
     225        { 
     226            Vector normal = (pos2 - pos1).Normalize(); 
     227            double ep = this.AbsolutePosition.ScalarProjection(normal); 
     228            double p1p = pos1.ScalarProjection(normal); 
     229            double p2p = pos2.ScalarProjection(normal); 
     230 
     231            if (ep < p1p || ep > p2p) 
     232                return false; 
     233 
     234            double pn = pos1.ScalarProjection(normal.RightNormal); 
     235            double en = this.AbsolutePosition.ScalarProjection(normal.RightNormal); 
     236            return Math.Abs(en - pn) <= 0.5 * Math.Sqrt(this.Width * this.Width + this.Height * this.Height); 
     237        } 
     238 
     239        /// <summary> 
     240        /// Muuttaa olion väriä toiseen hitaasti liukumalla. 
     241        /// </summary> 
     242        /// <param name="targetColor">Väri johon muutetaan</param> 
     243        /// <param name="seconds">Aika jossa muutos valmistuu</param> 
     244        public void FadeColorTo(Color targetColor, double seconds) 
     245        { 
     246            if (fadeTimer != null && fadeTimer.Enabled) 
     247            { 
     248                fadeTimer.Stop(); 
     249            } 
     250 
     251            double timeLeft = seconds; 
     252            double dt = GetPrecision(seconds); 
     253 
     254            int counter = 1; 
     255            Color original = this.Color; 
     256            int rd = targetColor.RedComponent - this.Color.RedComponent; 
     257            int gd = targetColor.GreenComponent - this.Color.GreenComponent; 
     258            int bd = targetColor.BlueComponent - this.Color.BlueComponent; 
     259            int ad = targetColor.AlphaComponent - this.Color.AlphaComponent; 
     260 
     261            fadeTimer = new Timer(); 
     262            fadeTimer.Interval = dt; 
     263            fadeTimer.Timeout += delegate 
     264            { 
     265                byte r = (byte)(original.RedComponent + rd * counter * dt / seconds); 
     266                byte g = (byte)(original.GreenComponent + gd * counter * dt / seconds); 
     267                byte b = (byte)(original.BlueComponent + bd * counter * dt / seconds); 
     268                byte a = (byte)(original.AlphaComponent + ad * counter * dt / seconds); 
     269                this.Color = new Color(r, g, b, a); 
     270                counter++; 
     271            }; 
     272            fadeTimer.Start((int)Math.Ceiling(seconds / dt)); 
     273        } 
     274 
     275        private double GetPrecision(double seconds) 
     276        { 
     277            double dt = 0.01; 
     278            while (dt > seconds) dt /= 10; 
     279            return dt; 
     280        } 
    151281    } 
    152282} 
Note: See TracChangeset for help on using the changeset viewer.