Changeset 7469 for 2016/25


Ignore:
Timestamp:
2016-06-20 14:12:55 (7 years ago)
Author:
tesatapa
Message:

valmis

Location:
2016/25/MatiasA/Pong 03/Pong 03/Pong_03
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 2016/25/MatiasA/Pong 03/Pong 03/Pong_03/Pong_03.cs

    r7468 r7469  
    1212    Vector nopeusYlos = new Vector(0, 200); 
    1313    Vector nopeusalas = new Vector(0, -200); 
    14     const double PALLON_MIN_NOPEUS = 10000; 
     14 
     15    IntMeter pelaajan1Pisteet; 
     16    IntMeter pelaajan2Pisteet; 
     17 
     18    const double PALLON_MIN_NOPEUS = 10000000; 
    1519    PhysicsObject maila1; 
    1620    PhysicsObject maila2; 
     21    IntMeter pelaajan1pisteet; 
     22    IntMeter pelaajan2pisteet; 
     23 
     24    PhysicsObject vasenReuna; 
     25    PhysicsObject oikeaReuna; 
     26 
    1727 
    1828    public override void Begin() 
     
    2131        AsetaOhjaimet(); 
    2232        LisaaLaskurit(); 
    23         Aloitapeli(); 
    24      
     33        AloitaPeli(); 
    2534 
    2635 
     
    3948    } 
    4049 
     50 
     51 
    4152    void LuoKentta() 
    4253    { 
     54         vasenReuna = Level.CreateLeftBorder(); 
     55        vasenReuna.Restitution = 1.0; 
     56        vasenReuna.IsVisible = false; 
     57 
     58         oikeaReuna = Level.CreateRightBorder(); 
     59        oikeaReuna.Restitution = 1.0; 
     60        oikeaReuna.IsVisible = false; 
     61 
     62        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     63        ylaReuna.Restitution = 1.0; 
     64        ylaReuna.IsVisible = false; 
     65 
     66        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     67        alaReuna.Restitution = 1.0; 
     68        alaReuna.IsVisible = false; 
     69 
    4370        pallo = new PhysicsObject(50, 50); 
    4471        pallo.Shape = Shape.Circle; 
     
    4875        pallo.Y = 0.0; 
    4976        pallo.Restitution = 1.0; 
     77        AddCollisionHandler(pallo, KasittelePallonTormays); 
    5078 
    5179 
    52        maila1= LuoMaila(Level.Left + 20.0, 0.0); 
    53        maila2= LuoMaila(Level.Right - 20.0, 0.0); 
     80        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     81        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    5482 
    5583 
     
    5886    } 
    5987 
    60     void Aloitapeli() 
     88    void AloitaPeli() 
    6189    { 
    6290        Vector impulssi = new Vector(500.0, 0.0); 
     
    6492    } 
    6593 
    66      
    67      
     94 
     95 
    6896 
    6997    void AsetaOhjaimet() 
     
    73101        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "pelaaja 1", maila1, nopeusalas); 
    74102        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    75         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit,  "Lopeta peli"); 
     103        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    76104 
    77105        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     
    99127 
    100128    } 
    101      
    102      
    103      
    104         PhysicsObject LuoMaila(double x, double y) 
     129 
     130 
     131 
     132    PhysicsObject LuoMaila(double x, double y) 
    105133    { 
    106134        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 120.0); 
     
    111139        Add(maila); 
    112140        return maila; 
    113       }    
    114       void LiikutaMailaaYlos(PhysicsObject maila) 
    115       { 
    116        
     141    } 
     142    void LiikutaMailaaYlos(PhysicsObject maila) 
     143    { 
    117144 
    118       } 
    119        
    120        void LisaaLaskurit() 
    121     { 
    122145 
    123146    } 
    124147 
     148    void LisaaLaskurit() 
     149    { 
     150        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     151        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     152    } 
    125153 
     154    IntMeter LuoPisteLaskuri(double x, double y) 
     155    { 
     156        IntMeter laskuri = new IntMeter(0); 
     157        laskuri.MaxValue = 10; 
    126158 
    127         
     159        Label naytto = new Label(); 
     160        naytto.BindTo(laskuri); 
     161        naytto.X = x; 
     162        naytto.Y = y; 
     163        naytto.TextColor = Color.White; 
     164        naytto.BorderColor = Level.BackgroundColor; 
     165        naytto.Color = Level.BackgroundColor; 
     166        Add(naytto); 
    128167 
    129      
    130      
    131         
    132      
     168        return laskuri; 
     169    } 
     170 
     171    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     172    { 
     173        if (kohde == oikeaReuna) 
     174        { 
     175            pelaajan1Pisteet.Value += 1; 
     176        } 
     177        else if (kohde == vasenReuna) 
     178        { 
     179            pelaajan2Pisteet.Value += 1; 
     180        } 
     181    } 
    133182} 
    134183 
Note: See TracChangeset for help on using the changeset viewer.