Ignore:
Timestamp:
2010-07-27 13:28:35 (13 years ago)
Author:
tieenyky
Message:

Jee hauska peli :)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2010/30/tieenyky/Pong/Peli.cs

    r1304 r1322  
    1010 
    1111        PhysicsObject pallo; 
    12  
    1312        PhysicsObject maila1; 
    1413        PhysicsObject maila2; 
     14 
     15        PhysicsObject vasenReuna; 
     16        PhysicsObject oikeaReuna; 
     17 
     18        IntMeter pelaajan1Pisteet; 
     19        IntMeter pelaajan2Pisteet; 
    1520 
    1621    protected override void Begin() 
     
    1823        LuoKentta(); 
    1924        AsetaOhjaimet(); 
     25        LisaaLaskurit(); 
    2026        AloitaPeli(); 
    2127    } 
     
    2329    void LuoKentta() 
    2430    { 
     31        vasenReuna = Level.CreateLeftBorder(); 
    2532        pallo = new PhysicsObject(40.0, 40.0); 
    2633        pallo.Shape = Shapes.Circle; 
     
    2835        pallo.Restitution = 1.0; 
    2936        Add( pallo ); 
    30  
     37        AddCollisionHandler(pallo, KasittelePallonTormays); 
    3138        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    3239        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    33  
     40        oikeaReuna = Level.CreateRightBorder(); 
    3441        Level.CreateBorders(1.0, false); 
    35         Level.BackgroundColor = Color.Black; 
    36          
     42        Level.BackgroundColor = Color.Black;        
    3743        Camera.ZoomToLevel(); 
    38  
     44        MessageDisplay.TextColor = Color.Red; 
    3945    } 
    4046 
     
    7581    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    7682    { 
     83        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     84        { 
     85            maila.Velocity = Vector.Zero; 
     86            return; 
     87        } 
     88 
     89        if ( (nopeus.Y > 0) && (maila.Top > Level.Top) ) 
     90        { 
     91            maila.Velocity = Vector.Zero; 
     92            return; 
     93        } 
    7794        maila.Velocity = nopeus; 
    7895    } 
    7996 
     97        void LisaaLaskurit() 
     98    { 
     99        pelaajan1Pisteet = LuoPisteLaskuri( Screen.Left + 100.0, Screen.Top - 100.0 ); 
     100        pelaajan2Pisteet = LuoPisteLaskuri( Screen.Right - 100.0, Screen.Top - 100.0 ); 
     101    } 
     102 
     103 
     104    IntMeter LuoPisteLaskuri(double x, double y) 
     105    { 
     106        IntMeter laskuri = new IntMeter(0); 
     107        laskuri.MaxValue = 10; 
     108        Label naytto = new Label(); 
     109        naytto.BindTo(laskuri); 
     110        naytto.X = x; 
     111        naytto.Y = y; 
     112        naytto.TextColor = Color.White; 
     113        Add(naytto); 
     114        return laskuri; 
     115    } 
     116 
     117    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     118    { 
     119        if (kohde == oikeaReuna) 
     120        { 
     121            pelaajan1Pisteet.Value += 1; 
     122        } 
     123        else if (kohde == vasenReuna) 
     124        { 
     125            pelaajan2Pisteet.Value += 1; 
     126        } 
     127    } 
     128 
     129 
     130 
    80131} 
Note: See TracChangeset for help on using the changeset viewer.