Changeset 5811 for 2014/koodauskerho


Ignore:
Timestamp:
2015-02-14 15:01:54 (8 years ago)
Author:
sieerinn
Message:
 
Location:
2014/koodauskerho/38/JaakkoS
Files:
13 added
15 edited

Legend:

Unmodified
Added
Removed
  • 2014/koodauskerho/38/JaakkoS/FarmDefense/FarmDefense/FarmDefense/FarmDefense.cs

    r5797 r5811  
    66using Jypeli.Effects; 
    77using Jypeli.Widgets; 
     8using System.Linq; 
    89 
    910public class FarmDefense : PhysicsGame 
     
    1112    Image nurmikonKuva = LoadImage("nurmikko"); 
    1213    Image tienKuva = LoadImage("tie"); 
     14    Image kanankuva = LoadImage("kana"); 
     15    Image kananmuna = LoadImage("muna1"); 
     16    Image[] Sudenkuvat = LoadImages("sus1", "sus2"); 
     17 
     18    List<Vector> pisteet; 
     19    Vector[] pisteTaulu; 
     20 
     21    int aalto = 1; 
     22    IntMeter elämät; 
     23 
     24    GameObject cursor; 
    1325 
    1426    public override void Begin() 
    1527    { 
    16         // Kirjoita ohjelmakoodisi tähän 
    17  
     28        IsMouseVisible = true; 
     29        SmoothTextures = false; 
     30        Aloitapeli(); 
     31    } 
     32 
     33    void Aloitapeli() 
     34    { 
     35        ClearAll(); 
    1836        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
    1937        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    2038 
     39        pisteet = new List<Vector>(); 
     40        pisteTaulu = new Vector[10]; 
     41 
     42        elämät = new IntMeter(10, 0, 10); 
     43        Label pisteNaytto = new Label(); 
     44        pisteNaytto.X = Screen.Left + 100; 
     45        pisteNaytto.Y = Screen.Top - 100; 
     46        pisteNaytto.TextColor = Color.Black; 
     47        pisteNaytto.Color = Color.White; 
     48 
     49        pisteNaytto.BindTo(elämät); 
     50        Add(pisteNaytto); 
     51 
     52        elämät.LowerLimit += GameOver; 
     53 
     54 
    2155        TileMap ruudut = TileMap.FromLevelAsset("kenttä1"); 
    2256 
    2357        ruudut.SetTileMethod('.', LuoNurmikko); 
    2458        ruudut.SetTileMethod('T', LuoTie); 
     59        ruudut.SetTileMethod('0', LuoKulma, 0); 
     60        ruudut.SetTileMethod('1', LuoKulma, 1); 
     61        ruudut.SetTileMethod('2', LuoKulma, 2); 
     62        ruudut.SetTileMethod('3', LuoKulma, 3); 
     63        ruudut.SetTileMethod('4', LuoKulma, 4); 
     64        ruudut.SetTileMethod('5', LuoKulma, 5); 
     65        ruudut.SetTileMethod('6', LuoKulma, 6); 
     66        ruudut.SetTileMethod('7', LuoKulma, 7); 
     67        ruudut.SetTileMethod('8', LuoKulma, 8); 
     68        ruudut.SetTileMethod('9', LuoKulma, 9); 
    2569        ruudut.Execute(70, 100); 
     70 
     71        foreach (Vector p in pisteTaulu) 
     72        { 
     73            if (p != Vector.Zero) 
     74            { 
     75                pisteet.Add(p); 
     76            } 
     77        } 
     78 
     79        Timer.SingleShot(10, Luoaalto); 
     80 
     81        Luopainikkeet(); 
     82 
     83        cursor = new GameObject(50, 50); 
     84        cursor.Color = Color.Transparent; 
     85        Add(cursor); 
     86        Mouse.ListenMovement(0, hiirenliikutus, null); 
     87        Mouse.Listen(MouseButton.Left, ButtonState.Released, LuoKana, null); 
     88    } 
     89 
     90    void LuoKana() 
     91    { 
     92        if (cursor.Image == null) 
     93        { 
     94            return; 
     95        } 
     96 
     97        GameObject kana = new GameObject(50, 50); 
     98        kana.Image = cursor.Image; 
     99        kana.Position = Mouse.PositionOnWorld; 
     100        Add(kana); 
     101 
     102        AssaultRifle ase; 
     103        ase = new AssaultRifle(30, 10); 
     104        ase.ProjectileCollision = AmmusOsui; 
     105        ase.IsVisible = false; 
     106        kana.Add(ase); 
     107 
     108        Timer ajastin = new Timer(); 
     109        ajastin.Interval = 0.8; 
     110        ajastin.Timeout += delegate 
     111        { 
     112            var vihut = GetObjectsWithTag("susi").Where((GameObject o) => Vector.Distance(kana.Position, o.Position) < 300).ToList(); 
     113            vihut.Sort((GameObject o1, GameObject o2) => Vector.Distance(o1.Position, kana.Position).CompareTo(Vector.Distance(o2.Position, kana.Position))); 
     114 
     115            if (vihut.Count > 0) 
     116            { 
     117                ase.AbsoluteAngle = (vihut[0].Position-kana.Position).Angle; 
     118                AmmuAseella(ase); 
     119            } 
     120        }; 
     121        ajastin.Start(); 
     122 
     123        cursor.Image = null; 
     124    } 
     125 
     126    void AmmusOsui(PhysicsObject ammus, PhysicsObject kohde) 
     127    { 
     128        ammus.Destroy(); 
     129        if (kohde.Tag == "susi") 
     130        { 
     131            ((Vihu)kohde).Elamalaskuri.Value --; 
     132        } 
     133    } 
     134 
     135    void AmmuAseella(AssaultRifle ase) 
     136    { 
     137        PhysicsObject ammus = ase.Shoot(); 
     138 
     139        if (ammus != null) 
     140        { 
     141            ammus.Size *= 1.5; 
     142            ammus.Image = kananmuna; 
     143            ammus.MaximumLifetime = TimeSpan.FromSeconds(8.0); 
     144        } 
     145    } 
     146 
     147    void hiirenliikutus(AnalogState hiirenTila) 
     148    { 
     149        cursor.X = Mouse.PositionOnWorld.X; 
     150        cursor.Y = Mouse.PositionOnWorld.Y; 
     151    } 
     152 
     153 
     154    void Luopainikkeet() 
     155    { 
     156        GameObject kana = new GameObject(50, 50); 
     157        kana.Image = kanankuva; 
     158        kana.Position = new Vector(Level.Right - 50, 0); 
     159        Add(kana); 
     160        Mouse.ListenOn(kana, MouseButton.Left, ButtonState.Pressed, delegate 
     161        { 
     162            cursor.Image = kana.Image; 
     163 
     164        }, null); 
     165 
     166    } 
     167 
     168    void GameOver() 
     169    { 
     170        MultiSelectWindow valikko = new MultiSelectWindow("Hävisit!", "Uudestaan", "Lopeta"); 
     171        valikko.ItemSelected += PainettiinValikonNappia; 
     172        Add(valikko); 
     173    } 
     174 
     175    void PainettiinValikonNappia(int valinta) 
     176    { 
     177        switch (valinta) 
     178        { 
     179            case 0: 
     180                Aloitapeli(); 
     181                break; 
     182            case 1: 
     183                Exit(); 
     184                break; 
     185        } 
    26186    } 
    27187 
     
    36196    void LuoNurmikko(Vector paikka, double leveys, double korkeus) 
    37197    { 
    38         PhysicsObject nurmikko = PhysicsObject.CreateStaticObject(leveys, korkeus); 
     198        GameObject nurmikko = new GameObject(leveys, korkeus); 
    39199        nurmikko.Position = paikka; 
    40200        nurmikko.Shape = Shape.Rectangle; 
    41201        nurmikko.Tag = "nurmikko"; 
    42202        nurmikko.Image = nurmikonKuva; 
    43         Add(nurmikko, 1); 
    44  
    45     } 
     203        Add(nurmikko, -1); 
     204    } 
     205 
    46206    void LuoTie(Vector paikka, double leveys, double korkeus) 
    47207    { 
    48         PhysicsObject tie = PhysicsObject.CreateStaticObject(leveys, korkeus); 
     208        GameObject tie = new GameObject(leveys, korkeus); 
    49209        tie.Position = paikka; 
    50210        tie.Shape = Shape.Rectangle; 
    51211        tie.Tag = "tie"; 
    52212        tie.Image = tienKuva; 
    53         Add(tie, 1); 
    54  
    55     } 
    56 } 
     213        Add(tie, -1); 
     214    } 
     215 
     216    void LuoKulma(Vector paikka, double leveys, double korkeus, int numero) 
     217    { 
     218        GameObject tie = new GameObject(leveys, korkeus); 
     219        tie.Position = paikka; 
     220        tie.Shape = Shape.Rectangle; 
     221        tie.Tag = "tie"; 
     222        tie.Image = tienKuva; 
     223        Add(tie, -1); 
     224 
     225        pisteTaulu[numero] = paikka; 
     226    } 
     227 
     228    void Luoaalto() 
     229    { 
     230        int susia = 5 + aalto * 3; 
     231 
     232        Timer ajastin = new Timer(); 
     233        ajastin.Interval = 1.5; 
     234        ajastin.Timeout += delegate 
     235        { 
     236            if (susia > 0) 
     237            { 
     238                susia--; 
     239                LuoSusi(3* (aalto / 2)); 
     240            } 
     241            else 
     242            { 
     243                ajastin.Stop(); 
     244                aalto++; 
     245                Timer.SingleShot(10, Luoaalto); 
     246            } 
     247        }; 
     248        ajastin.Start(); 
     249 
     250    } 
     251 
     252    void LuoSusi(int kestavyys) 
     253    { 
     254        Vihu susi = new Vihu(70, 100); 
     255        susi.Image = Sudenkuvat[0]; 
     256        Animation animaatio = new Animation(Sudenkuvat); 
     257        animaatio.FPS = 5; 
     258        susi.Animation = animaatio; 
     259        susi.Position = pisteet[0]; 
     260        susi.Animation.Start(); 
     261        susi.CollisionIgnoreGroup = 1; 
     262        susi.CanRotate = false; 
     263        susi.Tag = "susi"; 
     264        susi.MuutaElamamaara(kestavyys); 
     265         Add(susi); 
     266 
     267 
     268        PathFollowerBrain Aivo = new PathFollowerBrain(); 
     269        Aivo.Path = pisteet; 
     270        Aivo.Speed = 100; 
     271        Aivo.ArrivedAtEnd += delegate 
     272        { 
     273            elämät.Value--; 
     274            susi.Destroy(); 
     275        }; 
     276        susi.Brain = Aivo; 
     277     } 
     278    } 
  • 2014/koodauskerho/38/JaakkoS/FarmDefense/FarmDefense/FarmDefense/FarmDefense.csproj

    r5797 r5811  
    114114    <Compile Include="FarmDefense.cs" /> 
    115115    <Compile Include="Properties\AssemblyInfo.cs" /> 
     116    <Compile Include="Vihu.cs" /> 
    116117  </ItemGroup> 
    117118  <ItemGroup> 
  • 2014/koodauskerho/38/JaakkoS/FarmDefense/FarmDefense/FarmDefense/FarmDefense.csproj.Debug.cachefile

    r5797 r5811  
    22Content\nurmikko.xnb 
    33Content\kenttÀ1.xnb 
     4Content\sus1.xnb 
     5Content\sus2.xnb 
     6Content\kana.xnb 
     7Content\muna1.xnb 
  • 2014/koodauskerho/38/JaakkoS/FarmDefense/FarmDefense/FarmDefense/obj/x86/Debug/ContentPipeline-{2A79B1E6-582D-4907-808F-C874DEC572F7}.xml

    r5797 r5811  
    99      <Options>None</Options> 
    1010      <Output>C:\MyTemp\JaakkoS\FarmDefense\FarmDefense\FarmDefense\bin\x86\Debug\Content\tie.xnb</Output> 
    11       <Time>2015-01-17T13:15:07.5526569+02:00</Time> 
     11      <Time>2015-02-14T10:02:27.1354147+02:00</Time> 
    1212    </Item> 
    1313    <Item> 
     
    1818      <Options>None</Options> 
    1919      <Output>C:\MyTemp\JaakkoS\FarmDefense\FarmDefense\FarmDefense\bin\x86\Debug\Content\nurmikko.xnb</Output> 
    20       <Time>2015-01-17T13:15:21.6076569+02:00</Time> 
     20      <Time>2015-02-14T10:02:27.1354147+02:00</Time> 
    2121    </Item> 
    2222    <Item> 
     
    2727      <Options>None</Options> 
    2828      <Output>C:\MyTemp\JaakkoS\FarmDefense\FarmDefense\FarmDefense\bin\x86\Debug\Content\kenttä1.xnb</Output> 
    29       <Time>2015-01-17T13:26:16.6396569+02:00</Time> 
     29      <Time>2015-02-14T10:43:08.0282976+02:00</Time> 
     30    </Item> 
     31    <Item> 
     32      <Source>sus1.png</Source> 
     33      <Name>sus1</Name> 
     34      <Importer>TextureImporter</Importer> 
     35      <Processor>TextureProcessor</Processor> 
     36      <Options>None</Options> 
     37      <Output>C:\MyTemp\JaakkoS\FarmDefense\FarmDefense\FarmDefense\bin\x86\Debug\Content\sus1.xnb</Output> 
     38      <Time>2015-02-14T10:09:24.4685913+02:00</Time> 
     39    </Item> 
     40    <Item> 
     41      <Source>sus2.png</Source> 
     42      <Name>sus2</Name> 
     43      <Importer>TextureImporter</Importer> 
     44      <Processor>TextureProcessor</Processor> 
     45      <Options>None</Options> 
     46      <Output>C:\MyTemp\JaakkoS\FarmDefense\FarmDefense\FarmDefense\bin\x86\Debug\Content\sus2.xnb</Output> 
     47      <Time>2015-02-14T10:09:32.5184692+02:00</Time> 
     48    </Item> 
     49    <Item> 
     50      <Source>kana.png</Source> 
     51      <Name>kana</Name> 
     52      <Importer>TextureImporter</Importer> 
     53      <Processor>TextureProcessor</Processor> 
     54      <Options>None</Options> 
     55      <Output>C:\MyTemp\JaakkoS\FarmDefense\FarmDefense\FarmDefense\bin\x86\Debug\Content\kana.xnb</Output> 
     56      <Time>2015-02-14T11:52:17.3808976+02:00</Time> 
     57    </Item> 
     58    <Item> 
     59      <Source>muna1.png</Source> 
     60      <Name>muna1</Name> 
     61      <Importer>TextureImporter</Importer> 
     62      <Processor>TextureProcessor</Processor> 
     63      <Options>None</Options> 
     64      <Output>C:\MyTemp\JaakkoS\FarmDefense\FarmDefense\FarmDefense\bin\x86\Debug\Content\muna1.xnb</Output> 
     65      <Time>2015-02-14T11:52:34.3754976+02:00</Time> 
    3066    </Item> 
    3167    <BuildSuccessful>true</BuildSuccessful> 
     
    76112      <Assembly> 
    77113        <Key>C:\Windows\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework.Content.Pipeline\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Content.Pipeline.dll</Key> 
    78         <Value>2014-04-23T00:12:49.5168169+03:00</Value> 
     114        <Value>2014-04-23T01:01:53.8831999+03:00</Value> 
    79115      </Assembly> 
    80116    </Assemblies> 
  • 2014/koodauskerho/38/JaakkoS/FarmDefense/FarmDefense/FarmDefense/obj/x86/Debug/FarmDefense.csproj.FileListAbsolute.txt

    r5797 r5811  
    99C:\MyTemp\JaakkoS\FarmDefense\FarmDefense\FarmDefense\obj\x86\Debug\FarmDefense.pdb 
    1010C:\MyTemp\JaakkoS\FarmDefense\FarmDefense\FarmDefense\bin\x86\Debug\Content\kenttÀ1.xnb 
     11C:\MyTemp\JaakkoS\FarmDefense\FarmDefense\FarmDefense\obj\x86\Debug\FarmDefense.csprojResolveAssemblyReference.cache 
     12C:\MyTemp\JaakkoS\FarmDefense\FarmDefense\FarmDefense\bin\x86\Debug\Content\sus1.xnb 
     13C:\MyTemp\JaakkoS\FarmDefense\FarmDefense\FarmDefense\bin\x86\Debug\Content\sus2.xnb 
     14C:\MyTemp\JaakkoS\FarmDefense\FarmDefense\FarmDefense\bin\x86\Debug\Content\kana.xnb 
     15C:\MyTemp\JaakkoS\FarmDefense\FarmDefense\FarmDefense\bin\x86\Debug\Content\muna1.xnb 
  • 2014/koodauskerho/38/JaakkoS/FarmDefense/FarmDefense/FarmDefense/obj/x86/Debug/cachefile-{2A79B1E6-582D-4907-808F-C874DEC572F7}-targetpath.txt

    r5797 r5811  
    22Content\nurmikko.xnb 
    33Content\kenttÀ1.xnb 
     4Content\sus1.xnb 
     5Content\sus2.xnb 
     6Content\kana.xnb 
     7Content\muna1.xnb 
  • 2014/koodauskerho/38/JaakkoS/FarmDefense/FarmDefense/FarmDefenseContent/FarmDefenseContent.contentproj

    r5797 r5811  
    6666    </Compile> 
    6767  </ItemGroup> 
     68  <ItemGroup> 
     69    <Compile Include="sus1.png"> 
     70      <Name>sus1</Name> 
     71      <Importer>TextureImporter</Importer> 
     72      <Processor>TextureProcessor</Processor> 
     73    </Compile> 
     74  </ItemGroup> 
     75  <ItemGroup> 
     76    <Compile Include="sus2.png"> 
     77      <Name>sus2</Name> 
     78      <Importer>TextureImporter</Importer> 
     79      <Processor>TextureProcessor</Processor> 
     80    </Compile> 
     81  </ItemGroup> 
     82  <ItemGroup> 
     83    <Compile Include="kana.png"> 
     84      <Name>kana</Name> 
     85      <Importer>TextureImporter</Importer> 
     86      <Processor>TextureProcessor</Processor> 
     87    </Compile> 
     88  </ItemGroup> 
     89  <ItemGroup> 
     90    <Compile Include="muna1.png"> 
     91      <Name>muna1</Name> 
     92      <Importer>TextureImporter</Importer> 
     93      <Processor>TextureProcessor</Processor> 
     94    </Compile> 
     95  </ItemGroup> 
    6896  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    6997  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
  • 2014/koodauskerho/38/JaakkoS/FarmDefense/FarmDefense/FarmDefenseContent/kenttä1.txt

    r5797 r5811  
    1 .....T................... 
    2 .....TT.................. 
     1.....0................... 
     2.....1TT2................ 
     3........T................ 
     4........T................ 
     5........T................ 
     6......4T3................ 
    37......T.................. 
    4 ......TTT................ 
    5 ........T................ 
    6 .......TT................ 
    7 .......T................. 
    8 .......TTTTTTTTTTTTTTTTTT 
     8......5TTTTTTTTTTTTTTTTT6 
Note: See TracChangeset for help on using the changeset viewer.