Changeset 7307


Ignore:
Timestamp:
2016-06-14 15:01:23 (7 years ago)
Author:
latukova
Message:
 
Location:
2016/24/LasseK
Files:
9 added
7 edited

Legend:

Unmodified
Added
Removed
  • 2016/24/LasseK/PinPong/PinPong/PinPong/PinPong.cs

    r7264 r7307  
    1515    PhysicsObject pallo; 
    1616    PhysicsObject maila1; 
    17     IPhysicsObject maila2; 
     17    PhysicsObject maila2; 
     18    PhysicsObject vasenReuna; 
     19    PhysicsObject oikeaReuna; 
     20    IntMeter pelaajan1Pisteet; 
     21    IntMeter pelaajan2Pisteet; 
     22     
    1823    public override void Begin() 
    1924    { 
    20       
    21          LuoKentta(); 
     25        LisaaLaskurit(); 
     26        LuoKentta(); 
    2227        AloitaPeli(); 
    2328        AsetaOhjaimet(); 
     
    3944        Add(pallo); 
    4045 
    41         PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    42         maila.Shape = Shape.Rectangle; 
    43         maila.X = Level.Left + 20.0; 
    44         maila.Y = 0.0; 
    45         maila.Restitution = 1.0; 
    46         Add(maila); 
    47  
    4846        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    4947        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    50  
     48        AddCollisionHandler(pallo, KasittelePallonTormays); 
    5149 
    5250        pallo.X = -200.0; 
    5351 
    5452        pallo.Y = 0.0; 
    55         Level.CreateBorders(1.0, false); 
     53        vasenReuna = Level.CreateLeftBorder(); 
     54        vasenReuna.Restitution = 1.0; 
     55        vasenReuna.IsVisible = false; 
     56        oikeaReuna = Level.CreateRightBorder(); 
     57        oikeaReuna.Restitution = 1.0; 
     58        oikeaReuna.IsVisible = false; 
     59       PhysicsObject YlaReuna = Level.CreateTopBorder(); 
     60        YlaReuna.Restitution = 1.0; 
     61        YlaReuna.IsVisible = false; 
     62       PhysicsObject AlaReuna = Level.CreateBottomBorder(); 
     63        AlaReuna.Restitution = 1.0; 
     64        AlaReuna.IsVisible = false; 
     65 
    5666        pallo.Restitution = 1.0; 
    57         Level.Background.Color = Color.Pink; 
     67        Level.Background.Color = Color.HotPink; 
    5868        Camera.ZoomToLevel(); 
    5969    } 
     
    7080    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    7181    { 
     82 
     83        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     84        { 
     85            maila.Velocity = Vector.Zero; 
     86            return; 
     87        } 
     88        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     89 
     90        { 
     91            maila.Velocity = Vector.Zero; 
     92                return; 
     93        } 
     94             
    7295        maila.Velocity = nopeus; 
     96 
    7397    } 
    7498    void AsetaOhjaimet() 
    7599    { 
    76100        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylos", maila1, nopeusYlos); 
    77         Keyboard.Listen(Key.A, ButtonState.Released, null, maila1, Vector.Zero); 
     101        Keyboard.Listen(Key.A, ButtonState.Released,AsetaNopeus, null, maila1, Vector.Zero); 
    78102        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
    79103        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     
    89113    } 
    90114 
     115    IntMeter LuoPisteLaskuri(double x, double y) 
     116    { 
     117        IntMeter laskuri = new IntMeter(0); 
     118        laskuri.MaxValue = 10; 
     119        Label naytto = new Label(); 
     120        naytto.BindTo(laskuri); 
     121        naytto.X = x; 
     122        naytto.Y = y; 
     123        naytto.TextColor = Color.HotPink; 
     124        naytto.BorderColor = Level.Background.Color; 
     125        naytto.Color = Level.Background.Color; 
     126        Add(naytto); 
     127 
     128 
     129        return laskuri; 
     130    } 
     131    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     132    { 
     133 
     134        if (kohde == oikeaReuna) 
     135        { 
     136            pelaajan1Pisteet.Value += 1; 
     137        } 
     138        else if (kohde == vasenReuna) 
     139        { 
     140            pelaajan2Pisteet.Value += 1; 
     141        } 
     142    } 
     143    void LisaaLaskurit() 
     144    { 
     145        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     146        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     147 
     148 
     149 
     150    } 
     151 
     152 
     153 
    91154 
    92155 
     
    94157 
    95158 
    96     
  • 2016/24/LasseK/PinPong/PinPong/PinPong/obj/x86/Debug/ContentPipeline-{6DAC37A3-7F96-4641-8C99-0BC4C668F854}.xml

    r7264 r7307  
    1717      <Assembly> 
    1818        <Key>C:\Windows\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework.Content.Pipeline\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Content.Pipeline.dll</Key> 
    19         <Value>2015-09-16T13:46:35.8102287+03:00</Value> 
     19        <Value>2015-09-16T13:41:58.0471254+03:00</Value> 
    2020      </Assembly> 
    2121    </Assemblies> 
Note: See TracChangeset for help on using the changeset viewer.