Changeset 2937


Ignore:
Timestamp:
2012-06-12 10:46:41 (11 years ago)
Author:
anlakane
Message:

Talletus.

Location:
2012/24/LeeviL/Pong/Pong
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • 2012/24/LeeviL/Pong/Pong/Pong/Pong.cs

    r2923 r2937  
    1313 
    1414    PhysicsObject pallo; 
    15  
    1615    PhysicsObject maila1; 
    1716    PhysicsObject maila2; 
    1817 
     18    PhysicsObject oikeaReuna; 
     19    PhysicsObject vasenReuna; 
     20 
     21    IntMeter pelaajan1Pisteet; 
     22    IntMeter pelaajan2Pisteet; 
     23 
    1924    public override void Begin() 
    2025    { 
    21         // TODO: Kirjoita ohjelmakoodisi tähän 
    22         LuoKentta (); 
     26 
     27        LuoKentta(); 
    2328        AloitaPeli(); 
     29        LisaaLaskurit(); 
    2430        AsetaOhjaimet(); 
    2531    } 
     
    3339 
    3440    PhysicsObject LuoMaila(double X, double Y) 
    35     {  
    36      
    37   PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     41    { 
     42 
     43        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    3844        maila.Shape = Shape.Rectangle; 
    3945        maila.X = X; 
     
    4450        return maila; 
    4551    } 
     52 
     53    void LisaaLaskurit() 
     54    { 
     55        pelaajan1Pisteet = LuoPistelaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     56        pelaajan2Pisteet = LuoPistelaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     57    } 
     58 
     59    IntMeter LuoPistelaskuri(double x, double y) 
     60    { 
     61        IntMeter laskuri = new IntMeter(0); 
     62        laskuri.MaxValue = 10; 
     63        Label naytto = new Label(); 
     64        naytto.BindTo(laskuri); 
     65        naytto.X = x; 
     66        naytto.Y = y; 
     67        naytto.TextColor = Color.White; 
     68        naytto.BorderColor = Level.BackgroundColor; 
     69        naytto.Color = Level.BackgroundColor; 
     70        Add(naytto); 
     71        return laskuri; 
     72    } 
     73 
    4674 
    4775    void AsetaOhjaimet() 
     
    6391    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    6492    { 
     93        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     94        { 
     95            maila.Velocity = Vector.Zero; 
     96            return; 
     97        } 
     98 
     99        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     100        { 
     101            maila.Velocity = Vector.Zero; 
     102            return; 
     103        } 
     104 
    65105        maila.Velocity = nopeus; 
    66106    } 
    67107 
    68     void LuoKentta ()  
     108    void KasittlePallonTormaus(PhysicsObject pallo, PhysicsObject kohde) 
     109    { 
     110        if (kohde == oikeaReuna) 
     111        { 
     112            pelaajan1Pisteet.Value += 1; 
     113 
     114        } 
     115 
     116        else if (kohde == vasenReuna) 
     117        { 
     118            pelaajan2Pisteet.Value += 1; 
     119 
     120        } 
     121 
     122    } 
     123 
     124    void LuoKentta() 
    69125    { 
    70126        pallo = new PhysicsObject(40.0, 40.0); 
     
    75131        pallo.Restitution = 1.0; 
    76132 
     133        AddCollisionHandler(pallo, KasittlePallonTormaus); 
     134 
    77135        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    78136        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    79137 
    80         Level.CreateBorders(1.0, false); 
     138        vasenReuna = Level.CreateLeftBorder(); 
     139        vasenReuna.Restitution = 1.0; 
     140        vasenReuna.IsVisible = false; 
     141        oikeaReuna = Level.CreateRightBorder(); 
     142        oikeaReuna.Restitution = 1.0; 
     143        oikeaReuna.IsVisible = false; 
     144        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     145        alaReuna.Restitution = 1.0; 
     146        alaReuna.IsVisible = false; 
     147        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     148        ylaReuna.Restitution = 1.0; 
     149        ylaReuna.IsVisible = false; 
    81150        Level.BackgroundColor = Color.Black; 
    82151 
    83152        Camera.ZoomToLevel(); 
    84  
    85      
    86  
    87        
    88153    } 
    89154} 
Note: See TracChangeset for help on using the changeset viewer.