Changeset 7557 for 2016/26


Ignore:
Timestamp:
2016-06-28 14:59:24 (7 years ago)
Author:
karkaite
Message:
 
Location:
2016/26/PinjaV/Pong/Pong/Pong
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 2016/26/PinjaV/Pong/Pong/Pong/Pong.cs

    r7545 r7557  
    1414    PhysicsObject maila1; 
    1515    PhysicsObject maila2; 
     16    PhysicsObject vasenReuna; 
     17    PhysicsObject oikeaReuna; 
     18    IntMeter pelaajan1Pisteet; 
     19    IntMeter pelaajan2Pisteet; 
    1620    public override void Begin() 
    1721    { 
     
    3236        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    3337        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    34         Level.CreateBorders(1.0, false); 
    35         Level.Background.Color = Color.Red; 
     38 
     39        vasenReuna = Level.CreateLeftBorder(); 
     40        vasenReuna.Restitution = 1.0; 
     41        vasenReuna.IsVisible = false; 
     42 
     43        oikeaReuna = Level.CreateRightBorder(); 
     44        oikeaReuna.Restitution = 1.0; 
     45        oikeaReuna.IsVisible = false; 
     46 
     47        PhysicsObject yläReuna = Level.CreateBottomBorder(); 
     48        yläReuna.Restitution = 1.0; 
     49        yläReuna.IsVisible = false; 
     50 
     51        PhysicsObject alaReuna = Level.CreateTopBorder(); 
     52        alaReuna.Restitution = 1.0; 
     53        alaReuna.IsVisible = false; 
     54 
     55        Level.Background.Color = Color.Purple; 
    3656        Camera.ZoomToLevel(); 
     57        AddCollisionHandler(pallo, KasittelePallonTormays); 
    3758    } 
    3859    void AloitaPeli() 
     
    6889    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    6990    { 
    70         if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom )) 
     91        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
    7192        { 
    7293            maila.Velocity = Vector.Zero; 
     
    7495 
    7596        } 
    76         if (( nopeus.Y > 0) && (maila.Top > Level.Top)) 
     97        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     98        { 
     99            maila.Velocity = Vector.Zero; 
     100            return; 
     101        } 
    77102        maila.Velocity = nopeus; 
    78103    } 
    79104    void LisaaLaskurit() 
    80     {  
    81        // ... 
     105    { 
     106        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     107        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
    82108    } 
    83 } 
     109    IntMeter LuoPisteLaskuri(double x, double y) 
     110    { 
     111        IntMeter laskuri = new IntMeter(0); 
     112        laskuri.MaxValue = 10; 
     113        Label naytto = new Label(); 
     114        naytto.BindTo(laskuri); 
     115        naytto.X = x; 
     116        naytto.Y = y; 
     117        naytto.TextColor = Color.White; 
     118        naytto.BorderColor = Level.Background.Color; 
     119        Add(naytto); 
     120        return laskuri; 
     121    } 
     122    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     123    { 
     124    if (kohde == oikeaReuna) 
     125        { 
     126            pelaajan1Pisteet.Value += 1; 
     127        } 
     128     else if (kohde == vasenReuna) 
     129        { 
     130            pelaajan2Pisteet.Value += 1; 
     131        } 
     132    } 
     133}       
Note: See TracChangeset for help on using the changeset viewer.