Changeset 8851


Ignore:
Timestamp:
2017-07-03 15:01:29 (6 years ago)
Author:
npo17_44
Message:
 
Location:
2017/27/TuukkaH/Pong
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 2017/27/TuukkaH/Pong/Pong/Pong/Pong.cs

    r8828 r8851  
    1818    PhysicsObject maila2; 
    1919 
     20    PhysicsObject vasenReuna; 
     21    PhysicsObject oikeaReuna; 
     22 
     23    IntMeter pelaajan1Pisteet; 
     24    IntMeter pelaajan2Pisteet; 
     25 
     26 
    2027    public override void Begin() 
    2128    { 
    2229        LuoKentta(); 
    2330        AsetaOhjaimet(); 
     31        LisaaLaskurit(); 
    2432        AloitaPeli(); 
    2533    } 
    26  
    2734    void LuoKentta() 
    2835    { 
     
    3239        pallo.Y = 0.0; 
    3340        pallo.Restitution = 1.0; 
     41        Add(pallo); 
    3442        pallo.Color = Color.Ultramarine; 
    35         Add(pallo); 
     43        AddCollisionHandler(pallo, KasittelePallonTormays); 
    3644 
    3745        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    3846        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    3947 
    40         Level.CreateBorders(1.0, false); 
     48        vasenReuna = Level.CreateLeftBorder(); 
     49        vasenReuna.Restitution = 1.0; 
     50        vasenReuna.IsVisible = false; 
     51 
     52        oikeaReuna = Level.CreateRightBorder(); 
     53        oikeaReuna.Restitution = 1.0; 
     54        oikeaReuna.IsVisible = false; 
     55 
     56        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     57        ylaReuna.Restitution = 1.0; 
     58        ylaReuna.IsVisible = false; 
     59 
     60        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     61        alaReuna.Restitution = 1.0; 
     62        alaReuna.IsVisible = false; 
     63 
    4164        Level.Background.Color = Color.Aqua; 
    4265 
    4366        Camera.ZoomToLevel(); 
     67 
     68    } 
     69    void LisaaLaskurit() 
     70    { 
     71        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     72        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0);  // ... 
     73    } 
     74    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     75    { 
     76        if (kohde == oikeaReuna) 
     77        { 
     78            pelaajan1Pisteet.Value += 1; 
     79        } 
     80        else if (kohde == vasenReuna) 
     81        { 
     82            pelaajan2Pisteet.Value += 1; 
     83        } 
    4484    } 
    4585 
     
    5797    } 
    5898 
    59     void AloitaPeli() 
    60     { 
    61         Vector impulssi = new Vector(500.0, 0.0); 
    62         pallo.Hit(impulssi); 
    63     } 
     99    
    64100 
    65101    void AsetaOhjaimet() 
     
    78114        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    79115    } 
    80  
    81116    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    82117    { 
     118        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     119        { 
     120            maila.Velocity = Vector.Zero; 
     121            return; 
     122        } 
     123        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     124        { 
     125            maila.Velocity = Vector.Zero; 
     126            return; 
     127        } 
     128 
    83129        maila.Velocity = nopeus; 
    84130    } 
     131    IntMeter LuoPisteLaskuri(double x, double y) 
     132    { 
     133        IntMeter laskuri = new IntMeter(0); 
     134        laskuri.MaxValue = 10; 
     135 
     136        Label naytto = new Label(); 
     137        naytto.BindTo(laskuri); 
     138        naytto.X = x; 
     139        naytto.Y = y; 
     140        naytto.TextColor = Color.Ultramarine; 
     141        naytto.BorderColor = Level.Background.Color; 
     142        naytto.Color = Level.Background.Color; 
     143        Add(naytto); 
     144 
     145        return laskuri; 
     146    } 
     147 
     148    void AloitaPeli() 
     149    { 
     150        Vector impulssi = new Vector(500.0, 0.0); 
     151        pallo.Hit(impulssi); 
     152    } 
     153 
    85154} 
Note: See TracChangeset for help on using the changeset viewer.