Changeset 7713 for 2016/27


Ignore:
Timestamp:
2016-07-04 14:53:12 (3 years ago)
Author:
karkaite
Message:
 
Location:
2016/27/PaavoH/Pong
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 2016/27/PaavoH/Pong/Pong/Pong/Pong.cs

    r7679 r7713  
    99public class Pong : PhysicsGame 
    1010{ 
     11    Vector nopeusYlos = new Vector(0, 200); 
     12    Vector nopeusAlas = new Vector(0, -200); 
     13 
     14 
    1115    PhysicsObject pallo; 
     16 
     17    PhysicsObject maila1; 
     18    PhysicsObject maila2; 
    1219    public override void Begin() 
    1320    { 
    14          
     21 
    1522        LuoKentta(); 
    16         PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
    17         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    18         
    19         Vector impulssi = new Vector(500.0, 0.0); 
    20         pallo.Hit(impulssi); 
    21          
     23        AsetaOhjaimet(); 
     24        AloitaPeli(); 
     25 
     26 
     27 
     28 
    2229    } 
    2330    void LuoKentta() 
    2431    { 
    25          pallo = new PhysicsObject(40.0, 40.0); 
     32        pallo = new PhysicsObject(40.0, 40.0); 
    2633        Add(pallo); 
    2734        pallo.Shape = Shape.Circle; 
     
    3138        Level.CreateBorders(1.0, false); 
    3239        pallo.Restitution = 1.0; 
    33         Level.Background.Color = Color.Salmon; 
     40        Level.Background.Color = Color.DarkTurquoise; 
    3441        Camera.ZoomToLevel(); 
     42 
     43        PhysicsObject maila2 = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     44        maila2.Shape = Shape.Rectangle; 
     45        maila2.X = Level.Left + 20.0; 
     46        maila2.Y = 0.0; 
     47        maila2.Restitution = 1.0; 
     48        Add(maila2); 
     49        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     50        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
     51    } 
     52    PhysicsObject LuoMaila(double x, double y) 
     53    { 
    3554        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    3655        maila.Shape = Shape.Rectangle; 
    37         maila.X = Level.Left + 20.0; 
    38         maila.Y = 0.0; 
     56        maila.X = x; 
     57        maila.Y = y; 
    3958        maila.Restitution = 1.0; 
    4059        Add(maila); 
     60        return maila; 
    4161    } 
    4262 
     63    void AloitaPeli() 
     64    { 
     65        Vector impulssi = new Vector(500.0, 0.0); 
     66        pallo.Hit(impulssi); 
     67    } 
     68 
     69    void AsetaOhjaimet() 
     70    { 
     71        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     72        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     73        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     74        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     75 
     76        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     77        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     78        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     79        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     80 
     81        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
     82        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     83    } 
     84    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     85    { 
     86        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     87        { 
     88            maila.Velocity = Vector.Zero; 
     89            return; 
     90        } 
     91        maila.Velocity = nopeus; 
     92    } 
    4393} 
     94void LisaaLaskurit() 
     95{ 
     96    // ... 
     97} 
     98} 
     99IntMeter LuoPisteLaskuri() 
     100{ 
     101    IntMeter laskuri = new IntMeter(0); 
     102    laskuri.MaxValue = 10; 
     103    return laskuri; 
     104} 
     105} 
Note: See TracChangeset for help on using the changeset viewer.