Changeset 9048


Ignore:
Timestamp:
2017-07-24 13:11:36 (6 years ago)
Author:
npo17_60
Message:
 
Location:
2017/30/LeoL/Pong/Pong/Pong
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 2017/30/LeoL/Pong/Pong/Pong/Pong.cs

    r9039 r9048  
    1313 
    1414    PhysicsObject pallo; 
    15  
    1615    PhysicsObject maila1; 
    1716    PhysicsObject maila2; 
     17 
     18    PhysicsObject VasenReuna; 
     19    PhysicsObject OikeaReuna; 
     20 
     21    IntMeter pelaajan1Pisteet; 
     22    IntMeter pelaajan2Pisteet; 
    1823    public override void Begin() 
    1924    { 
    2025        // TODO: Kirjoita ohjelmakoodisi tähän 
    2126 
    22         luokentta(); 
    23         asetaohjaimet(); 
     27        LuoKentta(); 
     28        AsetaOhjaimet(); 
     29        LisaaLaskurit(); 
    2430        AloitaPeli(); 
    2531 
     
    2834    } 
    2935 
    30     void luokentta() 
     36    void LuoKentta() 
    3137    { 
    3238     pallo = new PhysicsObject(40.0, 40.0); 
     
    3541        pallo.X = -200.0; 
    3642        pallo.Y = 0.0; 
     43        AddCollisionHandler(pallo, KasittelePallonTormays); 
     44        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     45        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    3746 
    38         LuoMaila(Level.Left + 20.0, 0.0); 
    39         LuoMaila(Level.Right - 20.0, 0.0); 
    40  
    41  
    42         Level.CreateBorders(1.0, false); 
     47        PhysicsObject yläReuna = Level.CreateTopBorder(); 
     48        yläReuna.Restitution = 1.0; 
     49        yläReuna.IsVisible = false; 
     50        PhysicsObject AlaReuna = Level.CreateBottomBorder(); 
     51        AlaReuna.Restitution = 1.0; 
     52        AlaReuna.IsVisible = false; 
     53         OikeaReuna = Level.CreateRightBorder(); 
     54        OikeaReuna.Restitution = 1.0; 
     55        OikeaReuna.IsVisible = false; 
     56         VasenReuna = Level.CreateLeftBorder(); 
     57        VasenReuna.Restitution = 1.0; 
     58       VasenReuna.IsVisible = false; 
    4359        pallo.Restitution = 1.0; 
    4460        Level.Background.Color = Color.Black; 
    4561        Camera.ZoomToLevel(); 
     62         
     63    
    4664    } 
    4765    void AloitaPeli() 
     
    6078        return maila; 
    6179    } 
    62     void asetaohjaimet() 
     80    void AsetaOhjaimet() 
    6381    { 
    6482        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     
    7795    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    7896    { 
     97        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     98        { 
     99            maila.Velocity = Vector.Zero; 
     100            return; 
     101        } 
     102        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     103        { 
     104            maila.Velocity = Vector.Zero; 
     105            return; 
     106        } 
     107 
     108 
     109 
    79110        maila.Velocity = nopeus; 
     111    } 
     112 
     113    void LisaaLaskurit() 
     114    { 
     115        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     116        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     117    } 
     118IntMeter LuoPisteLaskuri(double x, double y) 
     119{ 
     120    IntMeter laskuri = new IntMeter(0); 
     121    laskuri.MaxValue = 10; 
     122     
     123    Label naytto = new Label(); 
     124    naytto.BindTo(laskuri); 
     125    naytto.X = x; 
     126    naytto.Y = y; 
     127    naytto.TextColor = Color.White; 
     128    naytto.BorderColor = Level.Background.Color; 
     129    naytto.Color = Level.Background.Color; 
     130    Add(naytto); 
     131 
     132    return laskuri; 
     133} 
     134    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     135    { 
     136        if (kohde == OikeaReuna) 
     137        { 
     138            pelaajan1Pisteet.Value += 1; 
     139        } 
     140        else if (kohde == VasenReuna) 
     141        { 
     142            pelaajan2Pisteet.Value += 1; 
     143        } 
     144 
    80145    } 
    81146 
Note: See TracChangeset for help on using the changeset viewer.