Changeset 8907 for 2017


Ignore:
Timestamp:
2017-07-05 10:35:38 (6 years ago)
Author:
npo17_33
Message:

tein meteorit ja alukset

Location:
2017/27/MikaelL
Files:
54 added
6 edited

Legend:

Unmodified
Added
Removed
  • 2017/27/MikaelL/pong/pong/pong/pong.cs

    r8867 r8907  
    1515    PhysicsObject maila1; 
    1616    PhysicsObject maila2; 
     17    IntMeter pelaajan1Pisteet; 
     18    IntMeter pelaajan2Pisteet; 
     19    PhysicsObject vasenReuna; 
     20    PhysicsObject oikeaReuna; 
     21 
     22 
    1723 
    1824    public override void Begin() 
     
    2127        LuoKentta(); 
    2228        AloitaPeli(); 
    23         AsetaOhjaimet(); 
     29        LisaaLaskurit(); 
    2430        maila1 = LuoMaila(Level.Left + 20, 0.0); 
    2531        maila2 = LuoMaila(Level.Right - 20, 0.0); 
    2632        Vector inpulssi = new Vector(500.0, 0.0); 
    27  
     33        AsetaOhjaimet(); 
    2834        pallo.Hit(inpulssi); 
    29  
     35        AddCollisionHandler(pallo, KasittelePallonTormays); 
    3036 
    3137    } 
     38 
    3239    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    3340    { 
    3441        maila.Velocity = nopeus; 
     42 
     43        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     44        { 
     45            maila.Velocity = Vector.Zero; 
     46            return; 
     47        } 
     48 
     49        maila.Velocity = nopeus; 
     50    } 
     51 
     52    void LisaaLaskurit() 
     53    { 
     54        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     55        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     56    } 
     57 
     58    IntMeter LuoPisteLaskuri(double x, double y) 
     59    { 
     60        IntMeter laskuri = new IntMeter(0); 
     61        laskuri.MaxValue = 10; 
     62        Label naytto = new Label(); 
     63        naytto.BindTo(laskuri); 
     64        naytto.X = x; 
     65        naytto.Y = y; 
     66        naytto.TextColor = Color.White; 
     67        naytto.BorderColor = Level.Background.Color; 
     68        naytto.Color = Level.Background.Color; 
     69        Add(naytto); 
     70        return laskuri; 
     71 
     72 
     73 
    3574    } 
    3675 
     
    4079        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
    4180        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     81        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     82        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     83        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     84        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     85        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     86        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     87        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
    4288 
    43  
    44         
    4589        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    4690    } 
     
    5498 
    5599 
    56         Level.CreateBorders(1.0, false); 
     100 
    57101        pallo.Restitution = 1.0; 
    58102        Level.Background.Color = Color.Crimson; 
    59103        Camera.ZoomToLevel(); 
    60104 
     105 
     106        oikeaReuna = Level.CreateRightBorder(); 
     107        oikeaReuna.Restitution = 1.0; 
     108        oikeaReuna.IsVisible = false; 
     109 
     110 
     111        vasenReuna = Level.CreateLeftBorder(); 
     112        vasenReuna.Restitution = 1.0; 
     113        vasenReuna.IsVisible = false; 
     114 
     115 
     116 
     117        PhysicsObject alareuna = Level.CreateLeftBorder(); 
     118        alareuna.Restitution = 1.0; 
     119        alareuna.IsVisible = false; 
     120 
     121 
     122 
     123        PhysicsObject ylareuna = Level.CreateLeftBorder(); 
     124        ylareuna.Restitution = 1.0; 
     125        ylareuna.IsVisible = false; 
    61126 
    62127    } 
     
    77142        return maila; 
    78143    } 
     144 
     145 
     146    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     147    { 
     148        if (kohde == oikeaReuna) 
     149        { 
     150            pelaajan1Pisteet.Value += 1; 
     151        } 
     152        else if (kohde == vasenReuna) 
     153        { 
     154            pelaajan2Pisteet.Value += 1; 
     155        } 
     156    } 
     157 
     158 
     159 
     160 
    79161} 
Note: See TracChangeset for help on using the changeset viewer.