Changeset 1307 for 2010


Ignore:
Timestamp:
2010-07-27 11:25:44 (13 years ago)
Author:
lijiolva
Message:

Valmis...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2010/30/lijiolva/p0ng/Peli.cs

    r1296 r1307  
    22using Jypeli; 
    33using Jypeli.Widgets; 
    4 using Jypeli.Assets; 
    54 
    65public class Peli : PhysicsGame 
     
    109 
    1110    PhysicsObject pallo; 
    12  
    1311    PhysicsObject maila1; 
    1412    PhysicsObject maila2; 
    15      
     13 
     14    IntMeter pelaajan1Pisteet; 
     15    IntMeter pelaajan2Pisteet; 
     16 
     17    PhysicsObject vasenReuna; 
     18    PhysicsObject oikeaReuna; 
     19 
    1620    protected override void Begin() 
    1721    { 
    18         //TODO: Alusta peli tässä 
     22        LuoKentta(); 
    1923        AsetaOhjaimet(); 
    20         LuoKentta() ; 
    21         AloitaPeli() ; 
    22          
     24        LisaaLaskurit(); 
     25        AloitaPeli(); 
    2326    } 
     27 
    2428    void LuoKentta() 
    2529    { 
    26         pallo = new PhysicsObject(40.0, 40.0); 
    27         pallo.Shape = Shapes.Circle ; 
    28         Add(pallo); 
    29         pallo.X = 200.0; 
    30         pallo.Y = 5.9; 
    31         pallo.Color = Color.DarkViolet ; 
    32         Level.CreateBorders( 1.0,false); 
     30        pallo = new PhysicsObject( 40.0, 40.0 ); 
     31        pallo.Shape = Shapes.Circle; 
     32        pallo.X = -200.0; 
     33        pallo.Y = 0.0; 
    3334        pallo.Restitution = 1.0; 
    34         Level.BackgroundColor = Color.DarkRed ; 
    35         Camera.ZoomToLevel(); 
     35        pallo.CanRotate = false; 
     36        Add( pallo ); 
     37         
     38 
    3639        maila1 = LuoMaila( Level.Left + 20.0, 0.0 ); 
    3740        maila2 = LuoMaila( Level.Right - 20.0, 0.0 ); 
     41 
     42        vasenReuna = Level.CreateLeftBorder(); 
     43        vasenReuna.Restitution = 1.0; 
     44        vasenReuna.IsVisible = false; 
    3845         
     46        oikeaReuna = Level.CreateRightBorder(); 
     47        oikeaReuna.Restitution = 1.0; 
     48        oikeaReuna.IsVisible = false; 
     49         
     50        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     51        vasenReuna.Restitution = 1.0; 
     52        vasenReuna.IsVisible = false; 
     53 
     54        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     55        vasenReuna.Restitution = 1.0; 
     56        vasenReuna.IsVisible = false; 
     57         
     58        Level.BackgroundColor = Color.Black; 
     59 
     60        Camera.ZoomToLevel(); 
     61        AddCollisionHandler(pallo, KasittelePallonTormays) ; 
    3962    } 
     63 
     64    PhysicsObject LuoMaila( double x, double y ) 
     65    { 
     66        PhysicsObject maila = PhysicsObject.CreateStaticObject( 20.0, 100.0 ); 
     67        maila.Shape = Shapes.Rectangle; 
     68        maila.X = x; 
     69        maila.Y = y; 
     70        maila.Restitution = 1.0; 
     71        Add( maila ); 
     72        return maila; 
     73    } 
     74 
    4075    void AloitaPeli() 
    4176    { 
    42       Vector impulssi = new Vector(500.0, 1.0); 
    43       pallo.Hit(impulssi); 
     77        Vector impulssi = new Vector( 500.0, 0.0 ); 
     78        pallo.Hit( impulssi ); 
    4479    } 
    45     PhysicsObject LuoMaila(double x, double y) 
    46     { 
    47        
    48       PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    49       maila.Shape = Shapes.Rectangle; 
    50       maila.X = x; 
    51       maila.Y = y; 
    52       maila.Restitution = 1.0; 
    53       Add(maila); 
    5480 
    55       return maila; 
    56     } 
    57     void AsetaOhjaimet() 
    58     { 
    59  
     81void AsetaOhjaimet() 
     82{ 
    6083    Keyboard.Listen( Key.A,      ButtonState.Down,     AsetaNopeus,     "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos ); 
    6184    Keyboard.Listen( Key.A,      ButtonState.Released, AsetaNopeus,     null,                             maila1, Vector.Zero ); 
     
    7093    Keyboard.Listen( Key.F1,     ButtonState.Pressed,  ShowControlHelp, "Näytä ohjeet" ); 
    7194    Keyboard.Listen( Key.Escape, ButtonState.Pressed,  Exit,            "Poistu" ); 
     95} 
     96     
    7297 
    73     } 
    74     void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     98    void AsetaNopeus( PhysicsObject maila, Vector nopeus ) 
    7599    { 
     100        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     101        { 
     102            maila.Velocity = Vector.Zero; 
     103            return; 
     104        } 
     105        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     106        { 
     107            maila.Velocity = Vector.Zero; 
     108            return; 
     109        } 
    76110        maila.Velocity = nopeus; 
    77111    } 
    78  
     112    void LisaaLaskurit() 
     113    { 
     114        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     115        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     116    } 
     117    IntMeter LuoPisteLaskuri(double x, double y) 
     118    { 
     119        IntMeter laskuri = new IntMeter(0); 
     120        laskuri.MaxValue = 10; 
     121        Label naytto = new Label(); 
     122        naytto.BindTo(laskuri); 
     123        naytto.X = x; 
     124        naytto.Y = y; 
     125        naytto.TextColor = Color.White; 
     126        Add(naytto); 
     127        return laskuri; 
     128    } 
     129    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     130    { 
     131        if (kohde == oikeaReuna) 
     132        { 
     133            pelaajan1Pisteet.Value += 1; 
     134        } 
     135        else if (kohde == vasenReuna) 
     136        { 
     137            pelaajan2Pisteet.Value += 1; 
     138        } 
     139    } 
     140} 
Note: See TracChangeset for help on using the changeset viewer.