Changeset 8535 for 2017/24/GregoryK


Ignore:
Timestamp:
2017-06-12 14:59:52 (2 years ago)
Author:
npo17_12
Message:
 
Location:
2017/24/GregoryK/Pong
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 2017/24/GregoryK/Pong/Pong/Pong/Pong.cs

    r8508 r8535  
    99public class Pong : 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 
    1319    public override void Begin() 
     
    1521        LuoKenttä(); 
    1622        AlotaPeli(); 
     23        AsetaOjaimet(); 
    1724 
    18         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     25 
     26 
    1927    } 
    2028    void LuoKenttä() 
    2129    { 
    22          pallo = new PhysicsObject(40.0, 40.0); 
     30        pallo = new PhysicsObject(40.0, 40.0); 
    2331        pallo.Shape = Shape.Circle; 
    2432        pallo.X = -200.0; 
     
    2836        Add(pallo); 
    2937 
    30         PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    31         maila.Shape = Shape.Rectangle; 
    32         maila.X = Level.Left + 20.0; 
    33         maila.Y = 0.0; 
    34         maila.Restitution = 1.0; 
    35         Add(maila); 
     38        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     39        maila2 = LuoMaila(Level.Right - 29.0, 0.0); 
    3640 
    3741        Level.CreateBorders(1.0, false); 
     
    4044        Camera.ZoomToLevel(); 
    4145    } 
    42      
     46 
    4347    void AlotaPeli() 
    4448    { 
     
    4751    } 
    4852 
    49     void LuoMaila(double x, double y) 
     53    PhysicsObject LuoMaila(double x, double y) 
    5054    { 
    5155        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     
    5559        maila.Restitution = 1.0; 
    5660        Add(maila); 
     61        return maila; 
    5762    } 
    58 } 
     63    void AsetaOjaimet() 
     64    { 
     65        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     66        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     67        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     68        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     69 
     70        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     71        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     72        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     73        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     74 
     75        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
     76        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     77    } 
     78 
     79    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     80    { 
     81        if (maila.Top > Level.Top) 
     82        { 
     83            maila.Velocity = Vector.Zero; 
     84            return; 
     85        } 
     86 
     87        maila.Velocity = nopeus; 
     88    } 
     89     
Note: See TracChangeset for help on using the changeset viewer.