Exemple #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            player = new Player(Content.Load<Texture2D>("character"), new Rectangle(20, 20, 50, 50), new Vector2(20, 0));
            levelGen = new LevelGenerator(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, Content.Load<Texture2D>("wall_0"), Content.Load<Texture2D>("floor_0"), new Vector2(0, 0), new Vector2(0, 0));
            // 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
        }
Exemple #2
0
 protected void LoadContent(Game game)
 {
     // Create a new SpriteBatch, which can be used to draw textures.
     spriteBatch = new SpriteBatch(GraphicsDevice);
     // Create the player object
     player = new Player(game.Content.Load<Texture2D>(@"images/playerSprite"),
                         new Vector2(100, 100),
                         new Vector2(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2),
                         game.Content.Load<Texture2D>(@"images/staminaBack"),
                         game.Content.Load<Texture2D>(@"images/staminaFront"));
     // creates the map object and fills the guard object
     map = new Map(game.Content.Load<Texture2D>("MapTest"));
     map.LoadMap(new StreamReader("MapTestText.txt"), game.Content.Load<Texture2D>("MapTest"));
     //testGuard = new Guard(new Vector2(0, 0), Content.Load<Texture2D>(@"images/guard"), 0, false, null);
 }
Exemple #3
0
 public void Update(Player player, GameTime gameTime)
 {
     // Update position
     if (hasPath && !seenPlayer)
     {
         if (pathNumb >= path.Count)
         {
             pathNumb = 0;
         }
         // Finds what command
         if (path[pathNumb].command == GuardCommand.MoveTo)
         {
             Vector2 movement = new Vector2(); // Stores the x and y movement
             double moveSpeed;
             GuardMove action = (GuardMove)path[pathNumb]; // Converts the path[pathNumb] to a GuardMove object in order to use the GuardObject members
             if (action.distance - action.traveled >= speed) // Gtes the correct distance to move
             {
                 moveSpeed = speed;
             }
             else // If te guard needs to move less than the speed it will make the movespeed = to the distance it needs to go
             {
                 moveSpeed = action.distance - action.traveled;
             }
             // Finds the x and the y movements depending on the direction
             // If the guard is moving in any direction other than down and to the right the x or y movement is multiplied by -1 to acomodate
             if (rotation < (90 * Math.PI / 180) || ((rotation - (90 * Math.PI / 180)) < .00009))
             {
                 movement.X = (float)(Math.Sin(rotation) * speed);
                 movement.Y = (float)(-1 * (Math.Cos(rotation) * speed));
             }
             else if (rotation < (180 * Math.PI / 180) || ((rotation - (180 * Math.PI / 180)) < .00009))
             {
                 movement.X = (float)(Math.Cos(rotation - (90 * Math.PI / 180)) * speed);
                 movement.Y = (float)(Math.Sin(rotation - (90 * Math.PI / 180)) * speed);
             }
             else if (rotation < (270 * Math.PI / 180) || ((rotation - (270 * Math.PI / 180)) < .00009))
             {
                 movement.X = (float)(-1 * (Math.Sin(rotation - (180 * Math.PI / 180)) * speed));
                 movement.Y = (float)(Math.Cos(rotation - (180 * Math.PI / 180)) * speed);
             }
             else
             {
                 movement.X = (float)(-1 * (Math.Cos(rotation - (270 * Math.PI / 180))) * speed);
                 movement.Y = (float)(-1 * (Math.Sin(rotation - (270 * Math.PI / 180))) * speed);
             }
             // Moves the guard
             position += movement;
             // Updates the traveled
             action.traveled += moveSpeed;
             // If the guard has moved the specified distance this code is run to rest the object and move to the next object
             if (action.traveled == action.distance)
             {
                 pathNumb++;
                 action.traveled = 0;
                 path[pathNumb - 1] = action;
             }
             else
             {
                 path[pathNumb] = action;
             }
         }
         else if (path[pathNumb].command == GuardCommand.Look)
         {
             GuardRotate guardRotate = (GuardRotate)path[pathNumb];
             // If this is the first time running this node reset the originalRot
             if (actionTimer == 0)
             {
                 guardRotate.originalRot = rotation;
             }
             // Update elapsed time
             actionTimer += gameTime.ElapsedGameTime.Milliseconds;
             // Finds the amount of rotation that is needed based on how much time has passed
             if (guardRotate.time > actionTimer)
             {
                 rotation = ((guardRotate.radians * actionTimer) / guardRotate.time) + guardRotate.originalRot;
             }
             else // Runs this code on the last pass of this node
             {
                 rotation = guardRotate.radians + guardRotate.originalRot;
                 path[pathNumb] = guardRotate;
                 pathNumb++;
                 actionTimer = 0;
             }
         }
     }
     // Check if player is in line of sight
     // Check if the player is within distance to be seen
     if ((getDistance(player.position, position) <= viewDistance) && !seenPlayer)
     {
         double playerAngle = getAngle(position, player.position);
         double angleDifferance;
         // If the angle of the playerAngle is below zero and the rotation - half view angle is above 0
         if ((playerAngle + .5 * (viewAngle * Math.PI / 180) >= 360 * Math.PI / 180) &&
             rotation - .5 * (viewAngle * Math.PI / 180) <= 360 * Math.PI / 180)
         {
             angleDifferance = 0 - (rotation + (Math.Abs(playerAngle - 360 * Math.PI / 180)));
         }
         // If the angle of the rotation + half view angle is below zero and the playerAngle is above 0
         else if ((rotation + .5 * (viewAngle * Math.PI / 180) >= 360 * Math.PI / 180) &&
             playerAngle - .5 * (viewAngle * Math.PI / 180) <= 360 * Math.PI / 180)
         {
             angleDifferance = 0 - (playerAngle + (Math.Abs(rotation - 360 * Math.PI / 180)));
         }
         else
         {
             angleDifferance = playerAngle - rotation;
         }
         // Find if the player is in the guards view angle
         if (Math.Abs(angleDifferance) < .5 * viewAngle * Math.PI / 180)
         {
             seenPlayer = true;
             actionTimer = 0;
         }
     }
     // Logic for hunting down player when seen
     if (seenPlayer)
     {
         actionTimer += gameTime.ElapsedGameTime.Milliseconds;
         // Look in the players direction
         if (actionTimer < 250)
         {
             rotation = (float)(getAngle(position, player.position));
         }
         // Lunge twords the player
         else if (actionTimer < 750)
         {
             double distanceX = ((position.X - player.position.X) / 4);
             double distanceY = ((position.Y - player.position.Y) / 4);
             position.X -= (float)distanceX;
             position.Y -= (float)distanceY;
         }
         // Reset the actiontimer for repeating
         else
         {
             actionTimer = 0;
         }
     }
 }
Exemple #4
0
 public void Draw(SpriteBatch spriteBatch, Player player)
 {
     //draw the guard
     spriteBatch.Draw(guardSheet, position + player.offset, guardRect, Color.White, rotation, new Vector2(16, 16), 1f, SpriteEffects.None, 1);
     //draw the guards line of sight ball
     foreach (Vector2 ball in rightBalls)
     {
         spriteBatch.Draw(guardSheet, position + player.offset, new Rectangle(0, 0, 16, 16), Color.White, rotation, new Vector2(8 + ball.X, 8 + ball.Y), 1f, SpriteEffects.None, 1);
     }
     foreach (Vector2 ball in leftBalls)
     {
         spriteBatch.Draw(guardSheet, position + player.offset, new Rectangle(0, 0, 16, 16), Color.White, rotation, new Vector2(8 + ball.X, 8 + ball.Y), 1f, SpriteEffects.None, 1);
     }
 }