| using System; |
| using System.Collections.Generic; |
| using Microsoft.Xna.Framework; |
| using Microsoft.Xna.Framework.Audio; |
| using Microsoft.Xna.Framework.Content; |
| using Microsoft.Xna.Framework.GamerServices; |
| using Microsoft.Xna.Framework.Graphics; |
| using Microsoft.Xna.Framework.Input; |
| using Microsoft.Xna.Framework.Net; |
| using Microsoft.Xna.Framework.Storage; |
| |
| |
| namespace NoTimeToCry |
| { |
| static public class Player |
| { |
| |
| enum CharState |
| { |
| Stand, Run, Attack, Walk |
| } |
| enum FaceDirection |
| { |
| N, NE, E, SE, S, SW, W, NW |
| } |
| |
| |
| //Attributes, Movement, ect.. |
| |
| static private Texture2D texture; |
| static private Texture2D runTexture; |
| static private Texture2D walkTexture; |
| static private Texture2D standTexture; |
| static private Texture2D attackTexture; |
| static private Image image = new Image(); |
| static private int frame = 0; |
| static public Vector2 Positon; |
| static public float Speed; |
| static public int Direction; |
| static public int Health; |
| static public int ArmorBase; |
| static public int DamageBase; |
| static public int CharLevel; |
| static public int Experience; |
| |
| |
| static public void loadTexture(Texture2D runTexture) |
| { |
| Player.texture = runTexture; |
| image.Initialize(); |
| image.LoadGraphics(Engine.spriteBatch, Player.texture); |
| } |
| |
| static public void changeTexture(CharState action) |
| { |
| if (action == CharState.Run) |
| { |
| image.LoadGraphics(Engine.spriteBatch, Player.runTexture); |
| } |
| if (action == CharState.walk) |
| { |
| image.LoadGraphics(Engine.spriteBatch, Player.walkTexture); |
| } |
| if (action == CharState.stand) |
| { |
| image.LoadGraphics(Engine.spriteBatch, Player.standTexture); |
| } |
| if (action == CharState.attack) |
| { |
| image.LoadGraphics(Engine.spriteBatch, Player.attackTexture); |
| } |
| } |
| |
| static public void update() |
| { |
| |
| movement(); |
| } |
| |
| static private void movement() |
| { |
| //TODO calculate player graphic and direction. |
| //Move player |
| //USE: Speed, Direction, Position, Frame, Face Direction |
| findDirection(); |
| findFrame(); |
| |
| |
| |
| } |
| |
| //Sets the direction the player is facing. |
| //Converts from numbers to NESW directions |
| static private void findDirection() |
| { |
| if (Direction == 0) |
| { |
| FaceDirection = FaceDirection.N; |
| } |
| if (Direction == 1) |
| { |
| FaceDirection = FaceDirection.NE; |
| } |
| if (Direction == 2) |
| { |
| FaceDirection = FaceDirection.E; |
| } |
| if (Direction == 3) |
| { |
| FaceDirection = FaceDirection.SE; |
| } |
| if (Direction == 4) |
| { |
| FaceDirection = FaceDirection.S; |
| } |
| if (Direction == 5) |
| { |
| FaceDirection = FaceDirection.SW; |
| } |
| if (Direction == 6) |
| { |
| FaceDirection = FaceDirection.W; |
| } |
| if (Direction == 7) |
| { |
| FaceDirection = FaceDirection.NW; |
| } |
| else { FaceDirection = FaceDirection.S; } |
| } |
| |
| //Will find correct frame on any given sprite sheet |
| //Char will load different sprite sheets for different actions |
| static private void findFrame() |
| { |
| |
| if (FaceDirection == FaceDirection.N) |
| { |
| if (frame > 7) |
| { frame = 0; } |
| image.calculateSource(frame); |
| } |
| if (FaceDirection == FaceDirection.NE) |
| { |
| if (frame > 15) |
| { frame = 8; } |
| image.calculateSource(frame + 8); |
| } |
| if (FaceDirection == FaceDirection.E) |
| { |
| if (frame > 23) |
| { frame = 16; } |
| image.calculateSource(frame + 16); |
| } |
| if (FaceDirection == FaceDirection.SE) |
| { |
| if (frame > 31) |
| { frame = 24; } |
| image.calculateSource(frame + 24); |
| } |
| if (FaceDirection == FaceDirection.S) |
| { |
| if (frame > 39) |
| { frame = 32; } |
| image.calculateSource(frame + 32); |
| } |
| if (FaceDirection == FaceDirection.SW) |
| { |
| if (frame > 47) |
| { frame = 40; } |
| image.calculateSource(frame + 40); |
| } |
| if (FaceDirection == FaceDirection.W) |
| { |
| if (frame > 55) |
| { frame = 48; } |
| image.calculateSource(frame + 48); |
| } |
| if (FaceDirection == FaceDirection.NW) |
| { |
| if (frame > 63) |
| { frame = 56; } |
| image.calculateSource(frame + 56); |
| } |
| |
| frame++; |
| } |
| |
| static public void draw() |
| { |
| image.Draw(Engine.gameTime); |
| } |
| |
| |
| |
| } |
| } |
| |