]> Dogcows Code - chaz/carfire/blobdiff - CarFire/CarFire/CarFire/Human.cs
removed outdated code.
[chaz/carfire] / CarFire / CarFire / CarFire / Human.cs
index e0f6cc59cb0f1d600d3172e564bd6d40f05ea648..142a82b25ca923316cc261dedddb345a1d0f1101 100644 (file)
@@ -11,58 +11,71 @@ namespace CarFire
 {\r
     public class Human : IPlayer\r
     {\r
-        //Member Variables\r
+        //The number of frames between each projectile is spawned.\r
+        const int shootCoolDown = 10;\r
         String CharName;\r
-        Map theMap;\r
-        int movementSpeed;\r
-        int gridX;\r
-        int gridY;\r
+        Game game;\r
         Texture2D charModel;\r
+        Texture2D projectileModel;\r
         int health;\r
         int damage;\r
         int range;\r
         int score;\r
-        bool isMoving;\r
-        int pixelX;\r
-        int pixelY;\r
+\r
+        MovementManager mMotion;\r
+\r
         bool visible;\r
+        Display theDisplay;\r
 \r
-        public Human(Map _theMap, String Name)\r
+        //Used to draw projectiles\r
+        int projectileSpeed;\r
+        int projectileCoolDown;\r
+        \r
+\r
+        public Human(Game theGame, String Name, Texture2D model, Texture2D projectile, Display mDisplay, Point position)\r
         {\r
-            theMap = _theMap;\r
+            game = theGame;\r
             CharName = Name;\r
-\r
-            movementSpeed = 20; // randomly set now\r
+            theDisplay = mDisplay;\r
             health = 100;\r
             score = 0;\r
             visible = false;\r
-        }\r
+            charModel = model;\r
+            projectileModel = projectile;\r
+            projectileSpeed = 30;\r
 \r
-        public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics)\r
-        {\r
-            charModel = contentManager.Load<Texture2D>("deselectBox"); //change to charModel when designed\r
+            // Speed is the number of grid cells you can move through per second.\r
+            mMotion = new MovementManager(position, 8.0f);\r
         }\r
 \r
-        public void UnloadContent()\r
+        public void LoadContent(ContentManager contentManager)\r
         {\r
+            charModel = contentManager.Load<Texture2D>("deselectBox"); //change to charModel when designed\r
+            projectileModel = contentManager.Load<Texture2D>("emptySelectBox"); //change to a projectile model later\r
 \r
         }\r
 \r
-        public long Update(GameTime gameTime, NetworkManager networkGame)\r
-        {\r
-            return 0;\r
 \r
+        public void Update(TimeSpan timeSpan)\r
+        {\r
         }\r
-\r
-        public long Draw(SpriteBatch spriteBatch)\r
+        /// <summary>\r
+        /// This method will draw a character to the screen.\r
+        /// </summary>\r
+        /// <param name="spriteBatch"></param>\r
+        public void Draw(SpriteBatch spriteBatch)\r
         {\r
-            return 0;\r
+            Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position);\r
+            spriteBatch.Draw(charModel, position, Color.White);\r
         }\r
 \r
         public int Health { get { return health; } }\r
         public int Score { get { return score; } }\r
         public bool alive { get { return health > 0; } }\r
 \r
+        public Vector2 Position { get { return mMotion.Position; } }\r
+        public Point Coordinates { get { return mMotion.Coordinates; } }\r
+\r
         public void causeDamageTo(int amount)\r
         {\r
             health -= amount;\r
@@ -75,52 +88,94 @@ namespace CarFire
         /// that is being moved to is an open space.\r
         /// </summary>\r
         /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>\r
-        public void MovePlayer(List<Keys> keysPressed)\r
+        public void MovePlayer(TimeSpan timeSpan, List<Keys> keysPressed)\r
         {\r
-            // move upleft\r
-            keysPressed.Contains<Keys>(Keys.Left);\r
-            if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY - 1))\r
-            {\r
-                gridX -= 1;\r
-                gridY -= 1;\r
-            }\r
-            // move upright\r
-            else if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1))\r
-            {\r
-                gridX += 1;\r
-                gridY -= 1;\r
-            }\r
-            // move downleft\r
-            else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1))\r
-            {\r
-                gridX -= 1;\r
-                gridY += 1;\r
-            }\r
-            // move downright\r
-            else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1))\r
+            bool moveLeft = keysPressed.Contains(Keys.Left);\r
+            bool moveRight = keysPressed.Contains(Keys.Right);\r
+            bool moveUp = keysPressed.Contains(Keys.Up);\r
+            bool moveDown = keysPressed.Contains(Keys.Down);\r
+            Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);\r
+            if (!keysPressed.Contains(Keys.LeftControl))\r
             {\r
-                gridX += 1;\r
-                gridY += 1;\r
+                if (game.IsCellOpen(destination))\r
+                {\r
+                    mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
+                }\r
+                else\r
+                {\r
+                    mMotion.Update(timeSpan);\r
+                }\r
             }\r
-            // move up\r
-            else if (keysPressed.Contains<Keys>(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1))\r
+            else\r
             {\r
-                gridY -= 1;\r
+                mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
             }\r
-            // move down\r
-            else if (keysPressed.Contains<Keys>(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1))\r
-            {\r
-                gridY += 1;\r
-            }\r
-            // move left\r
-            else if (keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY))\r
-            {\r
-                gridX -= 1;\r
-            }\r
-            // move right\r
-            else if (keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY))\r
+\r
+\r
+            if (projectileCoolDown > 0)\r
+                projectileCoolDown--;\r
+            else if (projectileCoolDown == 0)\r
             {\r
-                gridX += 1;\r
+                if (keysPressed.Contains<Keys>(Keys.Space))\r
+                {\r
+                    float velocityX = 0;\r
+                    float velocityY = 0;\r
+                    int startX = Coordinates.X;\r
+                    int startY = Coordinates.Y;\r
+                    if (mMotion.Direction == Direction.Down || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.LowerRight)\r
+                    {\r
+                        velocityY = 1;\r
+                        startY = Coordinates.Y + 1;\r
+                    }\r
+                    else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight)\r
+                    {\r
+                        velocityY = -1;\r
+                        startY = Coordinates.Y - 1;\r
+                    }\r
+                    if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight)\r
+                    {\r
+                        velocityX = 1;\r
+                        startX = Coordinates.X + 1;\r
+                    }\r
+                    else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft)\r
+                    {\r
+                        velocityX = -1;\r
+                        startX = Coordinates.X - 1;\r
+                    }\r
+                    Vector2 toShoot = new Vector2(velocityX, velocityY);\r
+                    toShoot.Normalize();\r
+                    toShoot *= projectileSpeed;\r
+                    projectileCoolDown = shootCoolDown;\r
+                    theDisplay.AddProjectiles(new Projectile(game.State.Map, projectileModel,\r
+                        toShoot, new Point(startX, startY)));\r
+\r
+                    /*\r
+                    if (state == State.up)\r
+                    {\r
+                        projectileCoolDown = shootCoolDown;\r
+                        theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,\r
+                            new Vector2(0, -projectileSpeed), new Point(Coordinates.X, Coordinates.Y - 1)));\r
+                    }\r
+                    if (state == State.down)\r
+                    {\r
+                        projectileCoolDown = shootCoolDown;\r
+                        theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,\r
+                            new Vector2(0, projectileSpeed), new Point(Coordinates.X, Coordinates.Y + 1)));\r
+                    }\r
+                    if (state == State.right)\r
+                    {\r
+                        projectileCoolDown = shootCoolDown;\r
+                        theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,\r
+                            new Vector2(projectileSpeed, 0), new Point (Coordinates.X + 1, Coordinates.Y)));\r
+                    }\r
+                    if (state == State.left)\r
+                    {\r
+                        projectileCoolDown = shootCoolDown;\r
+                        theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,\r
+                            new Vector2(-projectileSpeed, 0), new Point(Coordinates.X - 1, Coordinates.Y)));\r
+                    }\r
+                     */\r
+                }\r
             }\r
         }\r
 \r
@@ -130,10 +185,10 @@ namespace CarFire
             health += amount;\r
         }\r
 \r
-        public void Spawn(Point mapPoint)\r
+        public void Spawn(Vector2 spawn)\r
         {\r
-            gridX = mapPoint.X;\r
-            gridY = mapPoint.Y;\r
+            //gridX = (int)spawn.X;\r
+            //gridY = (int)spawn.Y;\r
             visible = true;\r
         }\r
 \r
This page took 0.028455 seconds and 4 git commands to generate.