Changeset 3445


Ignore:
Timestamp:
2012-07-02 14:55:35 (8 years ago)
Author:
eekrkolu
Message:

Talletus.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2012/27/EemilK/pong/pong/pong/pong.cs

    r3430 r3445  
    99public class pong : PhysicsGame 
    1010{ 
     11    Vector nopeusYlos = new Vector(0, 200); 
     12    Vector nopeusAlas = new Vector(0, -200); 
    1113    PhysicsObject pallo; 
     14    PhysicsObject maila1; 
     15    PhysicsObject maila2; 
    1216    public override void Begin() 
    1317    { 
    1418        // TODO: Kirjoita ohjelmakoodisi tähän 
    1519        LuoKentta(); 
    16         Vector impulssi = new Vector(500.0, 0.0); 
    17         pallo.Hit(impulssi); 
     20        AsetaOhjaimet(); 
     21        AloitaPeli(); 
     22 
    1823        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
    1924        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     
    2126    void LuoKentta() 
    2227    { 
    23         PhysicsObject pallo = new PhysicsObject(40.0, 40.0); 
     28        pallo = new PhysicsObject(40.0, 40.0); 
    2429        pallo.Shape = Shape.Circle; 
    2530        pallo.Color = Color.Red; 
     
    2833        pallo.Restitution = 1.0; 
    2934        Add(pallo); 
     35        maila1 = luoMaila(Level.Left + 20.0, 0.0); 
     36        maila2 = luoMaila(Level.Right - 20.0, 0.0); 
    3037        Level.CreateBorders(1.0, false); 
    3138        Level.BackgroundColor = Color.Black; 
    3239        Camera.ZoomToLevel(); 
    3340    } 
     41 
     42    void AloitaPeli() 
     43    { 
     44        Vector impulssi = new Vector(500.0, 0.0); 
     45        pallo.Hit(impulssi); 
     46    } 
     47 
     48    PhysicsObject luoMaila(double x, double y) 
     49    { 
     50        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     51        maila.Shape = Shape.Rectangle; 
     52        maila.Color = Color.Blue; 
     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.Down, AsetaNopeus, "Pelaaja1: liikuta mailaa ylös", maila1, nopeusYlos); 
     63        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     64        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja1: liikuta mailaa alas", maila1, nopeusAlas); 
     65        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     66        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja2: 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, "pelaaja2: liikuta mailaa alas", maila2, nopeusAlas); 
     69        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     70        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "näytä ohjeet");  
     71        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta Peli"); 
     72    } 
     73    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     74    { 
     75        maila.Velocity = nopeus; 
     76    } 
    3477} 
     78 
Note: See TracChangeset for help on using the changeset viewer.