Changeset 8529


Ignore:
Timestamp:
2017-06-12 14:57:50 (2 years ago)
Author:
npo17_28
Message:

jotain

Location:
2017/24/JaakkoK/Pong
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 2017/24/JaakkoK/Pong/Pong/Pong/Pong.cs

    r8522 r8529  
    88 
    99public class Pong : PhysicsGame 
    10 { 
     10{  
     11    Vector nopeusYlos = new Vector(0, 200); 
     12    Vector nopeusAlas = new Vector(0, -200); 
     13 
    1114    PhysicsObject pallo; 
     15 
     16    PhysicsObject maila1; 
     17    PhysicsObject maila2; 
     18 
    1219    public override void Begin() 
    1320    { 
     
    1825        pallo.Hit(impulssi); 
    1926        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
    20         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     27         
    2128    } 
    2229    void LuoKentta() 
     
    2835        pallo.Restitution = 1.0; 
    2936 
    30         LuoMaila(Level.Left + 20.0, 0.0); 
    31         LuoMaila(Level.Right - 20.0, 0.0); 
     37      maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     38      maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    3239 
    3340        Level.CreateBorders(1.0, false); 
     
    4148        Vector impulssi = new Vector(500.0, 0.0); 
    4249        pallo.Hit(impulssi); 
     50    } 
     51 
     52    void PhysicsObject LuoMaila(double x, double y) 
     53    { 
     54        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     55        maila.Shape = Shape.Rectangle; 
     56        maila.X = x; 
     57        maila.Y = y; 
     58        maila.Restitution = 1.0; 
     59        Add(maila); 
     60        return maila; 
     61    } 
     62    void AsetaOhjaimet() 
     63    { 
     64    Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     65    Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, Null, maila1 Vector.Zero); 
     66 
     67        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     68    } 
     69    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     70    { 
     71        maila.Velocity = nopeus; 
     72    } 
    4373 
    4474 
    45         void LuoMaila(double x, double y) 
    46         { 
    47     PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    48     maila.Shape = Shape.Rectangle; 
    49     maila.X = x; 
    50     maila.Y = y; 
    51     maila.Restitution = 1.0; 
    52     Add(maila); 
     75 
    5376        } 
    54     } 
    55 } 
Note: See TracChangeset for help on using the changeset viewer.