Ignore:
Timestamp:
2009-08-04 10:07:45 (14 years ago)
Author:
wevantti
Message:

Pong valmis

File:
1 edited

Legend:

Unmodified
Added
Removed
  • werner_v/Pong-1/Peli.cs

    r218 r229  
    1717#endregion 
    1818 
    19 namespace Pong1 
     19namespace Pong 
    2020{ 
    2121    public class Peli : PhysicsGame 
     
    2424        PhysicsObject maila1; 
    2525        PhysicsObject maila2; 
    26         Vector2D nopeusYlos = new Vector2D(0, 200); 
    27         Vector2D nopeusAlas = new Vector2D(0, -200); 
     26        Vector2D nopeusYlos = new Vector2D(0, 400); 
     27        Vector2D nopeusAlas = new Vector2D(0, -400); 
     28 
     29        Meter<int> Pelaajan1Pisteet; 
     30        Meter<int> Pelaajan2Pisteet; 
     31 
     32        void LisaaLaskurit() 
     33        { 
     34            Pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     35            Pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     36        } 
     37 
     38        Meter<int> LuoPisteLaskuri(double x, double y) 
     39        { 
     40            Meter<int> laskuri = new Meter<int>(0, 0, 10); 
     41            ValueDisplay naytto = new ValueDisplay(this); 
     42            naytto.BindTo(laskuri); 
     43            naytto.X = x; 
     44            naytto.Y = y; 
     45            naytto.ValueColor = Color.White; 
     46            Add(naytto); 
     47            return laskuri; 
     48        } 
    2849 
    2950        protected override void LoadContent() 
     
    3152            Level = LuoKentta(); 
    3253            AsetaOhjaimet(); 
     54            LisaaLaskurit(); 
    3355            AloitaPeli(); 
     56        } 
     57        void KasittelePallonTormays(Collision collision) 
     58        { 
     59            PhysicsObject pallo = collision.Obj; 
     60            PhysicsObject kohde = collision.Other; 
     61 
     62            if (kohde == Level.RightBorder) 
     63            { 
     64                Pelaajan1Pisteet.Value += 1; 
     65            } 
     66            else if (kohde == Level.LeftBorder) 
     67            { 
     68                Pelaajan2Pisteet.Value += 1; 
     69            } 
    3470        } 
    3571        Level LuoKentta() 
     
    4480            pallo.Restitution = 1.0; 
    4581            kentta.Objects.Add(pallo); 
     82            AddCollisionHandler(pallo, KasittelePallonTormays); 
    4683 
    4784            maila1 = LuoMaila(kentta.Left + 20.0, 0.0, kentta); 
     
    5390        void AloitaPeli() 
    5491        { 
    55             Vector2D impulssi = new Vector2D(2000.0, 0.0); 
     92            Vector2D impulssi = new Vector2D(5000.0, 0.0); 
    5693            pallo.Hit(impulssi); 
    5794        } 
Note: See TracChangeset for help on using the changeset viewer.