Changeset 4073 for 2013/24


Ignore:
Timestamp:
2013-06-11 14:58:04 (6 years ago)
Author:
betiterv
Message:

Talletus.

Location:
2013/24/BenjaminT
Files:
23 added
2 edited

Legend:

Unmodified
Added
Removed
  • 2013/24/BenjaminT/Pong/Pong/Pong/Pong.cs

    r4062 r4073  
    99public class Pong : PhysicsGame 
    1010{ 
     11    Image taustaKuva = LoadImage("Tardis"); 
     12    
    1113    Vector nopeusYlos = new Vector(0, 200); 
    1214    Vector nopeusAlas = new Vector(0, -200); 
    13  
    14  
    15  
    1615 
    1716    PhysicsObject pallo; 
     
    2019    PhysicsObject maila2; 
    2120 
     21    PhysicsObject vasenReuna; 
     22    PhysicsObject oikeaReuna; 
     23 
     24    IntMeter pelaajan1Pisteet; 
     25    IntMeter pelaajan2Pisteet; 
     26 
    2227    public override void Begin() 
    2328    { 
     
    2530        Vector impulssi = new Vector(500.0, 0.0); 
    2631        pallo.Hit(impulssi); 
    27  
     32        Level.Background.Image = taustaKuva; 
    2833        AsetaOhjaimet(); 
     34        LisaaLaskurit(); 
    2935 
    3036        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     
    3339    void LuoKentta() 
    3440    { 
    35         pallo = new PhysicsObject(40.0, 40.0); 
     41        pallo = new PhysicsObject(23.0, 23be.0); 
     42        
    3643        pallo.Shape = Shape.Circle; 
    37         pallo.X = -200.0; 
     44        pallo.KineticFriction = 0; 
     45        pallo.CanRotate = false; 
    3846        pallo.Y = 0.0; 
    3947        pallo.Restitution = 1.0; 
    4048        Add(pallo); 
    4149 
     50         
    4251        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    4352        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    4453 
    4554 
     55        AddCollisionHandler(pallo, KasittelePallonTormays); 
     56 
     57        vasenReuna = Level.CreateLeftBorder(); 
     58        vasenReuna.Restitution = 1.0; 
     59        vasenReuna.IsVisible = false; 
     60 
     61        oikeaReuna = Level.CreateRightBorder(); 
     62        oikeaReuna.Restitution = 1.0; 
     63        oikeaReuna.IsVisible = false; 
     64 
     65        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     66        ylaReuna.Restitution = 1.0; 
     67        ylaReuna.IsVisible = false; 
     68 
     69        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     70        alaReuna.Restitution = 1.0; 
     71        alaReuna.IsVisible = false; 
    4672 
    4773 
    4874 
    49  
    50  
    51  
    52  
    53  
    54         Level.CreateBorders(1.0, false); 
    5575        Level.BackgroundColor = Color.Black; 
    56  
    5776 
    5877 
     
    94113 
    95114 
    96         Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta maila ylös" , maila1, nopeusYlos); 
    97         Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus , null, maila1, Vector.Zero); 
     115        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta maila ylös", maila1, nopeusYlos); 
     116        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     117        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     118        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     119 
     120        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     121        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     122        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     123        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     124 
     125 
     126        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
     127 
     128 
     129 
    98130 
    99131        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    100132    } 
    101133 
    102      void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     134    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    103135    { 
     136        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     137        { 
     138            maila.Velocity = Vector.Zero; 
     139            return; 
     140 
     141        } 
    104142 
    105143        maila.Velocity = nopeus; 
     144    } 
     145 
     146    void LisaaLaskurit() 
     147    { 
     148        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     149        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
    106150 
    107151 
    108152    } 
    109153 
     154    IntMeter LuoPisteLaskuri(double x, double y) 
     155    { 
     156        IntMeter laskuri = new IntMeter(0); 
     157        laskuri.MaxValue = 10; 
     158 
     159        Label naytto = new Label(); 
     160        naytto.BindTo(laskuri); 
     161        naytto.X = x; 
     162        naytto.Y = y; 
     163        naytto.TextColor = Color.White; 
     164        naytto.BorderColor = Level.BackgroundColor; 
     165        naytto.Color = Level.BackgroundColor; 
     166        Add(naytto); 
     167 
     168 
     169 
     170 
     171 
     172        return laskuri; 
     173 
     174 
     175    } 
     176    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     177    { 
     178        if (kohde == oikeaReuna) 
     179        { 
     180            pelaajan1Pisteet.Value += 1; 
     181        } 
     182        else if (kohde == vasenReuna) 
     183        { 
     184            pelaajan2Pisteet.Value += 1; 
     185        } 
     186    } 
     187 
     188 
    110189} 
  • 2013/24/BenjaminT/Pong/Pong/PongContent/PongContent.contentproj

    r4043 r4073  
    4545    <Reference Include="AnimationExtension" /> 
    4646  </ItemGroup> 
     47  <ItemGroup> 
     48    <Compile Include="Tardis.png"> 
     49      <Name>Tardis</Name> 
     50      <Importer>TextureImporter</Importer> 
     51      <Processor>TextureProcessor</Processor> 
     52    </Compile> 
     53  </ItemGroup> 
    4754  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    4855  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
Note: See TracChangeset for help on using the changeset viewer.