Changeset 1554 for 2010/31


Ignore:
Timestamp:
2010-08-03 11:32:20 (13 years ago)
Author:
paaaanro
Message:

Pääsin vaihe kuutoseen.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2010/31/kirsipienmaki@gmail.com/Pong/Peli.cs

    r1533 r1554  
    66public class Peli : PhysicsGame 
    77{ 
     8    Vector nopeusYlos = new Vector(0, 200); 
     9    Vector nopeusAlas = new Vector(0, -200); 
     10 
    811    PhysicsObject pallo; 
    912 
     13    PhysicsObject maila1; 
     14    PhysicsObject maila2; 
    1015 
    1116    protected override void Begin() 
    1217    { 
    1318        LuoKentta(); 
    14         Vector impulssi = new Vector(500.0, 0.0); 
    15         pallo.Hit(impulssi); 
    16         
     19        AsetaOhjaimet(); 
     20        AloitaPeli(); 
     21    } 
    1722 
    18     } 
    1923    void LuoKentta() 
    2024    { 
     
    2428        pallo.X = -200.0; 
    2529        pallo.Y = 00.0; 
    26        Add(pallo); 
     30        Add(pallo); 
    2731 
    28        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    29        maila.Shape = Shapes.Rectangle; 
    30        maila.X = Level.Left + 20.0; 
    31        maila.Y = 0.0; 
    32        maila.Restitution = 1.0; 
    33        Add(maila); 
    34         
     32        maila1 = LuoMaila (Level.Left + 20.0, 0.0); 
     33        maila2 = LuoMaila (Level.Right - 20.0, 0.0); 
     34 
    3535        Level.CreateBorders(1.0, false); 
    36        Level.BackgroundColor = Color.Black; 
    37          
    38         Camera.ZoomToLevel(); } 
     36        Level.BackgroundColor = Color.Black; 
     37 
     38        Camera.ZoomToLevel(); 
     39    } 
     40    void AloitaPeli() 
     41    { 
     42        Vector impulssi = new Vector(500.0, 0.0); 
     43        pallo.Hit(impulssi); 
     44    } 
     45 
     46    PhysicsObject LuoMaila( double x,double y ) 
     47    { 
     48        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     49        maila.Shape = Shapes.Rectangle; 
     50        maila.X = x; 
     51        maila.Y = y; 
     52        maila.Restitution = 1.0; 
     53        Add(maila); 
     54 
     55        return maila; 
     56    } 
     57    void AsetaOhjaimet() 
     58    { 
     59        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     60        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero ); 
     61        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     62        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     63 
     64        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     65        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     66        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     67        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     68 
     69        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
     70        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 
     71    } 
     72    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     73    { 
     74        maila.Velocity = nopeus; 
     75    } 
     76 
    3977} 
    40 void AloitaPeli() 
    41 { 
    42 } 
     78 
     79 
     80 
Note: See TracChangeset for help on using the changeset viewer.