Ignore:
Timestamp:
2017-06-12 15:00:21 (2 years ago)
Author:
npo17_9
Message:
 
Location:
2017/24/VesaT/HasuPonkiPeli
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 2017/24/VesaT/HasuPonkiPeli/HasuPonkiPeli/HasuPonkiPeli/HasuPonkiPeli.cs

    r8504 r8539  
    99public class HasuPonkiPeli : PhysicsGame 
    1010{ 
     11    Vector nopeusYlos = new Vector(0, 200); 
     12    Vector nopeusAlas = new Vector(0, -200); 
     13 
    1114    PhysicsObject pallo; 
     15 
     16    PhysicsObject maila1; 
     17    PhysicsObject maila2; 
    1218    public override void Begin() 
    1319    { 
    1420        LuoKentta(); 
     21        AsetaOhjaimet(); 
    1522        AloitaPeli(); 
    1623 
    17             Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     24 
     25        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    1826    } 
    1927    void LuoKentta() 
     
    2129        pallo = new PhysicsObject(40.0, 40.0); 
    2230        Add(pallo); 
    23          
     31 
    2432        pallo.Shape = Shape.Circle; 
    2533        pallo.X = 0; 
     
    3038        Camera.ZoomToLevel(); 
    3139 
    32         LuoMaila(Level.Left + 20.0, 0.0); 
    33         LuoMaila(Level.Right + 20.0, 0.0); 
     40        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     41        maila2 = LuoMaila(Level.Right + 20.0, 0.0); 
    3442 
    35         
    3643 
    37          
     44 
     45 
    3846    } 
    3947 
     
    4452    } 
    4553 
    46     void LuoMaila(double x, double y) 
     54    PhysicsObject LuoMaila(double x, double y) 
    4755    { 
    4856        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     
    5260        maila.Restitution = 1.0; 
    5361        Add(maila); 
     62        return maila; 
    5463    } 
     64 
     65    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     66    { 
     67        maila.Velocity = nopeus; 
    5568    } 
     69 
     70    void AsetaOhjaimet() 
     71    { 
     72        Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     73        Keyboard.Listen(Key.W, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     74        Keyboard.Listen(Key.S, ButtonState.Down, AsetaNopeus, "Pelaaja 1 Liikuta mailaa alas", maila1, nopeusAlas); 
     75        Keyboard.Listen(Key.S, ButtonState.Released, AsetaNopeus, null, maila1 Vector.Zero); 
     76        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2 nopeusYlos); 
     77        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2 nopeusYlos); 
     78        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas) 
     79        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     80 
     81    } 
     82 
     83 
     84} 
Note: See TracChangeset for help on using the changeset viewer.