Changeset 4245 for 2013/26


Ignore:
Timestamp:
2013-06-26 14:57:08 (10 years ago)
Author:
juiitamm
Message:

Talletus.

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

Legend:

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

    r4227 r4245  
    66using Jypeli.Effects; 
    77using Jypeli.Widgets; 
    8  
    9 class Vihu : PhysicsObject 
     8class Player : PhysicsObject 
     9{ 
     10    private IntMeter health = new IntMeter(100, 0, 100); 
     11    public IntMeter Health { get { return health; } } 
     12 
     13    public Player(double width, double height, Shape shape) 
     14        : base(width, height, shape) 
     15    { 
     16        ProgressBar playerhealth = new ProgressBar(8, 3); 
     17        playerhealth.BindTo(health); 
     18        playerhealth.BarColor = Color.Green; 
     19        playerhealth.BorderColor = Color.Red; 
     20        playerhealth.X = -8; 
     21        playerhealth.Angle = Angle.RightAngle; 
     22        Add(playerhealth); 
     23        health.LowerLimit += delegate 
     24        { 
     25            this.Destroy(); 
     26        }; 
     27    } 
     28} 
     29class Enemy : PhysicsObject 
    1030{ 
    1131    private IntMeter health = new IntMeter(5, 0, 5); 
    1232    public IntMeter Health { get { return health; } } 
    1333     
    14     public Vihu(double leveys, double korkeus, Shape muoto) 
     34    public Enemy(double leveys, double korkeus, Shape muoto) 
    1535        : base(leveys, korkeus, muoto) 
    1636    { 
    1737        ProgressBar enemyhealth = new ProgressBar(6, 2.5); 
    1838        enemyhealth.BindTo(health); 
     39        enemyhealth.X = -8; 
     40        enemyhealth.Angle = Angle.RightAngle; 
    1941        Add(enemyhealth); 
    20  
     42        health.LowerLimit += delegate { 
     43            this.Destroy(); 
     44        }; 
     45    } 
     46} 
     47class Boss : PhysicsObject 
     48{ 
     49    private IntMeter health = new IntMeter(100, 0, 100); 
     50    public IntMeter Health { get { return health; } } 
     51 
     52    public Boss(double leveys, double korkeus, Shape muoto) 
     53        : base(leveys, korkeus, muoto) 
     54    { 
     55        ProgressBar enemyhealth = new ProgressBar(6, 2.5); 
     56        enemyhealth.BindTo(health); 
     57        enemyhealth.X = -20; 
     58        enemyhealth.Angle = Angle.RightAngle; 
     59        Add(enemyhealth); 
    2160        health.LowerLimit += delegate { 
    2261            this.Destroy(); 
     
    2968    Color[] shipcolors = { Color.DarkGray, Color.Silver, Color.DarkOrange, Color.Ultramarine }; 
    3069    Color[] shipcolors2 = { Color.Ruby, Color.Azure, Color.Emerald, Color.Emerald }; 
     70    Image boss1 = LoadImage("boss1"); 
    3171    Image shell = LoadImage("bullet"); 
    3272    Image pointer = LoadImage("pointer"); 
     73    Image rdamage = LoadImage("rdamage"); 
     74    Image rrepair = LoadImage("rrepair"); 
    3375 
    3476    String[] weaponnames = { "projectile","laser","plasma" }; 
     
    3981    PhysicsObject rightedge; 
    4082     
    41     PhysicsObject ship; 
     83    Player ship; 
    4284    Weapon weapon; 
    43     PhysicsObject ship2; 
     85    Player ship2; 
    4486    Weapon weapon2; 
    4587    //PhysicsObject hostile; 
     
    61103    IntMeter shipwpn2; 
    62104    int shipcounter; 
     105    int bigshipcounter; 
     106    int bosscounter; 
     107    int runecounter; 
    63108    public override void Begin() 
    64109    { 
     
    161206        Aluskuva2.Image.ReplaceColor(Color.Black, shipcolors2[shipcolor2.Value - 1]); 
    162207    } 
    163     void Createship() 
    164     { 
    165         ship = new PhysicsObject(16, 16, Shape.FromImage(Aluskuva.Image)); 
     208    void Createship(double x, double y) 
     209    { 
     210        ship = new Player(16, 16, Shape.FromImage(Aluskuva.Image)); 
    166211        ship.Image = Aluskuva.Image; 
    167212        ship.Restitution = 1.0; 
     213        ship.X = x; 
     214        ship.Y = y; 
    168215        ship.KineticFriction = 0.0; 
    169216        ship.MomentOfInertia = Double.PositiveInfinity; 
     
    175222        ship.CollisionIgnoreGroup = 1; 
    176223        ship.Tag = "player"; 
     224        ship.Destroyed += playerdeath; 
    177225        if (weapon is LaserGun) 
    178226        { 
     
    183231        } 
    184232    } 
    185     void Createship2()  
    186     { 
    187         ship2 = new PhysicsObject(16, 16, Shape.FromImage(Aluskuva2.Image)); 
     233    void Createship2(double x, double y) 
     234    { 
     235        ship2 = new Player(16, 16, Shape.FromImage(Aluskuva2.Image)); 
    188236        ship2.Image = Aluskuva2.Image; 
     237        ship2.X = x; 
     238        ship2.Y = y; 
    189239        ship2.Restitution = 1.0; 
    190240        ship2.KineticFriction = 0.0; 
     
    197247        ship2.CollisionIgnoreGroup = 1; 
    198248        ship2.Tag = "player"; 
     249        ship2.Destroyed += playerdeath; 
     250        if (weapon is LaserGun) 
     251        { 
     252            line = new GameObject(5000, 1.25); 
     253            line.Image = pointer; 
     254            line.X = 2500; 
     255            ship.Add(line); 
     256        } 
    199257    } 
    200258    void Spawnhostiles() 
    201259    { 
    202         while (shipcounter < 25) 
     260        while (shipcounter < 36) 
    203261        { 
    204262        int hostileship = RandomGen.NextInt(0, 100); 
     
    218276        shipcounter++; 
    219277        } 
     278        while (bigshipcounter < 4) 
     279        { 
     280            double bighostiley = 0.0; 
     281            double bighostilex = 0.0; 
     282            if (RandomGen.NextBool()) 
     283            { 
     284                bighostiley = Level.Bottom + 2 * Level.Top * RandomGen.NextInt(0, 2); 
     285                bighostilex = RandomGen.NextDouble(Level.Left, Level.Right); 
     286            } 
     287            else 
     288            { 
     289                bighostiley = RandomGen.NextDouble(Level.Bottom, Level.Top); 
     290                bighostilex = Level.Left + 2 * Level.Right * RandomGen.NextInt(0, 2); 
     291            } 
     292            Createbighostile(bighostiley, bighostilex); 
     293            bigshipcounter++; 
     294        } 
    220295    } 
    221296    void Createhostile(int randomship, double randomy, double randomx) 
    222297    { 
    223         Vihu hostile = new Vihu(16, 16, Shape.FromImage(shipimages[randomship])); 
     298        Enemy hostile = new Enemy(16, 16, Shape.FromImage(shipimages[randomship])); 
    224299        hostile.Image = shipimages[randomship]; 
    225300        hostile.Y = randomy; 
     
    231306        hostile.AngularDamping = 1; 
    232307        hostile.Tag = "hostile"; 
    233         Add(hostile); 
     308        hostile.Health.MaxValue = 5; 
     309        hostile.Health.Value = 5; 
    234310        hostile.CollisionIgnoreGroup = 2; 
    235311        hostile.Image.ReplaceColor(Color.White, Color.Ultramarine); 
    236312        hostile.Image.ReplaceColor(Color.Black, Color.Emerald); 
    237  
    238         hostile.Destroyed += death; 
    239  
    240         PlasmaCannon hostilew = new PlasmaCannon(0, 0); 
    241         hostilew.ProjectileCollision = plasmahit; 
     313        Add(hostile); 
     314 
     315        hostile.Destroyed += enemydeath; 
     316 
     317        AssaultRifle hostilew = new AssaultRifle(0, 0); 
     318        hostilew.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 10, 0); }; 
    242319        hostilew.FireRate = 0.5; 
    243         hostilew.Power.DefaultValue = 700; 
    244         hostilew.Power.Value = 700; 
     320        hostilew.Power.DefaultValue = 20; 
     321        hostilew.Power.Value = 20; 
    245322        hostile.Add(hostilew); 
    246323 
     
    248325        brain.Speed = 20; 
    249326        brain.DistanceFar = 10000; 
    250         brain.DistanceClose = 200; 
     327        brain.DistanceClose = 125; 
    251328        brain.StopWhenTargetClose = false; 
    252329        brain.TargetClose += delegate { fire(hostilew); }; 
     
    254331        hostile.Brain = brain; 
    255332    } 
    256     void death() 
     333    void Createbighostile(double y, double x) 
     334    { 
     335        Enemy Big1 = new Enemy(25, 29, Shape.FromImage(boss1)); 
     336        Big1.Image = boss1; 
     337        Big1.X = x; 
     338        Big1.Y = y; 
     339        Big1.Restitution = 1.0; 
     340        Big1.KineticFriction = 0.0; 
     341        Big1.MomentOfInertia = Double.PositiveInfinity; 
     342        Big1.LinearDamping = 0.95; 
     343        Big1.AngularDamping = 1; 
     344        Big1.Tag = "hostile"; 
     345        Big1.Health.MaxValue = 40; 
     346        Big1.Health.Value = 40; 
     347        Big1.CollisionIgnoreGroup = 2; 
     348        Big1.Image.ReplaceColor(Color.White, Color.Ultramarine); 
     349        Big1.Image.ReplaceColor(Color.Black, Color.Emerald); 
     350        Add(Big1); 
     351        Big1.Destroyed += bigenemydeath; 
     352 
     353        PlasmaCannon Big1w = new PlasmaCannon(0, 0); 
     354        Big1w.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 3, 0); }; 
     355        Big1w.FireRate = 1.5; 
     356        Big1w.Power.DefaultValue = 300; 
     357        Big1w.Power.Value = 300; 
     358        Big1.Add(Big1w); 
     359 
     360        FollowerBrain bigbrain1 = new FollowerBrain("player"); 
     361        bigbrain1.Speed = 15; 
     362        bigbrain1.DistanceFar = 10000; 
     363        bigbrain1.DistanceClose = 200; 
     364        bigbrain1.TurnSpeed = UnlimitedAngle.FromDegrees(10); 
     365        bigbrain1.StopWhenTargetClose = false; 
     366        bigbrain1.TargetClose += delegate { fire(Big1w); }; 
     367        bigbrain1.TurnWhileMoving = true; 
     368        Big1.Brain = bigbrain1; 
     369    } 
     370    void playerdeath() 
     371    { 
     372        MessageDisplay.Add("A player's ship has been destroyed"); 
     373        //MediaPlayer.Play("playerdeath"); 
     374    } 
     375    void enemydeath() 
    257376    { 
    258377        shipcounter--; 
    259         MediaPlayer.Play("Daah"); 
    260     } 
    261 //    void Createhealthbar() 
    262 //    { 
    263 //        health = new DoubleMeter(10); 
    264 //        health.MaxValue = 100; 
    265 //        //healthbar.LowerLimit += ElamaLoppui; 
    266 // 
    267 //        ProgressBar healthbar = new ProgressBar(150, 20); 
    268 //        healthbar.X = Screen.Left + 150; 
    269 //        healthbar.Y = Screen.Top - 20; 
    270 //        healthbar.BindTo(health); 
    271 //        Add(healthbar); 
    272 //    } 
     378    } 
     379    void bigenemydeath() 
     380    { 
     381        bigshipcounter--; 
     382    } 
     383    void boss1death() 
     384    { 
     385    } 
     386    void boss2death() 
     387    { 
     388    } 
    273389    void createedges() 
    274390    { 
     
    367483        shipweapon2.Y = 150; 
    368484        shipweapon2.BindTo(shipwpn2); 
    369  
    370485        Add(shiptype); 
    371486        Add(shipcolour); 
     
    374489        Add(shipcolour2); 
    375490        Add(shipweapon2); 
    376  
    377491        List<Label> valikonKohdat2; 
    378492        valikonKohdat2 = new List<Label>(); // Alustetaan lista, johon valikon kohdat tulevat 
     
    393507            case 1: 
    394508                weapon = new AssaultRifle(0, 0); 
    395                 weapon.ProjectileCollision = projectilehit; 
     509                weapon.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 0, 1); }; 
    396510                weapon.FireRate = 4.5; 
    397511                weapon.Power.Value = 100; 
     
    400514            case 2: 
    401515                weapon = new LaserGun(0, 0); 
    402                 weapon.ProjectileCollision = laserhit; 
    403                 weapon.FireRate = 1; 
    404                 weapon.Power.DefaultValue = 1200; 
    405                 weapon.Power.Value = 1200; 
     516                weapon.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 0, 5); }; 
     517                weapon.FireRate = 0.8; 
     518                weapon.Power.DefaultValue = 1000; 
     519                weapon.Power.Value = 1000; 
    406520                break; 
    407521            case 3: 
    408522                weapon = new PlasmaCannon(0, 0); 
    409                 weapon.ProjectileCollision = plasmahit; 
     523                weapon.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 0, 3); }; 
    410524                weapon.FireRate = 1.5; 
    411525                weapon.Power.Value = 750; 
     
    420534            case 1: 
    421535                weapon2 = new AssaultRifle(0, 0); 
    422                 weapon2.ProjectileCollision = projectilehit; 
     536                weapon2.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 0, 1); }; 
    423537                weapon2.FireRate = 4.5; 
    424538                weapon2.Power.Value = 100; 
     
    427541            case 2: 
    428542                weapon2 = new LaserGun(0, 0); 
    429                 weapon2.ProjectileCollision = laserhit; 
     543                weapon2.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 0, 5); }; 
    430544                weapon2.FireRate = 1; 
    431                 weapon2.Power.DefaultValue = 1200; 
    432                 weapon2.Power.Value = 1200; 
     545                weapon2.Power.DefaultValue = 1000; 
     546                weapon2.Power.Value = 1000; 
    433547                break; 
    434548            case 3: 
    435549                weapon2 = new PlasmaCannon(0, 0); 
    436                 weapon2.ProjectileCollision = plasmahit; 
     550                weapon2.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 0, 3); }; 
    437551                weapon2.FireRate = 1.5; 
    438552                weapon2.Power.Value = 750; 
     
    455569                ammus.IgnoresCollisionResponse = true; 
    456570                ammus.Image = shell; 
    457                 ammus.Size *=0.4; 
     571                ammus.Size *= 0.4; 
     572                ammus.CollisionIgnoreGroup = 4; 
    458573                AddCollisionHandler(ammus, CollisionHandler.DestroyObject); 
    459                 ammus.CollisionIgnoreGroup = 4; 
    460574            } 
    461575            if (ase is LaserGun) 
     
    473587        } 
    474588    } 
    475     void projectilehit(PhysicsObject ammus, PhysicsObject kohde) 
    476     { 
     589    void weaponhit(PhysicsObject ammus, PhysicsObject kohde, int playerDamage, int enemyDamage) 
     590    { 
     591        if (kohde.Tag == "player") 
     592        { 
     593            Player ship = kohde as Player; 
     594            //ship.Health.Value -= 3; 
     595            ship.Health.Value -= playerDamage; 
     596        } 
    477597        if (kohde.Tag == "hostile") 
    478598        { 
    479             Vihu vihollinen = kohde as Vihu; 
    480             vihollinen.Health.Value -= 1; 
    481         } 
    482     } 
    483     void laserhit(PhysicsObject ammus, PhysicsObject kohde) 
    484     { 
    485         if (kohde.Tag == "hostile") 
    486         { 
    487             Vihu vihollinen = kohde as Vihu; 
    488             vihollinen.Health.Value -= 5; 
    489         } 
    490     } 
    491     void plasmahit(PhysicsObject ammus, PhysicsObject kohde) 
    492     { 
    493         if (kohde.Tag == "hostile") 
    494         { 
    495             Vihu vihollinen = kohde as Vihu; 
    496             vihollinen.Health.Value -= 3; 
     599            Enemy ship = kohde as Enemy; 
     600            //ship.Health.Value -= 1; 
     601            ship.Health.Value -= enemyDamage; 
    497602        } 
    498603    } 
     
    504609        Keyboard.Listen(Key.D, ButtonState.Down, movement, null, 100, 0, ship); 
    505610        Keyboard.Listen(Key.Space, ButtonState.Down, fire, "", weapon); 
    506         Mouse.ListenMovement(0, Aim, ""); 
    507         Mouse.Listen(MouseButton.Left, ButtonState.Down, fire, "", weapon); 
    508         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    509     } 
    510     void Aim(AnalogState hiirenLiike) 
     611        Mouse.ListenMovement(0, Aim, null, ship); 
     612        Mouse.Listen(MouseButton.Left, ButtonState.Down, fire, null, weapon); 
     613        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, null); 
     614    } 
     615    void Aim(AnalogState hiirenLiike, Player ship) 
    511616    { 
    512617        Vector suunta = (Mouse.PositionOnWorld - ship.AbsolutePosition).Normalize(); 
     
    534639        Keyboard.Listen(Key.Add, ButtonState.Down, fire, "", weapon2); 
    535640    } 
    536     void thrust(double direction, PhysicsObject ship) 
     641    void thrust(double direction, Player ship) 
    537642    { 
    538643        Vector shipdirection = Vector.FromLengthAndAngle(100.0*direction, ship.Angle); 
    539644        ship.Push(shipdirection); 
    540645    } 
    541     void tilt(double direction, PhysicsObject ship) 
     646    void tilt(double direction, Player ship) 
    542647    { 
    543648        ship.AngularAcceleration = 10.0*direction; 
     
    549654        Level.CreateBorders(); 
    550655        Camera.ZoomToLevel(); 
    551         Createship(); 
     656        Createship(0, 0); 
    552657        Spawnhostiles(); 
    553658        Controlsship(); 
     
    564669        Level.CreateBorders(); 
    565670        Camera.ZoomToLevel(); 
    566         Createship(); 
    567         Createship2(); 
     671        Createship(-100, 0); 
     672        Createship2(100, 0); 
    568673        Spawnhostiles(); 
    569674        Controlsship1(); 
     
    575680        a.Start(); 
    576681    } 
     682    void Spawnrunes() 
     683    { 
     684        while (runecounter < 5) 
     685        { 
     686            int runetype = RandomGen.NextInt(0, 2); 
     687            double runey = 0.0; 
     688            double runex = 0.0; 
     689            if (RandomGen.NextBool()) 
     690            { 
     691                runey = Level.Bottom + 2 * Level.Top * RandomGen.NextInt(0, 2); 
     692                runex = RandomGen.NextDouble(Level.Left, Level.Right); 
     693            } 
     694            else 
     695            { 
     696                runey = RandomGen.NextDouble(Level.Bottom, Level.Top); 
     697                runex = Level.Left + 2 * Level.Right * RandomGen.NextInt(0, 2); 
     698            } 
     699            Createhostile(runetype, runey, runex); 
     700            runecounter++; 
     701        } 
     702    } 
     703    void Createrune(int runetype, double y, double x) 
     704    { 
     705 
     706        PhysicsObject Rune = new PhysicsObject(5, 5); 
     707        Rune.X = x; 
     708        Rune.Y = y; 
     709        Rune.CollisionIgnoreGroup = 2 & 3 & 4; 
     710 
     711        switch (runetype) 
     712        { 
     713            case 1: 
     714                //Addcollision 
     715                Rune.Image = rdamage; 
     716                break; 
     717            case 2: 
     718                //Addcollision 
     719                Rune.Image = rrepair; 
     720                break; 
     721            case 3: 
     722                //Addcollision 
     723                //Rune.Image = ...; 
     724                break; 
     725        } 
     726    } 
    577727} 
  • 2013/26/OtsoR/Projekti/Projekti/ProjektiContent/ProjektiContent.contentproj

    r4219 r4245  
    561561  </ItemGroup> 
    562562  <ItemGroup> 
    563     <Compile Include="Daah.mp3"> 
    564       <Name>Daah</Name> 
    565       <Importer>Mp3Importer</Importer> 
    566       <Processor>SongProcessor</Processor> 
     563    <Compile Include="boss1.png"> 
     564      <Name>boss1</Name> 
     565      <Importer>TextureImporter</Importer> 
     566      <Processor>TextureProcessor</Processor> 
     567    </Compile> 
     568  </ItemGroup> 
     569  <ItemGroup> 
     570    <Compile Include="rdamage.png"> 
     571      <Name>rdamage</Name> 
     572      <Importer>TextureImporter</Importer> 
     573      <Processor>TextureProcessor</Processor> 
     574    </Compile> 
     575    <Compile Include="rrepair.png"> 
     576      <Name>rrepair</Name> 
     577      <Importer>TextureImporter</Importer> 
     578      <Processor>TextureProcessor</Processor> 
    567579    </Compile> 
    568580  </ItemGroup> 
Note: See TracChangeset for help on using the changeset viewer.