Changeset 6564 for 2015/27/SampoR/Pong


Ignore:
Timestamp:
2015-06-30 11:00:43 (8 years ago)
Author:
jotapoti
Message:

valmis Pong-peli

Location:
2015/27/SampoR/Pong
Files:
30 added
1 edited

Legend:

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

    r6535 r6564  
    1515 
    1616    PhysicsObject pallo; 
    17  
    1817    PhysicsObject maila1; 
    1918    PhysicsObject maila2; 
     19 
     20    PhysicsObject vasenReuna; 
     21    PhysicsObject oikeaReuna; 
     22 
     23    IntMeter pelaajan1Pisteet; 
     24    IntMeter pelaajan2Pisteet; 
    2025 
    2126    public override void Begin() 
     
    3641        Add(pallo); 
    3742 
    38        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    39        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
     43        AddCollisionHandler(pallo, KasittelePallonTormays); 
    4044 
    41         Level.CreateBorders(1.0, false); 
    42         Level.Background.Color = Color.Black; 
     45        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     46        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
     47 
     48        vasenReuna = Level.CreateLeftBorder(); 
     49        vasenReuna.Restitution = 1.0; 
     50        vasenReuna.IsVisible = false; 
     51 
     52        oikeaReuna = Level.CreateRightBorder(); 
     53        oikeaReuna.Restitution = 1.0; 
     54        oikeaReuna.IsVisible = false; 
     55 
     56        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     57        alaReuna.Restitution = 1.0; 
     58        alaReuna.IsVisible = false; 
     59 
     60        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     61        ylaReuna.Restitution = 1.0; 
     62        ylaReuna.IsVisible = false; 
     63        
     64 
     65 
     66        Level.Background.Color = Color.LightGreen; 
    4367 
    4468        Camera.ZoomToLevel(); 
     
    105129    void LisaaLaskurit() 
    106130    { 
    107  
     131        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     132        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
    108133    } 
    109134 
    110     IntMeter LuoPisteLaskuri() 
     135    IntMeter LuoPisteLaskuri(double x, double y) 
    111136    { 
    112137        IntMeter laskuri = new IntMeter(0); 
    113138        laskuri.MaxValue = 10; 
     139 
     140        Label naytto = new Label(); 
     141        naytto.BindTo(laskuri); 
     142        naytto.X = x; 
     143        naytto.Y = y; 
     144        naytto.TextColor = Color.White; 
     145        naytto.BorderColor = Level.Background.Color; 
     146        naytto.Color = Level.Background.Color; 
     147        Add(naytto); 
     148 
    114149        return laskuri; 
    115150    } 
    116151 
    117 } 
     152    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     153    { 
     154        if (kohde == oikeaReuna) 
     155        { 
     156            pelaajan1Pisteet.Value += 1; 
     157        } 
     158        else if (kohde == vasenReuna) 
     159        { 
     160            pelaajan2Pisteet.Value += 1; 
     161        } 
     162    } 
     163}  
Note: See TracChangeset for help on using the changeset viewer.