2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
8 using Microsoft.Xna.Framework.Input;
13 /// Base class for all Characters,
14 /// includes: basic position information,
19 public class Character
35 /// Call this method to give the game a chance to load its content.
37 /// <param name="_currentMap">The map that this character will interact with</param>
38 /// <param name="_charModel">The model for this character</param>
39 /// <param name="_baseMovementSpeed">How fast the character moves</param>
40 /// <param name="_baseHealth">The starting health of the character</param>
41 /// <param name="_baseDamage">The base damage of the character</param>
42 /// <param name="_baseRange">The range of the character attack</param>
43 public Character( Map _currentMap,
45 int _baseMovementSpeed,
51 movementSpeed = _baseMovementSpeed;
52 gridX = 10; //should be included in the map as a designated spawn point to begin map
54 charModel = _charModel;
61 public void Draw(SpriteBatch spriteBatch)
63 spriteBatch.Draw(charModel, new Vector2(pixelX, pixelY), null, Color.White, 0, new Vector2(0f,0f), 1f, SpriteEffects.None, 0);
67 /// Basic getters and setters
69 public int GridX { get { return gridX; } set { gridX = value; } }
70 public int GridY { get { return gridY; } set { gridY = value; } }
71 public int PixelX { get { return pixelX; } set { pixelX = value; } }
72 public int PixelY { get { return pixelY; } set { pixelY = value; } }
73 public int Health { get { return health; } set { health = value; } }
74 public Map TheMap { get { return theMap; } }
77 /// Get if player is Moveing - Getter only
81 get { return isMoving; }
88 public class Player : Character
92 public Player( Map _currentMap,
94 int _baseMovementSpeed,
98 : base(_currentMap,_charModel,_baseMovementSpeed, _baseHealth, _baseDamage, _baseRange)
109 /// Updates the players position in the current window, the player is kept centered
110 /// in the window when possible. When the edge of the map is reached by one or more
111 /// of the edges of the window the player will then move towards the edges of the
114 /// <param name="ScreenWidth">Used to know how wide the current window is</param>
115 /// <param name="ScreenHeight">Used to know how tall the current window is</param>
116 public void updatePlayerScreenPosition(int ScreenWidth, int ScreenHeight)
119 // if left edge of map has been reached by screen
120 if (GridX * TheMap.GridToPixelRatio < ScreenWidth / 2)
122 PixelX = GridX * TheMap.GridToPixelRatio;
124 // if right edge of TheMap has been reached by screen
125 else if ((TheMap.MaxGridX - GridX) * TheMap.GridToPixelRatio < ScreenWidth / 2)
127 PixelX = ScreenWidth - (TheMap.MaxGridX - GridX) * TheMap.GridToPixelRatio;
129 // screen not touching left or right edge of map so center player horazontally on screen
132 PixelX = ScreenWidth / 2;
135 // if top edge of map is reached by screen edge
136 if (GridY * TheMap.GridToPixelRatio < ScreenHeight / 2)
138 PixelY = GridY * TheMap.GridToPixelRatio;
140 // if bottom edge of map has been reached by screen
141 else if ((TheMap.MaxGridY - GridY) * TheMap.GridToPixelRatio < ScreenHeight / 2)
143 PixelY = ScreenHeight - (TheMap.MaxGridY - GridY) * TheMap.GridToPixelRatio;
145 // screen not touching top or bottom edge of map so center player verticaly on screen
148 PixelY = ScreenHeight / 2;
153 /// Moves the current player being controlled based on a given set of key presses.
154 /// The player can only move one Grid space per movePlayer call. Thus this method
155 /// is made to be called ever update. The player will only move if the Grid space
156 /// that is being moved to is an open space.
158 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
159 public void movePlayer(List<Keys> keysPressed)
162 keysPressed.Contains<Keys>(Keys.Left);
163 if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Left) && TheMap.IsCellOpen(GridX - 1, GridY - 1))
169 else if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Right) && TheMap.IsCellOpen(GridX + 1, GridY - 1))
175 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Left) && TheMap.IsCellOpen(GridX - 1, GridY + 1))
181 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Right) && TheMap.IsCellOpen(GridX + 1, GridY + 1))
187 else if (keysPressed.Contains<Keys>(Keys.Up) && TheMap.IsCellOpen(GridX, GridY - 1))
192 else if (keysPressed.Contains<Keys>(Keys.Down) && TheMap.IsCellOpen(GridX, GridY + 1))
197 else if (keysPressed.Contains<Keys>(Keys.Left) && TheMap.IsCellOpen(GridX - 1, GridY))
202 else if (keysPressed.Contains<Keys>(Keys.Right) && TheMap.IsCellOpen(GridX + 1, GridY))
212 public class Monster : Character
215 public Monster( Map _currentMap,
216 Texture2D _charModel,
217 int _baseMovementSpeed,
221 : base(_currentMap,_charModel,_baseMovementSpeed, _baseHealth, _baseDamage, _baseRange)