Changeset 6558 for 2015


Ignore:
Timestamp:
2015-06-30 10:34:33 (8 years ago)
Author:
jasukuva
Message:

Pong peli on valmis

Location:
2015/27/JaakkoS/Pong/Pong
Files:
29 added
1 edited

Legend:

Unmodified
Added
Removed
  • 2015/27/JaakkoS/Pong/Pong/Pong/Pong.cs

    r6524 r6558  
    1313 
    1414    PhysicsObject pallo; 
    15  
    1615    PhysicsObject maila1; 
    1716    PhysicsObject maila2; 
     17 
     18    PhysicsObject vasenReuna; 
     19    PhysicsObject oikeaReuna; 
    1820 
    1921    IntMeter pelaajan1Pisteet; 
     
    4244       maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    4345 
    44         Level.CreateBorders(1.0, false); 
     46       vasenReuna = Level.CreateLeftBorder(); 
     47       vasenReuna.Restitution = 1.0; 
     48       vasenReuna.IsVisible = false; 
     49 
     50       oikeaReuna = Level.CreateRightBorder(); 
     51       oikeaReuna.Restitution = 1.0; 
     52       oikeaReuna.IsVisible = false; 
     53 
     54        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     55        alaReuna.Restitution = 1.0; 
     56        alaReuna.IsVisible = false; 
     57 
     58        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     59        ylaReuna.Restitution = 1.0; 
     60        ylaReuna.IsVisible = false; 
     61 
    4562        Level.Background.Color = Color.Black; 
    4663        Camera.ZoomToLevel(); 
    4764 
    48          
     65        AddCollisionHandler(pallo, KasittelePallonTormays); 
    4966    } 
    5067 
     
    6784        return maila; 
    6885    } 
     86 
    6987    void AsetaOhjaimet() 
    7088    { 
     
    82100        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    83101    } 
     102 
    84103    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    85104    { 
    86         if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     105        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
    87106        { 
    88107            maila.Velocity = Vector.Zero; 
    89108            return; 
    90109        } 
    91         if ((nopeus.Y > 0) && (maila.Bottom > Level.Bottom)) 
     110 
     111        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
    92112        { 
    93113            maila.Velocity = Vector.Zero; 
     
    97117        maila.Velocity = nopeus; 
    98118    } 
     119     
    99120    void LisaaLaskurit() 
    100121    { 
    101122        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
    102         pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right + 100.0, Screen.Top - 100.0); 
     123        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
    103124    } 
    104     IntMeter LisaaPisteLaskurit() 
     125 
     126    IntMeter LuoPisteLaskuri(double x, double y) 
    105127    { 
    106128        IntMeter laskuri = new IntMeter(0); 
     
    119141        return laskuri; 
    120142    } 
     143 
     144    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     145    { 
     146        if (kohde == oikeaReuna) 
     147        { 
     148            pelaajan1Pisteet.Value += 1; 
     149        } 
     150        else if (kohde == vasenReuna) 
     151        { 
     152            pelaajan2Pisteet.Value += 1; 
     153        } 
     154    } 
    121155} 
    122156 
Note: See TracChangeset for help on using the changeset viewer.