Changeset 1304 for 2010/30


Ignore:
Timestamp:
2010-07-27 11:24:47 (9 years ago)
Author:
tieenyky
Message:

jrr

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2010/30/tieenyky/Pong/Peli.cs

    r1293 r1304  
    55 
    66public class Peli : PhysicsGame 
    7 { 
     7    { 
     8        Vector nopeusYlos = new Vector(0, 200); 
     9        Vector nopeusAlas = new Vector(0, -200); 
     10 
     11        PhysicsObject pallo; 
     12 
     13        PhysicsObject maila1; 
     14        PhysicsObject maila2; 
     15 
    816    protected override void Begin() 
    917    { 
    10         PhysicsObject pallo = new PhysicsObject(40.0, 40.0); 
     18        LuoKentta(); 
     19        AsetaOhjaimet(); 
     20        AloitaPeli(); 
     21    } 
     22 
     23    void LuoKentta() 
     24    { 
     25        pallo = new PhysicsObject(40.0, 40.0); 
    1126        pallo.Shape = Shapes.Circle; 
    12         pallo.X = -200.0; 
    13         pallo.Y = 0.0; 
    14          
    15         Vector impulssi = new Vector(500.0, 0.0); 
    16         pallo.Hit(impulssi); 
     27        pallo.X = -200.0;        pallo.Y = 0.0; 
    1728        pallo.Restitution = 1.0; 
    18          
    1929        Add( pallo ); 
    20          
     30 
     31        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     32        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
     33 
    2134        Level.CreateBorders(1.0, false); 
    2235        Level.BackgroundColor = Color.Black; 
     36         
    2337        Camera.ZoomToLevel(); 
    2438 
     39    } 
    2540 
     41    void AloitaPeli() 
     42    { 
     43    Vector impulssi = new Vector(500.0, 0.0); 
     44    pallo.Hit(impulssi); 
    2645    } 
     46 
     47    PhysicsObject LuoMaila(double x, double y) 
     48    { 
     49        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     50        maila.Shape = Shapes.Rectangle; 
     51        maila.X = x; 
     52        maila.Y = y; 
     53        maila.Restitution = 1.0; 
     54        Add(maila); 
     55 
     56        return maila; 
     57    } 
     58 
     59    void AsetaOhjaimet() 
     60    { 
     61        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos ); 
     62        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero ); 
     63        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     64        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     65 
     66        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     67        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     68        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     69        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     70 
     71        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
     72        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 
     73    } 
     74 
     75    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     76    { 
     77        maila.Velocity = nopeus; 
     78    } 
     79 
    2780} 
Note: See TracChangeset for help on using the changeset viewer.