Changeset 8704


Ignore:
Timestamp:
2017-06-15 11:58:00 (2 years ago)
Author:
npo17_13
Message:
 
Location:
2017/24/SebastianH/JumpingAdventure
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 2017/24/SebastianH/JumpingAdventure/JumpingAdventure/JumpingAdventure/JumpingAdventure.cs

    r8676 r8704  
    1111    PhysicsObject spaceship; 
    1212    PhysicsObject ufo; 
     13    IntMeter elinvoimaLaskuri; 
    1314    public override void Begin() 
    1415    { 
    1516        Gravity = new Vector(0.0, -800.0); 
     17 
     18        LuoVihollinen(new Vector(100.0, 100.0), 80.0, 700.0); 
     19        LuoElinvoimalaskuri(); 
    1620 
    1721        spaceship = new PhysicsObject(30, 40, Shape.Star); 
     
    2024        spaceship.Color = Color.Fuchsia; 
    2125        spaceship.CanRotate = false; 
     26        AddCollisionHandler(spaceship, "pahis", PelaajaOsuu); 
    2227        Add(spaceship); 
    2328 
    24         ufo = new PhysicsObject(40, 20, Shape.Ellipse); 
    25         ufo.X = 300.0; 
    26         ufo.Y = -150.0; 
    27         ufo.Color = Color.Red; 
    28         Add(ufo); 
     29         
    2930 
    3031        Level.Background.CreateStars(100000); 
     
    3839        Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaPelaajaa, null, new Vector(0, 2000)); 
    3940        Keyboard.Listen(Key.Up, ButtonState.Released, PysaytaPelaaja, null, new Vector(0, 0)); 
    40         Keyboard.Listen(Key.Down, ButtonState.Down, LiikutaPelaajaa, null, new Vector(0, -1000)); 
    41         Keyboard.Listen(Key.Down, ButtonState.Released, PysaytaPelaaja, null, new Vector(0, 0)); 
    4241        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    4342    } 
     
    5049        spaceship.Velocity = Vector.Zero; 
    5150    } 
     51 
     52    void LuoVihollinen(Vector paikka, double leveys, double korkeus) 
     53    { 
     54        ufo = new PhysicsObject(leveys, korkeus, Shape.Ellipse); 
     55        ufo.Position = paikka; 
     56        ufo.Tag = "pahis"; 
     57        ufo.Color = Color.Red; 
     58        Add(ufo); 
     59    } 
     60 
     61    void LuoElinvoimalaskuri() 
     62    { 
     63        elinvoimaLaskuri = new IntMeter(3000); 
     64 
     65        Label elinvoimaNaytto = new Label(); 
     66        elinvoimaNaytto.X = Screen.Left + 100; 
     67        elinvoimaNaytto.Y = Screen.Top - 100; 
     68        elinvoimaNaytto.TextColor = Color.White; 
     69        elinvoimaNaytto.Color = Color.Black; 
     70 
     71        elinvoimaNaytto.BindTo(elinvoimaLaskuri); 
     72        Add(elinvoimaNaytto); 
     73    } 
     74 
     75    void PelaajaOsuu(PhysicsObject spaceship, PhysicsObject kohde) 
     76    { 
     77        elinvoimaLaskuri.Value--; 
     78 
     79        if (elinvoimaLaskuri <= 0) 
     80            spaceship.Destroy(); 
     81    } 
     82     
    5283} 
Note: See TracChangeset for help on using the changeset viewer.