Changeset 7504 for 2016/25


Ignore:
Timestamp:
2016-06-23 13:14:20 (7 years ago)
Author:
koannak
Message:
 
Location:
2016/25/MiskaL
Files:
55 added
6 edited

Legend:

Unmodified
Added
Removed
  • 2016/25/MiskaL/Pongis Khan/Pongis Khan/Pongis_Khan/Pongis_Khan.cs

    r7465 r7504  
    99public class Pongis_Khan : PhysicsGame 
    1010{ 
    11     Vector nopeusYlös = new Vector(0, 200); 
    12     Vector nopeusAlas = new Vector(0, -200); 
     11    Vector nopeusYlös = new Vector(0, 800); 
     12    Vector nopeusAlas = new Vector(0, -800); 
    1313    PhysicsObject pallo; 
    1414    PhysicsObject maila2; 
    1515    PhysicsObject maila; 
     16 
     17    PhysicsObject vasenReuna; 
     18    PhysicsObject oikeaReuna; 
     19 
     20 
     21    IntMeter pelaajan1Pisteet; 
     22    IntMeter pelaajan2Pisteet; 
     23 
     24 
     25 
    1626    public override void Begin() 
    1727    { 
    18          
     28 
    1929        LuoKentta(); 
    2030        AloitaPeli(); 
    2131        AsetaOhjaimet(); 
    22  
     32        LisaaLaskurit(); 
    2333 
    2434 
     
    2636        Level.Background.CreateGradient(Color.Black, Color.Black); 
    2737        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
    28         
     38 
    2939    } 
    3040    void LuoKentta() 
     
    3242        pallo = new PhysicsObject(50, 50); 
    3343        Add(pallo); 
    34         pallo.Shape = Shape.Circle; 
     44        pallo.Shape = Shape.Octagon; 
    3545        pallo.Color = Color.White; 
    3646        pallo.X = -200.0; 
    3747        pallo.Y = 0.0; 
    3848 
    39        maila2= LuoMaila(Level.Left + 20.0, 0.0); 
    40        maila = LuoMaila(Level.Right - 20.0, 0.0); 
     49        maila2 = LuoMaila(Level.Left + 20.0, 0.0); 
     50        maila = LuoMaila(Level.Right - 20.0, 0.0); 
     51 
     52         vasenReuna = Level.CreateLeftBorder(); 
     53        vasenReuna.Restitution = 1.0; 
     54        vasenReuna.IsVisible = false; 
     55 
     56        PhysicsObject Bottom = Level.CreateBottomBorder(); 
     57        Bottom.Restitution = 1.0; 
     58        Bottom.IsVisible = false; 
     59 
     60        PhysicsObject Top = Level.CreateTopBorder(); 
     61        Top.Restitution = 1.0; 
     62        Top.IsVisible = false; 
     63 
     64         oikeaReuna = Level.CreateRightBorder(); 
     65        oikeaReuna.Restitution = 1.0; 
     66        oikeaReuna.IsVisible = false; 
     67        Camera.ZoomToLevel(); 
     68 
     69        AddCollisionHandler(pallo, KasittelePallonTormays); 
     70} 
    4171 
    4272 
    43         Level.CreateBorders(1.0, false); 
    44         pallo.Restitution = 1.0; 
    45         Camera.ZoomToLevel(); 
    46  
    47  
    48     } 
    4973    protected override void Update(Time time) 
    5074    { 
     
    5478        } 
    5579        base.Update(time); 
    56      
     80 
    5781    } 
    5882    void AloitaPeli() 
     
    6286        pallo.Hit(impulssi); 
    6387    } 
    64     PhysicsObject LuoMaila(double x, double y) { 
     88    PhysicsObject LuoMaila(double x, double y) 
     89    { 
    6590        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    6691        maila.Shape = Shape.Rectangle; 
     
    7398    void AsetaOhjaimet() 
    7499    { 
    75         Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, maila, nopeusYlös, ""); 
    76         Keyboard.Listen(Key.W, ButtonState.Released, AsetaNopeus, "", maila, Vector. Zero); 
    77         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    78         Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus ,maila2 ""); 
    79         Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus,maila2, Vector. Zero); 
    80         Keyboard.Listen(Key.S, ButtonState.Down, AsetaNopeus, maila,  ); 
    81         Keyboard.Listen(Key.S, ButtonState.Released, AsetaNopeus, , maila, Vector.Zero); 
     100        Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, "", maila2, nopeusYlös); 
     101        Keyboard.Listen(Key.W, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     102        Keyboard.Listen(Key.S, ButtonState.Down, AsetaNopeus, "", maila2, nopeusAlas); 
     103        Keyboard.Listen(Key.S, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     104        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "", maila, nopeusYlös); 
     105        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila, Vector.Zero); 
     106        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "", maila, nopeusAlas); 
     107        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila, Vector.Zero); 
     108        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, ""); 
    82109    } 
    83110    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    84111    { 
     112 
     113        if ((nopeus.Y >= 0) && (maila.Top >= Level.Top)) 
     114        { 
     115            maila.Velocity = Vector.Zero; 
     116            return; 
     117        } 
     118            if ((nopeus.Y <= 0) && (maila.Bottom <= Level.Bottom)) 
     119            { 
     120                maila.Velocity = Vector.Zero; 
     121                return; 
     122            } 
    85123        maila.Velocity = nopeus; 
    86   
     124    } 
     125    void LisaaLaskurit() 
     126    { 
     127        
     128 
     129        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     130        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     131 
     132 
     133 
     134   
     135    } IntMeter LuoPisteLaskuri(double x, double y) 
     136    { 
     137 
     138        IntMeter laskuri = new IntMeter(0); 
     139        laskuri.MaxValue = 10; 
     140        Label naytto = new Label(); 
     141        naytto.BindTo(laskuri); 
     142 
     143        naytto.X = x; 
     144        naytto.Y = y; 
     145 
     146        naytto.TextColor = Color.White; 
     147        naytto.BorderColor = Level.Background.Color; 
     148        naytto.Color = Level.Background.Color; 
     149        Add(naytto); 
     150 
     151        return laskuri; 
     152    } 
     153    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     154    { 
     155        if (kohde == oikeaReuna) 
     156        { 
     157            pelaajan1Pisteet.Value += 1; 
     158        } 
     159        else if (kohde == vasenReuna) 
     160        { 
     161            pelaajan2Pisteet.Value += 1; 
     162        } 
    87163 
    88164 
     
    90166 
    91167 
     168    } 
    92169 
    93170 
    94  
    95  
    96     }  
     171    } 
Note: See TracChangeset for help on using the changeset viewer.