Changeset 7792


Ignore:
Timestamp:
2016-07-05 14:55:09 (3 years ago)
Author:
karkaite
Message:

pong ready.

Location:
2016/27/RuhanAnjanK
Files:
6 added
9 edited

Legend:

Unmodified
Added
Removed
  • 2016/27/RuhanAnjanK/Pong/Pong/Pong/Pong.cs

    r7729 r7792  
    1212{ 
    1313    Vector speedup = new Vector(0, 200); 
    14     Vector speeddown = new Vector(0, 200); 
     14    Vector speeddown = new Vector(0, -200); 
    1515 
    1616    PhysicsObject ball; 
    1717    PhysicsObject racket1; 
    1818    PhysicsObject racket2; 
     19 
     20    Image tileimage = LoadImage("tiles"); 
     21 
     22    PhysicsObject leftBorder; 
     23    PhysicsObject rightBorder; 
     24 
     25    IntMeter player1score; 
     26    IntMeter player2score; 
     27 
    1928    public override void Begin() 
    2029    { 
    21         // TODO: Kirjoita ohjelmakoodisi tähän 
    2230        CreateLevel(); 
     31        SetControls(); 
     32        AddCounters(); 
     33        StartGame(); 
     34    } 
     35    void AddCounters() 
     36    { 
     37        player1score = CreateScoreCounter(Screen.Left +100.0, Screen.Top -100.0); 
     38        player2score = CreateScoreCounter(Screen.Right - 100.0, Screen.Top - 100.0); 
     39    } 
    2340 
    24          Vector impulse = new Vector (500.0 , 0.0); 
    25         ball.Hit(impulse); 
     41    void SetControls() 
     42    { 
     43        Keyboard.Listen(Key.A, ButtonState.Down, SetSpeed, "Player 1: Move racket up", racket1, speedup); 
     44        Keyboard.Listen(Key.A, ButtonState.Released, SetSpeed, null, racket1, Vector.Zero); 
     45        Keyboard.Listen(Key.Z, ButtonState.Down, SetSpeed, "player 1: move racket down", racket1, speeddown); 
     46        Keyboard.Listen(Key.Z, ButtonState.Released, SetSpeed, null, racket1, Vector.Zero); 
     47 
     48        Keyboard.Listen(Key.Up, ButtonState.Down, SetSpeed, "player 2: move racket up", racket2, speedup); 
     49        Keyboard.Listen(Key.Up, ButtonState.Released, SetSpeed, null, racket2, Vector.Zero); 
     50        Keyboard.Listen(Key.Down, ButtonState.Down, SetSpeed, "player 2: move racket down", racket2, speeddown); 
     51        Keyboard.Listen(Key.Down, ButtonState.Released, SetSpeed, null, racket2, Vector.Zero); 
     52 
     53        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "show instructions"); 
     54        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "exitgame"); 
     55 
     56        ControllerOne.Listen(Button.DPadUp, ButtonState.Down, SetSpeed, "move racket up", racket1, speedup); 
     57        ControllerOne.Listen(Button.DPadUp, ButtonState.Down, SetSpeed, "move racket down",racket1, speeddown); 
     58        ControllerOne.Listen(Button.DPadDown, ButtonState.Released, SetSpeed, null, racket1, Vector.Zero); 
     59        ControllerOne.Listen(Button.DPadDown, ButtonState.Released, SetSpeed, null, racket1, Vector.Zero); 
     60 
     61        ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, SetSpeed, "move racket up", racket2, speedup); 
     62        ControllerTwo.Listen(Button.DPadUp, ButtonState.Released,SetSpeed, null,racket2, Vector.Zero); 
     63        ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, SetSpeed, "move racket down", racket2, speeddown); 
     64        ControllerTwo.Listen(Button.DPadDown, ButtonState.Released, SetSpeed, null, racket2, Vector.Zero); 
     65 
     66        ControllerOne.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "end game"); 
     67        ControllerTwo.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "end game"); 
     68    } 
     69 
     70void SetSpeed(PhysicsObject paddle, Vector speed) 
     71    { 
     72        paddle.Velocity = speed; 
     73    } 
     74 
     75   IntMeter CreateScoreCounter(double x, double y) 
     76    { 
     77        IntMeter counter = new IntMeter(0); 
     78        counter.MaxValue = 10; 
     79 
     80        Label display = new Label(); 
     81        display.BindTo(counter); 
     82        display.X = x; 
     83        display.Y = y; 
     84        display.TextColor = Color.Red; 
     85        display.BorderColor = Level.Background.Color; 
     86        Add(display); 
     87 
     88        return counter; 
     89         
     90         
     91         
     92    } 
    2693          
    27  
    28         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "end game"); 
    29     } 
    3094    void CreateLevel() 
    3195    { 
     
    3397        ball.Shape = Shape.Circle; 
    3498        ball.X = -200.0; 
     99        ball.Color = Color.HanPurple; 
    35100        ball.Y = 0.0; 
    36101        ball.Restitution = 1.0; 
     102        Add(ball); 
     103        AddCollisionHandler(ball, HandleBallCollision); 
    37104 
    38         Add(ball); 
     105        racket1 = CreateRacket(Level.Left + 20.0, 0.0); 
     106        racket1.Color = Color.MediumVioletRed; 
     107        racket2 = CreateRacket(Level.Right - 20.0, 0.0); 
     108        racket2.Color = Color.Orange; 
    39109 
    40        racket1 = CreateRacket(Level.Left + 20.0, 0.0); 
    41        racket2 = CreateRacket(Level.Right - 20.0, 0.0); 
     110        leftBorder = Level.CreateLeftBorder(); 
     111        leftBorder.Restitution = 1.0; 
     112        leftBorder.IsVisible = false; 
    42113 
    43         Level.CreateBorders(1.0, false); 
    44         Level.Background.Color = Color.Green; 
     114        rightBorder = Level.CreateRightBorder(); 
     115        rightBorder.Restitution = 1.0; 
     116        rightBorder.IsVisible = false; 
    45117 
     118        PhysicsObject topBorder = Level.CreateTopBorder(); 
     119        topBorder.Restitution = 1.0; 
     120        topBorder.IsVisible = false; 
     121 
     122        PhysicsObject bottomBorder = Level.CreateBottomBorder(); 
     123        bottomBorder.Restitution = 1.0; 
     124        bottomBorder.IsVisible = false; 
     125 
     126       //Level.Background.Image = tileimage; 
     127        GameObject tile = new GameObject(Level.Width*2, Level.Height); 
     128        tile.Image = tileimage; 
     129        Add(tile, -2); 
    46130        Camera.ZoomToLevel(); 
     131 
     132         
    47133    } 
     134 
    48135    PhysicsObject CreateRacket(double x, double y) 
    49136    { 
     
    55142        Add(racket); 
    56143        return racket; 
     144 
     145    } 
     146 
     147    void HandleBallCollision(PhysicsObject ball, PhysicsObject target) 
     148    { 
     149        if (target == rightBorder) 
     150        { 
     151            player1score.Value += 1; 
     152        } 
     153 
     154        else if (target == leftBorder) 
     155        { 
     156            player2score.Value += 1; 
     157        } 
    57158    } 
    58159 
  • 2016/27/RuhanAnjanK/Pong/Pong/Pong/obj/x86/Debug/ContentPipeline-{429747CF-5A2C-45BD-8AD5-3C1367D73B24}.xml

    r7676 r7792  
    22<XnaContent xmlns:Pipeline="Microsoft.Xna.Framework.Content.Pipeline"> 
    33  <Asset Type="Pipeline:BuildItemCollection"> 
     4    <Item> 
     5      <Source>tiles.jpg</Source> 
     6      <Name>tiles</Name> 
     7      <Importer>TextureImporter</Importer> 
     8      <Processor>TextureProcessor</Processor> 
     9      <Options>None</Options> 
     10      <Output>C:\MyTemp\ruhank\Pong\Pong\Pong\bin\x86\Debug\Content\tiles.xnb</Output> 
     11      <Time>2016-07-05T14:43:01.2045454+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> 
    1960        <Value>2015-09-16T19:06:04.2493246+03:00</Value> 
  • 2016/27/RuhanAnjanK/Pong/Pong/Pong/obj/x86/Debug/Pong.csproj.FileListAbsolute.txt

    r7676 r7792  
    77C:\MyTemp\ruhank\Pong\Pong\Pong\obj\x86\Debug\Pong.exe 
    88C:\MyTemp\ruhank\Pong\Pong\Pong\obj\x86\Debug\Pong.pdb 
     9C:\MyTemp\ruhank\Pong\Pong\Pong\bin\x86\Debug\Content\tiles.xnb 
  • 2016/27/RuhanAnjanK/Pong/Pong/PongContent/PongContent.contentproj

    r7676 r7792  
    4545    <Reference Include="AnimationExtension" /> 
    4646  </ItemGroup> 
     47  <ItemGroup> 
     48    <Compile Include="tiles.jpg"> 
     49      <Name>tiles</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.