Changeset 3678 for 2012/27


Ignore:
Timestamp:
2012-07-06 12:58:20 (11 years ago)
Author:
nivikinn
Message:

Talletus.

Location:
2012/27/NikoKi/EpicTankBattle/EpicTankBattle
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • 2012/27/NikoKi/EpicTankBattle/EpicTankBattle/EpicTankBattle/EpicTankBattle.cs

    r3611 r3678  
    1010{ 
    1111    public bool liikkumassa = false; 
     12    public IntMeter hp = new IntMeter(10, 0, 10); 
    1213    public Tankki(double leveys, double korkeus) 
    1314        : base(leveys, korkeus) 
     
    1617} 
    1718 
     19public class Ammus : PhysicsObject 
     20{ 
     21    public int tuhovoima = 1; 
     22    public Ammus(double leveys, double korkeus) 
     23        : base(leveys, korkeus) 
     24    { 
     25    } 
     26} 
     27 
    1828public class EpicTankBattle : PhysicsGame 
    1929{ 
     30    delegate Ammus AmmuksenLuoja(); 
     31 
     32 
    2033    Image Keltainentankki = LoadImage("Keltainentankki"); 
    2134    Image Sininentankki = LoadImage("Sininentankki"); 
     
    2639    Image Tykki = LoadImage("Tykki"); 
    2740    Image Rajahdys = LoadImage("Rajahdys"); 
     41    Image Kuula1 = LoadImage("Kuula1"); 
     42    Image Kuula2 = LoadImage("Kuula2"); 
     43    Image Kuula3 = LoadImage("Kuula3"); 
     44    Image Kuula4 = LoadImage("Kuula4"); 
     45    Image HP = LoadImage("HP"); 
     46    Image HPtausta = LoadImage("HPtausta"); 
    2847 
    2948 
     
    3655    Direction tankki2suunta = Direction.Left; 
    3756 
     57    AmmuksenLuoja[] LuoAmmus; 
     58    int P1ammus = 0; 
     59    int P2ammus = 0; 
     60 
     61    ExplosionSystem rajahdys = 
     62    new ExplosionSystem(LoadImage("Rajahdys"), 1000); 
     63 
    3864    public override void Begin() 
    3965    { 
    40         // TODO: Kirjoita ohjelmakoodisi tähän 
    41  
    42  
     66        MediaPlayer.Play("Musiikki"); 
     67        MediaPlayer.IsRepeating = true; 
     68 
     69        AlustaAmmukset(); 
     70        rajahdys.MaxScale = 0.01; 
     71        rajahdys.MaxLifetime = 0.001; 
     72        Add(rajahdys); 
     73 
     74        Level.Background.CreateGradient(Color.Silver, Color.Brown); 
     75        MultiSelectWindow alkuValikko = new MultiSelectWindow("EpicTankBattle", 
     76        "Aloita peli", "Lopeta"); 
     77        Add(alkuValikko); 
     78        alkuValikko.ItemSelected += PainettiinValikonNappia; 
    4379 
    4480        Gravity = new Vector(0, -2000); 
    45         //Level.CreateBorders(); 
    46         //Surface maasto = Surface.CreateBottom(Level, 20, 200, 20); 
    47         //Add(maasto); 
    4881 
    4982        ColorTileMap Ruudut = ColorTileMap.FromLevelAsset("Maapera"); 
     
    5184        Ruudut.Execute(20, 10); 
    5285 
    53         Level.CreateBorders(); 
     86        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     87        ylaReuna.Color = Color.Brown; 
     88        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     89        alaReuna.Color = Color.Brown; 
     90        PhysicsObject vasenReuna = Level.CreateLeftBorder(); 
     91        vasenReuna.Color = Color.Silver; 
     92        PhysicsObject oikeaReuna = Level.CreateRightBorder(); 
     93        oikeaReuna.Color = Color.Silver; 
     94 
     95         
    5496        Camera.StayInLevel = false; 
    5597        Camera.ZoomToLevel(); 
    56         /*Surface.CreateLeft(Level); 
    57         Surface.CreateRight(Level);*/ 
    5898 
    5999        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
     
    62102        P1 = new Tankki(40, 25); 
    63103        P1.Tag = "tankki"; 
    64         P1.Image = Punainentankki; 
     104        P1.hp.MaxValue = 50; 
     105        P1.hp.Value = 50; 
     106       // P1.Image = Punainentankki; 
     107        P1.Color = Color.Transparent; 
    65108        P1.PlatformTolerance = 1; 
    66109        P1.Acceleration = 0.6; 
    67110        P1.MaxVelocity = 3; 
    68111        P1.KineticFriction = 0; 
    69         Add(P1); 
     112         
     113 
     114        ProgressBar p1hpPalkki = new ProgressBar(150, 10); 
     115        p1hpPalkki.BindTo(P1.hp); 
     116        p1hpPalkki.BarColor = Color.Green; 
     117        p1hpPalkki.BorderColor = Color.White; 
     118        p1hpPalkki.Color = Color.Red; 
     119        p1hpPalkki.X = Screen.Left + 150; 
     120        p1hpPalkki.Y = Screen.Top - 70; 
     121        Add(p1hpPalkki); 
    70122 
    71123        P1tykki = new Cannon(60, 7); 
    72124        P1tykki.Tag = "tykki"; 
    73         P1tykki.Image = LoadImage("tykki"); 
     125       // P1tykki.Image = LoadImage("tykki"); 
     126        P1tykki.Color = Color.Transparent; 
    74127        P1tykki.Angle = Angle.StraightAngle; 
    75128        P1.Add(P1tykki); 
    76129 
     130         
     131 
    77132        P2 = new Tankki(40, 25); 
    78133        P2.Tag = "tankki"; 
    79         P2.Image = Vihreatankki; 
     134        P2.hp.MaxValue = 50; 
     135        P2.hp.Value = 50; 
     136       // P2.Image = Vihreatankki; 
     137        P2.Color = Color.Transparent; 
    80138        P2.PlatformTolerance = 1; 
    81139        P2.FacingDirection = Direction.Left; 
    82140        Add(P2); 
     141         
     142 
     143        ProgressBar p2hpPalkki = new ProgressBar(150, 10); 
     144        p2hpPalkki.BindTo(P2.hp); 
     145        p2hpPalkki.Angle += Angle.FromDegrees(180); 
     146        p2hpPalkki.BarColor = Color.Green; 
     147        p2hpPalkki.BorderColor = Color.White; 
     148        p2hpPalkki.Color = Color.Red; 
     149        p2hpPalkki.X = Screen.Right - 150; 
     150        p2hpPalkki.Y = Screen.Top - 70; 
     151        Add(p2hpPalkki); 
     152 
     153        P1.hp.LowerLimit += delegate 
     154        { 
     155            P1.Destroy(); 
     156            p1hpPalkki.Destroy(); 
     157            p2hpPalkki.Destroy(); 
     158            MessageDisplay.Add("Pelaaja1 kuoli"); 
     159            Timer.SingleShot(5.0, delegate 
     160            { 
     161                ClearAll(); 
     162                Begin(); 
     163            }); 
     164        }; 
     165        Add(P1); 
     166        P2.hp.LowerLimit += delegate 
     167        { 
     168            P2.Destroy(); 
     169            p1hpPalkki.Destroy(); 
     170            p2hpPalkki.Destroy(); 
     171            MessageDisplay.Add("Pelaaja2 kuoli"); 
     172            Timer.SingleShot(5.0, delegate 
     173            { 
     174                ClearAll(); 
     175                Begin(); 
     176            }); 
     177        }; 
     178        Add(P1); 
    83179 
    84180        P1.X = -700; 
     
    89185        P2tykki = new Cannon(60, 7); 
    90186        P2tykki.Tag = "tykki"; 
    91         P2tykki.Image = LoadImage("tykki"); 
     187       // P2tykki.Image = LoadImage("tykki"); 
     188        P1tykki.Color = Color.Transparent; 
    92189        P2.Add(P2tykki); 
    93190 
    94191        Nappaimisto(); 
     192    } 
     193 
     194    private void AlustaAmmukset() 
     195    { 
     196        LuoAmmus = new AmmuksenLuoja[4]; 
     197        LuoAmmus[0] = LuoPerusAmmus; 
     198        LuoAmmus[1] = LuoKakkosAmmus; 
     199        LuoAmmus[2] = LuoKolmosAmmus; 
     200        LuoAmmus[3] = LuoNelosAmmus; 
    95201    } 
    96202 
     
    135241        Keyboard.Listen(Key.LeftControl, ButtonState.Pressed, Ammu, null, P1, P1tykki); 
    136242        Keyboard.Listen(Key.RightControl, ButtonState.Pressed, Ammu, null, P2, P2tykki); 
     243 
     244        Keyboard.Listen(Key.LeftShift, ButtonState.Pressed, VaihdaP1, null); 
     245        Keyboard.Listen(Key.RightShift, ButtonState.Pressed, VaihdaP2, null); 
    137246 
    138247    } 
     
    192301        double tykinkulma = tykki.Angle.Degrees; 
    193302        double uusikulma; 
    194          
     303 
    195304        if (tankki1suunta == Direction.Right) 
    196305            uusikulma = tykinkulma + suunta; 
     
    198307            uusikulma = tykinkulma - suunta; 
    199308 
    200         if ( (tankki1suunta == Direction.Right && uusikulma <= -90 && uusikulma >= -180 ) || 
     309        if ((tankki1suunta == Direction.Right && uusikulma <= -90 && uusikulma >= -180) || 
    201310            (tankki1suunta == Direction.Left && uusikulma <= 0 && uusikulma >= -90)) 
    202311        { 
     
    224333    void Ammu(PhysicsObject pelaaja, Cannon tykki) 
    225334    { 
    226         PhysicsObject ammus = new PhysicsObject(30, 30); 
     335        PhysicsObject ammus; 
     336 
     337        if (pelaaja == P1) 
     338        { 
     339            ammus = LuoAmmus[P1ammus](); 
     340        } 
     341        else 
     342        { 
     343            ammus = LuoAmmus[P2ammus](); 
     344        } 
     345 
    227346        ammus.Position = pelaaja.Position - Vector.FromLengthAndAngle(tykki.Width / 2, tykki.Angle); 
    228347        //ammus.LifetimeLeft = TimeSpan.FromMilliseconds(500); 
     
    230349 
    231350        ammus.Hit(-2000 * Vector.FromAngle(tykki.Angle)); 
    232         AddCollisionHandler(ammus, "nelio", CollisionHandler.DestroyBoth); 
    233         AddCollisionHandler(ammus, "", CollisionHandler.DestroyObject); 
    234         AddCollisionHandler(ammus, "tankki", OsuuPelaajaan); 
    235     } 
    236  
    237     void OsuuPelaajaan(PhysicsObject ammus, PhysicsObject pelaaja) 
    238     { 
    239         pelaaja.Destroy(); 
     351        AddCollisionHandler(ammus, "nelio", Osuumaahan); 
     352        AddCollisionHandler(ammus, "", CollisionHandler.DestroyObject); // seiniä varten 
     353        AddCollisionHandler<PhysicsObject, Tankki>(ammus, "tankki", OsuuPelaajaan); 
     354    } 
     355 
     356    void Osuumaahan(PhysicsObject Ammus, PhysicsObject Maa) 
     357    { 
     358        Ammus.Destroy(); 
     359        Maa.Destroy(); 
     360        rajahdys.AddEffect(Maa.Position, 20); 
     361    } 
     362 
     363    void VaihdaP1() 
     364    { 
     365        P1ammus++; 
     366        if (P1ammus >= LuoAmmus.Length) P1ammus = 0; 
     367    } 
     368 
     369    void VaihdaP2() 
     370    { 
     371        P2ammus++; 
     372        if (P2ammus >= LuoAmmus.Length) P2ammus = 0; 
     373    } 
     374 
     375    Ammus LuoPerusAmmus() 
     376    { 
     377        Ammus ammus = new Ammus(10, 10); 
     378        ammus.tuhovoima = 2; 
     379        ammus.Image = Kuula1; 
     380        return ammus; 
     381    } 
     382 
     383    Ammus LuoKakkosAmmus() 
     384    { 
     385        Ammus ammus = new Ammus(15, 15); 
     386        ammus.tuhovoima = 4; 
     387        ammus.Image = Kuula2; 
     388        ammus.Mass = 1.3; 
     389        return ammus; 
     390    } 
     391 
     392    Ammus LuoKolmosAmmus() 
     393    { 
     394        Ammus ammus = new Ammus(20, 20); 
     395        ammus.Image = Kuula3; 
     396        ammus.tuhovoima = 8; 
     397        ammus.Mass = 1.7; 
     398        return ammus; 
     399    } 
     400 
     401    Ammus LuoNelosAmmus() 
     402    { 
     403        Ammus ammus = new Ammus(20, 35); 
     404        ammus.Image = Kuula4; 
     405        ammus.tuhovoima = 12; 
     406        ammus.Mass = 3; 
     407        return ammus; 
     408    } 
     409 
     410    void OsuuPelaajaan(PhysicsObject ammus, Tankki pelaaja) 
     411    { 
     412        pelaaja.hp.Value--; 
    240413    } 
    241414 
     
    247420        //Add(rajahdyssysteemi); 
    248421    } 
    249  
     422    void PainettiinValikonNappia(int valinta) 
     423    { 
     424        switch (valinta) 
     425        { 
     426            case 0: 
     427                Tankki1VariValikko(); 
     428                break; 
     429            case 1: 
     430                Exit(); 
     431                break; 
     432        } 
     433 
     434 
     435 
     436    } 
     437    void Tankki1VariValikko() 
     438    { 
     439        MultiSelectWindow P1VariValikko = new MultiSelectWindow("Valitse Pelaaja 1 väri", 
     440        "Punainen", "Vihreä", "Sininen", "Keltainen", "Valkoinen", "Musta"); 
     441        Add(P1VariValikko); 
     442        P1VariValikko.ItemSelected += PainettiinP1VariValikonNappia; 
     443    } 
     444    void PainettiinP1VariValikonNappia(int valinta2) 
     445    { 
     446        switch (valinta2) 
     447        { 
     448            case 0: 
     449                P1.Image = LoadImage("Punainentankki"); 
     450                P1tykki.Image = LoadImage("Tykki"); 
     451                Tankki2VariValikko(); 
     452 
     453                break; 
     454            case 1: 
     455                P1.Image = LoadImage("Vihreatankki"); 
     456                P1tykki.Image = LoadImage("Tykki"); 
     457                Tankki2VariValikko(); 
     458                break; 
     459            case 2: 
     460                P1.Image = LoadImage("Sininentankki"); 
     461                P1tykki.Image = LoadImage("Tykki"); 
     462                Tankki2VariValikko(); 
     463                break; 
     464            case 3: 
     465                P1.Image = LoadImage("Keltainentankki"); 
     466                P1tykki.Image = LoadImage("Tykki"); 
     467                Tankki2VariValikko(); 
     468                break; 
     469            case 4: 
     470                P1.Image = LoadImage("Valkoinentankki"); 
     471                P1tykki.Image = LoadImage("Tykki"); 
     472                Tankki2VariValikko(); 
     473                break; 
     474            case 5: 
     475                P1.Image = LoadImage("Mustatankki"); 
     476                P1tykki.Image = LoadImage("Tykki"); 
     477                Tankki2VariValikko(); 
     478                break; 
     479        } 
     480 
     481    } 
     482 
     483    void Tankki2VariValikko() 
     484    { 
     485        MultiSelectWindow P2VariValikko = new MultiSelectWindow("Valitse Pelaaja 2 väri", 
     486        "Punainen", "Vihreä", "Sininen", "Keltainen", "Valkoinen", "Musta"); 
     487        Add(P2VariValikko); 
     488        P2VariValikko.ItemSelected += PainettiinP2VariValikonNappia; 
     489    } 
     490    void PainettiinP2VariValikonNappia(int valinta3) 
     491    { 
     492        switch (valinta3) 
     493        { 
     494            case 0: 
     495                P2.Image = LoadImage("Punainentankki"); 
     496                P1tykki.Image = LoadImage("Tykki"); 
     497                break; 
     498            case 1: 
     499                P2.Image = LoadImage("Vihreatankki"); 
     500                P2tykki.Image = LoadImage("Tykki"); 
     501                break; 
     502            case 2: 
     503                P2.Image = LoadImage("Sininentankki"); 
     504                P2tykki.Image = LoadImage("Tykki"); 
     505                break; 
     506            case 3: 
     507                P2.Image = LoadImage("Keltainentankki"); 
     508                P2tykki.Image = LoadImage("Tykki"); 
     509                break; 
     510            case 4: 
     511                P2.Image = LoadImage("Valkoinentankki"); 
     512                P2tykki.Image = LoadImage("Tykki"); 
     513                break; 
     514            case 5: 
     515                P2.Image = LoadImage("Mustatankki"); 
     516                P2tykki.Image = LoadImage("Tykki"); 
     517                break; 
     518        } 
     519 
     520    } 
    250521} 
    251522 
  • 2012/27/NikoKi/EpicTankBattle/EpicTankBattle/EpicTankBattleContent/EpicTankBattleContent.contentproj

    r3588 r3678  
    127127    </Compile> 
    128128  </ItemGroup> 
     129  <ItemGroup> 
     130    <Compile Include="HP.png"> 
     131      <Name>HP</Name> 
     132      <Importer>TextureImporter</Importer> 
     133      <Processor>TextureProcessor</Processor> 
     134    </Compile> 
     135    <Compile Include="HPtausta.png"> 
     136      <Name>HPtausta</Name> 
     137      <Importer>TextureImporter</Importer> 
     138      <Processor>TextureProcessor</Processor> 
     139    </Compile> 
     140  </ItemGroup> 
     141  <ItemGroup> 
     142    <Compile Include="Musiikki.mp3"> 
     143      <Name>Musiikki</Name> 
     144      <Importer>Mp3Importer</Importer> 
     145      <Processor>SongProcessor</Processor> 
     146    </Compile> 
     147  </ItemGroup> 
    129148  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    130149  <!--  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.