Changeset 4264 for 2013/26


Ignore:
Timestamp:
2013-06-27 14:50:22 (10 years ago)
Author:
chsarre
Message:

Talletus.

Location:
2013/26/ChristianS/Testi/Testi
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • 2013/26/ChristianS/Testi/Testi/Testi/Testi.cs

    r4234 r4264  
    1111    AssaultRifle rambonAse; 
    1212 
    13     const double nopeus = 300; 
     13    const double perusNopeus = 150; 
    1414    const double hyppyNopeus = 850; 
    1515    const int RUUDUN_KOKO = 50; 
    1616 
     17     
     18 
     19    EasyHighScore topLista = new EasyHighScore(); 
     20 
     21 
     22    Vector nopeusX = new Vector(perusNopeus, 0); 
     23    Vector nopeusYlos = new Vector(0, perusNopeus); 
     24    Vector nopeusAlas = new Vector(0, -perusNopeus+15); 
     25 
    1726    Pelaaja pelaaja; 
     27 
     28    IntMeter pistelaskuri; 
     29 
     30    Image pelaajanKuva = LoadImage("steve"); 
     31    Image tahtiKuva = LoadImage("tahti"); 
     32    Image seinaKuva = LoadImage("glass"); 
     33    Image zombi = LoadImage("zombi"); 
    1834     
    1935 
    20     Image pelaajanKuva = LoadImage("rambo"); 
    21     Image tahtiKuva = LoadImage("tahti"); 
    22  
    2336    public override void Begin() 
    2437    { 
     38        MediaPlayer.Play("taustamusa2"); 
     39        MediaPlayer.IsRepeating = true; 
     40         
     41        ClearAll(); 
    2542        Mouse.IsCursorVisible = true; 
    2643        LuoKentta(); 
    2744        LisaaNappaimet(); 
     45        LisaaLaskurit(); 
     46        PhysicsObject randomOlio = new PhysicsObject(20.0, 20.0); 
    2847 
    2948        Camera.Follow(pelaaja); 
     
    3352        int laskuri = 0; 
    3453 
    35         while (laskuri < 25) 
     54        while (laskuri < 100) 
    3655        { 
    37             LuoSatunnainenPallo(Color.Green, "pahis"); 
     56            LuoSatunnainenOlio(); 
    3857            laskuri++; 
    3958        } 
     59 
    4060        Timer ajastin = new Timer(); 
    41         ajastin.Interval = 2; 
    42         ajastin.Timeout += delegate { LuoSatunnainenPallo(Color.Green, "pahis"); }; 
     61        ajastin.Interval = 1; 
     62        ajastin.Timeout += delegate { LuoSatunnainenOlio(); }; 
    4363        ajastin.Start(); 
    4464    } 
     
    5676    } 
    5777 
    58     private void LuoSatunnainenPallo(Color vari, String tagi) 
     78    private void LuoSatunnainenOlio() 
    5979    { 
    6080        double x = RandomGen.NextDouble(Level.Left, Level.Right); 
     
    6282        double r = RandomGen.NextDouble(10, 50); 
    6383        // Color vari = RandomGen.NextColor(); 
    64         LuoMuoto(Shape.Circle, x, y, r, vari, tagi); 
     84        LuoMuoto(x, y, r); 
    6585    } 
    6686 
     
    7090        taso.Position = paikka; 
    7191        taso.CollisionIgnoreGroup = 1; 
    72         taso.Color = Color.Green; 
     92        taso.Image = seinaKuva; 
    7393        Add(taso); 
    7494    } 
     
    92112        pelaaja.Image = pelaajanKuva; 
    93113        pelaaja.CollisionIgnoreGroup = 2; 
    94         // pelaaja.LinearDamping = 0.95; 
     114        pelaaja.LinearDamping = 0.6; 
    95115        pelaaja.Tag = "rambo"; 
    96116        AddCollisionHandler(pelaaja, "tahti", TormaaTahteen); 
    97117        AddCollisionHandler(pelaaja, "tahti", CollisionHandler.AddMeterValue(pelaaja.ElamaLaskuri, 2)); 
    98118        rambonAse = new AssaultRifle(30, 10); 
    99         rambonAse.Ammo.Value = 1250; 
    100         rambonAse.FireRate = 8; 
     119        rambonAse.Ammo.Value = int.MaxValue; 
     120        rambonAse.FireRate = 10; 
    101121        rambonAse.ProjectileCollision = AmmusOsui; 
    102122        pelaaja.Add(rambonAse); 
    103         AddCollisionHandler(pelaaja, "pahis", delegate(PhysicsObject tormaaja, PhysicsObject kohde) { LuoSatunnainenPallo(Color.Green, "pahis"); }); 
     123        AddCollisionHandler(pelaaja, "pahis", delegate(PhysicsObject tormaaja, PhysicsObject kohde) { LuoSatunnainenOlio(); }); 
    104124        AddCollisionHandler(pelaaja, PelaajaTormasi); 
    105125        Add(pelaaja); 
     
    112132        elamaPalkki.BindTo(pelaaja.ElamaLaskuri); 
    113133        Add(elamaPalkki); 
    114     } 
     134 
     135        LuoAmmusLaskuri(0, 0); 
     136    } 
     137 
     138    void JatketaankoValinta() 
     139    { 
     140        MultiSelectWindow valikko = new MultiSelectWindow("Game Over", "Uusi peli", "Lopeta peli"); 
     141        valikko.AddItemHandler(0, Begin); 
     142        valikko.AddItemHandler(1, Exit); 
     143        Add(valikko); 
     144    } 
     145 
    115146 
    116147    void Kuolit() 
     
    118149        MessageDisplay.Add("Zombi söi sinut!"); 
    119150        pelaaja.Destroy(); 
     151        topLista.EnterAndShow(pistelaskuri.Value); 
     152        topLista.HighScoreWindow.Closed += delegate { JatketaankoValinta(); }; 
    120153    } 
    121154 
     
    124157        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
    125158        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    126         Vector nopeusX = new Vector(150, 0); 
    127         Vector nopeusYlos = new Vector(0, 150); 
    128         Vector nopeusAlas = new Vector(0, -135); 
     159         
    129160 
    130161        Mouse.ListenMovement(0.1, KuunteleHiirenLiiketta, null); 
    131162 
     163        Keyboard.Listen(Key.D, ButtonState.Down, LiikutaOikealle, "Liikkuu oikealle", pelaaja); 
     164        Keyboard.Listen(Key.A, ButtonState.Down, LiikutaVasemmalle, "Liikkuu vasemmalle", pelaaja); 
     165        Keyboard.Listen(Key.W, ButtonState.Down, LiikutaYlos, "Liikkuu eteen", pelaaja); 
     166        Keyboard.Listen(Key.S, ButtonState.Down, LiikutaAlas, "Liikkuu taakse", pelaaja); 
     167 
     168        /* 
    132169        Keyboard.Listen(Key.D, ButtonState.Pressed, Liikuta, "Liikkuu oikealle", pelaaja, nopeusX); 
    133170        Keyboard.Listen(Key.D, ButtonState.Released, Liikuta, "Liikkuu oikealle", pelaaja, new Vector(-nopeusX.X, pelaaja.Velocity.Y)); 
     
    138175        Keyboard.Listen(Key.S, ButtonState.Pressed, Liikuta, "Liikkuu taakse", pelaaja, nopeusAlas); 
    139176        Keyboard.Listen(Key.S, ButtonState.Released, Liikuta, "Liikkuu taakse", pelaaja, new Vector(pelaaja.Velocity.X, -nopeusAlas.Y)); 
    140         Mouse.Listen(MouseButton.Left, ButtonState.Down, AmmuAseella, "Ammu", rambonAse);  
    141          
     177         */ 
     178        Mouse.Listen(MouseButton.Left, ButtonState.Down, AmmuAseella, "Ammu", rambonAse); 
     179 
    142180    } 
    143181 
     
    148186    } 
    149187 
    150  
    151     void Liikuta(PhysicsObject hahmo, Vector nopeus) 
    152     { 
    153         hahmo.Velocity += nopeus; 
     188    void LiikutaYlos(PhysicsObject hahmo) 
     189    { 
     190        hahmo.Push(nopeusYlos * 30); 
     191    } 
     192 
     193    void LiikutaAlas(PhysicsObject hahmo) 
     194    { 
     195        hahmo.Push(nopeusAlas * 30); 
     196    } 
     197 
     198 
     199    void LiikutaVasemmalle(PhysicsObject hahmo) 
     200    { 
     201        //hahmo.Velocity += nopeus; 
     202        hahmo.Push(-nopeusX * 30); 
     203    } 
     204 
     205 
     206    void LiikutaOikealle(PhysicsObject hahmo) 
     207    { 
     208        //hahmo.Velocity += nopeus; 
     209        hahmo.Push(nopeusX * 30); 
    154210    } 
    155211 
     
    157213    { 
    158214        MessageDisplay.Add("Keräsit tähden!"); 
     215 
     216        nopeusAlas *= 1.5; 
     217        nopeusX *= 1.5; 
     218        nopeusYlos *= 1.5; 
     219 
     220        Timer ajastin = new Timer(); 
     221        ajastin.Interval = 15; 
     222        ajastin.Timeout += delegate { 
     223            nopeusAlas /= 1.5; 
     224            nopeusX /= 1.5; 
     225            nopeusYlos /= 1.5; 
     226            //nopeusYlos.Y = perusNopeus; nopeusX.X = perusNopeus; nopeusAlas.Y = -perusNopeus + 15; 
     227        }; 
     228        ajastin.Start(1); 
     229 
     230 
    159231        tahti.Destroy(); 
    160232    } 
     
    162234    { 
    163235        ammus.Destroy(); 
    164         if (kohde.Tag.Equals("pahis")) 
     236        if (kohde.Image == null) return; 
     237        if (kohde.Image.Equals(zombi)) 
    165238        { 
     239            //if(kohde.Color.Equals(zombi)) 
     240            pistelaskuri.Value++; 
    166241            kohde.Destroy(); 
    167242        } 
     
    179254        } 
    180255    } 
    181     void LuoMuoto(Shape muoto, double x, double y, double sade, Color vari, String tagi) 
     256    void LuoMuoto(double x, double y, double sade) 
    182257    { 
    183258        PhysicsObject olio = new PhysicsObject(sade, sade); 
    184         olio.Shape = muoto; 
    185         olio.Color = vari; 
     259        //olio.Shape = muoto; 
     260        //olio.Color = vari; 
    186261        olio.Restitution = 1.0; 
    187262        olio.Y = y; 
    188263        olio.X = x; 
    189         olio.Tag = tagi; 
     264        olio.CanRotate = false; 
     265        //olio.Tag = tagi; 
     266        olio.Image = zombi; 
    190267        olio.Hit(RandomGen.NextVector(10, 100)); 
     268        FollowerBrain seuraajanAivot = new FollowerBrain(pelaaja); 
     269        seuraajanAivot.Speed = 100; 
     270        seuraajanAivot.DistanceFar = 600; 
     271        seuraajanAivot.DistanceClose = 2; 
     272        seuraajanAivot.StopWhenTargetClose = false; 
     273        olio.Brain = seuraajanAivot; 
    191274        Add(olio); 
     275 
    192276    } 
    193277    void PelaajaTormasi(PhysicsObject tormaaja, PhysicsObject kohde) 
    194278    { 
    195         if (kohde.Tag.Equals("pahis")) 
     279        if (kohde.Image == null) return; 
     280        if (kohde.Image.Equals(zombi)) 
    196281        { 
    197282            //Tässä vähennetään elämää esim elamat.Value -= 5; 
     
    203288 
    204289    } 
     290 
     291    void LisaaLaskurit() 
     292    { 
     293        pistelaskuri = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     294    } 
     295    IntMeter LuoPisteLaskuri(double x, double y) 
     296    { 
     297        IntMeter laskuri = new IntMeter(0); 
     298        laskuri.MaxValue = int.MaxValue; 
     299 
     300        Label naytto = new Label(); 
     301        naytto.BindTo(laskuri); 
     302        naytto.X = x; 
     303        naytto.Y = y; 
     304        naytto.TextColor = Color.White; 
     305        naytto.BorderColor = Level.BackgroundColor; 
     306        naytto.Color = Level.BackgroundColor; 
     307        Add(naytto); 
     308 
     309        return laskuri; 
     310    } 
     311    void LuoAmmusLaskuri(double x, double y) 
     312    { 
     313        Label naytto = new Label(); 
     314        naytto.BindTo(rambonAse.Ammo); 
     315        naytto.X = x; 
     316        naytto.Y = y; 
     317        naytto.TextColor = Color.White; 
     318        naytto.BorderColor = Level.BackgroundColor; 
     319        naytto.Color = Level.BackgroundColor; 
     320        Add(naytto); 
     321    } 
     322    void KasitteleammusOsui(PhysicsObject pallo, PhysicsObject kohde) 
     323    { 
     324 
     325    } 
    205326} 
    206327 
     
    213334        : base(leveys, korkeus) 
    214335    { 
    215          
    216     } 
     336 
     337    } 
     338     
     339 
    217340} 
  • 2013/26/ChristianS/Testi/Testi/TestiContent/TestiContent.contentproj

    r4234 r4264  
    6565  </ItemGroup> 
    6666  <ItemGroup> 
    67     <Compile Include="rambo.png"> 
    68       <Name>rambo</Name> 
     67    <Compile Include="glass.png"> 
     68      <Name>glass</Name> 
    6969      <Importer>TextureImporter</Importer> 
    7070      <Processor>TextureProcessor</Processor> 
     71    </Compile> 
     72  </ItemGroup> 
     73  <ItemGroup> 
     74    <Compile Include="steve.png"> 
     75      <Name>steve</Name> 
     76      <Importer>TextureImporter</Importer> 
     77      <Processor>TextureProcessor</Processor> 
     78    </Compile> 
     79  </ItemGroup> 
     80  <ItemGroup> 
     81    <Compile Include="zombi.png"> 
     82      <Name>zombi</Name> 
     83      <Importer>TextureImporter</Importer> 
     84      <Processor>TextureProcessor</Processor> 
     85    </Compile> 
     86  </ItemGroup> 
     87  <ItemGroup> 
     88    <Compile Include="taustamusa.mp3"> 
     89      <Name>taustamusa</Name> 
     90      <Importer>Mp3Importer</Importer> 
     91      <Processor>SongProcessor</Processor> 
     92    </Compile> 
     93  </ItemGroup> 
     94  <ItemGroup> 
     95    <Compile Include="taustamusa2.mp3"> 
     96      <Name>taustamusa2</Name> 
     97      <Importer>Mp3Importer</Importer> 
     98      <Processor>SongProcessor</Processor> 
    7199    </Compile> 
    72100  </ItemGroup> 
Note: See TracChangeset for help on using the changeset viewer.