using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using SharpDX.MediaFoundation; using SharpDX.WIC; using System; using System.Diagnostics; using System.Windows.Forms; namespace _2CharPro { public class Game1 : Game { private GraphicsDeviceManager _graphics; private SpriteBatch _spriteBatch; //setting the boundary of the screen.(Point.Zero means that it will begin at the corner of the screen) Rectangle screenBound = new Rectangle(Point.Zero, new Point(1920, 1080)); // the first point sets the posittion and the second the screen size Rectangle playArea = new Rectangle(new Point(0,540), new Point(1920, 540)); //This sets the second screen bound(new means do the constructor for this class(premade instances dont require the new tag)) Texture2D pixel; Texture2D character1; Vector2 character1Pos; Vector2 character1Velocity = Vector2.Zero; //just means that the characetr wont move Vector2 character1DefaultScale = new Vector2(152, 256); Vector2 character1PerspectiveScale = Vector2.Zero; float character1Accel = 6000f; //remember after a number, put an f down float character1Damping = 8f; //makes ts slide Texture2D character2; Vector2 character2Pos; Vector2 character2Velocity = Vector2.Zero; Vector2 character2DefaultScale = new Vector2(152, 256); Vector2 character2PerspectiveScale = Vector2.Zero; float character2Accel = 6000f; float character2Damping = 8f; KeyboardState keyboardState; KeyboardState keyboardStatePrev; Texture2D meadow; Vector2 meadowPos; int scaleMultiplier = 4; //a quick work around for characters being to small public Game1() { _graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; IsMouseVisible = true; } protected override void Initialize() { // TODO: Add your initialization logic here _graphics.PreferredBackBufferHeight = 1000; _graphics.PreferredBackBufferWidth = 1920; _graphics.ApplyChanges(); meadowPos = screenBound.Size.ToVector2() / new Vector2(2.0f); character1Pos = screenBound.Size.ToVector2() / new Vector2(2.0f); character2Pos = screenBound.Size.ToVector2() / new Vector2(2.0f); base.Initialize(); } protected override void LoadContent() { pixel = new Texture2D(GraphicsDevice, 1, 1); pixel.SetData(new[] { Color.White }); _spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here character1 = Content.Load("character1"); character2 = Content.Load("character2"); meadow = Content.Load("meadow"); } protected override void Update(GameTime gameTime) { // TODO: Add your update logic here keyboardStatePrev = keyboardState; keyboardState = Keyboard.GetState(); //what does this do??? if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape)) { Exit(); } //movement if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.W)) character1Velocity.Y -= character1Accel * (float)gameTime.ElapsedGameTime.TotalSeconds; //c1V becomes whatever the sum if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.S)) character1Velocity.Y += character1Accel * (float)gameTime.ElapsedGameTime.TotalSeconds; if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A)) character1Velocity.X -= character1Accel * (float)gameTime.ElapsedGameTime.TotalSeconds; if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D)) character1Velocity.X += character1Accel * (float)gameTime.ElapsedGameTime.TotalSeconds; character1Velocity *= (1 - character1Damping * (float)gameTime.ElapsedGameTime.TotalSeconds); //every second it trys to go to 0 character1Pos += character1Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; if (character1Pos.X <= playArea.Left + 64 || character1Pos.X >= playArea.Right - 64) character1Velocity.X *= -1.0f; if (character1Pos.Y <= playArea.Top + 64 || character1Pos.Y >= playArea.Bottom - 64) character1Velocity.Y *= -1.0f; character1Pos.X = MathHelper.Max(character1Pos.X, playArea.Left + 64); character1Pos.X = MathHelper.Min(character1Pos.X, playArea.Right - 64); character1Pos.Y = MathHelper.Max(character1Pos.Y, playArea.Top + 50); character1Pos.Y = MathHelper.Min(character1Pos.Y, playArea.Bottom - 50); ////////////////////////////////////////////////////////////////////////////////////// //movement2 if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up)) character2Velocity.Y -= character2Accel * (float)gameTime.ElapsedGameTime.TotalSeconds; //c1V becomes whatever the sum if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down)) character2Velocity.Y += character2Accel * (float)gameTime.ElapsedGameTime.TotalSeconds; if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left)) character2Velocity.X -= character2Accel * (float)gameTime.ElapsedGameTime.TotalSeconds; if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right)) character2Velocity.X += character2Accel * (float)gameTime.ElapsedGameTime.TotalSeconds; character2Velocity *= (1 - character2Damping * (float)gameTime.ElapsedGameTime.TotalSeconds); //every second it trys to go to 0 character2Pos += character2Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; if (character2Pos.X <= playArea.Left + 64 || character2Pos.X >= playArea.Right - 64) character2Velocity.X *= -1.0f; if (character2Pos.Y <= playArea.Top + 64 || character2Pos.Y >= playArea.Bottom - 64) character2Velocity.Y *= -1.0f; character2Pos.X = MathHelper.Max(character2Pos.X, playArea.Left + 64); character2Pos.X = MathHelper.Min(character2Pos.X, playArea.Right - 64); character2Pos.Y = MathHelper.Max(character2Pos.Y, playArea.Top + 50); character2Pos.Y = MathHelper.Min(character2Pos.Y, playArea.Bottom - 50); character1Pos.Y = (character1Pos.Y - playArea.Y) / playArea.Height; character2Pos.Y = (character2Pos.Y - playArea.Y) / playArea.Height; character1PerspectiveScale.X = 152 + (int)(character1DefaultScale.X * character1Pos.Y * scaleMultiplier); character1PerspectiveScale.Y = 256 + (int)(character1DefaultScale.Y * character1Pos.Y * scaleMultiplier); character2PerspectiveScale.X = 152 + (int)(character2DefaultScale.X * character2Pos.Y * scaleMultiplier); character2PerspectiveScale.Y = 256 + (int)(character2DefaultScale.Y * character2Pos.Y * scaleMultiplier); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here Rectangle drawBoundChar1 = new Rectangle(character1Pos.ToPoint(), new Point((int)character1PerspectiveScale.X, (int)character1PerspectiveScale.Y)); //why does it want ints Rectangle drawMeadow = new Rectangle(meadowPos.ToPoint(), new Point(1920, 1080)); Rectangle drawBoundChar2 = new Rectangle(character2Pos.ToPoint(), new Point((int)character2PerspectiveScale.X, (int)character2PerspectiveScale.Y)); //why does it want ints //character2 _spriteBatch.Begin(); _spriteBatch.Draw( meadow, drawMeadow, null, Color.White, 0.0f, meadow.Bounds.Size.ToVector2()/2.0f, SpriteEffects.None, 0.0f ); _spriteBatch.Draw( pixel, playArea, Color.Red * 0.3f); if (character1Pos.Y > character2Pos.Y) { _spriteBatch.Draw( character1, drawBoundChar1, null, Color.White, 0.0f, character1.Bounds.Size.ToVector2() / 2.0f, SpriteEffects.None, 0.0f ); _spriteBatch.Draw( character2, drawBoundChar2, null, Color.White, 0.0f, character2.Bounds.Size.ToVector2() / 2.0f, SpriteEffects.None, 0.0f ); } else { _spriteBatch.Draw( character2, drawBoundChar2, null, Color.White, 0.0f, character2.Bounds.Size.ToVector2() / 2.0f, SpriteEffects.None, 0.0f ); _spriteBatch.Draw( character1, drawBoundChar1, null, Color.White, 0.0f, character1.Bounds.Size.ToVector2() / 2.0f, SpriteEffects.None, 0.0f ); } _spriteBatch.End(); base.Draw(gameTime); } } }