Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11.  
  12. namespace Follow
  13. {
  14.  
  15.     public class Game1 : Microsoft.Xna.Framework.Game
  16.     {
  17.         GraphicsDeviceManager graphics;
  18.         SpriteBatch spriteBatch;
  19.         SpriteFont MainText;
  20.         Texture2D Player;
  21.         Texture2D Enemy;
  22.         Vector2 playerPosition;
  23.         Vector2 enemyPosition;
  24.         Rectangle enemyBound;
  25.         Rectangle playerBound;
  26.  
  27.         bool moveableright = true;
  28.         bool moveableleft = true;
  29.         bool moveabledown = true;
  30.         bool moveableup = true;
  31.         bool spacerespond = true;
  32.         bool spaceinstrucshow = true;
  33.         bool enterinstrucshow = false;
  34.         bool moveable = false;
  35.         bool followinstrucshow = false;
  36.         bool fpressable = false;
  37.         bool rectanglefollow = false;
  38.         bool tryagainshow = false;
  39.         bool epressable = false;
  40.  
  41.         int n = 1;
  42.         int listcount = 0;
  43.  
  44.         List<float> xMovement = new List<float>();
  45.         List<float> yMovement = new List<float>();
  46.  
  47.         Random EnemyStartPos = new Random();
  48.  
  49.  
  50.  
  51.         public Game1()
  52.         {
  53.             graphics = new GraphicsDeviceManager(this);
  54.             Content.RootDirectory = "Content";
  55.         }
  56.  
  57.         protected override void Initialize()
  58.         {
  59.             // TODO: Add your initialization logic here
  60.             playerPosition = new Vector2(130, 30);
  61.             enemyPosition = new Vector2(20, 30);
  62.  
  63.             base.Initialize();
  64.         }
  65.  
  66.         protected override void LoadContent()
  67.         {
  68.             // Create a new SpriteBatch, which can be used to draw textures.
  69.             spriteBatch = new SpriteBatch(GraphicsDevice);
  70.  
  71.             // TODO: use this.Content to load your game content here
  72.             Player = Content.Load<Texture2D>("Player");
  73.             Enemy = Content.Load<Texture2D>("block");
  74.  
  75.             playerBound = new Rectangle((int)playerPosition.X, (int)playerPosition.Y, Player.Width, Player.Height);
  76.             enemyBound = new Rectangle((int)enemyPosition.X, (int)enemyPosition.Y, Enemy.Width, Enemy.Height);
  77.  
  78.             MainText = Content.Load<SpriteFont>("MainFont");
  79.  
  80.         }
  81.  
  82.  
  83.  
  84.         protected override void UnloadContent()
  85.         {
  86.             // TODO: Unload any non ContentManager content here
  87.         }
  88.  
  89.  
  90.         protected override void Update(GameTime gameTime)
  91.         {
  92.             // Allows the game to exit
  93.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  94.                 this.Exit();
  95.  
  96.             KeyboardState keyboardState = Keyboard.GetState();
  97.             enemyBound.X = (int)enemyPosition.X;
  98.             enemyBound.Y = (int)enemyPosition.Y;
  99.  
  100.             playerBound.X = (int)playerPosition.X;
  101.             playerBound.Y = (int)playerPosition.Y;
  102.  
  103.    
  104.  
  105.             if (keyboardState.IsKeyDown(Keys.Space) && spacerespond ==true)
  106.             {
  107.                 moveable = true;
  108.                 spaceinstrucshow = false;
  109.                 enterinstrucshow = true;
  110.                 spacerespond = false;
  111.  
  112.             }
  113.  
  114.             if (keyboardState.IsKeyDown(Keys.Enter) && spaceinstrucshow == false)
  115.             {
  116.                 moveable = false;
  117.                 enterinstrucshow = false;
  118.                 followinstrucshow = true;
  119.                 fpressable = true;
  120.             }
  121.  
  122.             if (keyboardState.IsKeyDown(Keys.F) && fpressable == true)
  123.             {
  124.                 rectanglefollow = true;
  125.                 followinstrucshow = false;
  126.             }
  127.  
  128.             if (keyboardState.IsKeyDown(Keys.E) && fpressable == true)
  129.             {
  130.                 xMovement.Clear();
  131.                 yMovement.Clear();
  132.                 moveableright = true;
  133.                 moveableleft = true;
  134.                 moveabledown = true;
  135.                 moveableup = true;
  136.                 spacerespond = true;
  137.                 spaceinstrucshow = true;
  138.                 enterinstrucshow = false;
  139.                 moveable = false;
  140.                 followinstrucshow = false;
  141.                 fpressable = false;
  142.                 rectanglefollow = false;
  143.                 tryagainshow = false;
  144.                 epressable = false;
  145.                 playerPosition.X = 130;
  146.                 playerPosition.Y = 30;
  147.                 enemyPosition.X = 20;
  148.                 enemyPosition.Y = 30;
  149.                 n = 1;
  150.                 listcount = 0;
  151.             }
  152.  
  153.  
  154.             if (moveable == true)
  155.             {
  156.                 if (playerPosition.X > 760)
  157.                 {
  158.                     moveableright = false;
  159.                 }
  160.  
  161.                 if (playerPosition.X < 5)
  162.                 {
  163.                     moveableleft = false;
  164.                 }
  165.  
  166.                 if (playerPosition.Y > 439)
  167.                 {
  168.                     moveabledown = false;
  169.                 }
  170.  
  171.                 if (playerPosition.Y < 5)
  172.                 {
  173.                     moveableup = false;
  174.                 }
  175.  
  176.                 if (keyboardState.IsKeyDown(Keys.W) && moveableup == true)
  177.                 {
  178.                     playerPosition.Y -= 3;
  179.                 }
  180.  
  181.                 if (keyboardState.IsKeyDown(Keys.S) && moveabledown == true)
  182.                 {
  183.                     playerPosition.Y += 3;
  184.                 }
  185.  
  186.                 if (keyboardState.IsKeyDown(Keys.A) && moveableleft == true)
  187.                 {
  188.                     playerPosition.X -= 3;
  189.                 }
  190.  
  191.                 if (keyboardState.IsKeyDown(Keys.D) && moveableright == true)
  192.                 {
  193.                     playerPosition.X += 3;
  194.                 }
  195.  
  196.                 xMovement.Add(playerPosition.X);
  197.                 yMovement.Add(playerPosition.Y);
  198.                 listcount++;
  199.             }
  200.  
  201.             if (rectanglefollow == true)
  202.             {
  203.                 if (n < listcount)
  204.                 {
  205.                     enemyPosition.X = xMovement[n] - 110;
  206.                     enemyPosition.Y = yMovement[n];
  207.                     n++;
  208.                 }
  209.  
  210.                 else
  211.                 {
  212.                     rectanglefollow = false;
  213.                     tryagainshow = true;
  214.                     epressable = true;
  215.                 }
  216.                
  217.             }
  218.  
  219.             moveableright = true;
  220.             moveableleft = true;
  221.             moveabledown = true;
  222.             moveableup = true;
  223.  
  224.             base.Update(gameTime);
  225.         }
  226.  
  227.         protected override void Draw(GameTime gameTime)
  228.         {
  229.             GraphicsDevice.Clear(Color.Yellow);
  230.  
  231.             // TODO: Add your drawing code here
  232.             spriteBatch.Begin();
  233.             spriteBatch.Draw(Player, playerPosition, Color.White);
  234.             spriteBatch.Draw(Enemy, enemyPosition, Color.White);
  235.  
  236.             if (spaceinstrucshow == true)
  237.             {
  238.                 spriteBatch.DrawString(MainText, "PRESS SPACE TO GIVE PATH", new Vector2(100, 150), Color.Gray);
  239.             }
  240.  
  241.             if (enterinstrucshow == true)
  242.             {
  243.                 spriteBatch.DrawString(MainText, "PRESS ENTER TO FINISH GIVING PATH", new Vector2(100, 150), Color.Gray);
  244.             }
  245.  
  246.             if (followinstrucshow == true)
  247.             {
  248.                 spriteBatch.DrawString(MainText, "PRESS F TO BEGIN FOLLOW", new Vector2(100, 150), Color.Gray);
  249.             }
  250.  
  251.             if (tryagainshow == true)
  252.             {
  253.                 spriteBatch.DrawString(MainText, "PRESS E TO TRY AGAIN", new Vector2(100, 150), Color.Gray);
  254.             }
  255.             spriteBatch.End();
  256.  
  257.             base.Draw(gameTime);
  258.         }
  259.     }
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement