Changeset 2968


Ignore:
Timestamp:
2012-06-13 09:37:07 (11 years ago)
Author:
sijoseha
Message:

Talletus.

Location:
2012/24/AnttoniS
Files:
45 added
6 edited

Legend:

Unmodified
Added
Removed
  • 2012/24/AnttoniS/Pong/Pong.sln

    r2915 r2968  
    44Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pong", "Pong\Pong\Pong.csproj", "{1EEF96B7-AF40-48FC-BD3F-A15296E0C48A}" 
    55EndProject 
    6 Project("{96E2B04D-8817-42C6-938A-82C39BA4D311}") = "PongContent", "Pong\PongContent\PongContent.contentproj", "{0DA0C7C8-574C-485E-A440-D79D48E7AD0C}" 
     6Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PongContent", "Pong\PongContent\PongContent.contentproj", "{0DA0C7C8-574C-485E-A440-D79D48E7AD0C}" 
    77EndProject 
    88Global 
  • 2012/24/AnttoniS/Pong/Pong/Pong/Pong.cs

    r2915 r2968  
    99public class Pong : PhysicsGame 
    1010{ 
    11     Vector nopeusYlos = new Vector(0, 200); 
    12     Vector nopeusAlas = new Vector(0, -200); 
     11    Vector nopeusYlos = new Vector(0, 1000); 
     12    Vector nopeusAlas = new Vector(0, -1000); 
    1313 
    1414    PhysicsObject pallo; 
     
    1717    PhysicsObject maila2; 
    1818 
     19    PhysicsObject vasenReuna; 
     20    PhysicsObject oikeaReuna; 
     21 
     22    IntMeter pelaajan1Pisteet; 
     23    IntMeter pelaajan2pisteet; 
     24 
    1925    public override void Begin() 
    2026    { 
     
    2228        LuoKentta(); 
    2329        AsetaOhjaimet(); 
     30        LisaaLaskurit(); 
    2431        AloitaPeli(); 
    2532     
     
    3845        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2 : Liikuta mailaa ylös", maila2, nopeusYlos); 
    3946        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
    40         Keyboard.Listen(Key.Down, ButtonState.Down 
     47        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikutaa mailaa alas", maila2, nopeusAlas); 
     48        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     49        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
    4150        Keyboard.Listen (Key.Escape, ButtonState.Pressed,ConfirmExit, "Lopeta peli" ); 
    4251    } 
     
    4756    void AloitaPeli() 
    4857    { 
    49         Vector impulssi = new Vector(500, 0.0); 
     58        Vector impulssi = new Vector(2000, 1.0); 
    5059        pallo.Hit(impulssi); 
    5160    } 
    5261    void LuoKentta() 
    5362    { 
    54         pallo = new PhysicsObject(40, 40); 
     63        pallo = new PhysicsObject(50, 50); 
    5564        Add(pallo); 
    5665        pallo.Color = Color.Yellow; 
     
    6069        pallo.Restitution = 1.0; 
    6170        Add(pallo); 
     71        AddCollisionHandler(pallo, KasittelePallonTormays); 
    6272 
    6373        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    6474        maila2 = LuoMaila(Level.Right - 20.0,0.0); 
    6575 
    66         Level.CreateBorders(1.0, false); 
     76        vasenReuna = Level.CreateLeftBorder(); 
     77        vasenReuna.Restitution = 1.0; 
     78        vasenReuna.IsVisible = false; 
     79        oikeaReuna = Level.CreateRightBorder(); 
     80        oikeaReuna.Restitution = 1.0; 
     81        oikeaReuna.IsVisible = false; 
     82        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     83        ylaReuna.Restitution = 1.0; 
     84        ylaReuna.IsVisible = false; 
     85        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     86        alaReuna.Restitution = 1.0; 
     87        alaReuna.IsVisible = false; 
    6788        pallo.Restitution = 1.0; 
    6889        Level.BackgroundColor = Color.YellowGreen; 
     
    83104        return maila; 
    84105    } 
     106 
     107    void LisaaLaskurit() 
     108    { 
     109        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     110        pelaajan2pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     111    } 
     112 
     113    IntMeter LuoPisteLaskuri( double x, double y) 
     114    { 
     115        IntMeter laskuri = new IntMeter(0); 
     116        laskuri.MaxValue = 10; 
     117        Label naytto = new Label(); 
     118        naytto.BindTo(laskuri); 
     119        naytto.X = x; 
     120        naytto.Y = y; 
     121        naytto.TextColor = Color.White; 
     122        naytto.BorderColor = Level.BackgroundColor; 
     123        naytto.Color = Level.BackgroundColor; 
     124        Add(naytto); 
     125        return laskuri; 
     126    } 
     127    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     128    { 
     129        if (kohde == oikeaReuna) 
     130        { 
     131            pelaajan1Pisteet.Value += 1; 
     132        } 
     133        else if (kohde == vasenReuna) 
     134        { 
     135            pelaajan2pisteet.Value += 1; 
     136        } 
     137    } 
     138 
     139       
     140    
     141 
     142 
     143 
     144 
     145        
     146     
     147     
     148 
     149 
     150 
    85151} 
Note: See TracChangeset for help on using the changeset viewer.