Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- namespace Follow
- {
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- SpriteFont MainText;
- Texture2D Player;
- Texture2D Enemy;
- Vector2 playerPosition;
- Vector2 enemyPosition;
- Rectangle enemyBound;
- Rectangle playerBound;
- bool moveableright = true;
- bool moveableleft = true;
- bool moveabledown = true;
- bool moveableup = true;
- bool spacerespond = true;
- bool spaceinstrucshow = true;
- bool enterinstrucshow = false;
- bool moveable = false;
- bool followinstrucshow = false;
- bool fpressable = false;
- bool rectanglefollow = false;
- bool tryagainshow = false;
- bool epressable = false;
- int n = 1;
- int listcount = 0;
- List<float> xMovement = new List<float>();
- List<float> yMovement = new List<float>();
- Random EnemyStartPos = new Random();
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- }
- protected override void Initialize()
- {
- // TODO: Add your initialization logic here
- playerPosition = new Vector2(130, 30);
- enemyPosition = new Vector2(20, 30);
- base.Initialize();
- }
- protected override void LoadContent()
- {
- // Create a new SpriteBatch, which can be used to draw textures.
- spriteBatch = new SpriteBatch(GraphicsDevice);
- // TODO: use this.Content to load your game content here
- Player = Content.Load<Texture2D>("Player");
- Enemy = Content.Load<Texture2D>("block");
- playerBound = new Rectangle((int)playerPosition.X, (int)playerPosition.Y, Player.Width, Player.Height);
- enemyBound = new Rectangle((int)enemyPosition.X, (int)enemyPosition.Y, Enemy.Width, Enemy.Height);
- MainText = Content.Load<SpriteFont>("MainFont");
- }
- protected override void UnloadContent()
- {
- // TODO: Unload any non ContentManager content here
- }
- protected override void Update(GameTime gameTime)
- {
- // Allows the game to exit
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
- this.Exit();
- KeyboardState keyboardState = Keyboard.GetState();
- enemyBound.X = (int)enemyPosition.X;
- enemyBound.Y = (int)enemyPosition.Y;
- playerBound.X = (int)playerPosition.X;
- playerBound.Y = (int)playerPosition.Y;
- if (keyboardState.IsKeyDown(Keys.Space) && spacerespond ==true)
- {
- moveable = true;
- spaceinstrucshow = false;
- enterinstrucshow = true;
- spacerespond = false;
- }
- if (keyboardState.IsKeyDown(Keys.Enter) && spaceinstrucshow == false)
- {
- moveable = false;
- enterinstrucshow = false;
- followinstrucshow = true;
- fpressable = true;
- }
- if (keyboardState.IsKeyDown(Keys.F) && fpressable == true)
- {
- rectanglefollow = true;
- followinstrucshow = false;
- }
- if (keyboardState.IsKeyDown(Keys.E) && fpressable == true)
- {
- xMovement.Clear();
- yMovement.Clear();
- moveableright = true;
- moveableleft = true;
- moveabledown = true;
- moveableup = true;
- spacerespond = true;
- spaceinstrucshow = true;
- enterinstrucshow = false;
- moveable = false;
- followinstrucshow = false;
- fpressable = false;
- rectanglefollow = false;
- tryagainshow = false;
- epressable = false;
- playerPosition.X = 130;
- playerPosition.Y = 30;
- enemyPosition.X = 20;
- enemyPosition.Y = 30;
- n = 1;
- listcount = 0;
- }
- if (moveable == true)
- {
- if (playerPosition.X > 760)
- {
- moveableright = false;
- }
- if (playerPosition.X < 5)
- {
- moveableleft = false;
- }
- if (playerPosition.Y > 439)
- {
- moveabledown = false;
- }
- if (playerPosition.Y < 5)
- {
- moveableup = false;
- }
- if (keyboardState.IsKeyDown(Keys.W) && moveableup == true)
- {
- playerPosition.Y -= 3;
- }
- if (keyboardState.IsKeyDown(Keys.S) && moveabledown == true)
- {
- playerPosition.Y += 3;
- }
- if (keyboardState.IsKeyDown(Keys.A) && moveableleft == true)
- {
- playerPosition.X -= 3;
- }
- if (keyboardState.IsKeyDown(Keys.D) && moveableright == true)
- {
- playerPosition.X += 3;
- }
- xMovement.Add(playerPosition.X);
- yMovement.Add(playerPosition.Y);
- listcount++;
- }
- if (rectanglefollow == true)
- {
- if (n < listcount)
- {
- enemyPosition.X = xMovement[n] - 110;
- enemyPosition.Y = yMovement[n];
- n++;
- }
- else
- {
- rectanglefollow = false;
- tryagainshow = true;
- epressable = true;
- }
- }
- moveableright = true;
- moveableleft = true;
- moveabledown = true;
- moveableup = true;
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.Yellow);
- // TODO: Add your drawing code here
- spriteBatch.Begin();
- spriteBatch.Draw(Player, playerPosition, Color.White);
- spriteBatch.Draw(Enemy, enemyPosition, Color.White);
- if (spaceinstrucshow == true)
- {
- spriteBatch.DrawString(MainText, "PRESS SPACE TO GIVE PATH", new Vector2(100, 150), Color.Gray);
- }
- if (enterinstrucshow == true)
- {
- spriteBatch.DrawString(MainText, "PRESS ENTER TO FINISH GIVING PATH", new Vector2(100, 150), Color.Gray);
- }
- if (followinstrucshow == true)
- {
- spriteBatch.DrawString(MainText, "PRESS F TO BEGIN FOLLOW", new Vector2(100, 150), Color.Gray);
- }
- if (tryagainshow == true)
- {
- spriteBatch.DrawString(MainText, "PRESS E TO TRY AGAIN", new Vector2(100, 150), Color.Gray);
- }
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement