Changeset 4220 for 2013/26


Ignore:
Timestamp:
2013-06-25 14:54:30 (10 years ago)
Author:
alpynnon
Message:

Talletus.

Location:
2013/26/AleksiP
Files:
19 added
1 edited

Legend:

Unmodified
Added
Removed
  • 2013/26/AleksiP/pingpong/pingpong/pingpong/pingpong.cs

    r4198 r4220  
    1313 
    1414    PhysicsObject pallo; 
     15    PhysicsObject maila1; 
     16    PhysicsObject maila2; 
    1517 
    16     PhysicsObject maila1; 
    17         PhysicsObject maila2; 
     18    PhysicsObject vasenReuna; 
     19    PhysicsObject oikeaReuna; 
     20 
     21    IntMeter pelaajan1Pisteet; 
     22    IntMeter pelaajan2Pisteet; 
    1823 
    1924    public override void Begin() 
     
    2227        AloitaPeli(); 
    2328        AsetaOhjaimet(); 
     29        LisaaLaskurit(); 
    2430 
    2531        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
    26          
     32 
    2733 
    2834    } 
     
    3137        pallo = new PhysicsObject(50.0, 50.0); 
    3238        Add(pallo); 
     39        AddCollisionHandler(pallo, KasittelePallonTormays); 
    3340        pallo.Shape = Shape.Circle; 
    3441        pallo.Color = Color.LightGreen; 
     
    3643        pallo.X = 40.0; 
    3744 
    38        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    39        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
     45        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     46        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    4047 
    41         Level.CreateBorders(1.0, false); 
     48 vasenReuna = Level.CreateLeftBorder(); 
     49        vasenReuna.Restitution = 1.0; 
     50        vasenReuna.KineticFriction = 0.0; 
     51        vasenReuna.IsVisible = false; 
     52 
     53 oikeaReuna = Level.CreateRightBorder(); 
     54        oikeaReuna.Restitution = 1.0; 
     55        oikeaReuna.KineticFriction = 0.0; 
     56        oikeaReuna.IsVisible = false; 
     57 
     58        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     59        alaReuna.Restitution = 1.0; 
     60        alaReuna.KineticFriction = 0.0; 
     61        alaReuna.IsVisible = false; 
     62 
     63        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     64        ylaReuna.Restitution = 1.0; 
     65        ylaReuna.KineticFriction = 0.0; 
     66        ylaReuna.IsVisible = false; 
     67 
    4268        pallo.Restitution = (1.7); 
    4369        Level.BackgroundColor = Color.Black; 
    4470        Camera.ZoomToLevel(); 
    45 } 
     71    } 
    4672    void AloitaPeli() 
    4773    { 
    48         Vector impulssi = new Vector(500.0, 0.0); 
     74        Vector impulssi = new Vector(1000.0, 0.0); 
    4975        pallo.Hit(impulssi); 
    5076    } 
    51    PhysicsObject LuoMaila(double x, double y) 
     77    PhysicsObject LuoMaila(double x, double y) 
    5278    { 
    5379        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     
    6187    } 
    6288 
     89    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     90    { 
     91 
     92        if (kohde == oikeaReuna) 
     93        { 
     94            pelaajan1Pisteet.Value += 1; 
     95        } 
     96        else if (kohde == vasenReuna) 
     97        { 
     98            pelaajan2Pisteet.Value += 999999; 
     99        } 
     100 
     101 
     102    } 
    63103    void AsetaOhjaimet() 
    64104    { 
     
    79119    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    80120    { 
     121        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     122        { 
     123            maila.Velocity = Vector.Zero; 
     124            return; 
     125        } 
     126         
     127if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     128{ 
     129    maila.Velocity = Vector.Zero; 
     130    return; 
     131        } 
    81132        maila.Velocity = nopeus; 
    82133    } 
     134 
     135    void LisaaLaskurit() 
     136    { 
     137        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     138        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     139    } 
     140 
     141    IntMeter LuoPisteLaskuri(double x, double y) 
     142    { 
     143        IntMeter laskuri = new IntMeter(0); 
     144        laskuri.MaxValue = 10000000; 
     145        Label naytto = new Label(); 
     146        naytto.BindTo(laskuri); 
     147        naytto.X = x; 
     148        naytto.Y = y; 
     149        naytto.TextColor = Color.Red; 
     150        naytto.BorderColor = Level.BackgroundColor; 
     151        naytto.Color = Level.BackgroundColor; 
     152        Add(naytto); 
     153 
     154        return laskuri; 
     155    } 
    83156} 
    84  
Note: See TracChangeset for help on using the changeset viewer.