Changeset 5529 for 2014


Ignore:
Timestamp:
2014-07-22 10:52:30 (9 years ago)
Author:
sieerinn
Message:

Pongin muokkaamista

Location:
2014/30/LauriR/Pong
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 2014/30/LauriR/Pong/Pong/Pong/Pong.cs

    r5508 r5529  
    99public class Pong : PhysicsGame 
    1010{ 
    11     Vector nopeusYlos = new Vector(0, 200); 
    12     Vector nopeusAlas = new Vector(0, -200); 
    13  
    14     PhysicsObject pallo; 
     11    Vector nopeusYlos = new Vector(0, 400); 
     12    Vector nopeusAlas = new Vector(0, -400); 
     13 
    1514    PhysicsObject maila1; 
    1615    PhysicsObject maila2; 
     
    2726        AsetaOhjaimet(); 
    2827        LisaaLaskurit(); 
    29         AloitaPeli(); 
    30     } 
    31  
    32     void LuoKentta() 
    33     { 
    34         pallo = new PhysicsObject(40.0, 40.0); 
    35         pallo.Shape = Shape.Circle; 
    36         pallo.X = -350.0; 
    37         pallo.Y = 0.0; 
     28        
     29    } 
     30 
     31    void LuoPallo() 
     32    { 
     33        PhysicsObject pallo = new PhysicsObject(40.0, 40.0); 
     34        pallo.Shape = Shape.Hexagon; 
     35        pallo.Color = RandomGen.NextColor(); 
     36        pallo.X = RandomGen.NextDouble(-100,100); 
     37        pallo.Y = RandomGen.NextDouble(-100, 100); 
    3838        pallo.Restitution = 1.0; 
    3939        pallo.KineticFriction = 0.0; 
     
    4242        AddCollisionHandler(pallo, KasittelePallonTormays); 
    4343 
     44        Vector impulssi = new Vector(500.0, 0.0); 
     45        pallo.Hit(impulssi); 
     46    } 
     47 
     48    void LuoKentta() 
     49    { 
     50        for (int i = 0; i < 10; i++) 
     51        { 
     52 
     53 
     54            LuoPallo(); 
     55 
     56        } 
     57       
    4458        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    4559        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
     
    6579        alaReuna.KineticFriction = 0.0; 
    6680 
    67         Level.BackgroundColor = Color.Black; 
     81        Level.Background.Color = Color.Green; 
     82         
     83        maila1.Color = Color.Wheat; 
     84        maila2.Color = Color.Wheat; 
    6885 
    6986        Camera.ZoomToLevel(); 
     
    91108    { 
    92109        IntMeter laskuri = new IntMeter(0); 
    93         laskuri.MaxValue = 10; 
     110        laskuri.MaxValue = 1000; 
    94111 
    95112        Label naytto = new Label(); 
     
    98115        naytto.Y = y; 
    99116        naytto.TextColor = Color.White; 
    100         naytto.BorderColor = Level.BackgroundColor; 
    101         naytto.Color = Level.BackgroundColor; 
     117        naytto.BorderColor = Level.Background.Color; 
     118        naytto.Color = Level.Background.Color; 
    102119        Add(naytto); 
    103120 
     
    117134    } 
    118135 
    119     void AloitaPeli() 
    120     { 
    121         Vector impulssi = new Vector(500.0, 0.0); 
    122         pallo.Hit(impulssi); 
    123     } 
    124  
    125136    void AsetaOhjaimet() 
    126137    { 
     138        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
     139 
    127140        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
    128141        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     
    167180        maila.Velocity = nopeus; 
    168181    } 
     182 
     183    const double PALLON_MIN_NOPEUS = 500; 
     184 
     185    protected override void Update(Time time) 
     186    { 
     187        /* 
     188        if (pallo != null && Math.Abs(pallo.Velocity.X) < PALLON_MIN_NOPEUS) 
     189        { 
     190            pallo.Velocity = new Vector(pallo.Velocity.X * 1.1, pallo.Velocity.Y); 
     191        } 
     192         */ 
     193        base.Update(time); 
     194    } 
    169195} 
    170196 
Note: See TracChangeset for help on using the changeset viewer.