Changeset 2949


Ignore:
Timestamp:
2012-06-12 14:37:48 (11 years ago)
Author:
eefadjuk
Message:

Talletus.

Location:
2012/24/EeroF/Bong
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • 2012/24/EeroF/Bong/Bong/Bong/Bong.cs

    r2930 r2949  
    88 
    99public class Bong : PhysicsGame 
    10 { 
     10{    
     11 
     12    Vector nopeusYlos = new Vector (0, 400 ); 
     13    Vector nopeusAlas = new Vector(0, -400); 
     14    PhysicsObject pelaaja; 
     15    PhysicsObject pelaaja2; 
     16 
     17    PhysicsObject pallo = new PhysicsObject(40, 40); 
     18 
     19    IntMeter pelaajan1Pisteet; 
     20    IntMeter pelaajan2Pisteet; 
     21 
     22 
    1123    public override void Begin() 
    1224    { 
    13         // Moi 
    14         PhysicsObject pallo = new PhysicsObject(40, 40); 
    15         Add(pallo); 
    16         pallo.Shape = Shape.Circle; 
    17         PhysicsObject pelaaja1 = new PhysicsObject(15, 70); 
    18         Add(pelaaja1); 
    19         pallo.Color = Color.OrangeRed; 
    20         pelaaja1.Color = Color.Lime; 
    21         PhysicsObject pelaaja2 = new PhysicsObject(15, 70); 
    22         pelaaja2.Color = Color.Pink; 
    23         Add(pelaaja2); 
    24         pelaaja2.X = -450; 
    25         pelaaja1.X = 450; 
    26         pelaaja2.Y = 0; 
    27         pelaaja1.Y = 0; 
    28         pelaaja1.Restitution = 1; 
    2925 
    3026 
    31         Vector impulssi = new Vector(500, 20); 
    32         pallo.Hit(impulssi); 
    33         Level.CreateBorders(1, false); 
    34         pallo.Restitution = 1; 
    35         Level.BackgroundColor = Color.Cyan; 
    36         Camera.ZoomToLevel(); 
     27 
     28        LuoKentta(); 
     29        AloitaPeli(); 
     30        AsetaOhjaimet(); 
    3731 
    3832 
     
    4135 
    4236 
     37        
    4338 
    44         PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
     39 
     40    } 
     41    void LuoKentta() 
     42    { 
     43       pelaaja = LuoMaila(-500, 0, Color.Violet); 
     44        pelaaja2 = LuoMaila(500, 0, Color.Lime); 
     45 
     46        Add(pallo); 
     47        pallo.Shape = Shape.Circle; 
     48        pallo.Color = Color.OrangeRed; 
     49        pallo.Restitution = 1; 
     50       // pallo.Gravity (200) ; 
     51 
     52        Level.CreateBorders(1, false); 
     53 
     54        Level.BackgroundColor = Color.Cyan; 
     55        Camera.ZoomToLevel(); 
     56 
     57    } 
     58     
     59 
     60    void AloitaPeli() 
     61    { 
     62        Vector impulssi = new Vector(500, 300); 
     63        pallo.Hit(impulssi); 
     64 
     65 
     66 
     67 
     68    } 
     69 
     70    PhysicsObject LuoMaila(double x, double y, Color vari) 
     71    { 
     72        PhysicsObject pelaaja = PhysicsObject.CreateStaticObject (15, 70); 
     73        Add(pelaaja); 
     74        pelaaja.Shape = Shape.Ellipse; 
     75        pelaaja.Color = vari; 
     76        pelaaja.X = x; 
     77        pelaaja.Y = y; 
     78        pelaaja.Restitution = 1; 
     79        return pelaaja; 
     80         
     81 
     82 
     83    } 
     84     
     85    void AsetaOhjaimet() 
     86    { 
     87        Keyboard.Listen(Key.S, ButtonState.Down, AsetaNopeus, null, pelaaja, nopeusAlas); 
     88        Keyboard.Listen(Key.S, ButtonState.Released, AsetaNopeus, null, pelaaja, Vector.Zero); 
     89        Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, null, pelaaja, nopeusYlos); 
     90        Keyboard.Listen(Key.W, ButtonState.Released, AsetaNopeus, null, pelaaja, Vector.Zero); 
     91        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, null, pelaaja2, nopeusYlos); 
     92        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, pelaaja2, Vector.Zero); 
     93        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, null, pelaaja2, nopeusAlas); 
     94        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, pelaaja2, Vector.Zero); 
     95         
     96 
    4597        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    4698    } 
    47     void LuoKenttä() 
     99 
     100 
     101    void AsetaNopeus(PhysicsObject pelaaja,Vector nopeus  ) 
    48102    { 
    49     } 
     103        pelaaja.Velocity = nopeus; 
     104 
     105        if ( (nopeus.Y > 0 ) && (pelaaja.Top > Level.Top) ) 
     106        { 
     107            pelaaja.Velocity = Vector.Zero; 
     108            return; 
     109        } 
     110 
     111    
     112                if ((nopeus.Y < 0) && (pelaaja.Bottom < Level.Bottom)) 
     113        { 
     114                    pelaaja.Velocity = Vector.Zero; 
     115                    return; 
     116        } 
     117 
     118       } 
     119    void LisaaLaskurit() 
     120    { 
     121       pelaajan1Pisteet = LuoPisteLaskuri ( Screen.Left + 100.0, Screen.Top - 100.0 ); 
     122       pelaajan2Pisteet = LuoPisteLaskuri ( Screen.Right - 100.0, Screen.Top - 100.0 ); 
    50123} 
    51124 
     125 
     126 
     127    } 
     128    IntMeter LuoPistelaskuri (double x, double y) 
     129    { 
     130        IntMeter laskuri = new IntMeter(0); 
     131        
     132        laskuri.MaxValue = 10; 
     133        Label naytto = new Label  (0); 
     134        naytto.BindTo(laskuri); 
     135        naytto.X = x; 
     136        naytto.Y = y; 
     137        naytto.TextColor = Color.White; 
     138        naytto.BorderColor = Level.BackgroundColor; 
     139        naytto.Color = Level.BackgroundColor; 
     140        Add(naytto); 
     141        return laskuri; 
     142 
     143 
     144    } 
     145 
     146 
     147 
     148 
     149     
     150 
     151} 
     152 
Note: See TracChangeset for help on using the changeset viewer.