Changeset 7528 for 2016/26


Ignore:
Timestamp:
2016-06-27 14:56:45 (3 years ago)
Author:
karkaite
Message:
 
Location:
2016/26/RasmusL/Pong
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 2016/26/RasmusL/Pong/Pong/Pong/Pong.cs

    r7517 r7528  
    99public class Pong : PhysicsGame 
    1010{ 
     11    Vector nopeusYlos = new Vector(0, 200); 
     12    Vector nopeusAlas = new Vector(0, -200); 
    1113    PhysicsObject pallo; 
     14 
     15    PhysicsObject maila1; 
     16    PhysicsObject maila2; 
    1217    public override void Begin() 
    1318    { 
     
    1520        AsetaOhjaimet(); 
    1621        AloitaPeli(); 
     22 
     23        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    1724 
    1825        // TODO: Kirjoita ohjelmakoodisi tähän 
     
    2835        pallo.Y = 0.0; 
    2936 
    30         LuoMaila(Level.Left + 20.0, 0.0); 
    31         LuoMaila(Level.Right - 20.0, 0.0); 
     37        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     38        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    3239 
    3340        Level.CreateBorders(1.0, false); 
     
    4350    } 
    4451 
    45     void LuoMaila(double x, double y) 
     52    PhysicsObject LuoMaila(double x, double y) 
    4653    { 
    4754        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     
    5158        maila.Restitution = 1.0; 
    5259        Add(maila); 
     60        return maila; 
    5361    } 
    5462 
    5563    void AsetaOhjaimet() 
    5664    { 
     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 
     71        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     72        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     73        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     74        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     75 
     76 
     77        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
     78 
     79 
    5780        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     81 
     82    } 
     83    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     84    { 
     85        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     86        { 
     87            maila.Velocity = Vector.Zero; 
     88            return; 
     89        } 
     90        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     91        { 
     92            maila.Velocity = Vector.Zero; 
     93            return; 
     94        } 
     95 
     96        maila.Velocity = nopeus; 
    5897    } 
    5998 
Note: See TracChangeset for help on using the changeset viewer.