Changeset 1991 for 2011


Ignore:
Timestamp:
2011-06-14 14:58:15 (12 years ago)
Author:
paaaanro
Message:
 
Location:
2011/24/PauliN
Files:
31 added
1 edited

Legend:

Unmodified
Added
Removed
  • 2011/24/PauliN/Peli.cs

    r1958 r1991  
    1717    PhysicsObject maila2; 
    1818 
     19    PhysicsObject vasenReuna; 
     20    PhysicsObject oikeaReuna; 
     21 
     22    IntMeter Pelaajan1Pisteet; 
     23    IntMeter Pelaajan2Pisteet; 
     24 
    1925    public override void Begin() 
    2026    {  
    2127        LuoKentta (); 
    2228        AsetaOhjaimet(); 
     29        LisaaLaskurit(); 
    2330        Aloitapeli (); 
    2431    } 
     
    3946        pallo.Y = 0; 
    4047        pallo.Restitution = 1.0; 
     48        pallo.KineticFriction = 0.0; 
     49        AddCollisionHandler(pallo, KasittelePallonTormays); 
    4150 
    4251        maila1 = LuoMaila (Level.Left + 20, 0); 
     
    4554        Camera.ZoomToLevel(); 
    4655 
    47         Level.CreateBorders(1.0, false); 
     56        vasenReuna = Level.CreateLeftBorder(); 
     57        vasenReuna.Restitution = 1; 
     58        vasenReuna.IsVisible = false; 
     59 
     60        oikeaReuna = Level.CreateRightBorder(); 
     61        vasenReuna.Restitution = 1; 
     62        vasenReuna.IsVisible = false; 
     63 
     64        PhysicsObject yläReuna = Level.CreateTopBorder(); 
     65        yläReuna.Restitution = 1; 
     66        yläReuna.IsVisible = false; 
     67 
     68        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     69        alaReuna.Restitution = 1; 
     70        alaReuna.IsVisible = false; 
     71          
     72 
     73 
    4874        Level.BackgroundColor = Color.Black; 
    4975        MessageDisplay.TextColor = Color.White; 
     76 
     77        AddCollisionHandler (pallo, KasittelePallonTormays); 
    5078 
    5179         
     
    89117 
    90118    } 
    91     void AsetaNopeus(PhysicsObject Maila, Vector Nopeus) 
     119 
     120    void AsetaNopeus ( PhysicsObject Maila, Vector Nopeus) 
    92121    { 
    93         if (Maila.Top > Level.Top) 
     122        if ( (Nopeus.Y < 0 ) && (Maila.Bottom < Level.Bottom) ) 
     123        {  
     124            Maila.Velocity = Vector.Zero; 
     125            return; 
     126        } 
     127 
     128        if ( (Nopeus.Y > 0 ) && (Maila.Top > Level.Top) ) 
    94129        { 
    95130            Maila.Velocity = Vector.Zero; 
    96131            return; 
    97132        } 
    98          
     133 
     134            Maila.Velocity = Nopeus; 
     135    } 
     136    void LisaaLaskurit() 
     137    { 
     138        Pelaajan1Pisteet = LuoPisteLaskuri ( Screen.Left + 100.0 , Screen.Top - 100.0 ); 
     139        Pelaajan2Pisteet = LuoPisteLaskuri ( Screen.Right - 100.0 , Screen.Top - 100.0 ); 
     140    } 
     141    IntMeter LuoPisteLaskuri (double x, double y) 
     142    { 
     143        IntMeter laskuri = new IntMeter(0); 
     144        laskuri.MaxValue = 10; 
     145        Label naytto = new Label(); 
     146        naytto.BindTo(laskuri); 
     147        naytto.X = x; 
     148        naytto.Y = y; 
     149        naytto.TextColor = Color.White; 
     150        naytto.BorderColor = Level.BackgroundColor; 
     151        naytto.Color = Level.BackgroundColor; 
     152        Add(naytto); 
     153 
     154        return laskuri; 
     155    } 
    99156 
    100157 
    101158 
    102             Maila.Velocity = Nopeus; 
     159     
     160    void KasittelePallonTormays ( PhysicsObject pallo, PhysicsObject kohde ) 
     161    { 
     162        if (kohde == oikeaReuna) 
     163        { 
     164            Pelaajan1Pisteet.Value += 1; 
     165        } 
     166        else if (kohde == vasenReuna) 
     167        { 
     168            Pelaajan2Pisteet.Value += 1; 
     169 
     170        } 
     171 
    103172    } 
    104173 
Note: See TracChangeset for help on using the changeset viewer.