From 4974b4845e3f1cff3667bd79130a877535f3f256 Mon Sep 17 00:00:00 2001 From: brady Date: Thu, 15 Apr 2010 04:42:53 +0000 Subject: [PATCH] Began basic interface for Character, Player and Monster, Began Human Class git-svn-id: https://bd85.net/svn/cs3505_group@86 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Human.cs | 142 +++++++++++++++++++++++++++++ CarFire/CarFire/CarFire/IPlayer.cs | 35 +++++++ 2 files changed, 177 insertions(+) create mode 100644 CarFire/CarFire/CarFire/Human.cs create mode 100644 CarFire/CarFire/CarFire/IPlayer.cs diff --git a/CarFire/CarFire/CarFire/Human.cs b/CarFire/CarFire/CarFire/Human.cs new file mode 100644 index 0000000..e0f6cc5 --- /dev/null +++ b/CarFire/CarFire/CarFire/Human.cs @@ -0,0 +1,142 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; + +namespace CarFire +{ + public class Human : IPlayer + { + //Member Variables + String CharName; + Map theMap; + int movementSpeed; + int gridX; + int gridY; + Texture2D charModel; + int health; + int damage; + int range; + int score; + bool isMoving; + int pixelX; + int pixelY; + bool visible; + + public Human(Map _theMap, String Name) + { + theMap = _theMap; + CharName = Name; + + movementSpeed = 20; // randomly set now + health = 100; + score = 0; + visible = false; + } + + public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics) + { + charModel = contentManager.Load("deselectBox"); //change to charModel when designed + } + + public void UnloadContent() + { + + } + + public long Update(GameTime gameTime, NetworkManager networkGame) + { + return 0; + + } + + public long Draw(SpriteBatch spriteBatch) + { + return 0; + } + + public int Health { get { return health; } } + public int Score { get { return score; } } + public bool alive { get { return health > 0; } } + + public void causeDamageTo(int amount) + { + health -= amount; + } + + /// + /// Moves the current player being controlled based on a given set of key presses. + /// The player can only move one grid space per movePlayer call. Thus this method + /// is made to be called ever update. The player will only move if the grid space + /// that is being moved to is an open space. + /// + /// A general list of keys that are pressed. Other keys can be included but only direction keys will be used + public void MovePlayer(List keysPressed) + { + // move upleft + keysPressed.Contains(Keys.Left); + if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY - 1)) + { + gridX -= 1; + gridY -= 1; + } + // move upright + else if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1)) + { + gridX += 1; + gridY -= 1; + } + // move downleft + else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1)) + { + gridX -= 1; + gridY += 1; + } + // move downright + else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1)) + { + gridX += 1; + gridY += 1; + } + // move up + else if (keysPressed.Contains(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1)) + { + gridY -= 1; + } + // move down + else if (keysPressed.Contains(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1)) + { + gridY += 1; + } + // move left + else if (keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY)) + { + gridX -= 1; + } + // move right + else if (keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY)) + { + gridX += 1; + } + } + + + public void powerUp(int amount) + { + health += amount; + } + + public void Spawn(Point mapPoint) + { + gridX = mapPoint.X; + gridY = mapPoint.Y; + visible = true; + } + + + } +} \ No newline at end of file diff --git a/CarFire/CarFire/CarFire/IPlayer.cs b/CarFire/CarFire/CarFire/IPlayer.cs new file mode 100644 index 0000000..7eb7611 --- /dev/null +++ b/CarFire/CarFire/CarFire/IPlayer.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; + +namespace CarFire +{ + public interface ICharacter + { + void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics); + void UnloadContent(); + long Update(GameTime gameTime, NetworkManager networkGame); + long Draw(SpriteBatch spriteBatch); + int Health { get; } + void causeDamageTo(int amount); + } + + public interface IPlayer : ICharacter + { + void MovePlayer(List keysPressed); + int Score { get; } + void powerUp(int amount); + void Spawn(Point mapPoint); + bool alive { get; } + } + + public interface IMonster : ICharacter + { + bool visible { get; } + } +} -- 2.43.0