Changeset 1552 for 2010


Ignore:
Timestamp:
2010-08-03 11:30:46 (9 years ago)
Author:
paaaanro
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2010/31/mimakrja/pong/Peli.cs

    r1520 r1552  
    66public class Peli : PhysicsGame 
    77{ 
     8    Vector nopeusYlos = new Vector( 0, 200 ); 
     9    Vector nopeusAlas = new Vector( 0, -200 ); 
     10 
     11    PhysicsObject pallo; 
     12    PhysicsObject maila1; 
     13    PhysicsObject maila2; 
     14 
     15    IntMeter pelaajan1Pisteet; 
     16    IntMeter pelaajan2Pisteet; 
     17 
    818    protected override void Begin() 
    919    { 
    1020        LuoKentta(); 
    11         Vector impulssi = new Vector(750.0, 50.0); 
    12         pallo.Hit(impulssi); 
    13          
     21        AsetaOhjaimet(); 
     22        LisaaLaskurit(); 
     23        AloitaPeli();         
    1424    } 
    1525 
    1626    void LuoKentta() 
    17     { 
    18         PhysicsObject pallo = new PhysicsObject(40.0, 40.0); 
     27    {         
     28        pallo = new PhysicsObject(40.0, 40.0); 
    1929        pallo.Shape = Shapes.Circle; 
    2030        Add(pallo); 
    21         Level.CreateBorders(1.0, false); 
     31        PhysicsObject vasenReuna = Level.CreateLeftBorder(); 
     32        vasenReuna.Restitution = 1.0; 
     33        vasenReuna.IsVisible = false; 
     34 
    2235        pallo.Restitution = 1.0; 
    2336        Level.BackgroundColor = Color.Black; 
    2437        Camera.ZoomToLevel(); 
     38 
     39        maila1 = LuoMaila(Level.Left + 20.0, 0.0 ); 
     40        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
     41 
     42        AddCollisionHandler(pallo, KasittelePallonTormays); 
     43    } 
     44 
     45    void AloitaPeli() 
     46    { 
     47        Vector impulssi = new Vector(500.0, 0.0); 
     48        pallo.Hit(impulssi); 
     49    } 
     50 
     51    PhysicsObject LuoMaila(double x, double y) 
     52    { 
     53        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     54        maila.Shape = Shapes.Rectangle; 
     55        maila.X = x; 
     56        maila.Y = y; 
     57        maila.Restitution = 1.0; 
     58        Add(maila); 
     59 
     60        return maila; 
     61    } 
     62 
     63    void AsetaOhjaimet() 
     64    { 
     65        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     66        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     67        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     68        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     69 
     70        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     71        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     72        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     73        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     74 
     75        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
     76        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 
     77 
     78        ControllerOne.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila1, nopeusYlos); 
     79        ControllerOne.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     80        ControllerOne.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila1, nopeusAlas); 
     81        ControllerOne.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     82 
     83        ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila2, nopeusYlos); 
     84        ControllerTwo.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     85        ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila2, nopeusAlas); 
     86        ControllerTwo.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     87 
     88        ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu"); 
     89        ControllerTwo.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu"); 
     90    } 
     91 
     92    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     93    { 
     94        if ( (nopeus.Y < 0) && (maila.Bottom < Level.Bottom) ) 
     95        { 
     96            maila.Velocity = Vector.Zero; 
     97            return; 
     98        } 
     99        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     100        { 
     101            maila.Velocity = Vector.Zero; 
     102            return; 
     103        } 
     104 
     105        maila.Velocity = nopeus; 
     106    } 
     107    IntMeter LuoPisteLaskuri( double x, double y ) 
     108    { 
     109        IntMeter laskuri = new IntMeter(0); 
     110        laskuri.MaxValue = 10; 
     111        Label naytto = new Label(); 
     112        naytto.BindTo(laskuri); 
     113        naytto.X = x; 
     114        naytto.Y = y; 
     115        naytto.TextColor = Color.White; 
     116        Add(naytto); 
     117        return laskuri; 
     118    } 
     119 
     120    void LisaaLaskurit() 
     121    { 
     122        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     123        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     124 
     125    } 
     126 
     127    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     128    { 
     129 
    25130    } 
    26131} 
Note: See TracChangeset for help on using the changeset viewer.