Changeset 7287 for 2016/24


Ignore:
Timestamp:
2016-06-14 13:59:46 (7 years ago)
Author:
tesatapa
Message:
 
Location:
2016/24/OliverK
Files:
143 added
6 edited

Legend:

Unmodified
Added
Removed
  • 2016/24/OliverK/Pong/Pong/Pong/Pong.cs

    r7277 r7287  
    1717 
    1818    PhysicsObject pallo; 
    19  
    20  
    21  
    22  
    2319    PhysicsObject maila1; 
    2420    PhysicsObject maila2; 
    2521 
     22    PhysicsObject vasenReuna; 
     23    PhysicsObject oikeaReuna; 
    2624 
     25    IntMeter pelaajan1Pisteet; 
     26    IntMeter pelaajan2Pisteet; 
    2727 
    2828    public override void Begin() 
     
    3131        AsetaOhjaimet(); 
    3232        AloitaPeli(); 
     33        LisaaLaskurit(); 
    3334 
    3435 
     
    5455        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
    5556 
     57        Keyboard.Listen(Key.Right, ButtonState.Pressed, hidasta, "Hidasta palloa"); 
     58        Keyboard.Listen(Key.Left, ButtonState.Pressed, nopeuta, "Nopeuta palloa"); 
     59 
     60 
    5661        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
    5762        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    5863    } 
     64 
     65    void hidasta() { 
     66        pallo.Velocity /=2; 
     67 
     68            } 
     69    void nopeuta() 
     70    { 
     71        pallo.Velocity *= 3.1; 
     72    } 
     73 
     74 
    5975    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    6076    { 
     
    6581            maila.Velocity = Vector.Zero; return; 
    6682        } 
    67         if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     83        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
    6884        {  
    6985            maila.Velocity = Vector.Zero; return; 
     
    7490 
    7591} 
     92    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     93    { 
     94        if (kohde == oikeaReuna) 
     95        { 
     96            pelaajan1Pisteet.Value += 1; 
     97        } 
     98        else if (kohde == vasenReuna) 
     99        { 
     100            pelaajan2Pisteet.Value += 1; 
     101                        } 
     102    } 
     103 
    76104    void LuoKentta() 
    77105    { 
     
    80108        Add(pallo); 
    81109 
    82  
     110        AddCollisionHandler(pallo, KasittelePallonTormays); 
    83111 
    84112 
     
    86114        pallo.X = -200.0; 
    87115        pallo.Y = 0.0; 
     116         
     117 
     118        vasenReuna = Level.CreateLeftBorder(); 
     119        vasenReuna.Restitution = 1.0; 
     120        vasenReuna.KineticFriction = 0.0; 
     121        vasenReuna.IsVisible = false; 
     122 
     123        oikeaReuna = Level.CreateRightBorder(); 
     124        oikeaReuna.Restitution = 1.0; 
     125        oikeaReuna.KineticFriction = 0.0; 
     126        oikeaReuna.IsVisible = false; 
     127 
     128        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     129        ylaReuna.Restitution = 1.0; 
     130        ylaReuna.KineticFriction = 0.0; 
     131        ylaReuna.IsVisible = false; 
     132 
     133        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     134        alaReuna.Restitution = 1.0; 
     135        alaReuna.IsVisible = false; 
     136        alaReuna.KineticFriction = 0.0; 
    88137 
    89138 
     
    91140        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    92141 
    93         Level.CreateBorders(1.0, false); 
     142        
    94143        Level.Background.Color = Color.Red; 
    95144 
     
    107156        return maila; 
    108157    } 
     158    void LisaaLaskurit() 
     159    { 
     160        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     161        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     162        // ... 
     163    } 
     164    IntMeter LuoPisteLaskuri(double x, double y) 
     165    { 
     166        IntMeter laskuri = new IntMeter(0); 
     167        laskuri.MaxValue = 100; 
     168 
     169        Label naytto = new Label(); 
     170        naytto.BindTo(laskuri); 
     171        naytto.X = x; 
     172        naytto.Y = y; 
     173        naytto.TextColor = Color.White; 
     174        naytto.BorderColor = Level.Background.Color; 
     175        naytto.Color = Level.Background.Color; 
     176        Add(naytto); 
     177 
     178        return laskuri; 
     179    } 
    109180} 
Note: See TracChangeset for help on using the changeset viewer.