Changeset 7525 for 2016/26


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

Legend:

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

    r7512 r7525  
    99public class Pong : PhysicsGame 
    1010{ 
     11    Vector nopeusYlos = new Vector(0, 200); 
     12    Vector nopeusAlas = new Vector(0, -200); 
    1113    PhysicsObject pallo; 
     14    PhysicsObject maila1; 
     15    PhysicsObject maila2; 
    1216    public override void Begin() 
    1317    { 
    1418        LuoKentta(); 
    15          
    16         Vector impulssi = new Vector(600.0, 0.0); 
    17         pallo.Hit(impulssi); 
    18          
    19         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     19        AsetaOhjaimet(); 
     20        AloitaPeli(); 
     21 
    2022    } 
    2123    void LuoKentta() 
    2224    { 
    23         PhysicsObject pallo = new PhysicsObject(40.0, 40.0); 
     25        pallo = new PhysicsObject(40.0, 40.0); 
    2426        pallo.X = -300.0; 
    2527        pallo.Y = 50.0; 
     
    2729        pallo.Shape = Shape.Circle; 
    2830        Add(pallo); 
     31        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     32        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    2933        Level.CreateBorders(1.0, false); 
    3034        Level.Background.Color = Color.Purple; 
    3135        Camera.ZoomToLevel(); 
    3236    } 
     37    void AloitaPeli() 
     38    { 
     39        Vector impulssi = new Vector(600.0, 0.0); 
     40        pallo.Hit(impulssi); 
     41    } 
     42    PhysicsObject LuoMaila(double x, double y) 
     43    { 
     44        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     45        maila.Shape = Shape.Rectangle; 
     46        maila.X = x; 
     47        maila.Y = y; 
     48        maila.Restitution = 1.0; 
     49        Add(maila); 
     50        return maila; 
     51    } 
     52    void AsetaOhjaimet() 
     53    { 
     54        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     55        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     56        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     57        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     58 
     59        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     60        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     61        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     62        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     63 
     64        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
     65        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     66    } 
     67    void AsetaNopeus(IPhysicsObject maila, Vector nopeus) 
     68    { 
     69        maila.Velocity = nopeus; 
     70    } 
    3371} 
Note: See TracChangeset for help on using the changeset viewer.