]> Dogcows Code - chaz/carfire/blobdiff - CarFire/CarFire/CarFire/Human.cs
removed outdated code.
[chaz/carfire] / CarFire / CarFire / CarFire / Human.cs
index 0d68d302d07c6d4b186a5d1d36d6c08317622ef1..142a82b25ca923316cc261dedddb345a1d0f1101 100644 (file)
@@ -11,18 +11,10 @@ namespace CarFire
 {\r
     public class Human : IPlayer\r
     {\r
-        public enum State\r
-        {\r
-            left,\r
-            right,\r
-            up,\r
-            down\r
-        };\r
         //The number of frames between each projectile is spawned.\r
         const int shootCoolDown = 10;\r
-        State state;\r
         String CharName;\r
-        Map theMap;\r
+        Game game;\r
         Texture2D charModel;\r
         Texture2D projectileModel;\r
         int health;\r
@@ -40,22 +32,20 @@ namespace CarFire
         int projectileCoolDown;\r
         \r
 \r
-        public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay, Point position)\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
             theDisplay = mDisplay;\r
             health = 100;\r
             score = 0;\r
             visible = false;\r
-            //default state\r
-            state = State.up;\r
             charModel = model;\r
             projectileModel = projectile;\r
             projectileSpeed = 30;\r
 \r
             // Speed is the number of grid cells you can move through per second.\r
-            mMotion = new MovementManager(position, 5.0f);\r
+            mMotion = new MovementManager(position, 8.0f);\r
         }\r
 \r
         public void LoadContent(ContentManager contentManager)\r
@@ -65,26 +55,18 @@ namespace CarFire
 \r
         }\r
 \r
-        public void UnloadContent()\r
-        {\r
 \r
-        }\r
-\r
-        public long Update(GameTime gameTime, NetworkManager networkGame)\r
+        public void Update(TimeSpan timeSpan)\r
         {\r
-            return 0;\r
-\r
         }\r
         /// <summary>\r
         /// This method will draw a character to the screen.\r
         /// </summary>\r
         /// <param name="spriteBatch"></param>\r
-        /// <returns></returns>\r
-        public long Draw(SpriteBatch spriteBatch)\r
+        public void Draw(SpriteBatch spriteBatch)\r
         {\r
-            Rectangle position = theMap.GetRectangleFromCoordinates(mMotion.Position);\r
+            Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position);\r
             spriteBatch.Draw(charModel, position, Color.White);\r
-            return 0;\r
         }\r
 \r
         public int Health { get { return health; } }\r
@@ -112,23 +94,21 @@ namespace CarFire
             bool moveRight = keysPressed.Contains(Keys.Right);\r
             bool moveUp = keysPressed.Contains(Keys.Up);\r
             bool moveDown = keysPressed.Contains(Keys.Down);\r
-            if (moveLeft)\r
-                state = State.left;\r
-            else if (moveRight)\r
-                state = State.right;\r
-            else if (moveUp)\r
-                state = State.up;\r
-            else if (moveDown)\r
-                state = State.down;\r
-\r
             Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);\r
-            if (theMap.IsCellOpen(destination))\r
+            if (!keysPressed.Contains(Keys.LeftControl))\r
             {\r
-                mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);\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
             else\r
             {\r
-                mMotion.Update(timeSpan);\r
+                mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
             }\r
 \r
 \r
@@ -138,31 +118,63 @@ namespace CarFire
             {\r
                 if (keysPressed.Contains<Keys>(Keys.Space))\r
                 {\r
-                    //TODO spawn projectile... needs to be added to display though\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), Coordinates.X, Coordinates.Y - 1));\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), Coordinates.X, Coordinates.Y + 1));\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), Coordinates.X + 1, Coordinates.Y));\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), Coordinates.X - 1, Coordinates.Y));\r
+                            new Vector2(-projectileSpeed, 0), new Point(Coordinates.X - 1, Coordinates.Y)));\r
                     }\r
+                     */\r
                 }\r
             }\r
         }\r
This page took 0.024176 seconds and 4 git commands to generate.