From: Zachary Date: Tue, 27 Apr 2010 18:29:59 +0000 (+0000) Subject: git-svn-id: https://bd85.net/svn/cs3505_group@163 92bb83a3-7c8f-8a45-bc97-515c4e399668 X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=commitdiff_plain;h=e8ee0aa62a7e8b5dffa9e02c00c3e353a9e93b4c;hp=f4202b11a1891486216aab3c6b1370fc9a3eb89a git-svn-id: https://bd85.net/svn/cs3505_group@163 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- diff --git a/CarFire/CarFire/CarFire/AnimateMelee.cs b/CarFire/CarFire/CarFire/AnimateMelee.cs new file mode 100644 index 0000000..e114dbe --- /dev/null +++ b/CarFire/CarFire/CarFire/AnimateMelee.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Content; + +namespace CarFire +{ + class AnimateMelee + { + + //member variables + private AnimatedTexture SpriteTexture; + string[] fileNames = new string[] { "graphics/meleeAttack", "graphics/meleeDying", + "graphics/meleeExplosion", "graphics/meleeStanding", "graphics/meleeWalking" }; + private ContentManager contentManager; + //private GraphicsDeviceManager graphics; + //private SpriteBatch spriteBatch; + + private string ph; + private Vector2 position; + private SpriteBatch character; + + //constructor(s) + public AnimateMelee(ContentManager content) + { + SpriteTexture = new AnimatedTexture(Vector2.Zero, 0, 1.0f, 0.5f); + contentManager = content; + ph = fileNames[3]; + position = Vector2.Zero; + } + + //methods + + public void AttackLeft(SpriteBatch spriteBatch) + { + ph = fileNames[0]; + //graphics = graphicsDeviceManager; + //this.spriteBatch = spriteBatch; + //spriteBatch. + + character = new SpriteBatch(spriteBatch.GraphicsDevice); + Animate(); + + + // SpriteTexture.Load(graphics.GraphicsDevice, contentManager, "fileNames[0]", 8, 12, true, 1); + } + + public void Animate() + { + //character = new SpriteBatch(graphics.GraphicsDevice); + // "character" is the name of the sprite asset in the project. + Console.WriteLine(ph); + SpriteTexture.Load(character.GraphicsDevice, contentManager, ph, 8, 12, true, 1); + //viewport = graphics.GraphicsDevice.Viewport; + position = new Vector2(0, 0);//viewport.Width / 2, 0);//viewport.Height / 2f); + + character.Begin(); + SpriteTexture.DrawFrame(character, position); + character.End(); + } + + } +} diff --git a/CarFire/CarFire/CarFire/AnimatedTexture.cs b/CarFire/CarFire/CarFire/AnimatedTexture.cs new file mode 100644 index 0000000..f4aab89 --- /dev/null +++ b/CarFire/CarFire/CarFire/AnimatedTexture.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; + +namespace CarFire +{ + public class AnimatedTexture + { + private int framecount; + private Texture2D myTexture; + private float TimePerFrame; + private int Frame, Row; + private float TotalElapsed; + private bool Paused, loop; + + public float Rotation, Scale, Depth; + public Vector2 Origin; + + //rotation is pretty much always zero, scale determines size, depth is 0.5f + public AnimatedTexture(Vector2 Origin, float Rotation, float Scale, float Depth) + { + this.Origin = Origin; + this.Rotation = Rotation; + this.Scale = Scale; + this.Depth = Depth; + } + //asset is the file name w/o the extension, framecount is the # of frames per row, framespersec determines speed of the animation + //loop will determine if the animation repeats, row chooses which row of the animation to play starting with 0 + public void Load(GraphicsDevice device, ContentManager content, string asset, int FrameCount, int FramesPerSec, bool Loop, int row) + { + framecount = FrameCount; + myTexture = content.Load(asset); + TimePerFrame = (float)1 / FramesPerSec; + Frame = 0; + TotalElapsed = 0; + Paused = false; + loop = Loop; + Row = row; + } + + // class AnimatedTexture + public void UpdateFrame(float elapsed) + { + if (Paused) + return; + TotalElapsed += elapsed; + if (TotalElapsed > TimePerFrame) + { + Frame++; + // Keep the Frame between 0 and the total frames, minus one. + Frame = Frame % framecount; + TotalElapsed -= TimePerFrame; + } + //If loop is false and the current Frame is the last frame + //then stop playing the animation + if ((Frame == framecount - 1) && loop == false) + Pause(); + + } + + // class AnimatedTexture + public void DrawFrame(SpriteBatch Batch, Vector2 screenpos) + { + DrawFrame(Batch, Frame, screenpos); + } + public void DrawFrame(SpriteBatch Batch, int frame, Vector2 screenpos) + { + + int FrameWidth = myTexture.Width / framecount; + Rectangle sourcerect = new Rectangle(FrameWidth * Frame, Row * 64, + FrameWidth, 64); + Batch.Draw(myTexture, screenpos, sourcerect, Color.White, + Rotation, Origin, Scale, SpriteEffects.None, Depth); + } + + public bool IsPaused + { + get { return Paused; } + } + public void Reset() + { + Frame = 0; + TotalElapsed = 0f; + } + public void Stop() + { + Pause(); + Reset(); + } + public void Play() + { + Paused = false; + } + public void Pause() + { + Paused = true; + + } + + } +} diff --git a/CarFire/CarFire/CarFire/CarFire.csproj b/CarFire/CarFire/CarFire/CarFire.csproj index b8666d5..e8a431b 100644 --- a/CarFire/CarFire/CarFire/CarFire.csproj +++ b/CarFire/CarFire/CarFire/CarFire.csproj @@ -85,6 +85,8 @@ + + diff --git a/CarFire/CarFire/CarFire/Melee.cs b/CarFire/CarFire/CarFire/Melee.cs index f113824..cb25ac8 100644 --- a/CarFire/CarFire/CarFire/Melee.cs +++ b/CarFire/CarFire/CarFire/Melee.cs @@ -22,6 +22,9 @@ namespace CarFire int velocityY; #endregion + //zac variable + AnimateMelee animateMelee; + #region Public Methods public Melee(Game theGame, String Name, Point position, int playerIndex) : base(theGame, Name, position, playerIndex, baseHealth, baseDamage) @@ -36,6 +39,10 @@ namespace CarFire charModel = contentManager.Load("cs"); //change to charModel when designed projectileModel = contentManager.Load("projectile"); //change to a projectile model later + /*Zac + */ + animateMelee = new AnimateMelee(contentManager); + } /// /// This method will draw a character to the screen. @@ -44,7 +51,9 @@ namespace CarFire public override void Draw(SpriteBatch spriteBatch) { Rectangle position = Game.State.Map.GetRectangleFromCoordinates(Motion.Position); - spriteBatch.Draw(charModel, position, Color.White); + //spriteBatch.Draw(charModel, position, Color.White); + animateMelee.AttackLeft(spriteBatch); + } public override void Attack(List keysPressed)