Changeset 1999 for 2011


Ignore:
Timestamp:
2011-06-14 15:01:55 (12 years ago)
Author:
joleelah
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2011/24/OtsoM/Pong/Pong/FysiikkaPeli/Peli.cs

    r1957 r1999  
    44using System.Text; 
    55using Jypeli; 
     6using Jypeli.Widgets; 
    67 
    78class Peli : PhysicsGame 
    8 { 
     9{    Vector nopeusYlös = new Vector( 0, 200 ); 
     10     Vector nopeusAlas = new Vector( 0, -200 ); 
     11 
     12 
    913    PhysicsObject pallo; 
    10  
     14    PhysicsObject maila1; 
     15    PhysicsObject maila2; 
     16    IntMeter pelaajan1Pisteet; 
     17    IntMeter pelaajan2Pisteet; 
    1118 
    1219    public override void Begin() 
     
    1421        // TODO: Kirjoita ohjelmakoodisi tähän 
    1522        LuoKentta(); 
    16         Vector impulssi = new Vector(600.0, 0.0); 
    17         pallo.Hit(impulssi); 
    18  
    19         
     23        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 
     24        AsetaOhjaimet(); 
     25        LisaaLaskurit(); 
     26        AloitaPeli(); 
    2027    } 
    2128 
     
    2431 
    2532        pallo = new PhysicsObject(50.0, 50.0); 
    26         pallo.Shape = Shape.Star; 
     33        pallo.Shape = Shape.Heart; 
     34 
     35        AddCollisionHandler( pallo, KasittelePallonTormays );    
     36             
     37             
     38             
    2739        pallo.Restitution = 1.0; 
    2840        pallo.Color = Color.Fuchsia; 
     
    3244        Add(pallo); 
    3345 
    34         
     46        maila1 = LuoMaila( Level.Left + 20.0, 0.0); 
     47        maila2 = LuoMaila( Level.Right - 20.0, 0.0); 
    3548 
    36         Level.CreateBorders(1.0, false); 
     49 
     50        PhysicsObject vasenReuna = Level.CreateBorders(); 
     51        vasenReuna.Restitution = 1.0; 
     52        vasenReuna.IsVisible = false; 
     53         
     54         
     55         
    3756        Level.BackgroundColor = Color.Lime; 
    3857        Camera.ZoomToLevel(); 
    39         PhysicsObject maila = PhysicsObject.CreateStaticObject( 20.0, 100.0 ); 
     58    } 
     59     
     60 
     61 
     62    void AloitaPeli() 
     63    { 
     64        Vector impulssi = new Vector(600.0, 0.0); 
     65        pallo.Hit(impulssi); 
     66     
     67 
     68    } 
     69   
     70     
     71 
     72 
     73    PhysicsObject  LuoMaila( double x, double y ){ 
     74        
     75PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    4076        maila.Shape = Shape.Rectangle; 
    41         maila.X = Level.Left + 20.0; 
    42         maila.Y = 0.0; 
     77        maila.X = x; 
     78        maila.Y = y; 
    4379        maila.Restitution = 1.0; 
    4480        Add(maila); 
     81 
     82        return maila; 
     83 
     84 
     85 
     86 
     87    } 
     88 
     89 
     90 
     91 
     92 
     93 
     94 
     95    void AsetaOhjaimet() 
     96    { 
     97        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlös); 
     98        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     99 
     100        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     101        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     102        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 
     103 
     104 
     105        { 
     106            Keyboard.Listen(Key.I, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlös); 
     107            Keyboard.Listen(Key.I, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     108 
     109            Keyboard.Listen(Key.K, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     110            Keyboard.Listen(Key.K, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     111            Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 
     112 
     113 
     114 
     115 
     116 
    45117        } 
     118    } 
    46119 
    47     PhysicsObject pallo; 
     120    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     121    { 
     122        maila.Velocity = nopeus; 
     123    } 
     124 
     125    void LisaaLaskurit() 
     126    { 
     127     pelaajan1Pisteet = LuoPisteLaskuri( Screen.Left + 100.0, Screen.Top - 100.0 ); 
     128     pelaajan2Pisteet = LuoPisteLaskuri( Screen.Right - 100.0, Screen.Top - 100.0 ); 
     129 
     130    //... 
     131     
     132     
     133     
     134    } 
     135 
     136 
     137    IntMeter LuoPisteLaskuri( double x, double y ) 
     138 
     139    { 
     140        IntMeter laskuri = new IntMeter( 0 ); 
     141        laskuri.MaxValue = 10; 
     142        Label naytto = new Label(); 
     143        naytto.BindTo(laskuri); 
     144        naytto.X = x; 
     145        naytto.Y = y; 
     146        naytto.TextColor = Color.White; 
     147        naytto.BorderColor = Level.BackgroundColor; 
     148        naytto.Color = Level.BackgroundColor; 
     149        Add( naytto ); 
     150        return laskuri; 
     151 
     152 
     153 
     154 
     155    } 
     156 
     157 
     158    void KasittelePallonTormays(PhysicsObject kohde) 
     159    { 
     160        if (kohde == vasenReuna) 
     161 
     162            pelaajan1Pisteet.Value += 1; 
     163 
     164 
     165 
     166 
     167 
     168        else if (kohde == vasenReuna) 
     169            pelaajan2Pisteet.Value += 1; 
     170 
     171 
     172    } 
     173 
    48174 
    49175 
Note: See TracChangeset for help on using the changeset viewer.