Changeset 7710


Ignore:
Timestamp:
2016-07-04 14:52:56 (3 years ago)
Author:
karkaite
Message:
 
Location:
2016/27/EmiliaM/PongLong
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • 2016/27/EmiliaM/PongLong/PongLong/PongLong/PongLong.cs

    r7682 r7710  
    99public class PongLong : 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; 
     18 
    1219    public override void Begin() 
    1320    { 
    14         LuoKentta();  
     21        LuoKentta(); 
     22        AsetaOhjaimet(); 
     23        AloitaPeli(); 
    1524        
    1625         
     
    2130 
    2231 
    23         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     32         
    2433    } 
    2534 
     
    3645        pallo.Restitution = 1.0; 
    3746 
     47        maila1 = LuoMaila(Level.Right - 20.0, 0.0); 
     48        maila2 = LuoMaila(Level.Left + 20.0, 0.0); 
     49        
     50        Level.CreateBorders(1.0, false); 
     51        Level.Background.Color = Color.Red; 
     52    } 
     53 
     54    void AloitaPeli() 
     55    { 
     56        Vector impulssi = new Vector(500.0, 0.0); 
     57        pallo.Hit(impulssi); 
     58 
     59 
     60 
     61    } 
     62 
     63    PhysicsObject LuoMaila(double x, double y) 
     64    { 
    3865        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    3966        maila.Shape = Shape.Rectangle; 
    40         maila.X = Level.Left +  
    41         
    42             Level.CreateBorders(1.0, false); 
    43         Level.Background.Color = Color.Red; 
    44         Vector impulssi = new Vector(500.0, 0.0); 
    45         pallo.Hit(impulssi); 
     67        maila.X = x; 
     68        maila.Y = y; 
     69        maila.Restitution = 1.0; 
     70        Add(maila); 
     71        return maila; 
     72 
     73    } 
     74 
     75    void AsetaOhjaimet() 
     76    { 
     77        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     78        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector. Zero); 
     79        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     80        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     81 
     82        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     83        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     84        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, Vector.Zero); 
     85        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, nopeusAlas); 
     86 
     87        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
     88        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     89 
     90    } 
     91 
     92    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     93    { 
     94        maila.Velocity = nopeus; 
    4695    } 
    4796  
Note: See TracChangeset for help on using the changeset viewer.