Changeset 5535 for 2014


Ignore:
Timestamp:
2014-07-22 14:01:45 (9 years ago)
Author:
aajualal
Message:

PONGO VALMIS!!!!!!!!!!!!!!

Location:
2014/30/AarniAR
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • 2014/30/AarniAR/Pongo/Pongo/Pongo/Pongo.cs

    r5516 r5535  
    1111    PhysicsObject pallo; 
    1212    Vector nopeusylos = new Vector(0, 200); 
    13     Vector nopeusalas = new Vector(0, 200); 
     13    Vector nopeusalas = new Vector(0, -200); 
     14    PhysicsObject vasenReuna; 
     15    PhysicsObject oikeaReuna; 
    1416 
    1517    PhysicsObject maila1; 
    1618    PhysicsObject maila2; 
     19 
     20    IntMeter pelaajan1Pisteet; 
     21    IntMeter pelaajan2Pisteet; 
    1722 
    1823    public override void Begin() 
     
    2429 
    2530        aloitapeli(); 
     31        lisaalaskurit(); 
    2632 
    2733        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
    2834    } 
    29          
     35 
    3036 
    3137    void Luokentta() 
     
    3339        pallo = new PhysicsObject(50.0, 55.0); 
    3440        Add(pallo); 
    35         pallo.Shape = Shape.Diamond; 
     41        pallo.Shape = Shape.Circle; 
    3642        pallo.Color = Color.DarkRed; 
    3743        pallo.X = Level.Left + 80.0; 
    3844        pallo.Y = 0.0; 
    3945 
    40        maila1 = luomaila(Level.Left + 20.0, 0.0); 
     46        maila1 = luomaila(Level.Left + 20.0, 0.0); 
     47        maila2 = luomaila(Level.Right - 20.0, 0.0); 
     48        vasenReuna = Level.CreateLeftBorder(); 
     49        vasenReuna.Restitution = 1.0; 
     50        vasenReuna.IsVisible = false; 
     51        oikeaReuna = Level.CreateRightBorder(); 
     52        oikeaReuna.Restitution = 1.0; 
     53        vasenReuna.IsVisible = false; 
     54        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     55        alaReuna.Restitution = 1.0; 
     56        alaReuna.IsVisible = true; 
     57        PhysicsObject ylareuna = Level.CreateTopBorder(); 
     58        ylareuna.Restitution = 1.0; 
     59        ylareuna.IsVisible = true; 
    4160 
    42         Level.CreateBorders(1.0, true); 
    43         
     61 
    4462        pallo.Restitution = 1.0; 
    45         pallo.CanRotate = false; 
     63        pallo.CanRotate = true; 
    4664        Level.Background.Color = Color.Emerald; 
    4765        Camera.Zoom(1.3); 
    48  
    49         PhysicsObject maila2 = PhysicsObject.CreateStaticObject(30.0, 200.0); 
    50             maila2.Shape = Shape.Circle; 
    51         maila2.X = Level.Right - 20.0; 
    52         maila2.Y = 0.0; 
    53         maila2.Restitution = 1.0; 
    54         Add(maila2); 
     66        AddCollisionHandler(pallo, KasittelePallonTormays); 
    5567    } 
    5668    void aloitapeli() 
     
    5971        pallo.Hit(impulssi); 
    6072 
    61          
     73 
    6274    } 
    63     PhysicsObject luomaila(double X, double Y) 
     75    PhysicsObject luomaila(double x, double y) 
    6476    { 
    6577        PhysicsObject maila = PhysicsObject.CreateStaticObject(30.0, 200.0); 
    6678        maila.Shape = Shape.Circle; 
    67         maila.X = Level.Left + 20.0; 
    68         maila.Y = 0.0; 
     79        maila.X = x; 
     80        maila.Y = y; 
    6981        maila.Restitution = 1.0; 
    7082        Add(maila); 
     
    7587    { 
    7688        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    77         Keyboard.Listen(Key.Up, ButtonState.Pressed, asetanopeus, "liiku ylos",maila1,nopeusylos); 
     89        Keyboard.Listen(Key.Up, ButtonState.Down, asetanopeus, "liiku ylos", maila1, nopeusylos); 
    7890        Keyboard.Listen(Key.Up, ButtonState.Released, asetanopeus, null, maila1, Vector.Zero); 
    79         Keyboard.Listen(Key. Down, ButtonState.Pressed, asetanopeus, "liiku alas", maila1, nopeusalas); 
     91        Keyboard.Listen(Key.Down, ButtonState.Down, asetanopeus, "liiku alas", maila1, nopeusalas); 
     92        Keyboard.Listen(Key.Down, ButtonState.Released, asetanopeus, null, maila1, Vector.Zero); 
    8093 
     94        Keyboard.Listen(Key.W, ButtonState.Down, asetanopeus, "liiku ylös", maila2, nopeusylos); 
     95        Keyboard.Listen(Key.W, ButtonState.Released, asetanopeus, null, maila2, Vector.Zero); 
     96        Keyboard.Listen(Key.S, ButtonState.Down, asetanopeus, "liiku alas", maila2, nopeusalas); 
     97        Keyboard.Listen(Key.S, ButtonState.Released, asetanopeus, null, maila2, Vector.Zero); 
     98        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "näytä ohjeet"); 
    8199    } 
    82100    void asetanopeus(PhysicsObject maila, Vector nopeus) 
    83101    { 
     102        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     103        { 
     104            maila.Velocity = Vector.Zero; 
     105            return; 
     106        } 
     107        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     108        { 
     109            maila.Velocity = Vector.Zero; 
     110            return; 
     111        } 
     112 
    84113        maila.Velocity = nopeus; 
     114 
     115    } 
     116    void lisaalaskurit() 
     117    { 
     118        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     119        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     120    } 
     121    IntMeter LuoPisteLaskuri(double x, double y) 
     122    { 
     123        IntMeter laskuri = new IntMeter(0); 
     124        laskuri.MaxValue = 100; 
     125 
     126        Label naytto = new Label(); 
     127        naytto.BindTo(laskuri); 
     128        naytto.X = x; 
     129        naytto.Y = y; 
     130        naytto.TextColor = Color.Yellow; 
     131        naytto.BorderColor = Level.Background.Color; 
     132        naytto.Color = Level.Background.Color; 
     133        Add(naytto); 
     134        return laskuri; 
     135    } 
     136    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     137    { 
     138        if (kohde == oikeaReuna) 
     139        { 
     140            pelaajan1Pisteet.Value += 1; 
     141        } 
     142        else if (kohde == vasenReuna) 
     143        { 
     144            pelaajan2Pisteet.Value += 1; 
     145        } 
     146 
    85147    } 
    86148} 
    87  
Note: See TracChangeset for help on using the changeset viewer.