Changeset 7474 for 2016/25


Ignore:
Timestamp:
2016-06-20 15:56:47 (7 years ago)
Author:
koannak
Message:
 
Location:
2016/25/PetteriR
Files:
271 added
6 edited

Legend:

Unmodified
Added
Removed
  • 2016/25/PetteriR/Pang/Pang/Pang/Pang.cs

    r7464 r7474  
    1111public class Pang : PhysicsGame 
    1212{ 
     13    Vector nopeusYlos = new Vector(0, 200); 
     14    Vector nopeusAlas = new Vector(0, - 200); 
    1315 
    1416    PhysicsObject pallo; 
     17    PhysicsObject maila1; 
     18    PhysicsObject maila2; 
    1519 
    1620    public override void Begin() 
    1721    { 
    1822        LuoKentta(); 
     23        AsetaOhjaimet(); 
    1924        AloitaPeli(); 
    2025 
    21          Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     26        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    2227    } 
    2328 
     
    2934        pallo.Y = 0.0; 
    3035        pallo.Restitution = 1.0; 
     36        pallo.Color = Color.Black; 
    3137        Add(pallo); 
    3238 
    33         LuoMaila(Level.Left + 20.0, 0.0); 
    34         LuoMaila(Level.Right - 20.0, 0.0); 
     39        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     40        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    3541 
    3642        Level.CreateBorders(1.0, false); 
    37         Level.Background.Color = Color.Black; 
     43        Level.Background.Color = Color.Blue; 
    3844 
    3945        Camera.ZoomToLevel(); 
    4046    } 
    4147 
    42     void AloitaPeli() 
    43     { 
    44         Vector impulssi = new Vector(500.0, 0.0); 
    45         pallo.Hit(impulssi); 
    46     } 
    47  
    48     void LuoMaila(double x, double y) 
     48    PhysicsObject LuoMaila(double x, double y) 
    4949    { 
    5050        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    5151        maila.Shape = Shape.Rectangle; 
    5252        maila.X = x; 
    53         maila.Y = y; 
     53        maila.Y = 
    5454        maila.Restitution = 1.0; 
    5555        Add(maila); 
     56        return maila; 
    5657    } 
    57 } 
     58 
     59    void AloitaPeli() 
     60    { 
     61        Vector impulssi = new Vector(800.0, 0.0); 
     62        pallo.Hit(impulssi); 
     63    } 
     64 
     65    void AsetaOhjaimet() 
     66    { 
     67        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     68        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     69        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     70        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     71 
     72        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     73        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     74        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     75        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     76 
     77        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
     78        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     79    } 
     80 
     81    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     82    { 
     83        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     84        { 
     85            maila.Velocity = Vector.Zero; 
     86            return; 
     87        } 
     88        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     89        { 
     90            maila.Velocity = Vector.Zero; 
     91            return; 
     92        } 
     93 
     94        maila.Velocity = nopeus; 
     95 
     96    } 
     97 
     98 
     99 
Note: See TracChangeset for help on using the changeset viewer.