Changeset 4219 for 2013/26


Ignore:
Timestamp:
2013-06-25 14:50:21 (10 years ago)
Author:
juiitamm
Message:

Talletus.

Location:
2013/26/OtsoR/Projekti/Projekti
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • 2013/26/OtsoR/Projekti/Projekti/Projekti/Projekti.cs

    r4203 r4219  
    77using Jypeli.Widgets; 
    88 
     9class Vihu : PhysicsObject 
     10{ 
     11    private IntMeter health = new IntMeter(3, 0, 3); 
     12    public IntMeter Health { get { return health; } } 
     13     
     14    public Vihu(double leveys, double korkeus, Shape muoto) 
     15        : base(leveys, korkeus, muoto) 
     16    { 
     17        ProgressBar elamaPalkki = new ProgressBar(6, 2.5); 
     18        elamaPalkki.BindTo(health); 
     19        Add(elamaPalkki); 
     20 
     21        health.LowerLimit += delegate {  
     22            this.Destroy();  
     23        }; 
     24    } 
     25} 
     26 
    927public class Projekti : PhysicsGame 
    1028{ 
     
    1331    Color[] shipcolors2 = { Color.Ruby, Color.Azure, Color.Emerald, Color.Emerald }; 
    1432    Image shell = LoadImage("bullet"); 
     33    Image pointer = LoadImage("pointer"); 
    1534 
    1635    String[] weaponnames = { "projectile","laser","plasma" }; 
     
    2544    PhysicsObject ship2; 
    2645    Weapon weapon2; 
    27     PhysicsObject hostile; 
     46    //PhysicsObject hostile; 
    2847    Weapon hostilew; 
     48    GameObject line; 
    2949 
    3050    Label number; 
    3151    Label number2; 
     52    Label colour; 
    3253    Label weaponlabel; 
    3354    Label weaponlabel2; 
     
    90111        Add(number); 
    91112 
     113        colour = new Label("style"); 
     114        colour.X = -125; 
     115        colour.Y = 125; 
     116        Add(colour); 
     117 
    92118        weaponlabel = new Label(weaponnames[0]); 
    93119        weaponlabel.X = 125; 
     
    150176        ship.CollisionIgnoreGroup = 1; 
    151177        ship.Tag = "player"; 
    152     } 
    153     void Createship2() 
     178        if (weapon is LaserGun) 
     179        { 
     180            line = new GameObject(5000, 1.25); 
     181            line.Image = pointer; 
     182            line.X = 2500; 
     183            ship.Add(line); 
     184        } 
     185    } 
     186    void Createship2()  
    154187    { 
    155188        ship2 = new PhysicsObject(16, 16, Shape.FromImage(Aluskuva2.Image)); 
     
    168201    void Spawnhostiles() 
    169202    { 
    170         int shipcounter = 0; 
    171  
    172         while (shipcounter < 5) 
     203        while (shipcounter < 25) 
    173204        { 
    174205        int hostileship = RandomGen.NextInt(0, 100); 
     
    184215            hostiley = RandomGen.NextDouble(Level.Bottom, Level.Top); 
    185216            hostilex = Level.Left + 2 * Level.Right * RandomGen.NextInt(0, 2); 
    186  
    187217        } 
    188218        Createhostile(hostileship, hostiley, hostilex); 
     
    192222    void Createhostile(int randomship, double randomy, double randomx) 
    193223    { 
    194         hostile = new PhysicsObject(16, 16, Shape.FromImage(shipimages[randomship])); 
     224        Vihu hostile = new Vihu(16, 16, Shape.FromImage(shipimages[randomship])); 
    195225        hostile.Image = shipimages[randomship]; 
    196226        hostile.Y = randomy; 
     
    207237        hostile.Image.ReplaceColor(Color.Black, Color.Emerald); 
    208238 
     239        hostile.Destroyed += death; 
     240 
    209241        PlasmaCannon hostilew = new PlasmaCannon(0, 0); 
    210242        hostilew.ProjectileCollision = weaponhit; 
     
    223255        hostile.Brain = brain; 
    224256    } 
     257    void death() 
     258    { 
     259        shipcounter--; 
     260        MediaPlayer.Play("Daah"); 
     261    } 
     262//    void Createhealthbar() 
     263//    { 
     264//        health = new DoubleMeter(10); 
     265//        health.MaxValue = 10; 
     266//        //healthbar.LowerLimit += ElamaLoppui; 
     267// 
     268//        ProgressBar healthbar = new ProgressBar(150, 20); 
     269//        healthbar.X = Screen.Left + 150; 
     270//        healthbar.Y = Screen.Top - 20; 
     271//        healthbar.BindTo(health); 
     272//        Add(healthbar); 
     273//    } 
    225274    void createedges() 
    226275    { 
     
    335384        foreach (Label valikonKohta2 in valikonKohdat2) 
    336385        { 
    337             Add(valikonKohta2); 
     386           Add(valikonKohta2); 
    338387        } 
    339388        Mouse.ListenOn(kohta2, MouseButton.Left, ButtonState.Pressed, coopbase, null); 
     
    347396                weapon.ProjectileCollision = weaponhit; 
    348397                weapon.FireRate = 4.5; 
     398                weapon.Power.Value = 100; 
     399                weapon.Power.DefaultValue = 100; 
    349400                break; 
    350401            case 2: 
     
    352403                weapon.ProjectileCollision = weaponhit; 
    353404                weapon.FireRate = 1; 
    354                 weapon.Power.DefaultValue = 3000; 
    355                 weapon.Power.Value = 3000; 
     405                weapon.Power.DefaultValue = 1200; 
     406                weapon.Power.Value = 1200; 
    356407                break; 
    357408            case 3: 
    358409                weapon = new PlasmaCannon(0, 0); 
    359410                weapon.ProjectileCollision = weaponhit; 
    360                 weapon.FireRate = 1; 
     411                weapon.FireRate = 1.5; 
    361412                weapon.Power.Value = 750; 
    362413                weapon.Power.DefaultValue = 750; 
     
    371422                weapon2 = new AssaultRifle(0, 0); 
    372423                weapon2.ProjectileCollision = weaponhit; 
    373                 weapon2.FireRate = 4; 
     424                weapon2.FireRate = 4.5; 
     425                weapon2.Power.Value = 100; 
     426                weapon2.Power.DefaultValue = 100; 
    374427                break; 
    375428            case 2: 
    376429                weapon2 = new LaserGun(0, 0); 
    377430                weapon2.ProjectileCollision = weaponhit; 
    378                 weapon2.FireRate = 0.5; 
     431                weapon2.FireRate = 1; 
     432                weapon2.Power.DefaultValue = 1200; 
     433                weapon2.Power.Value = 1200; 
    379434                break; 
    380435            case 3: 
    381436                weapon2 = new PlasmaCannon(0, 0); 
    382437                weapon2.ProjectileCollision = weaponhit; 
    383                 weapon2.FireRate = 2; 
     438                weapon2.FireRate = 1.5; 
     439                weapon2.Power.Value = 750; 
     440                weapon2.Power.DefaultValue = 750; 
    384441                break; 
    385442        } 
     
    401458                ammus.Image = shell; 
    402459                ammus.Size *=0.4; 
     460                AddCollisionHandler(ammus, CollisionHandler.DestroyObject); 
     461                ammus.CollisionIgnoreGroup = 4; 
    403462            } 
    404463            if (ase is LaserGun) 
    405464            { 
     465                ammus.Size *= 2; 
    406466                ammus.IgnoresCollisionResponse = true; 
    407467            } 
    408468            if (ase is PlasmaCannon) 
    409469            { 
    410                 ammus.Size *= 1.5; 
     470                ammus.Size *= 1.2; 
     471                AddCollisionHandler(ammus, CollisionHandler.DestroyObject); 
     472                ammus.IgnoresCollisionResponse = true; 
     473                ammus.CollisionIgnoreGroup = 3; 
    411474            } 
    412475        } 
     
    416479    void weaponhit(PhysicsObject ammus, PhysicsObject kohde) 
    417480    { 
    418         if (kohde.Tag == "hostile") kohde.Destroy(); 
    419         ammus.Destroy(); 
    420     } 
    421  
     481 
     482        if (kohde.Tag == "hostile") 
     483        { 
     484            Vihu vihollinen = kohde as Vihu; 
     485            vihollinen.Health.Value -= 1; 
     486        } 
     487    } 
     488    void Controlsship() 
     489    { 
     490        Keyboard.Listen(Key.W, ButtonState.Down, movement, null, 0, 100, ship); 
     491        Keyboard.Listen(Key.S, ButtonState.Down, movement, null, 0, -100, ship); 
     492        Keyboard.Listen(Key.A, ButtonState.Down, movement, null, -100, 0, ship); 
     493        Keyboard.Listen(Key.D, ButtonState.Down, movement, null, 100, 0, ship); 
     494        Keyboard.Listen(Key.Space, ButtonState.Down, fire, "", weapon); 
     495        Mouse.ListenMovement(0, Aim, ""); 
     496        Mouse.Listen(MouseButton.Left, ButtonState.Down, fire, "", weapon); 
     497        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     498    } 
     499    void Aim(AnalogState hiirenLiike) 
     500    { 
     501        Vector suunta = (Mouse.PositionOnWorld - ship.AbsolutePosition).Normalize(); 
     502        ship.Angle = suunta.Angle; 
     503    } 
     504    void movement(int x, int y, PhysicsObject ship) 
     505    { 
     506        ship.Push(new Vector(x, y)); 
     507    } 
    422508    void Controlsship1() 
    423509    { 
     
    454540        Createship(); 
    455541        Spawnhostiles(); 
    456         Controlsship1(); 
     542        Controlsship(); 
    457543        Timer a = new Timer(); 
    458         a.Interval = 5; 
     544        a.Interval = 1; 
    459545        a.Timeout += Spawnhostiles; 
    460546        a.Start(); 
  • 2013/26/OtsoR/Projekti/Projekti/ProjektiContent/ProjektiContent.contentproj

    r4203 r4219  
    553553    </Compile> 
    554554  </ItemGroup> 
     555  <ItemGroup> 
     556    <Compile Include="pointer.png"> 
     557      <Name>pointer</Name> 
     558      <Importer>TextureImporter</Importer> 
     559      <Processor>TextureProcessor</Processor> 
     560    </Compile> 
     561  </ItemGroup> 
     562  <ItemGroup> 
     563    <Compile Include="Daah.mp3"> 
     564      <Name>Daah</Name> 
     565      <Importer>Mp3Importer</Importer> 
     566      <Processor>SongProcessor</Processor> 
     567    </Compile> 
     568  </ItemGroup> 
    555569  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    556570  <!--  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.