Changeset 8216


Ignore:
Timestamp:
2016-07-28 14:56:32 (7 years ago)
Author:
pybesilt
Message:

Tein vihollisille liikeradan ja paransin luotien osumis fysiikoita. aloin tekemään myös toista vihollista

Location:
2016/30/PyryS/Peli
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 2016/30/PyryS/Peli/Peli/Peli/Peli.cs

    r8171 r8216  
    66using Jypeli.Effects; 
    77using Jypeli.Widgets; 
     8using System.Collections.Generic; 
    89 
    910public class Peli : PhysicsGame 
     
    1516    Vector nopeusVasempaan = new Vector(-50000, 0); 
    1617 
    17     AssaultRifle vihu1Laser; 
     18    Pelaaja pelaaja; 
    1819    AssaultRifle pelaajanAse; 
    19  
    20     PhysicsObject wihu; 
    21     PhysicsObject vihu; 
    22     PhysicsObject pelaaja; 
     20     
    2321    PhysicsObject oikeareuna; 
    2422    PhysicsObject vasenreuna; 
    2523     
     24     
    2625    public override void Begin() 
    2726    { 
     
    2928         
    3029        Leveli(); 
     30        LuoPelaaja(0, -400); 
    3131        Ohjaimet(); 
    32          
    33  
    34  
    35         PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
     32        Vihollinen2Ase(); 
     33        Vihollinen2(Level.Right, 0); 
     34 
     35        Timer vihuSpawnausAika = new Timer(); 
     36        vihuSpawnausAika.Interval = 2.0; 
     37        vihuSpawnausAika.Timeout += delegate { LuoVihollinen(Level.Right, 20); }; 
     38        vihuSpawnausAika.Start(7); 
     39         
     40 
     41 
     42 
     43 
    3644        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    3745    } 
     
    3947    void LuoVihollinen(double x, double y) 
    4048    { 
    41         Vihollinen vihu1 = new Vihollinen(40.0, 40.0);  
     49        Vihollinen vihu1 = new Vihollinen(x, y);  
    4250        vihu1.X = x; 
    4351        vihu1.Y = y; 
     52        vihu1.LifetimeLeft = TimeSpan.FromSeconds(10.0); 
    4453        //vihu1.CollisionIgnoreGroup = 1; 
     54        AddCollisionHandler(vihu1, "joku", CollisionHandler.AddMeterValue(vihu1.VihuHealth, -1)); 
     55        vihu1.CanRotate = false; 
     56        vihu1.CollisionIgnoreGroup = 3; 
    4557        Add(vihu1); 
     58         
    4659 
    4760    //AddCollisionHandler(vihu1, "joku", VihuunOsuu); 
    48         vihu1Laser = new AssaultRifle(30, 10); 
     61        AssaultRifle vihu1Laser = new AssaultRifle(30, 10); 
    4962        vihu1Laser.InfiniteAmmo = true; 
     63        vihu1Laser.Angle = Angle.FromDegrees(-90); 
    5064        vihu1Laser.ProjectileCollision = VihuOsuu; 
    5165        vihu1.Add(vihu1Laser); 
    5266 
    5367        Timer ammusajastin = new Timer(); 
    54         ammusajastin.Interval = 1.5; 
    55         ammusajastin.Timeout += V1LaserAmpuu; 
     68        ammusajastin.Interval = 0.2; 
     69        ammusajastin.Timeout += delegate() { V1LaserAmpuu(vihu1Laser); }; 
    5670        ammusajastin.Start(); 
    5771         
    5872 
    59  
    60           
    61 } 
    62     void Leveli() 
    63     { 
    64  
    65         pelaaja = new PhysicsObject(40.0, 40.0); 
     73        PathFollowerBrain vihu1Aivot = new PathFollowerBrain(200); 
     74 
     75 
     76 
     77        List<Vector> polku = new List<Vector>(); 
     78        polku.Add(new Vector(Level.Right, 0)); 
     79        polku.Add(new Vector(Level.Right - 50, 0)); 
     80        polku.Add(new Vector(Level.Right - 100, 10)); 
     81        polku.Add(new Vector(Level.Right - 200, 50)); 
     82        polku.Add(new Vector(Level.Right - 250, 100)); 
     83        polku.Add(new Vector(Level.Right - 300, 125)); 
     84        polku.Add(new Vector(Level.Right - 350, 150)); 
     85        polku.Add(new Vector(Level.Right - 400, 200)); 
     86        polku.Add(new Vector(Level.Right - 450, 250)); 
     87        polku.Add(new Vector(Level.Right - 650, 600)); 
     88        //polku.Add(new Vector(-100, 50)); 
     89        //polku.Add(new Vector(-250, -200)); 
     90 
     91        vihu1Aivot.Path = polku; 
     92        vihu1Aivot.Loop = false; 
     93        vihu1Aivot.Speed = 200; 
     94 
     95        vihu1.Brain = vihu1Aivot; 
     96 
     97 
     98 
     99 
     100 
     101 
     102 
     103 
     104    } 
     105    void LuoPelaaja(double x, double y) 
     106    { 
     107        pelaaja = new Pelaaja(40.0, 40.0); 
    66108        pelaaja.Shape = Shape.Triangle; 
    67109        pelaaja.X = 0.0; 
     
    72114        pelaaja.MaxVelocity = 1.0; 
    73115        pelaaja.CanRotate = false; 
     116        AddCollisionHandler(pelaaja, "vihu1Luoti", VahennaElamaa); 
    74117        Add(pelaaja); 
    75118 
    76119        PelaanjaAse(); 
    77  
    78  
     120    } 
     121    void Leveli() 
     122    { 
    79123        oikeareuna = Level.CreateRightBorder(); 
    80124        vasenreuna = Level.CreateLeftBorder(); 
     125        oikeareuna.CollisionIgnoreGroup = 3; 
     126        vasenreuna.CollisionIgnoreGroup = 3; 
    81127        oikeareuna.Restitution = 0.0; 
    82128        vasenreuna.Restitution = 0.0; 
     129        Level.BackgroundColor = Color.Black; 
    83130             
    84         vihu = new Vihollinen(50.0, 50.0); 
    85         wihu = new Vihollinen(-50, -50); 
    86131         
    87132 
     
    111156    { 
    112157        laser.Destroy(); 
    113         if (kohde == pelaaja) 
    114         { 
    115             kohde.Destroy(); 
    116         } 
     158         
    117159    } 
    118160 
    119161    void PelaanjaAse () 
    120162    { 
    121         pelaajanAse = new AssaultRifle(30, 10); 
     163        pelaajanAse = new AssaultRifle(10, 10); 
    122164        pelaajanAse.InfiniteAmmo = true; 
    123         //pelaajanAse.ProjectileCollision = PelaajaaOsuu; 
     165        pelaajanAse.ProjectileCollision = PelaajaOsuu; 
    124166        pelaajanAse.Angle = Angle.FromDegrees(90); 
    125167        pelaajanAse.Image = null; 
     
    127169    } 
    128170 
    129     void V1LaserAmpuu () 
    130     { 
    131         PhysicsObject laser = vihu1Laser.Shoot(); 
     171    void PelaajaOsuu (PhysicsObject luoti, PhysicsObject kohde) 
     172    { 
     173 
     174        if (kohde is Vihollinen) 
     175        { 
     176            luoti.Destroy(); 
     177        } 
     178 
     179    } 
     180 
     181    void V1LaserAmpuu (AssaultRifle ase) 
     182    { 
     183        PhysicsObject laser = ase.Shoot(); 
    132184         
    133185        if (laser != null) 
    134186        { 
    135             Vector vihuAmpumisSuunta = (pelaaja.Position - vihu.Position).Normalize(); 
     187            Vector vihuAmpumisSuunta = (pelaaja.Position - ase.Position).Normalize(); 
    136188            laser.Velocity = vihuAmpumisSuunta * 300; 
     189            laser.Tag = "vihu1Luoti"; 
    137190            laser.Angle = vihuAmpumisSuunta.Angle; 
    138191            laser.CollisionIgnoreGroup = 2; 
     
    147200        { 
    148201            pelaajanammus.Size *= 3; 
    149             //pelaajanammus.Tag = "joku"; 
     202            pelaajanammus.Tag = "joku"; 
    150203            pelaajanammus.CollisionIgnoreGroup = 2; 
    151         } 
    152          
    153     } 
    154  
    155     void PelaajaaOsuu (PhysicsObject luoti, PhysicsObject kohde) 
    156     { 
    157         luoti.Destroy(); 
    158         if (kohde == vihu) 
    159         { 
    160             kohde.Destroy(); 
    161204             
    162205        } 
    163     } 
    164     /*void VihuunOsuu (PhysicsObject vihu, PhysicsObject ammus) 
    165     { 
    166         vihu.Destroy(); 
    167         ammus.Destroy(); 
    168  
    169     }*/ 
     206         
     207    } 
     208     
     209    void VahennaElamaa(PhysicsObject pelaaja, PhysicsObject luoti) 
     210    { 
     211        (pelaaja as Pelaaja).VahennaElamaa(); 
     212    } 
     213 
     214    void Vihollinen2(double x, double y) 
     215    { 
     216        Vihollinen2 vihu2 = new Vihollinen2(50, 50); 
     217        vihu2.Color = Color.Red; 
     218        vihu2.X = x; 
     219        vihu2.Y = y; 
     220        vihu2.CanRotate = false; 
     221        vihu2.CollisionIgnoreGroup = 3; 
     222        AddCollisionHandler(vihu2, "joku", CollisionHandler.AddMeterValue(vihu2.Vihu2Health, -1)); 
     223        Add(vihu2); 
     224 
     225 
     226 
     227        PathFollowerBrain vihu2Aivot = new PathFollowerBrain(200); 
     228 
     229 
     230 
     231        List<Vector> polku = new List<Vector>(); 
     232        polku.Add(new Vector(Level.Right, 0)); 
     233        polku.Add(new Vector(Level.Left + 20, 0)); 
     234        polku.Add(new Vector(0, 400)); 
     235        polku.Add(new Vector(Level.Right + 10000, 0)); 
     236 
     237        vihu2Aivot.Path = polku; 
     238        vihu2Aivot.Loop = false; 
     239        vihu2Aivot.Speed = 200; 
     240 
     241        vihu2.Brain = vihu2Aivot; 
     242 
     243    } 
     244 
     245    void Vihollinen2Ase() 
     246    { 
     247        PhysicsObject clusterBall = new PhysicsObject(75, 75);  
     248        clusterBall.Shape = Shape.Circle; 
     249          
     250 
     251        Add(clusterBall); 
     252    } 
    170253 
    171254} 
    172255class Vihollinen : PhysicsObject 
    173256{ 
     257    private IntMeter vihuHealth = new IntMeter(2, 0, 2); 
     258    public IntMeter VihuHealth { get { return vihuHealth; } } 
     259     
     260 
     261    public Vihollinen(double leveys, double korkeus) 
     262        : base(40, 40) 
     263    { 
     264        VihuHealth.LowerLimit += delegate { this.Destroy(); }; 
     265    } 
     266     
     267    
     268     
     269} 
     270 
     271class Pelaaja : PhysicsObject 
     272{ 
    174273    private IntMeter elamaLaskuri = new IntMeter(3, 0, 3); 
    175274    public IntMeter ElamaLaskuri { get { return elamaLaskuri; } } 
    176  
    177     public Vihollinen(double leveys, double korkeus) 
     275    private bool voikoOttaaOsumaa = true; 
     276    public Pelaaja(double leveys, double korkeus) 
     277        : base(leveys, korkeus) 
     278    { 
     279        elamaLaskuri.LowerLimit += delegate { this.Destroy(); }; 
     280    } 
     281    public void VahennaElamaa () 
     282    { 
     283        if (voikoOttaaOsumaa) 
     284        { 
     285            elamaLaskuri.Value -= 1; 
     286            voikoOttaaOsumaa = false; 
     287            Timer.SingleShot(1, delegate { voikoOttaaOsumaa = true; }); 
     288        } 
     289    } 
     290} 
     291 
     292class Vihollinen2 : PhysicsObject 
     293{ 
     294    private IntMeter vihu2Health = new IntMeter(10, 0, 10); 
     295    public IntMeter Vihu2Health { get { return vihu2Health; } } 
     296 
     297 
     298    public Vihollinen2(double leveys, double korkeus) 
    178299        : base(40, 40) 
    179300    { 
    180         elamaLaskuri.LowerLimit += delegate { this.Destroy(); }; 
    181     } 
     301        Vihu2Health.LowerLimit += delegate { this.Destroy(); }; 
     302    } 
     303 
    182304 
    183305 
    184306} 
    185307 
     308 
Note: See TracChangeset for help on using the changeset viewer.