Changeset 3751 for 2012/30


Ignore:
Timestamp:
2012-07-25 15:04:10 (11 years ago)
Author:
anlakane
Message:

Talletus.

Location:
2012/30/JesseN/Oma peli
Files:
26 added
20 edited

Legend:

Unmodified
Added
Removed
  • 2012/30/JesseN/Oma peli/OmaPeli/OmaPeli/OmaPeli/OmaPeli.cs

    r3724 r3751  
    99public class OmaPeli : PhysicsGame 
    1010{ 
    11     PlatformCharacter Hahmo; 
     11    HahmoClass hahmo; 
    1212    Image hahmostand = LoadImage("CharStand32"); 
    1313    Image[] hahmojuoksu = LoadImages("CharRun1", "CharRun2", "CharRun3"); 
    1414    Image hahmojump = LoadImage("CharJump"); 
    1515    Image hahmofall = LoadImage("CharJump"); 
     16    Image panos = LoadImage("Bullet"); 
     17    Image tahtaa = LoadImage("CharShoot32bit"); 
     18    Image[] flyer = LoadImages("EnemyFlying1", "EnemyFlying2", "EnemyFlying3", "EnemyFlying4"); 
     19 
     20    Image vesiblock = LoadImage("Water"); 
     21    Image puublock = LoadImage("Wood"); 
     22    Image ruohoblock = LoadImage("Grass"); 
     23    Image multablock = LoadImage("Dirt"); 
     24    Image lehdetblock = LoadImage("Leaves"); 
     25    Image panos2 = LoadImage("Bullet2"); 
     26    Image kiviblock = LoadImage("Stone"); 
     27 
     28 
    1629     
    1730 
     
    1932    public override void Begin() 
    2033    { 
    21         Luokentta(); 
     34        MultiSelectWindow alkuValikko = new MultiSelectWindow("Pelin alkuvalikko", 
     35"Aloita peli", "Parhaat pisteet", "Lopeta"); 
     36        Add(alkuValikko); 
     37 
     38        alkuValikko.ItemSelected += PainettiinValikonNappia; 
     39 
     40 
     41 
     42 
     43 
     44 
     45 
     46 
     47 
     48        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
     49        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     50    } 
     51 
     52    void PainettiinValikonNappia(int valinta) 
     53    { 
     54        switch (valinta) 
     55        { 
     56            case 0: 
     57                Luokentta(); 
     58                break; 
     59            case 1: 
     60                Exit(); 
     61                break; 
     62 
     63 
     64        } 
     65    } 
     66 
     67    void Luokentta() 
     68    { 
     69        
     70 
     71 
     72 
     73        ColorTileMap ruudut = ColorTileMap.FromLevelAsset("Level1"); 
     74 
     75        ruudut.SetTileMethod(Color.BrightGreen, LuoRuoho); 
     76        ruudut.SetTileMethod(Color.Cyan, LuoVesi); 
     77        ruudut.SetTileMethod(Color.Red, LuoVihollinen); 
     78        ruudut.SetTileMethod(Color.DarkBlue, LuoLehdet); 
     79        ruudut.SetTileMethod(Color.HanPurple, LuoPuu); 
     80        ruudut.SetTileMethod(Color.Black, LuoMulta); 
     81        ruudut.SetTileMethod(Color.Orange, LuoPelaaja); 
     82        ruudut.SetTileMethod(Color.Rose, LuoKivi); 
     83 
     84 
     85        ruudut.Execute(45, 45); 
     86 
     87        //Level.AmbientLight = 1.0; 
     88 
     89        //Light valo = new Light(); 
     90        //valo.Intensity = 0.8; 
     91        //valo.Distance = 150; 
     92        //valo.Position = hahmo.Position; 
     93        //Add(valo); 
     94        //int pMaxMaara = 200; 
     95        //ExplosionSystem rajahdys = new ExplosionSystem(LoadImage(""), pMaxMaara); 
     96        //Add(rajahdys); 
     97    } 
     98 
     99    void LuoKivi(Vector paikka, double leveys, double korkeus) 
     100    { 
     101        PhysicsObject kivi = PhysicsObject.CreateStaticObject(leveys, korkeus); 
     102        kivi.Position = paikka; 
     103        kivi.Image = kiviblock; 
     104        kivi.CollisionIgnoreGroup = 1; 
     105        Add(kivi); 
     106 
     107    } 
     108 
     109    void LuoPelaaja(Vector paikka, double leveys, double korkeus) 
     110    { 
     111        hahmo = new HahmoClass(48, 48); 
     112        hahmo.AnimWalk = new Animation(hahmojuoksu); 
     113        hahmo.AnimWalk.FPS = 10; 
     114        hahmo.AnimIdle = new Animation(hahmostand); 
     115        hahmo.AnimJump = new Animation(hahmojump); 
     116        hahmo.AnimFall = new Animation(hahmofall); 
     117        hahmo.Weapon = new LaserGun(30, 30); 
     118        hahmo.Weapon.Ammo.Value = 10000; 
     119        hahmo.Weapon.Image = null; 
     120        hahmo.Weapon.Color = Color.Transparent; 
     121        hahmo.Weapon.Power.DefaultValue = 1000; 
     122        hahmo.Weapon.CanHitOwner = false; 
     123        Add(hahmo); 
     124        hahmo.Position = paikka; 
    22125        Gravity = new Vector(0.0, -1000.0); 
    23126        Ohjaus(); 
     127        Camera.Follow(hahmo); 
     128 
     129    } 
     130 
     131    void LuoMulta(Vector paikka, double leveys, double korkeus) 
     132    { 
     133        PhysicsObject multa = PhysicsObject.CreateStaticObject(leveys, korkeus); 
     134        multa.Position = paikka; 
     135        multa.Image = multablock; 
     136        multa.CollisionIgnoreGroup = 1; 
     137        Add(multa); 
     138 
     139 
     140 
     141    } 
     142 
     143    void LuoRuoho(Vector paikka, double leveys, double korkeus) 
     144    { 
     145        PhysicsObject ruoho = PhysicsObject.CreateStaticObject(leveys, korkeus); 
     146        ruoho.Position = paikka; 
     147        ruoho.Image = ruohoblock; 
     148        ruoho.CollisionIgnoreGroup = 1; 
     149        Add(ruoho); 
     150    } 
     151 
     152    void LuoPuu(Vector paikka, double leveys, double korkeus) 
     153    { 
     154        PhysicsObject puu = PhysicsObject.CreateStaticObject(leveys, korkeus); 
     155        puu.Position = paikka; 
     156        puu.Image = puublock; 
     157        puu.CollisionIgnoreGroup = 1; 
     158        puu.IgnoresCollisionResponse = true; 
     159        Add(puu, -1); 
     160    } 
     161 
     162    void LuoLehdet(Vector paikka, double leveys, double korkeus) 
     163    { 
     164        PhysicsObject lehdet = PhysicsObject.CreateStaticObject(leveys, korkeus); 
     165        lehdet.Position = paikka; 
     166        lehdet.Image = lehdetblock; 
     167        lehdet.CollisionIgnoreGroup = 1; 
     168        lehdet.IgnoresCollisionResponse = true; 
     169        Add(lehdet, -1); 
     170    } 
     171 
     172    void LuoVesi(Vector paikka, double leveys, double korkeus) 
     173    { 
     174        PhysicsObject vesi = PhysicsObject.CreateStaticObject(leveys, korkeus); 
     175        vesi.Position = paikka; 
     176        vesi.Image = vesiblock; 
     177        vesi.CollisionIgnoreGroup = 1; 
     178        vesi.IgnoresCollisionResponse = true; 
     179        Add(vesi, -1); 
     180    } 
     181 
     182    void LuoVihollinen(Vector paikka, double leveys, double korkeus) 
     183    { 
     184        Vihuclass lentava = new Vihuclass(50, 50); 
     185        lentava.Position = paikka; 
     186        lentava.Shape = Shape.Circle; 
     187        FollowerBrain seuraajanAivot1 = new FollowerBrain(hahmo); 
     188        seuraajanAivot1.Speed = 100; 
     189        lentava.IgnoresGravity = true; 
     190        //seuraajanAivot1.DistanceFar = 500; 
     191        //seuraajanAivot1.DistanceClose = 100; 
     192        //seuraajanAivot1.StopWhenTargetClose = true; 
     193        //seuraajanAivot1.TargetClose += vihulahella; 
     194        lentava.Animation = new Animation(flyer); 
     195        lentava.Animation.Start(); 
     196        lentava.Animation.FPS = 10; 
     197        lentava.CanRotate = false; 
     198        lentava.Brain = seuraajanAivot1; 
     199        LaserGun lentavagun = new LaserGun(10, 10); 
     200        lentavagun.Ammo.Value = 10000; 
     201        //lentavagun.ProjectileCollision = AmmusOsui; 
     202        lentavagun.Image = null; 
     203        lentavagun.Color = Color.Transparent; 
     204        lentava.Tag = "vihollinen"; 
    24205         
    25  
    26  
    27         PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
    28         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    29     } 
    30  
    31     void Luokentta() 
    32     { 
    33         Level.CreateBorders(false); 
    34         Hahmo = new PlatformCharacter(75, 75); 
    35         Hahmo.AnimWalk = new Animation(hahmojuoksu); 
    36         Hahmo.AnimWalk.FPS = 10; 
    37         Hahmo.AnimIdle = new Animation(hahmostand); 
    38         Hahmo.AnimJump = new Animation(hahmojump); 
    39         Hahmo.AnimFall = new Animation(hahmofall); 
    40         Hahmo.Weapon = new Cannon(30, 30); 
    41          
    42         Add(Hahmo); 
    43  
    44         //Hahmo.CanRotate = false; 
    45         //Hahmo.Restitution = 0.5; 
    46  
    47  
    48          
    49     } 
     206        lentava.Add(lentavagun); 
     207 
     208        Timer ajastin = new Timer(); 
     209        ajastin.Interval = 1.0; 
     210        ajastin.Timeout += delegate { VihollinenAmpuu(lentava, lentavagun, ajastin); }; 
     211        ajastin.Start(); 
     212        Add(lentava); 
     213    } 
     214 
     215    void AmmusViholliseen(PhysicsObject ammus, Vihuclass lentava) 
     216    { 
     217        lentava.Hitpoints.Value -= 1; 
     218        //pisteet.value += 1; 
     219 
     220    } 
     221 
     222    void VihollinenAmpuu(PhysicsObject lentava, LaserGun lentavagun, Timer ajastin) 
     223    { 
     224        if (lentava.IsDestroyed == true) 
     225        { 
     226            ajastin.Stop(); 
     227            return; 
     228        } 
     229 
     230        Vector suunta = (hahmo.Position - lentava.Position); 
     231        if (suunta.Magnitude < 600) 
     232        { 
     233            lentavagun.Angle = suunta.Angle; 
     234            PhysicsObject ammus2 = lentavagun.Shoot(); 
     235 
     236            if (ammus2 != null) 
     237            { 
     238                ammus2.Shape = Shape.Circle; 
     239                ammus2.Size = new Vector(10, 10); 
     240                ammus2.Image = panos2; 
     241                AddCollisionHandler(ammus2, CollisionHandler.DestroyObject); 
     242 
     243 
     244 
     245            } 
     246        } 
     247    } 
     248 
     249     
     250 
     251    void vihulahella(Vector paikka, double leveys, double korkeus) 
     252    { 
     253 
     254    } 
     255 
     256     
    50257 
    51258    void Ohjaus() 
     
    53260        Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaHahmoa, "Pelaaja liiku vasemmalle", -400.0); 
    54261        Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaHahmoa, "Pelaaja liiku oikealle", 400.0); 
    55         Keyboard.Listen(Key.Space, ButtonState.Pressed, hyppy, "Pelaaja hyppää", 800.0); 
    56  
     262        Keyboard.Listen(Key.Space, ButtonState.Pressed, hyppy, "Pelaaja hyppää", 650.0); 
     263        Keyboard.Listen(Key.A, ButtonState.Pressed, AmmuAseella, "Ammu", hahmo); 
    57264    } 
    58265 
    59266    void LiikutaHahmoa(double vektori) 
    60267    { 
    61         Hahmo.Walk(vektori); 
    62  
    63  
     268        hahmo.Walk(vektori); 
    64269    } 
    65270 
    66271    void hyppy(double hyppyvoima) 
    67272    { 
    68         Hahmo.Jump(hyppyvoima); 
    69     } 
     273        hahmo.Jump(hyppyvoima); 
     274    } 
     275 
     276    void AmmuAseella(PlatformCharacter hahmo) 
     277    { 
     278        PhysicsObject ammus = hahmo.Weapon.Shoot(); 
     279        hahmo.PlayAnimation(tahtaa); 
     280        //hahmo.Animation = new Animation(tahtaa); 
     281        //hahmo.Animation.Start(1); 
     282 
     283        if (ammus != null) 
     284        { 
     285            ammus.Shape = Shape.Circle; 
     286            ammus.Size = new Vector(10, 10); 
     287            ammus.Image = panos; 
     288            AddCollisionHandler(ammus, CollisionHandler.DestroyObject); 
     289            AddCollisionHandler<PhysicsObject, Vihuclass>(ammus, "vihollinen", AmmusViholliseen); 
     290        } 
     291    } 
     292 
     293    
    70294 
    71295} 
  • 2012/30/JesseN/Oma peli/OmaPeli/OmaPeli/OmaPeli/OmaPeli.csproj

    r3724 r3751  
    111111  </ItemGroup> 
    112112  <ItemGroup> 
     113    <Compile Include="HahmoClass.cs" /> 
    113114    <Compile Include="Ohjelma.cs" /> 
    114115    <Compile Include="OmaPeli.cs" /> 
    115116    <Compile Include="Properties\AssemblyInfo.cs" /> 
     117    <Compile Include="Vihuclass.cs" /> 
    116118  </ItemGroup> 
    117119  <ItemGroup> 
  • 2012/30/JesseN/Oma peli/OmaPeli/OmaPeli/OmaPeliContent/OmaPeliContent.contentproj

    r3724 r3751  
    110110    </Compile> 
    111111  </ItemGroup> 
     112  <ItemGroup> 
     113    <Compile Include="EnemyFlying1.png"> 
     114      <Name>EnemyFlying1</Name> 
     115      <Importer>TextureImporter</Importer> 
     116      <Processor>TextureProcessor</Processor> 
     117    </Compile> 
     118  </ItemGroup> 
     119  <ItemGroup> 
     120    <Compile Include="EnemyFlying2.png"> 
     121      <Name>EnemyFlying2</Name> 
     122      <Importer>TextureImporter</Importer> 
     123      <Processor>TextureProcessor</Processor> 
     124    </Compile> 
     125  </ItemGroup> 
     126  <ItemGroup> 
     127    <Compile Include="EnemyFlying3.png"> 
     128      <Name>EnemyFlying3</Name> 
     129      <Importer>TextureImporter</Importer> 
     130      <Processor>TextureProcessor</Processor> 
     131    </Compile> 
     132  </ItemGroup> 
     133  <ItemGroup> 
     134    <Compile Include="EnemyFlying4.png"> 
     135      <Name>EnemyFlying4</Name> 
     136      <Importer>TextureImporter</Importer> 
     137      <Processor>TextureProcessor</Processor> 
     138    </Compile> 
     139  </ItemGroup> 
     140  <ItemGroup> 
     141    <Compile Include="Level1.png"> 
     142      <Name>Level1</Name> 
     143      <Importer>TextureImporter</Importer> 
     144      <Processor>TextureProcessor</Processor> 
     145    </Compile> 
     146  </ItemGroup> 
     147  <ItemGroup> 
     148    <Compile Include="Dirt.png"> 
     149      <Name>Dirt</Name> 
     150      <Importer>TextureImporter</Importer> 
     151      <Processor>TextureProcessor</Processor> 
     152    </Compile> 
     153  </ItemGroup> 
     154  <ItemGroup> 
     155    <Compile Include="Leaves.png"> 
     156      <Name>Leaves</Name> 
     157      <Importer>TextureImporter</Importer> 
     158      <Processor>TextureProcessor</Processor> 
     159    </Compile> 
     160  </ItemGroup> 
     161  <ItemGroup> 
     162    <Compile Include="Grass.png"> 
     163      <Name>Grass</Name> 
     164      <Importer>TextureImporter</Importer> 
     165      <Processor>TextureProcessor</Processor> 
     166    </Compile> 
     167  </ItemGroup> 
     168  <ItemGroup> 
     169    <Compile Include="Water.png"> 
     170      <Name>Water</Name> 
     171      <Importer>TextureImporter</Importer> 
     172      <Processor>TextureProcessor</Processor> 
     173    </Compile> 
     174  </ItemGroup> 
     175  <ItemGroup> 
     176    <Compile Include="Wood.png"> 
     177      <Name>Wood</Name> 
     178      <Importer>TextureImporter</Importer> 
     179      <Processor>TextureProcessor</Processor> 
     180    </Compile> 
     181  </ItemGroup> 
     182  <ItemGroup> 
     183    <Compile Include="Bullet2.png"> 
     184      <Name>Bullet2</Name> 
     185      <Importer>TextureImporter</Importer> 
     186      <Processor>TextureProcessor</Processor> 
     187    </Compile> 
     188  </ItemGroup> 
     189  <ItemGroup> 
     190    <Compile Include="Stone.png"> 
     191      <Name>Stone</Name> 
     192      <Importer>TextureImporter</Importer> 
     193      <Processor>TextureProcessor</Processor> 
     194    </Compile> 
     195  </ItemGroup> 
    112196  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    113197  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
Note: See TracChangeset for help on using the changeset viewer.