Changeset 8576 for 2017


Ignore:
Timestamp:
2017-06-13 12:35:41 (2 years ago)
Author:
npo17_19
Message:
 
Location:
2017/24/VihantiK/Pong/Pong
Files:
4 added
10 edited

Legend:

Unmodified
Added
Removed
  • 2017/24/VihantiK/Pong/Pong/Pong/Pong.cs

    r8524 r8576  
    11using System; 
    22using System.Collections.Generic; 
     3using System.Linq; 
     4using System.Text; 
    35using Jypeli; 
    46using Jypeli.Assets; 
     
    911public class Pong : PhysicsGame 
    1012{ 
     13    Vector nopeusYlos = new Vector(0, 1000); 
     14    Vector nopeusAlas = new Vector(0, -1000); 
     15 
     16    PhysicsObject pallo; 
     17    PhysicsObject maila1; 
     18    PhysicsObject maila2; 
     19 
     20    PhysicsObject vasenReuna; 
     21    PhysicsObject oikeaReuna; 
     22 
     23    IntMeter pelaajan1Pisteet; 
     24    IntMeter pelaajan2Pisteet; 
     25 
    1126    public override void Begin() 
    1227    { 
    13         PhysicsObject pallo = new PhysicsObject(40.0, 40.0); 
     28        LuoKentta(); 
     29        AsetaOhjaimet(); 
     30        LisaaLaskurit(); 
     31        AloitaPeli(); 
     32    } 
     33 
     34    void LuoKentta() 
     35    { 
     36        pallo = new PhysicsObject(60.0, 60.0); 
    1437        pallo.Shape = Shape.Circle; 
    1538        pallo.X = -200.0; 
    1639        pallo.Y = 0.0; 
    1740        pallo.Restitution = 1.0; 
     41        pallo.KineticFriction = 0.0; 
     42        pallo.MomentOfInertia = Double.PositiveInfinity; 
     43        Add(pallo); 
     44        AddCollisionHandler(pallo, KasittelePallonTormays); 
    1845 
    19         Add(pallo); 
     46        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     47        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    2048 
    21         Level.CreateBorders(1.0, false); 
    22         Level.BackgroundColor = Color.Black; 
     49        vasenReuna = Level.CreateLeftBorder(); 
     50        vasenReuna.Restitution = 1.0; 
     51        vasenReuna.KineticFriction = 0.0; 
     52        vasenReuna.IsVisible = false; 
     53 
     54        oikeaReuna = Level.CreateRightBorder(); 
     55        oikeaReuna.Restitution = 1.0; 
     56        oikeaReuna.KineticFriction = 0.0; 
     57        oikeaReuna.IsVisible = false; 
     58 
     59        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     60        ylaReuna.Restitution = 1.0; 
     61        ylaReuna.KineticFriction = 0.0; 
     62        ylaReuna.IsVisible = false; 
     63 
     64        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     65        alaReuna.Restitution = 1.0; 
     66        alaReuna.IsVisible = false; 
     67        alaReuna.KineticFriction = 0.0; 
     68 
     69        Level.Background.Color = Color.Black; 
    2370 
    2471        Camera.ZoomToLevel(); 
     72    } 
    2573 
     74    PhysicsObject LuoMaila(double x, double y) 
     75    { 
     76        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     77        maila.Shape = Shape.Rectangle; 
     78        maila.X = x; 
     79        maila.Y = y; 
     80        maila.Restitution = 1.0; 
     81        maila.KineticFriction = 0.0; 
     82        Add(maila); 
     83        return maila; 
     84    } 
     85 
     86    void LisaaLaskurit() 
     87    { 
     88        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     89        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     90    } 
     91 
     92    IntMeter LuoPisteLaskuri(double x, double y) 
     93    { 
     94        IntMeter laskuri = new IntMeter(0); 
     95        laskuri.MaxValue = 10; 
     96 
     97        Label naytto = new Label(); 
     98        naytto.BindTo(laskuri); 
     99        naytto.X = x; 
     100        naytto.Y = y; 
     101        naytto.TextColor = Color.White; 
     102        naytto.BorderColor = Level.Background.Color; 
     103        naytto.Color = Level.Background.Color; 
     104        Add(naytto); 
     105 
     106        return laskuri; 
     107    } 
     108 
     109    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     110    { 
     111        if (kohde == oikeaReuna) 
     112        { 
     113            pelaajan1Pisteet.Value += 1; 
     114        } 
     115        else if (kohde == vasenReuna) 
     116        { 
     117            pelaajan2Pisteet.Value += 1; 
     118        } 
     119    } 
     120 
     121    void AloitaPeli() 
     122    { 
    26123        Vector impulssi = new Vector(500.0, 0.0); 
    27124        pallo.Hit(impulssi); 
     125    } 
    28126 
     127    void AsetaOhjaimet() 
     128    { 
     129        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     130        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     131        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     132        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     133 
     134        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     135        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     136        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     137        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     138 
     139        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
    29140        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     141 
     142        ControllerOne.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila1, nopeusYlos); 
     143        ControllerOne.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     144        ControllerOne.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila1, nopeusAlas); 
     145        ControllerOne.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     146 
     147        ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila2, nopeusYlos); 
     148        ControllerTwo.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     149        ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila2, nopeusAlas); 
     150        ControllerTwo.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     151 
     152        ControllerOne.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     153        ControllerTwo.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    30154    } 
    31 }     
     155 
     156    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     157    { 
     158        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     159        { 
     160            maila.Velocity = Vector.Zero; 
     161            return; 
     162        } 
     163        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     164        { 
     165            maila.Velocity = Vector.Zero; 
     166            return; 
     167        } 
     168 
     169        maila.Velocity = nopeus; 
     170    } 
     171} 
  • 2017/24/VihantiK/Pong/Pong/Pong/obj/x86/Debug/ContentPipeline-{7217D983-BE37-41B7-8915-581AE9075CCE}.xml

    r8500 r8576  
    22<XnaContent xmlns:Pipeline="Microsoft.Xna.Framework.Content.Pipeline"> 
    33  <Asset Type="Pipeline:BuildItemCollection"> 
     4    <Item> 
     5      <Source>donald-2075124_1920.png</Source> 
     6      <Name>donald-2075124_1920</Name> 
     7      <Importer>TextureImporter</Importer> 
     8      <Processor>TextureProcessor</Processor> 
     9      <Options>None</Options> 
     10      <Output>C:\MyTemp\VihantiK\Pong\Pong\Pong\bin\x86\Debug\Content\donald-2075124_1920.xnb</Output> 
     11      <Time>2017-06-13T11:07:24.0857425+03:00</Time> 
     12    </Item> 
    413    <BuildSuccessful>true</BuildSuccessful> 
    514    <Settings> 
     
    1625    <Assemblies> 
    1726      <Assembly> 
     27        <Key>C:\Program Files (x86)\Jypeli\lib\ContentExtensions\TextFileContentExtension.dll</Key> 
     28        <Value>2015-02-09T20:18:44+02:00</Value> 
     29      </Assembly> 
     30      <Assembly> 
     31        <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.XImporter.dll</Key> 
     32        <Value>2011-09-01T16:22:30+03:00</Value> 
     33      </Assembly> 
     34      <Assembly> 
     35        <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.VideoImporters.dll</Key> 
     36        <Value>2011-09-01T16:22:30+03:00</Value> 
     37      </Assembly> 
     38      <Assembly> 
     39        <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.dll</Key> 
     40        <Value>2011-09-01T16:22:30+03:00</Value> 
     41      </Assembly> 
     42      <Assembly> 
     43        <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.FBXImporter.dll</Key> 
     44        <Value>2011-09-01T16:22:30+03:00</Value> 
     45      </Assembly> 
     46      <Assembly> 
     47        <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.EffectImporter.dll</Key> 
     48        <Value>2011-09-01T16:22:30+03:00</Value> 
     49      </Assembly> 
     50      <Assembly> 
     51        <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.AudioImporters.dll</Key> 
     52        <Value>2011-09-01T16:22:30+03:00</Value> 
     53      </Assembly> 
     54      <Assembly> 
     55        <Key>C:\Program Files (x86)\Jypeli\lib\ContentExtensions\AnimationExtension.dll</Key> 
     56        <Value>2015-02-17T22:27:18+02:00</Value> 
     57      </Assembly> 
     58      <Assembly> 
    1859        <Key>C:\WINDOWS\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework.Content.Pipeline\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Content.Pipeline.dll</Key> 
    19         <Value>2016-09-06T11:06:57.0488145+03:00</Value> 
     60        <Value>2017-06-09T17:02:21.2130348+03:00</Value> 
    2061      </Assembly> 
    2162    </Assemblies> 
  • 2017/24/VihantiK/Pong/Pong/Pong/obj/x86/Debug/Pong.csproj.FileListAbsolute.txt

    r8515 r8576  
    77C:\MyTemp\VihantiK\Pong\Pong\Pong\obj\x86\Debug\Pong.pdb 
    88C:\MyTemp\VihantiK\Pong\Pong\Pong\obj\x86\Debug\Pong.csprojResolveAssemblyReference.cache 
     9C:\MyTemp\VihantiK\Pong\Pong\Pong\bin\x86\Debug\Content\donald-2075124_1920.xnb 
  • 2017/24/VihantiK/Pong/Pong/PongContent/PongContent.contentproj

    r8500 r8576  
    4545    <Reference Include="AnimationExtension" /> 
    4646  </ItemGroup> 
     47  <ItemGroup> 
     48    <Compile Include="donald-2075124_1920.png"> 
     49      <Name>donald-2075124_1920</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.