diff --git a/.vs/Pong/DesignTimeBuild/.dtbcache.v2 b/.vs/Pong/DesignTimeBuild/.dtbcache.v2 index ca39ced..dfca572 100644 Binary files a/.vs/Pong/DesignTimeBuild/.dtbcache.v2 and b/.vs/Pong/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/Pong/FileContentIndex/0e3141ae-869d-4d70-b5c3-fc2b1a8dbb34.vsidx b/.vs/Pong/FileContentIndex/0e3141ae-869d-4d70-b5c3-fc2b1a8dbb34.vsidx new file mode 100644 index 0000000..370610d Binary files /dev/null and b/.vs/Pong/FileContentIndex/0e3141ae-869d-4d70-b5c3-fc2b1a8dbb34.vsidx differ diff --git a/.vs/Pong/FileContentIndex/560caa5c-e1b4-4e74-98f8-5be430cb36e0.vsidx b/.vs/Pong/FileContentIndex/5ae92d2b-4fd7-4baf-9bbf-9dfb60363837.vsidx similarity index 100% rename from .vs/Pong/FileContentIndex/560caa5c-e1b4-4e74-98f8-5be430cb36e0.vsidx rename to .vs/Pong/FileContentIndex/5ae92d2b-4fd7-4baf-9bbf-9dfb60363837.vsidx diff --git a/.vs/Pong/FileContentIndex/73c45c9f-ea6f-446d-95e6-ea1ec5f384ba.vsidx b/.vs/Pong/FileContentIndex/73c45c9f-ea6f-446d-95e6-ea1ec5f384ba.vsidx new file mode 100644 index 0000000..c7cb0f1 Binary files /dev/null and b/.vs/Pong/FileContentIndex/73c45c9f-ea6f-446d-95e6-ea1ec5f384ba.vsidx differ diff --git a/.vs/Pong/FileContentIndex/7f7c00a6-b8cc-4db1-8295-06fa43b6a8fb.vsidx b/.vs/Pong/FileContentIndex/7f7c00a6-b8cc-4db1-8295-06fa43b6a8fb.vsidx deleted file mode 100644 index 50869bd..0000000 Binary files a/.vs/Pong/FileContentIndex/7f7c00a6-b8cc-4db1-8295-06fa43b6a8fb.vsidx and /dev/null differ diff --git a/.vs/Pong/FileContentIndex/fcc1d421-2701-4d84-aa56-b48d0ea36427.vsidx b/.vs/Pong/FileContentIndex/fcc1d421-2701-4d84-aa56-b48d0ea36427.vsidx deleted file mode 100644 index d87ff83..0000000 Binary files a/.vs/Pong/FileContentIndex/fcc1d421-2701-4d84-aa56-b48d0ea36427.vsidx and /dev/null differ diff --git a/.vs/Pong/v17/.futdcache.v2 b/.vs/Pong/v17/.futdcache.v2 index 959db52..7998317 100644 Binary files a/.vs/Pong/v17/.futdcache.v2 and b/.vs/Pong/v17/.futdcache.v2 differ diff --git a/.vs/Pong/v17/.suo b/.vs/Pong/v17/.suo index 5ab4caf..f5f81e3 100644 Binary files a/.vs/Pong/v17/.suo and b/.vs/Pong/v17/.suo differ diff --git a/.vs/ProjectEvaluation/pong.metadata.v5 b/.vs/ProjectEvaluation/pong.metadata.v5 index a8fde08..5f7095c 100644 Binary files a/.vs/ProjectEvaluation/pong.metadata.v5 and b/.vs/ProjectEvaluation/pong.metadata.v5 differ diff --git a/.vs/ProjectEvaluation/pong.projects.v5 b/.vs/ProjectEvaluation/pong.projects.v5 index aa73d3f..c13b07a 100644 Binary files a/.vs/ProjectEvaluation/pong.projects.v5 and b/.vs/ProjectEvaluation/pong.projects.v5 differ diff --git a/Pong/Game1.cs b/Pong/Game1.cs index be51fa6..38145e2 100644 --- a/Pong/Game1.cs +++ b/Pong/Game1.cs @@ -10,6 +10,7 @@ namespace Pong { private GraphicsDeviceManager _graphics; private SpriteBatch _spriteBatch; private Random random; + private KeyboardState kState; public Texture2D ballTexture; public Texture2D playerOneTexture; @@ -23,6 +24,7 @@ namespace Pong { Vector2 ballDir; float ballSpeed; + float playerSpeed; public Game1() { _graphics = new GraphicsDeviceManager(this); @@ -43,15 +45,19 @@ namespace Pong { playerOneTexture = new Texture2D(_graphics.GraphicsDevice, 20, 125); playerTwoTexture = new Texture2D(_graphics.GraphicsDevice, 20, 125); + //filling the player rectangles with color data Color[] data = new Color[playerOneTexture.Width*playerOneTexture.Height]; for (int i = 0; i < data.Length; ++i) data[i] = Color.White; playerOneTexture.SetData(data); playerTwoTexture.SetData(data); ballPosition = new Vector2(_graphics.PreferredBackBufferWidth / 2, _graphics.PreferredBackBufferHeight / 2); - ballDir = new Vector2(random.Next(-7, 7), random.Next(-7, 7)); + ballDir = new Vector2(random.Next(-5, 5), random.Next(-7, 7)); + ballDir.X = ballDir.X < 0 ? -5 : 5; ballSpeed = 100.0f; + playerSpeed = 500f; + //players starting position playerOnePosition = new Vector2(25, _graphics.PreferredBackBufferHeight / 2 - playerOneTexture.Height / 2); playerTwoPosition = new Vector2(_graphics.PreferredBackBufferWidth - 50, _graphics.PreferredBackBufferHeight / 2 - playerTwoTexture.Height / 2); @@ -69,20 +75,35 @@ namespace Pong { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); - /*KeyboardState kState = Keyboard.GetState(); + kState = Keyboard.GetState(); + //Player one movement + if (kState.IsKeyDown(Keys.W)) { + playerOnePosition.Y -= playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; + if(playerOnePosition.Y < 0) { + playerOnePosition.Y = 0; + } + } + if (kState.IsKeyDown(Keys.S)) { + playerOnePosition.Y += playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; + if (playerOnePosition.Y + playerOneTexture.Height > _graphics.PreferredBackBufferHeight) { + playerOnePosition.Y = _graphics.PreferredBackBufferHeight - playerOneTexture.Height; + } + } + + //Player two movement if (kState.IsKeyDown(Keys.Up)) { - ballPosition.Y -= ballSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; + playerTwoPosition.Y -= playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; + if (playerTwoPosition.Y < 0) { + playerTwoPosition.Y = 0; + } } if (kState.IsKeyDown(Keys.Down)) { - ballPosition.Y += ballSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; + playerTwoPosition.Y += playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; + if (playerTwoPosition.Y + playerTwoTexture.Height > _graphics.PreferredBackBufferHeight) { + playerTwoPosition.Y = _graphics.PreferredBackBufferHeight - playerTwoTexture.Height; + } } - if (kState.IsKeyDown(Keys.Left)) { - ballPosition.X -= ballSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; - } - if (kState.IsKeyDown(Keys.Right)) { - ballPosition.X += ballSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; - }*/ ballPosition.X += ballDir.X * ballSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; ballPosition.Y += ballDir.Y * ballSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; diff --git a/Pong/bin/Debug/net6.0/Pong.dll b/Pong/bin/Debug/net6.0/Pong.dll index 0af8372..4685cbc 100644 Binary files a/Pong/bin/Debug/net6.0/Pong.dll and b/Pong/bin/Debug/net6.0/Pong.dll differ diff --git a/Pong/bin/Debug/net6.0/Pong.pdb b/Pong/bin/Debug/net6.0/Pong.pdb index bce9161..f24b2ef 100644 Binary files a/Pong/bin/Debug/net6.0/Pong.pdb and b/Pong/bin/Debug/net6.0/Pong.pdb differ diff --git a/Pong/obj/Debug/net6.0/Pong.dll b/Pong/obj/Debug/net6.0/Pong.dll index 0af8372..4685cbc 100644 Binary files a/Pong/obj/Debug/net6.0/Pong.dll and b/Pong/obj/Debug/net6.0/Pong.dll differ diff --git a/Pong/obj/Debug/net6.0/Pong.pdb b/Pong/obj/Debug/net6.0/Pong.pdb index bce9161..f24b2ef 100644 Binary files a/Pong/obj/Debug/net6.0/Pong.pdb and b/Pong/obj/Debug/net6.0/Pong.pdb differ