Changeset 1310 for 2010/30/nilaiton/Pong


Ignore:
Timestamp:
2010-07-27 11:26:20 (13 years ago)
Author:
nilaiton
Message:

asdasdasdasd

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2010/30/nilaiton/Pong/Peli.cs

    r1287 r1310  
    1010 
    1111    PhysicsObject pallo; 
     12    PhysicsObject vasenReuna; 
     13    PhysicsObject oikeaReuna; 
    1214 
    1315    PhysicsObject maila1; 
    1416    PhysicsObject maila2; 
     17    IntMeter pelaajan1Pisteet; 
     18    IntMeter pelaajan2Pisteet; 
    1519 
    1620    protected override void Begin() 
     
    1822        LuoKentta(); 
    1923        AsetaOhjaimet(); 
    20  
     24        LisaaLaskurit(); 
    2125        AloitaPeli(); 
    2226 
    2327 
    24      
     28       
    2529 
    2630    } 
     
    2933    { 
    3034  pallo = new PhysicsObject(40.0, 40.0); 
    31         pallo.Shape = Shapes.Circle; 
     35        pallo.Shape = Shapes.Triangle; 
    3236        Add(pallo); 
    3337        pallo.X = -200.0; 
    3438        pallo.Y = 0.0; 
    35  
     39        pallo.CanRotate = true; 
     40        pallo.KineticFriction = 0.0; 
    3641        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    3742        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
     43        pallo.Color = Color.Fuchsia; 
     44        pallo.Velocity = new Vector ( 20.0, 20.0); 
     45 
     46        PhysicsObject pallo2; 
     47 
     48        pallo2 = new PhysicsObject(60.0, 60.0); 
     49        pallo2.Shape = Shapes.Triangle; 
     50        Add(pallo2); 
     51        pallo2.X = -200.0; 
     52        pallo2.Y = 0.0; 
     53        pallo2.CanRotate = true; 
     54        pallo2.KineticFriction = 0.0; 
     55        
     56        pallo2.Color = Color.SkyBlue; 
     57        pallo2.Velocity = new Vector(20.0, 20.0); 
     58        pallo2.Restitution = 1.0; 
     59        AddCollisionHandler(pallo, KasittelePallonTormays); 
     60       
     61        vasenReuna = Level.CreateLeftBorder(); 
     62        vasenReuna.Restitution = 1.0; 
     63        vasenReuna.IsVisible = false; 
     64        oikeaReuna = Level.CreateRightBorder(); 
     65        oikeaReuna.Restitution = 1.0; 
     66        oikeaReuna.IsVisible = false; 
     67        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     68        ylaReuna.Restitution = 1.0; 
     69        ylaReuna.IsVisible = false; 
     70        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     71        alaReuna.Restitution = 1.0; 
     72        alaReuna.IsVisible = false; 
    3873 
    3974 
    40         Level.CreateBorders(1.0,false); 
     75 
     76 
    4177        pallo.Restitution = 1.0; 
    42         Level.BackgroundColor = Color.DarkRed; 
     78        Level.BackgroundColor = Color.TransparentBlack; 
    4379        Camera.ZoomToLevel(); 
    4480 
    45          
     81        AddCollisionHandler(pallo, KasittelePallonTormays); 
     82 
    4683 
    4784    } 
     
    5491    { 
    5592        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    56         maila.Shape = Shapes.Circle; 
     93        maila.Shape = Shapes.Rectangle; 
    5794        maila.X = x; 
    5895        maila.Y = y; 
    5996        maila.Restitution = 1.0; 
    6097        Add(maila); 
     98        maila.Color = Color.Aqua; 
    6199 
    62100        return maila; 
     
    82120    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    83121    { 
     122        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     123        { 
     124            maila.Velocity = Vector.Zero; 
     125            return; 
     126        } 
    84127        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
    85128        { 
     
    88131        } 
    89132 
    90         maila.Velocity = nopeus;  
     133        maila.Velocity = nopeus; 
     134 
     135    } 
     136    void LisaaLaskurit() 
     137    { 
     138        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     139        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     140 
     141    } 
     142    IntMeter LuoPisteLaskuri(double x, double y) 
     143    { 
     144        IntMeter laskuri = new IntMeter(0); 
     145        laskuri.MaxValue = 10; 
     146        Label naytto = new Label(500,500); 
     147        naytto.BindTo(laskuri); 
     148        naytto.X = x; 
     149        naytto.Y = y; 
     150        naytto.TextColor = Color.OrangeRed; 
     151         
     152        Add(naytto); 
     153        return laskuri; 
     154    } 
     155    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     156    { 
     157        if (kohde == oikeaReuna) 
     158        { 
     159            pelaajan1Pisteet.Value += 1; 
     160        } 
     161        else if (kohde == vasenReuna) 
     162        { 
     163            pelaajan2Pisteet.Value += 1; 
     164        } 
    91165    } 
    92166 
Note: See TracChangeset for help on using the changeset viewer.