Changeset 4189


Ignore:
Timestamp:
2013-06-24 14:57:43 (10 years ago)
Author:
juskovan
Message:

Talletus.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2013/26/JustusK/Pong/Pong/Pong/Pong.cs

    r4182 r4189  
    99public class Pong : PhysicsGame 
    1010{ 
     11    Vector nopeusYlos = new Vector(0, 200); 
     12    Vector nopeusAlas = new Vector(0, -200); 
     13 
    1114    PhysicsObject pallo; 
    12      
     15 
     16    PhysicsObject maila1; 
     17    PhysicsObject maila2; 
     18 
    1319    public override void Begin() 
    14     { 
     20       { 
    1521        LuoKentta(); 
     22        AsetaOhjaimet();   
     23        AloitaPeli(); 
    1624 
    17         Vector impulssi = new Vector(500.0, 0.0); 
    18         pallo.Hit(impulssi); 
    19  
    20         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    21     } 
     25           Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     26       } 
     27    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     28        { 
     29        maila.Velocity = nopeus; 
     30        } 
    2231    void LuoKentta() 
    2332    { 
    24         PhysicsObject pallo = new PhysicsObject(40.0, 40.0); 
     33        pallo = new PhysicsObject(40.0, 40.0); 
    2534        pallo.Shape = Shape.Circle; 
    26         pallo.X = 40.0; 
    27         pallo.Y = 40.0; 
     35        pallo.X = -200.0; 
     36        pallo.Y = 0.0; 
    2837        pallo.Restitution = 1.0; 
    2938        Add(pallo); 
    3039 
    31         Level.CreateBorders(1.0, true); 
     40        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     41        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
     42 
     43        Level.CreateBorders(1.0, false); 
    3244        Level.BackgroundColor = Color.Black; 
    3345 
    3446        Camera.ZoomToLevel(); 
     47     } 
     48 
     49    void AsetaOhjaimet() 
     50    { 
     51        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     52        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     53     
     54        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    3555    } 
     56         
     57        PhysicsObject LuoMaila(double x, double y) 
     58        { 
     59          PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     60          maila.Shape = Shape.Rectangle; 
     61          maila.X = x; 
     62          maila.Y = y; 
     63          maila.Restitution = 1.0; 
     64          Add(maila); 
     65          return maila; 
     66    } 
     67        
     68    void AloitaPeli() 
     69    { 
     70            Vector impulssi = new Vector(500.0, 0.0); 
     71            pallo.Hit(impulssi); 
     72     
     73    } 
     74 
    3675} 
Note: See TracChangeset for help on using the changeset viewer.