Changeset 2322 for 2011/26


Ignore:
Timestamp:
2011-06-29 15:00:52 (12 years ago)
Author:
eljajohy
Message:
 
Location:
2011/26/EliasH
Files:
17 added
1 edited

Legend:

Unmodified
Added
Removed
  • 2011/26/EliasH/Pong/Pong/Pong/Peli.cs

    r2239 r2322  
    1616    PhysicsObject maila2; 
    1717 
     18    PhysicsObject vasenReuna; 
     19    PhysicsObject oikeaReuna; 
     20 
     21    IntMeter pelaajan1Pisteet; 
     22    IntMeter pelaajan2Pisteet; 
     23 
    1824    public override void Begin() 
    1925    { 
    2026        LuoKentta(); 
    2127        AsetaOhjaimet(); 
     28        LisaaLaskurit(); 
    2229        AloitaPeli(); 
    2330    } 
     
    2936        pallo.Y = 0.0; 
    3037        pallo.Restitution = 1.0; 
     38        pallo.KineticFriction = 0.0; 
     39        pallo.MomentOfInertia = Double.PositiveInfinity; 
    3140        Add(pallo); 
     41        AddCollisionHandler(pallo, KasittelePallonTormays); 
    3242 
    3343        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    3444        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    3545 
     46        vasenReuna = Level.CreateLeftBorder(); 
     47        vasenReuna.Restitution = 1.0; 
     48        vasenReuna.KineticFriction = 0.0; 
     49        vasenReuna.IsVisible = false; 
     50        oikeaReuna = Level.CreateRightBorder(); 
     51        oikeaReuna.Restitution = 1.0; 
     52        oikeaReuna.KineticFriction = 0.0; 
     53        oikeaReuna.IsVisible = false; 
     54        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     55        ylaReuna.Restitution = 1.0; 
     56        ylaReuna.KineticFriction = 0.0; 
     57        ylaReuna.IsVisible = false; 
     58        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     59        alaReuna.Restitution = 1.0; 
     60        alaReuna.KineticFriction = 0.0; 
     61        alaReuna.IsVisible = false; 
    3662 
    37         Level.CreateBorders(1.0, false); 
    3863        Level.BackgroundColor = Color.Black; 
    3964 
     
    4772        maila.Y = y; 
    4873        maila.Restitution = 1.0; 
     74        maila.KineticFriction = 0.0; 
    4975        Add(maila); 
    5076        return maila; 
     
    7197        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
    7298        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 
    73          
     99 
    74100    } 
    75101 
     
    86112            return; 
    87113        } 
    88         maila.Velocity = nopeus;   
    89        } 
     114        maila.Velocity = nopeus; 
     115    } 
    90116 
    91117 
     118    void LisaaLaskurit() 
     119    { 
     120        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     121        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     122    } 
    92123 
     124    IntMeter LuoPisteLaskuri(double x, double y) 
     125    { 
     126        IntMeter laskuri = new IntMeter(0); 
     127        laskuri.MaxValue = 10; 
     128        Label naytto = new Label(); 
     129        naytto.BindTo(laskuri); 
     130        naytto.X = x; 
     131        naytto.Y = y; 
     132        naytto.TextColor = Color.White; 
     133        naytto.BorderColor = Level.BackgroundColor; 
     134        naytto.Color = Level.BackgroundColor; 
     135        Add(naytto); 
     136        return laskuri; 
     137    } 
    93138 
     139    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     140    { 
     141        if (kohde == oikeaReuna) 
     142        { 
     143            pelaajan1Pisteet.Value += 1; 
     144        } 
     145        else if (kohde == vasenReuna) 
     146        { 
     147            pelaajan2Pisteet.Value += 1; 
     148        } 
    94149 
    95  
    96  
    97     void LuoPisteLaskuri(double x, double y) 
    98     { } 
    99 }      
     150    } 
     151} 
Note: See TracChangeset for help on using the changeset viewer.