Changeset 1555 for 2010


Ignore:
Timestamp:
2010-08-03 11:33:12 (13 years ago)
Author:
paaaanro
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2010/31/pakralki/pong_1/Peli.cs

    r1523 r1555  
    66public class Peli : PhysicsGame 
    77{ 
     8    Vector nopeusYlos = new Vector(0, 200); 
     9    Vector nopeusAlas = new Vector(0, -200); 
     10 
     11 
    812    PhysicsObject pallo; 
     13 
     14    PhysicsObject maila1; 
     15    PhysicsObject maila2; 
    916 
    1017    protected override void Begin() 
    1118    { 
    1219        Luokentta(); 
     20        AsetaOhjaimet(); 
    1321        Aloitapeli(); 
    1422    } 
     
    2432        pallo.Hit(impulssi); 
    2533 
    26         LuoMaila(Level.Left + 20.0, 0.0); 
    27         Luo 
    28  
     34        
    2935        Level.CreateBorders(1.0, false); 
    3036        pallo.Restitution = 1.0; 
    3137        Level.BackgroundColor = Color.Black; 
    3238        Camera.ZoomToLevel(); 
    33         PhysicsObject maila = PhysicsObject.CreateStaticObject(10.0, 100.0); 
    34         maila.Shape = Shapes.Rectangle; 
    35         maila.X = Level.Left + 20.0; 
    36         maila.Y = 0.0; 
    37         maila.Restitution = 1.0; 
    38         Add(maila); 
     39 
     40        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     41        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    3942 
    4043    } 
     
    4548        pallo.Hit(impulssi); 
    4649    } 
    47     void LuoMaila(double x, double y) 
    48     { 
    49         PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     50    PhysicsObject LuoMaila(double x, double y) 
     51{ 
     52        PhysicsObject maila = PhysicsObject.CreateStaticObject( 20.0, 100.0 ); 
    5053        maila.Shape = Shapes.Rectangle; 
    5154        maila.X = x; 
    5255        maila.Y = y; 
    5356        maila.Restitution = 1.0; 
    54         Add(maila); 
    55     } 
     57        Add( maila ); 
     58        return maila; 
     59        } 
     60 
     61              
     62         
     63        void AsetaOhjaimet() 
     64{ 
     65            Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta Mailaa ylös", maila1, nopeusYlos); 
     66            Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     67            Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     68            Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     69 
     70            Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     71            Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     72            Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     73            Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     74 
     75            Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
     76 
     77            Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 
     78        } 
     79        void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     80        { 
     81            if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     82            { 
     83                maila.Velocity = Vector.Zero; 
     84                return; 
     85            } 
     86            if ( (nopeus.Y > 0) && (maila.Top > Level.Top) ) 
     87            { 
     88                maila.Velocity = Vector.Zero; 
     89                return; 
     90            } 
     91                maila.Velocity = nopeus; 
     92        } 
    5693} 
Note: See TracChangeset for help on using the changeset viewer.