Changeset 4211 for 2013/26


Ignore:
Timestamp:
2013-06-25 12:48:45 (10 years ago)
Author:
rotaraih
Message:

Talletus.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2013/26/RoopeR/Pong/Pong/Pong/Pong.cs

    r4197 r4211  
    99public class Pong : PhysicsGame 
    1010{ 
     11    Vector nopeusYlos = new Vector(0, 200); 
     12    Vector nopeusAlas = new Vector(0, -200); 
    1113    PhysicsObject pallo; 
    1214 
     15    PhysicsObject maila1; 
     16    PhysicsObject maila2; 
     17    IntMeter pelaajan1Pisteet; 
     18    IntMeter pelaajan2Pisteet; 
    1319    public override void Begin() 
    1420    { 
    1521        LuoKentta(); 
    1622        Aloitapeli(); 
     23        LisaaLaskurit(); 
    1724        AsetaOhjaimet(); 
    1825        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
     
    2633        pallo = new PhysicsObject(40, 40); 
    2734        pallo.Shape = Shape.Circle; 
    28         pallo.Restitution = 1.0; 
     35        pallo.Restitution = 2.0; 
    2936        Add(pallo); 
    30  
    31         LuoMaila(Level.Left + 20.0, 0.0); 
    32         LuoMaila(Level.Right - 20.0, 0.0); 
     37        AddCollisionHandler(pallo, KasittelePallonTormays); 
     38        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     39        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    3340 
    3441        Level.BackgroundColor = Color.Blue; 
    35         Level.CreateBorders(1.0, false); 
     42        PhysicsObject vasenReuna = Level.CreateLeftBorder(); 
     43        vasenReuna.Restitution = 1.0; 
     44        vasenReuna.IsVisible= false; 
    3645 
    37         Camera.ZoomToLevel(); 
     46        Camera.ZoomToLevel(-10.5); 
    3847 
    3948    } 
     
    4453    } 
    4554 
    46     void LuoMaila(double x, double y) 
     55    PhysicsObject LuoMaila(double x, double y) 
    4756    { 
    4857        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     
    5261        maila.Y = y; 
    5362        Add(maila); 
     63        return maila; 
    5464    } 
    5565 
    5666    void AsetaOhjaimet() 
    5767    { 
    58         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    59         Keyboard.Listen(Key.A, ButtonState.Down, LiikutaMaila1Ylos, "Pelaaja 1: Liikuta mailaa ylös"); 
    60         Keyboard.Listen(Key.A, ButtonState.Released, PysaytaMaila1, null); 
     68        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "pelaaja !: Liikuta mailaa ylos", maila1, nopeusYlos); 
     69        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     70        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     71        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     72        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     73        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     74        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     75 
     76        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
     77        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylos", maila2, nopeusYlos); 
     78 
    6179    } 
    62   void LiikutaMailaaYlos(PhysicsObject maila)   
    63   Vector nopeus = new Vector(0, -200); 
    64     maila.Velocity= nopeus; 
    65   } 
    66 void LiikutaMailaaAlas(PhysicsObject maila) 
     80    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     81    { 
     82        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     83        { 
     84            maila.Velocity = Vector.Zero; 
     85            return; 
     86        } 
     87        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     88        { 
     89            maila.Velocity = Vector.Zero; 
     90            return; 
     91        } 
     92        maila.Velocity = nopeus; 
     93 
     94    } 
     95 
     96    void LisaaLaskurit() 
     97    { 
     98        pelaajan1Pisteet = LuoPistelaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     99        pelaajan2Pisteet = LuoPistelaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     100    } 
     101    IntMeter LuoPistelaskuri(double x, double y) 
     102    { 
     103        IntMeter laskuri = new IntMeter(0); 
     104        laskuri.MaxValue = 10; 
     105        Label naytto = new Label(); 
     106        naytto.X = x; 
     107        naytto.Y = y; 
     108        naytto.BindTo(laskuri); 
     109        naytto.TextColor = Color.Emerald; 
     110        naytto.BorderColor = Level.BackgroundColor; 
     111        //naytto.Color = Level.BackgroundColor; 
     112        Add(naytto); 
     113        return laskuri; 
     114    } 
     115} 
     116void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
    67117{ 
     118if (kohde== oikeaReuna) 
     119} 
     120pelaajan1pisteet.Value+=1; 
     121} 
     122else if (kohde== vasenReuna) 
     123{ 
     124pelaajan2Pisteet.Value+=1; 
     125} 
     126} 
Note: See TracChangeset for help on using the changeset viewer.