Changeset 1315 for 2010


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

sain mailat liikkumaan

Location:
2010/30/heanjule/Pong
Files:
1 added
1 edited

Legend:

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

    r1292 r1315  
    66public class Peli : PhysicsGame 
    77{ 
     8    Vector nopeusYlos = new Vector(0, 200); 
     9    Vector nopeusAlas = new Vector(0, -200); 
     10 
    811    PhysicsObject pallo; 
     12 
     13    PhysicsObject maila1; 
     14    PhysicsObject maila2; 
    915 
    1016    protected override void Begin() 
    1117    { 
    1218        LuoKentta(); 
    13         AloitaPeli();      
     19        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 
     20        AloitaPeli(); 
     21        AsetaOhjaimet(); 
    1422    } 
    1523 
     
    1826        pallo = new PhysicsObject(40.0, 40.0); 
    1927        pallo.Shape = Shapes.Circle; 
     28        pallo.Color = Color.Green; 
    2029        pallo.X = -200.0; 
    2130        pallo.Y = 0.0; 
     
    2332        Add(pallo); 
    2433 
    25         LuoMaila(Level.Left + 20.0, 0.0); 
    26         LuoMaila(Level.Right - 20.0, 0.0); 
     34        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     35        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    2736 
    2837        Level.CreateBorders(1.0, false); 
     
    3140        Camera.ZoomToLevel(); 
    3241    } 
    33          
     42 
    3443    void AloitaPeli() 
    3544    { 
    3645        Vector impulssi = new Vector(600.0, 0.0); 
    37         pallo.Hit( impulssi ); 
     46        pallo.Hit(impulssi); 
    3847    } 
    3948 
    40     void LuoMaila(double x, double y) 
     49    PhysicsObject LuoMaila(double x, double y) 
    4150    { 
    4251        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     
    4655        maila.Restitution = 1.0; 
    4756        Add(maila); 
     57 
     58        return maila; 
    4859    } 
     60 
     61    void AsetaOhjaimet() 
     62    { 
     63        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa Ylos", maila1, nopeusYlos); 
     64        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     65        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa Ylos", maila1, nopeusAlas); 
     66        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     67 
     68        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa Ylos", maila2, nopeusYlos); 
     69        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     70        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa Ylos", maila2, nopeusAlas); 
     71        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     72 
     73        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
     74        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 
     75    } 
     76    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     77    { 
     78        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     79        { 
     80            maila.Velocity = Vector.Zero; 
     81            return; 
     82        } 
     83        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     84        { 
     85            maila.Velocity = Vector.Zero; 
     86            return; 
     87        }  
     88             
     89        maila.Velocity = nopeus; 
     90    } 
     91 
    4992} 
Note: See TracChangeset for help on using the changeset viewer.