Changeset 3363 for 2012/26


Ignore:
Timestamp:
2012-06-29 10:45:20 (11 years ago)
Author:
vivasuom
Message:

Talletus.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2012/26/RoniR/Garden_Run/Garden_Run/Garden_Run/Garden_Run.cs

    r3347 r3363  
    99public class Garden_Run : PhysicsGame 
    1010{ 
    11     const double nopeus = 1000; 
     11    const double nopeus = 250; 
    1212    const double hyppyNopeus = 1000; 
    1313    const int RUUDUN_KOKO = 100; 
     
    2626    int kentanNro = 1; 
    2727    IntMeter tahtilaskuri; 
     28    IntMeter hpLaskuri; 
    2829 
    2930    public override void Begin() 
     
    3536    { 
    3637        ClearAll(); 
    37  
     38        hpLaskuri = new IntMeter(10, 0, 10); 
     39        hpLaskuri.LowerLimit += PeliHavitty; 
     40 
     41        Label hpNaytto = new Label(); 
     42        hpNaytto.BindTo(hpLaskuri); 
     43        hpNaytto.Color = Color.Black; 
     44        hpNaytto.TextColor = Color.White; 
     45        hpNaytto.Position = new Vector(Screen.Right - 50, Screen.Top - 50); 
     46        Add(hpNaytto); 
    3847 
    3948        if (kenttaNro == 1) LuoKentta("kentta1", "kentta1reitti"); 
    4049        else if (kenttaNro == 2) LuoKentta("kentta2", null); 
    41  
    42  
    4350        LisaaOhjaimet(); 
    4451 
     
    5360    } 
    5461 
     62    void PeliHavitty() 
     63    { 
     64        ClearAll(); 
     65        Label label = new Label("Hävisit pelin"); 
     66        Add(label); 
     67    } 
     68 
    5569    void LuoKentta(string kentta, string kenttaReitti) 
    5670    { 
     
    7084        }; 
    7185 
    72         pelaaja = new PhysicsObject(RUUDUN_KOKO / 1.5, RUUDUN_KOKO/ 1.5); 
     86        pelaaja = new PhysicsObject(RUUDUN_KOKO / 1.5, RUUDUN_KOKO / 1.5); 
    7387 
    7488        ColorTileMap kentta1 = ColorTileMap.FromLevelAsset(kentta); 
     
    153167        pelaaja.Image = pelaajanKuva; 
    154168        AddCollisionHandler(pelaaja, "tahti", TormaaTahteen); 
     169        AddCollisionHandler<PhysicsObject, Vihu>(pelaaja, delegate(PhysicsObject p, Vihu v) { hpLaskuri.Value--; }); 
    155170        pelaaja.CollisionIgnoreGroup = 2; 
    156171        pelaaja.AngularDamping = 0.9; 
     
    161176    void LuoMonsteri(Vector paikka, double leveys, double korkeus) 
    162177    { 
    163         PhysicsObject monsteri = new PhysicsObject(leveys / 1.5, korkeus / 1.5); 
     178        Vihu monsteri = new Vihu(leveys / 1.5, korkeus / 1.5); 
    164179        monsteri.Position = paikka; 
    165180        monsteri.Mass = 2.0; 
     
    170185        seuraaja.DistanceClose = 500; 
    171186        seuraaja.DistanceFar = 500; 
    172 //         seuraaja.DistanceToTarget.AddTrigger(10, TriggerDirection. 
     187        //         seuraaja.DistanceToTarget.AddTrigger(10, TriggerDirection. 
    173188        seuraaja.DistanceToTarget.Changed += delegate 
    174189        { 
     
    180195    void LuoMonsteri(Vector paikka, double leveys, double korkeus, List<Vector> reitti = null) 
    181196    { 
    182         PhysicsObject monsteri = new PhysicsObject(leveys / 1.5, korkeus / 1.5); 
     197        Vihu monsteri = new Vihu(leveys / 1.5, korkeus / 1.5); 
    183198        monsteri.Position = paikka; 
    184199        monsteri.Mass = 2.0; 
     
    187202        monsteri.CollisionIgnoreGroup = 2; 
    188203        Add(monsteri); 
    189          
     204 
    190205        if (reitti != null) 
    191206        { 
     
    204219        } 
    205220    } 
     221 
    206222 
    207223    void LuoMaali(Vector paikka, double leveys, double korkeus) 
     
    228244        Mouse.ListenMovement(0.1, KuunteleLiiketta, null); 
    229245        Mouse.Listen(MouseButton.Left, ButtonState.Pressed, ammu, "ammu", pelaaja); 
    230          
     246 
    231247    } 
    232248 
     
    260276        luoti.Shape = Shape.Circle; 
    261277        luoti.Color = Color.Silver; 
     278        luoti.Tag = "pelaajanAmmus"; 
    262279        luoti.CollisionIgnoreGroup = 2; 
     280        AddCollisionHandler(luoti, CollisionHandler.DestroyObject); 
     281        AddCollisionHandler<PhysicsObject, Vihu>(luoti, delegate(PhysicsObject ammus, Vihu vihu) { vihu.elamaLaskuri.Value--; }); 
    263282        Add(luoti); 
    264283    } 
    265284} 
     285 
     286class Vihu : PhysicsObject 
     287{ 
     288    public IntMeter elamaLaskuri = new IntMeter(10, 0, 10); 
     289 
     290    public Vihu(double leveys, double korkeus) 
     291        : base(leveys, korkeus) 
     292    { 
     293        elamaLaskuri.LowerLimit += delegate { this.Destroy(); }; 
     294    } 
     295} 
     296 
Note: See TracChangeset for help on using the changeset viewer.