Changeset 3820 for 2012/30


Ignore:
Timestamp:
2012-07-27 12:53:34 (11 years ago)
Author:
anlakane
Message:

Talletus.

Location:
2012/30/TinoS
Files:
24 added
1 edited

Legend:

Unmodified
Added
Removed
  • 2012/30/TinoS/Pong/Pong/Pong/Pong.cs

    r3690 r3820  
    1414    PhysicsObject maila1; 
    1515    PhysicsObject maila2; 
     16 
     17    IntMeter pelaajan1Pisteet; 
     18    IntMeter pelaajan2Pisteet; 
     19 
     20    PhysicsObject vasenReuna; 
     21    PhysicsObject oikeaReuna; 
     22 
     23 
    1624    public override void Begin() 
    1725    { 
     
    1927        AsetaOhjaimet(); 
    2028        AloitaPeli(); 
     29        LisaaLaskurit(); 
    2130 
    2231        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
     
    3342        Pallo.Hit(impulssi); 
    3443        Pallo.Restitution = 1.0; 
    35         Level.CreateBorders(1.0, false); 
    36        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    37        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
     44 
     45        PhysicsObject vasenReuna = Level.CreateLeftBorder(); 
     46        vasenReuna.Restitution = 1.0; 
     47        vasenReuna.IsVisible = false; 
     48 
     49        PhysicsObject oikeaReuna = Level.CreateRightBorder(); 
     50        oikeaReuna.Restitution = 1.0; 
     51        oikeaReuna.IsVisible = false; 
     52 
     53 
     54        vasenReuna.Restitution = 1.0; 
     55        vasenReuna.IsVisible = false; 
     56        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     57        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    3858        Level.BackgroundColor = Color.Black; 
    3959        Camera.ZoomToLevel(); 
    40          
     60 
     61        AddCollisionHandler(Pallo, KasittelePallonTormays); 
     62 
    4163    } 
    4264    void AloitaPeli() 
     
    5981    { 
    6082        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    61         Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös",maila1,nopeusYlos); 
    62         Keyboard.Listen(Key.W, ButtonState.Released, AsetaNopeus, null,maila1, Vector.Zero); 
     83        Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     84        Keyboard.Listen(Key.W, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    6385        Keyboard.Listen(Key.S, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
    6486        Keyboard.Listen(Key.S, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     
    7193    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    7294    { 
    73         if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
    74         {maila.Velocity = Vector.Zero; 
     95        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     96        { 
     97            maila.Velocity = Vector.Zero; 
    7598            return; 
    7699        } 
     100        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     101        { 
     102            maila.Velocity = Vector.Zero; 
     103            return; 
     104        } 
     105 
    77106        maila.Velocity = nopeus; 
     107 
    78108    } 
    79 }    
     109    void LisaaLaskurit() 
     110    { 
     111        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     112        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     113    } 
     114     IntMeter LuoPisteLaskuri(double x, double y) 
     115     { 
     116    IntMeter laskuri = new IntMeter(0); 
     117    
    80118 
     119    laskuri.MaxValue = 10; 
     120    Label naytto =new Label(); 
     121    naytto.BindTo(laskuri); 
     122    naytto.X = x; 
     123    naytto.Y = y; 
     124    naytto.TextColor = Color.White; 
     125    naytto.BorderColor = Level.BackgroundColor; 
     126    Add(naytto); 
     127    return laskuri; 
     128     } 
     129     void KasittelePallonTormays(PhysicsObject Pallo, PhysicsObject kohde) 
     130     { 
     131         if (kohde == oikeaReuna) 
     132         { 
     133             pelaajan1Pisteet.Value +=1; 
     134         } 
     135         else if (kohde == vasenReuna) 
     136         { 
     137             pelaajan2Pisteet.Value += 1; 
     138         } 
     139     } 
     140} 
     141 
Note: See TracChangeset for help on using the changeset viewer.