Changeset 2784 for 2012


Ignore:
Timestamp:
2012-06-05 09:50:01 (11 years ago)
Author:
juiitamm
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2012/23/HannesM/Pong/Pong/Pong/Pong.cs

    r2765 r2784  
    1414    PhysicsObject pallo; 
    1515 
     16    PhysicsObject vasenReuna; 
     17    PhysicsObject oikeaReuna; 
     18 
    1619    PhysicsObject maila1; 
    1720    PhysicsObject maila2; 
     21 
     22    IntMeter pelaajan1Pisteet; 
     23    IntMeter pelaajan2Pisteet; 
    1824 
    1925    public override void Begin() 
     
    2228        AsetaOhjaimet(); 
    2329        AloitaPeli(); 
     30        LisaaLaskuri(); 
    2431    } 
    2532 
     
    2734    { 
    2835        pallo = new PhysicsObject(30, 30); 
    29         pallo.Shape = Shape.Circle; 
    30         pallo.Color = Color.Red; 
     36        pallo.Shape = Shape.Hexagon; 
     37        pallo.Color = Color.Green; 
    3138        pallo.X = -200; 
    3239        pallo.Y = 0; 
     
    3845 
    3946        Level.BackgroundColor = Color.Black; 
    40         Level.CreateBorders(1.0, false); 
     47 
     48        vasenReuna = Level.CreateLeftBorder(); 
     49        vasenReuna.Restitution = 1.0; 
     50        vasenReuna.IsVisible = false; 
     51        oikeaReuna = Level.CreateRightBorder(); 
     52        oikeaReuna.Restitution = 1.0; 
     53        oikeaReuna.IsVisible = false; 
     54        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     55        ylaReuna.Restitution = 1.0; 
     56        ylaReuna.KineticFriction = 0.0; 
     57        ylaReuna.IsVisible = false; 
     58        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     59        alaReuna.Restitution = 1.0; 
     60        alaReuna.IsVisible = false; 
     61        alaReuna.KineticFriction = 0.0; 
     62 
    4163 
    4264        Camera.ZoomToLevel(); 
     
    4466        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
    4567        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     68 
     69        AddCollisionHandler(pallo, PallonTormays); 
     70 
    4671    } 
    4772    void AloitaPeli() 
     
    5378    { 
    5479        PhysicsObject maila = PhysicsObject.CreateStaticObject(10.0, 100.0); 
     80        maila.Color = Color.Gold; 
    5581        maila.Shape = Shape.Rectangle; 
    5682        maila.X = x; 
     
    78104    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    79105    { 
     106        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     107        { 
     108            maila.Velocity = Vector.Zero; 
     109            return; 
     110        } 
     111        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     112        { 
     113            maila.Velocity = Vector.Zero; 
     114            return; 
     115 
     116        } 
     117 
    80118        maila.Velocity = nopeus; 
     119    } 
     120    void LisaaLaskuri() 
     121    { 
     122        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left +100, Screen.Top - 100); 
     123        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100, Screen.Top - 100); 
     124    } 
     125    IntMeter LuoPisteLaskuri(double x, double y) 
     126    { 
     127        IntMeter laskuri = new IntMeter(0); 
     128        laskuri.MaxValue = 5; 
     129        Label naytto = new Label(); 
     130        naytto.BindTo(laskuri); 
     131        naytto.X = x; 
     132        naytto.Y = y; 
     133        naytto.TextColor = Color.Red; 
     134        naytto.BorderColor = Level.BackgroundColor; 
     135        naytto.Color = Level.BackgroundColor; 
     136        Add(naytto); 
     137 
     138        return laskuri; 
     139 
     140    } 
     141    void PallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     142    { 
     143        if (kohde == oikeaReuna) 
     144        { 
     145            pelaajan1Pisteet.Value += 1; 
     146        } 
     147        else if (kohde == vasenReuna) 
     148        { 
     149            pelaajan2Pisteet.Value += 1; 
     150        } 
    81151    } 
    82152 
Note: See TracChangeset for help on using the changeset viewer.