Changeset 542 for 2010/23


Ignore:
Timestamp:
2010-06-08 11:28:08 (13 years ago)
Author:
paaaanro
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2010/23/teematma/Pong/Peli.cs

    r519 r542  
    99    { 
    1010        PhysicsObject Pallo; 
     11        PhysicsObject maila1; 
     12        PhysicsObject maila2; 
    1113 
    1214        protected override void Begin() 
    1315        { 
    1416            LuoKentta(); 
     17            AsetaOhjaimet(); 
    1518            AloitaPeli(); 
    1619        } 
     
    2629            Pallo.Y = 0; 
    2730 
    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); 
     31 
     32            maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     33            maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    3434             
    3535            Level.CreateBorders( 1.0, false); 
    36             Level.BackgroundColor = Color.YellowGreen; 
     36            Level.BackgroundColor = Color.Black; 
    3737             
    3838            Camera.StayInLevel = true; 
     39            SetWindowSize(true); 
    3940 
    4041            } 
     
    4445                Pallo.Hit(impulssi); 
    4546            } 
    46         } 
     47 
     48 
     49            PhysicsObject LuoMaila(double x, double y) 
     50            { 
     51                PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     52                maila.Shape = Shapes.Rectangle; 
     53                maila.X = x; 
     54                maila.Y = y; 
     55                maila.Restitution = 1.0; 
     56                Add(maila); 
     57                return maila; 
     58              
     59            } 
     60            void AsetaOhjaimet() 
     61            { 
     62                Keyboard.Listen(Key.A, ButtonState.Pressed, LiikutaMailaaYlos, "Pelaaja 1: liikuta mailaa ylös", maila1); 
     63                Keyboard.Listen(Key.A, ButtonState.Released, PysaytaMaila, null, maila1); 
     64                Keyboard.Listen(Key.Z, ButtonState.Pressed, LiikutaMailaaAlas, "pelaaja 1: liikuta mailaa alas", maila1); 
     65                Keyboard.Listen(Key.Z, ButtonState.Released, PysaytaMaila, null, maila1); 
     66 
     67                Keyboard.Listen(Key.Up, ButtonState.Pressed, LiikutaMailaaYlos, "Pelaaja 2: liikuta mailaa ylös", maila2); 
     68                Keyboard.Listen(Key.Up, ButtonState.Released, PysaytaMaila, null, maila2); 
     69                Keyboard.Listen(Key.Down, ButtonState.Pressed, LiikutaMailaaAlas, "Pelaaja 2: liikuta mailaa alas", maila2); 
     70                Keyboard.Listen(Key.Down, ButtonState.Released, PysaytaMaila, null, maila2); 
     71 
     72                Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "poistu"); 
     73 
     74            } 
     75            void LiikutaMailaaYlos(PhysicsObject Maila) 
     76            { 
     77                Vector nopeus = new Vector(0, 400); 
     78                Maila.Velocity = nopeus; 
     79            } 
     80            void LiikutaMailaaAlas(PhysicsObject Maila) 
     81            { 
     82                Vector nopeus = new Vector(0, -400); 
     83                Maila.Velocity = nopeus; 
     84            } 
     85 
     86            void PysaytaMaila(PhysicsObject Maila) 
     87            { 
     88                Maila.Velocity = Vector.Zero; 
     89            } 
     90        }    
    4791    } 
    4892 
Note: See TracChangeset for help on using the changeset viewer.