Changeset 1308 for 2010


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

PinkiPonki? Paranneltu! :3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2010/30/mikmatla/Pong/Peli.cs

    r1285 r1308  
    66public class Peli : PhysicsGame 
    77{ 
    8     Vector nopeusYlos = new Vector(0, 200.0); 
    9     Vector nopeusAlas = new Vector( 0, -200.0); 
     8    Vector nopeusYlos = new Vector(0, 300.0); 
     9    Vector nopeusAlas = new Vector( 0, -300.0); 
    1010 
    1111    PhysicsObject Pallo; 
    12  
    1312    PhysicsObject maila1; 
    1413    PhysicsObject maila2; 
     14 
     15    PhysicsObject vasenReuna; 
     16    PhysicsObject oikeaReuna; 
     17 
     18    IntMeter pelaajan1Pisteet; 
     19    IntMeter pelaajan2Pisteet; 
    1520 
    1621    protected override void Begin() 
     
    1823        LuoKentta(); 
    1924        AsetaOhjaimet(); 
     25        LisaaLaskurit(); 
    2026        AloitaPeli(); 
    2127    } 
    22  
     28     
    2329    void LuoKentta() 
    2430    { 
    25  
    2631        Pallo = new PhysicsObject(40.0, 40.0); 
    2732        Pallo.Shape = Shapes.Circle; 
     
    3439        maila2 = LuoMaila(Level.Right - 30.0, 0.0); 
    3540 
    36         Level.CreateBorders(1.0, false); 
     41        AddCollisionHandler(Pallo, KasittelePallonTormays); 
     42 
     43        vasenReuna = Level.CreateLeftBorder(); 
     44        vasenReuna.Restitution = 1.0; 
     45        vasenReuna.IsVisible = false; 
     46        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     47        ylaReuna.Restitution = 1.0; 
     48        ylaReuna.IsVisible = false; 
     49        oikeaReuna = Level.CreateRightBorder(); 
     50        oikeaReuna.Restitution = 1.0; 
     51        oikeaReuna.IsVisible = false; 
     52        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     53        alaReuna.Restitution = 1.0; 
     54        alaReuna.IsVisible = false; 
     55 
     56        oikeaReuna.IgnoresCollisionResponse = true; 
     57        vasenReuna.IgnoresCollisionResponse = true; 
     58 
    3759        Level.BackgroundColor = Color.YellowGreen; 
    3860 
    3961        Camera.ZoomToLevel(); 
     62    } 
     63 
     64    void LuoPallo() 
     65    { 
     66        Pallo = new PhysicsObject(40.0, 40.0); 
     67        Pallo.Shape = Shapes.Circle; 
     68        Pallo.X = 0.0; 
     69        Pallo.Y = 0.0; 
     70        Pallo.Restitution = 1.0; 
     71        Add(Pallo); 
    4072    } 
    4173 
     
    76108    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    77109    { 
     110        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     111        { 
     112            maila.Velocity = Vector.Zero; 
     113            return; 
     114        } 
     115 
     116        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     117        { 
     118            maila.Velocity = Vector.Zero; 
     119            return; 
     120        } 
     121 
    78122        maila.Velocity = nopeus; 
    79123    } 
     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    IntMeter LuoPisteLaskuri(double x, double y) 
     132    { 
     133        IntMeter laskuri = new IntMeter(3); 
     134        laskuri.MinValue = 1; 
     135        Label naytto = new Label(); 
     136        naytto.BindTo(laskuri); 
     137        naytto.X = x; 
     138        naytto.Y = y; 
     139        naytto.TextColor = Color.White; 
     140        Add(naytto); 
     141        return laskuri; 
     142    } 
     143 
     144    void KasittelePallonTormays(PhysicsObject Pallo, PhysicsObject kohde) 
     145    { 
     146        if (kohde == oikeaReuna) 
     147        { 
     148            PalloKeskelle(Pallo); 
     149            pelaajan2Pisteet.Value -= 1; 
     150        } 
     151        else if (kohde == vasenReuna) 
     152        { 
     153            PalloKeskelle(Pallo); 
     154            pelaajan1Pisteet.Value -= 1; 
     155        } 
     156    } 
     157 
     158    private void PalloKeskelle(PhysicsObject Pallo) 
     159    { 
     160        Pallo.Velocity = new Vector(0, 0); 
     161        Pallo.X = 0; 
     162        Pallo.Y = 0; 
     163        AloitaPeli(); 
     164    } 
    80165} 
Note: See TracChangeset for help on using the changeset viewer.