Changeset 6860 for 2015


Ignore:
Timestamp:
2015-07-21 14:09:59 (8 years ago)
Author:
mivasata
Message:

Valmis Pong-peli. Restart tapahtuu painamalla välilyöntiä.

Location:
2015/30/ValtteriT/Pong
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 2015/30/ValtteriT/Pong/Pong/Pong/Pong.cs

    r6843 r6860  
    1515    PhysicsObject maila1; 
    1616    PhysicsObject maila2; 
     17    PhysicsObject oikeaReuna; 
     18    PhysicsObject vasenReuna; 
    1719 
    1820    IntMeter pelaajan1Pisteet; 
     
    2123    public override void Begin() 
    2224    { 
     25        ClearAll(); 
    2326        LuoKentta(); 
    2427        AsetaOhjaimet(); 
     
    3740        pallo = new PhysicsObject(40.0, 40.0); 
    3841        pallo.Shape = Shape.Circle; 
    39          
     42        pallo.KineticFriction = 0.0; 
     43        pallo.MomentOfInertia = Double.PositiveInfinity; 
    4044        pallo.X = 200.0; 
    4145        pallo.Y = 0.0; 
    4246        pallo.Restitution = 1.0; 
    4347        Add(pallo); 
     48        AddCollisionHandler(pallo, KasittelePallonTormays); 
    4449         
    4550        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    4651        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    4752 
    48         Level.CreateBorders(1.0, false); 
     53        vasenReuna = Level.CreateLeftBorder(); 
     54        vasenReuna.Restitution = 1.0; 
     55        vasenReuna.IsVisible = false; 
     56        oikeaReuna = Level.CreateRightBorder(); 
     57        oikeaReuna.Restitution = 1.0; 
     58        oikeaReuna.IsVisible = false; 
     59        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     60        ylaReuna.Restitution = 1.0; 
     61        ylaReuna.IsVisible = false; 
     62        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     63        alaReuna.Restitution = 1.0; 
     64        alaReuna.IsVisible = false; 
     65 
    4966        Level.Background.Color = Color.Black; 
    5067 
     
    8198        Keyboard.Listen(Key.Down,   ButtonState.Released,  AsetaNopeus,     null, maila2, Vector.Zero); 
    8299 
     100        Keyboard.Listen(Key.Space,  ButtonState.Pressed,   Begin,           "Uusi peli"); 
    83101        Keyboard.Listen(Key.F1,     ButtonState.Pressed,   ShowControlHelp, "Näytä ohjeet"); 
    84102        Keyboard.Listen(Key.Escape, ButtonState.Pressed,   ConfirmExit,     "Lopeta peli"); 
     
    125143        return laskuri; 
    126144    } 
     145 
     146void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     147{ 
     148    if (kohde == oikeaReuna) 
     149    { 
     150        pelaajan1Pisteet.Value += 1; 
     151    } 
     152    else if (kohde == vasenReuna) 
     153    { 
     154        pelaajan2Pisteet.Value += 1; 
     155    } 
    127156} 
     157} 
Note: See TracChangeset for help on using the changeset viewer.