]> Dogcows Code - chaz/carfire/commitdiff
git-svn-id: https://bd85.net/svn/cs3505_group@163 92bb83a3-7c8f-8a45-bc97-515c4e399668
authorZachary <Zachary@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Tue, 27 Apr 2010 18:29:59 +0000 (18:29 +0000)
committerZachary <Zachary@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Tue, 27 Apr 2010 18:29:59 +0000 (18:29 +0000)
CarFire/CarFire/CarFire/AnimateMelee.cs [new file with mode: 0644]
CarFire/CarFire/CarFire/AnimatedTexture.cs [new file with mode: 0644]
CarFire/CarFire/CarFire/CarFire.csproj
CarFire/CarFire/CarFire/Melee.cs

diff --git a/CarFire/CarFire/CarFire/AnimateMelee.cs b/CarFire/CarFire/CarFire/AnimateMelee.cs
new file mode 100644 (file)
index 0000000..e114dbe
--- /dev/null
@@ -0,0 +1,66 @@
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using Microsoft.Xna.Framework;\r
+using Microsoft.Xna.Framework.Graphics;\r
+using Microsoft.Xna.Framework.Content;\r
+\r
+namespace CarFire\r
+{\r
+    class AnimateMelee\r
+    {\r
+\r
+        //member variables\r
+        private AnimatedTexture SpriteTexture;\r
+        string[] fileNames = new string[] { "graphics/meleeAttack", "graphics/meleeDying", \r
+            "graphics/meleeExplosion", "graphics/meleeStanding", "graphics/meleeWalking" };\r
+        private ContentManager contentManager;\r
+        //private GraphicsDeviceManager graphics;\r
+        //private SpriteBatch spriteBatch;\r
+\r
+        private string ph;\r
+        private Vector2 position;\r
+        private SpriteBatch character;\r
+\r
+        //constructor(s)\r
+        public AnimateMelee(ContentManager content)\r
+        {\r
+            SpriteTexture = new AnimatedTexture(Vector2.Zero, 0, 1.0f, 0.5f);\r
+            contentManager = content;\r
+            ph = fileNames[3];\r
+            position = Vector2.Zero;\r
+        }\r
+\r
+        //methods\r
+\r
+        public void AttackLeft(SpriteBatch spriteBatch)\r
+        {\r
+            ph = fileNames[0];\r
+            //graphics = graphicsDeviceManager;\r
+            //this.spriteBatch = spriteBatch;\r
+            //spriteBatch.\r
+\r
+            character = new SpriteBatch(spriteBatch.GraphicsDevice);\r
+            Animate();\r
+\r
+\r
+            // SpriteTexture.Load(graphics.GraphicsDevice, contentManager, "fileNames[0]", 8, 12, true, 1);\r
+        }\r
+\r
+        public void Animate()\r
+        {\r
+            //character = new SpriteBatch(graphics.GraphicsDevice);\r
+            // "character" is the name of the sprite asset in the project.\r
+            Console.WriteLine(ph);\r
+            SpriteTexture.Load(character.GraphicsDevice, contentManager, ph, 8, 12, true, 1);\r
+            //viewport = graphics.GraphicsDevice.Viewport;\r
+            position = new Vector2(0, 0);//viewport.Width / 2, 0);//viewport.Height / 2f);\r
+\r
+            character.Begin();\r
+            SpriteTexture.DrawFrame(character, position);\r
+            character.End();\r
+        }\r
+\r
+    }\r
+}\r
diff --git a/CarFire/CarFire/CarFire/AnimatedTexture.cs b/CarFire/CarFire/CarFire/AnimatedTexture.cs
new file mode 100644 (file)
index 0000000..f4aab89
--- /dev/null
@@ -0,0 +1,104 @@
+using System;\r
+using System.Collections.Generic;\r
+using Microsoft.Xna.Framework;\r
+using Microsoft.Xna.Framework.Content;\r
+using Microsoft.Xna.Framework.Graphics;\r
+using Microsoft.Xna.Framework.Input;\r
+\r
+namespace CarFire\r
+{\r
+    public class AnimatedTexture\r
+    {\r
+        private int framecount;\r
+        private Texture2D myTexture;\r
+        private float TimePerFrame;\r
+        private int Frame, Row;\r
+        private float TotalElapsed;\r
+        private bool Paused, loop;\r
+\r
+        public float Rotation, Scale, Depth;\r
+        public Vector2 Origin;\r
+\r
+        //rotation is pretty much always zero, scale determines size, depth is 0.5f\r
+        public AnimatedTexture(Vector2 Origin, float Rotation, float Scale, float Depth)\r
+        {\r
+            this.Origin = Origin;\r
+            this.Rotation = Rotation;\r
+            this.Scale = Scale;\r
+            this.Depth = Depth;\r
+        }\r
+        //asset is the file name w/o the extension, framecount is the # of frames per row, framespersec determines speed of the animation\r
+        //loop will determine if the animation repeats, row chooses which row of the animation to play starting with 0\r
+        public void Load(GraphicsDevice device, ContentManager content, string asset, int FrameCount, int FramesPerSec, bool Loop, int row)\r
+        {\r
+            framecount = FrameCount;\r
+            myTexture = content.Load<Texture2D>(asset);\r
+            TimePerFrame = (float)1 / FramesPerSec;\r
+            Frame = 0;\r
+            TotalElapsed = 0;\r
+            Paused = false;\r
+            loop = Loop;\r
+            Row = row;\r
+        }\r
+\r
+        // class AnimatedTexture\r
+        public void UpdateFrame(float elapsed)\r
+        {\r
+            if (Paused)\r
+                return;\r
+            TotalElapsed += elapsed;\r
+            if (TotalElapsed > TimePerFrame)\r
+            {\r
+                Frame++;\r
+                // Keep the Frame between 0 and the total frames, minus one.\r
+                Frame = Frame % framecount;\r
+                TotalElapsed -= TimePerFrame;\r
+            }\r
+            //If loop is false and the current Frame is the last frame \r
+            //then stop playing the animation\r
+            if ((Frame == framecount - 1) && loop == false)\r
+                Pause();\r
+\r
+        }\r
+\r
+        // class AnimatedTexture\r
+        public void DrawFrame(SpriteBatch Batch, Vector2 screenpos)\r
+        {\r
+            DrawFrame(Batch, Frame, screenpos);\r
+        }\r
+        public void DrawFrame(SpriteBatch Batch, int frame, Vector2 screenpos)\r
+        {\r
+\r
+            int FrameWidth = myTexture.Width / framecount;\r
+            Rectangle sourcerect = new Rectangle(FrameWidth * Frame, Row * 64,\r
+                FrameWidth, 64);\r
+            Batch.Draw(myTexture, screenpos, sourcerect, Color.White,\r
+                Rotation, Origin, Scale, SpriteEffects.None, Depth);\r
+        }\r
+\r
+        public bool IsPaused\r
+        {\r
+            get { return Paused; }\r
+        }\r
+        public void Reset()\r
+        {\r
+            Frame = 0;\r
+            TotalElapsed = 0f;\r
+        }\r
+        public void Stop()\r
+        {\r
+            Pause();\r
+            Reset();\r
+        }\r
+        public void Play()\r
+        {\r
+            Paused = false;\r
+        }\r
+        public void Pause()\r
+        {\r
+            Paused = true;\r
+\r
+        }\r
+\r
+    }\r
+}\r
index b8666d53348c2d6fad38b69410f9222d52791cff..e8a431bbabc8f359971f648224e96bf77115ad36 100644 (file)
@@ -85,6 +85,8 @@
   </ItemGroup>\r
   <ItemGroup>\r
     <Compile Include="AI.cs" />\r
+    <Compile Include="AnimatedTexture.cs" />\r
+    <Compile Include="AnimateMelee.cs" />\r
     <Compile Include="GameLogic.cs" />\r
     <Compile Include="HUD.cs" />\r
     <Compile Include="IEntity.cs" />\r
index f113824b4b250ba3119bebf2714a4f38dea65faa..cb25ac81514530f916b051bb7125892163575eb2 100644 (file)
@@ -22,6 +22,9 @@ namespace CarFire
         int velocityY;\r
         #endregion \r
 \r
+        //zac variable\r
+        AnimateMelee animateMelee;\r
+\r
         #region Public Methods\r
         public Melee(Game theGame, String Name, Point position, int playerIndex)\r
             : base(theGame, Name, position, playerIndex, baseHealth, baseDamage)\r
@@ -36,6 +39,10 @@ namespace CarFire
             charModel = contentManager.Load<Texture2D>("cs"); //change to charModel when designed\r
             projectileModel = contentManager.Load<Texture2D>("projectile"); //change to a projectile model later\r
 \r
+            /*Zac\r
+             */\r
+            animateMelee = new AnimateMelee(contentManager); \r
+\r
         }\r
         /// <summary>\r
         /// This method will draw a character to the screen.\r
@@ -44,7 +51,9 @@ namespace CarFire
         public override void Draw(SpriteBatch spriteBatch)\r
         {\r
             Rectangle position = Game.State.Map.GetRectangleFromCoordinates(Motion.Position);\r
-            spriteBatch.Draw(charModel, position, Color.White);\r
+            //spriteBatch.Draw(charModel, position, Color.White);\r
+            animateMelee.AttackLeft(spriteBatch);\r
+            \r
         }\r
 \r
         public override void Attack(List<Keys> keysPressed)\r
This page took 0.02934 seconds and 4 git commands to generate.