internal Rectangle GetAnimatedSpriteFrame(SpriteDirection direction) { Rectangle SpriteSet = GetSpriteSet(); switch (direction) { case SpriteDirection.Front: SpriteSet.Offset(AnimateFrame * 32, 0); break; case SpriteDirection.Left: SpriteSet.Offset(AnimateFrame * 32, 32); break; case SpriteDirection.Right: SpriteSet.Offset(AnimateFrame * 32, 64); break; case SpriteDirection.Back: SpriteSet.Offset(AnimateFrame * 32, 96); break; default: break; } return(SpriteSet); }
/// <summary> /// Initialize members /// </summary> /// <param name="position"></param> /// <param name="millisecondsPerFrame"></param> public MultiSprite(Vector2 position, int millisecondsPerFrame) { this.position = position; this.millisecondsPerFrame = millisecondsPerFrame; States = new Dictionary<string, SpriteSheet>(); movementDirection = SpriteDirection.Right; }
public override void ChangeDirection(SpriteDirection direction) { base.ChangeDirection(direction); switch (direction) { case SpriteDirection.S: firstFrame = (moving ? 1 : 0); lastFrame = 2; frame = firstFrame; break; case SpriteDirection.N: firstFrame = (moving ? 4 : 3); lastFrame = 5; frame = firstFrame; break; case SpriteDirection.NW: case SpriteDirection.W: case SpriteDirection.SW: firstFrame = 6; lastFrame = 7; frame = firstFrame; break; case SpriteDirection.NE: case SpriteDirection.E: case SpriteDirection.SE: firstFrame = 8; lastFrame = 9; frame = firstFrame; break; } }
// Update is called once per frame void Update() { if (!Application.isPlaying) { return; } MoveDir = Vector3.zero; HandleUpdate(); if (MoveDir.x > 0) { sDirection = SpriteDirection.RIGHT; } else if (MoveDir.x < 0) { sDirection = SpriteDirection.LEFT; } else if (MoveDir.y > 0) { sDirection = SpriteDirection.UP; } else if (MoveDir.y < 0) { sDirection = SpriteDirection.DOWN; } spriteRender.sprite = sprites[(int)sDirection]; }
void Update() { if (!playing) { return; } float getAxis = _microgame.Owner.GetAxis(PlayerAxis.Horizontal); if (getAxis < 0 && _currentDirection == SpriteDirection.right) { flipImage(); _currentDirection = SpriteDirection.left; _HitsRemaining--; } else if (getAxis > 0 && _currentDirection == SpriteDirection.left) { flipImage(); _currentDirection = SpriteDirection.right; _HitsRemaining--; } if (_HitsRemaining <= 0) { _microgame.EndMicrogame(true); } }
protected override void CollidedWith(GameObject go, Vector2 onPoint, Vector2 normal) { // look for hittable implementation var hitComponent = go.GetComponent <IWeaponHittable>(); if (hitComponent != null) { hitComponent.Hit(damage, onPoint, SpriteDirection.ConvertVectorToLookingDirection(normal)); } if (go.layer == LayerMask.NameToLayer("Floor")) { transform.parent = go.transform; transform.position = new Vector3(onPoint.x, onPoint.y, 0); transform.rotation = Quaternion.identity; rigidbody2d.velocity = Vector2.zero; rigidbody2d.angularVelocity = 0f; rigidbody2d.gravityScale = 0f; fireCoroutine = StartCoroutine(FloorFireCoroutine()); return; } if (fireCoroutine == null) { Destroy(gameObject); } }
/// <summary> /// Moves the character by specified pixels and animates a walk if player is not attacking /// </summary> /// <param name="x">Pixels to move horizontally</param> /// <param name="y">Pixels to move vertically</param> public bool Move(float x, float y) { if (State != SpriteState.Attack) { speed = baseSpeed * Math.Sqrt(x * x + y * y); position.X += x; position.Y += y; //Set direction if (Math.Abs(y) > Math.Abs(x)) //If movement is more vertical than horizontal { Direction = y > 0 ? SpriteDirection.South : SpriteDirection.North; } else //If movement is more horizontal than vertical { Direction = x > 0 ? SpriteDirection.East : SpriteDirection.West; } if (Math.Abs(x) > 0 || Math.Abs(y) > 0) { State = SpriteState.Walk; //if moving, set state to walk } else { State = SpriteState.Idle; } return(true); } return(false); }
public void Step(SpriteDirection direction) { FlipStepOffset(); CurrentDirection = direction; CurrentBitmapIndex = (Int32)direction * 3 + 1 + _stepOffset; _resetStepFrameDelay = Constants.MAP_MOVE_CHARACTER_TICKS - 2; }
/// <summary> /// Initialize members /// </summary> /// <param name="assetName"></param> /// <param name="currentFrame"></param> /// <param name="frameSize"></param> /// <param name="sheetSize"></param> /// <param name="spriteDirection"></param> public SpriteSheet(string assetName, Point currentFrame, Point frameSize, Point sheetSize, SpriteDirection spriteDirection) { AssetName = assetName; CurrentFrame = currentFrame; FrameSize = frameSize; SheetSize = sheetSize; SpriteDirection = spriteDirection; }
public LivableEntity SpDir(string tag, SpriteDirection dir) { if (this[tag] == null) { throw new NRuntimeException($"NPC tag:{tag} は存在しません."); } return(SpDir(this[tag], dir)); }
private void LoadAnimations() { walkAnimationList = Resources.LoadAll<Sprite>("DwarfWalk").ToList(); otherAnimationList = Resources.LoadAll<Sprite>("DwarfOther").ToList(); spriteDirection = SpriteDirection.Down; animationState = AnimationState.IdleDown; }
protected override void Shoot(float shootSpeed, LookingDirection direction) { // set drirection spriteDirection.FaceDirection(direction); // setup velocity rigidbody2d.velocity = new Vector2(SpriteDirection.LookingDirectionToVector2(direction).x *Mathf.Sin(throwingAngle), Mathf.Cos(throwingAngle)) * shootSpeed; }
private void LoadAnimations() { walkAnimationList = Resources.LoadAll <Sprite>("Sprites/Sprites/DwarfWalk").ToList(); otherAnimationList = Resources.LoadAll <Sprite>("Sprites/Sprites/DwarfOther").ToList(); spriteDirection = SpriteDirection.Down; animationState = AnimationState.IdleDown; }
/// <summary> /// Creates new argument for spawning entity /// </summary> /// <param name="entityID">ID of entity</param> /// <param name="name">Name of entity</param> /// <param name="type">Type of entity</param> /// <param name="maxNum">Maximum number of entities that can be spawned</param> /// <param name="direction">Initial direction</param> /// <param name="position">Current position</param> /// <param name="bounds">Bounds for entity to walk in</param> public EntitySpawnEventArgs(string entityID, string name, EntityType type, int maxNum, SpriteDirection direction, Vector2 position, RectangleF bounds) { this.entityID = entityID; this.name = name; this.spawnType = type; this.maxNum = maxNum; this.position = position; this.moveLimit = bounds; this.startDirection = direction; }
protected override void TriggeredWith(Collider2D collider) { // look for hittable implementation var hitComponent = collider.GetComponentInParent <IWeaponHittable>(); if (hitComponent != null) { hitComponent.Hit(damage, collider.transform.position, SpriteDirection.ConvertVectorToLookingDirection(MyExtensions.FromVector3(collider.transform.position - transform.position))); } }
/// <summary> /// Creates new enemy in a certain area at a certain positon with a certain name, ID, direction and bounds /// </summary> /// <param name="currentArea">Area enemy is in</param> /// <param name="position">Position of enemy</param> /// <param name="name">Unique name of entity</param> /// <param name="enemyID">ID of enemy</param> /// <param name="direction">Default direction enemy faces</param> /// <param name="bounds">Area that enemy can move in</param> public Enemy(Area currentArea, Vector2 position, string name, string enemyID, SpriteDirection direction, RectangleF bounds) : base(currentArea, position, name, enemyID) { path = AppDomain.CurrentDomain.BaseDirectory + @"Content\enemies\" + enemyID + ".xml"; walkLimit = new RectangleF(bounds.Location, bounds.Size); currentCD = 0; startDirection = direction; base.LoadEntity(position, path); }
public void SetDirection(SpriteDirection direction) { if (direction == SpriteDirection.Left) { Effect = SpriteEffects.FlipHorizontally; } else { Effect = SpriteEffects.None; } }
/// <summary> /// Initializes a new instance of the <see cref="WalkerComponent" /> class. /// </summary> /// <param name="owner">The sprite that owns this component.</param> /// <param name="startingDirection"> /// The initial direction (Left, Right, or FacePlayer) that the sprites /// starts out facing. /// </param> /// <param name="initialHorizontalVelocity"> /// The initial velocity that the sprite has. Provide a positive value; /// the sign is automatically determined based on initial direction. /// </param> /// <param name="turnOnEdges"> /// A flag indicating whether this sprite turns when it crosses an edge. /// </param> /// <param name="turnOnSpriteCollisions"> /// A value indicating whether this sprite turns when it collides with /// another sprite. /// </param> public WalkerComponent(Sprite owner, SpriteDirection startingDirection, float initialHorizontalVelocity, bool turnOnEdges = false, bool turnOnSpriteCollisions = true) { Owner = owner; StartingDirection = startingDirection; InitialHorizontalVelocity = initialHorizontalVelocity; Direction = (StartingDirection == SpriteDirection.FacePlayer || StartingDirection == SpriteDirection.Left) ? Direction.Left : Direction.Right; CurrentVelocity = initialHorizontalVelocity; TurnOnCliffs = turnOnEdges; TurnOnSpriteCollisions = turnOnSpriteCollisions; }
protected override void CollidedWith(GameObject go, Vector2 onPoint, Vector2 normal) { // look for hittable implementation var hitComponent = go.GetComponent <IWeaponHittable>(); if (hitComponent != null) { hitComponent.Hit(damage, onPoint, SpriteDirection.ConvertVectorToLookingDirection(normal)); } Destroy(gameObject); }
private string GetSprite(SpriteSet set, SpriteDirection direction, bool walking) { switch (set) { case SpriteSet.NORMAL: return(walking ? spriteSetNormalWalk[(int)direction] : spriteSetNormal[(int)direction]); case SpriteSet.PAPER: return(walking ? spriteSetPaperWalk[(int)direction] : spriteSetPaper[(int)direction]); default: return(walking ? spriteSetNormalWalk[(int)direction] : spriteSetNormal[(int)direction]); } }
public Sprite() { x = 0d; y = 0d; speed = 3d; scale = 1d; direction = SpriteDirection.S; frame = 0; frequency = 10; lastFrame = 0; moving = false; animationTimer = new Timer(tickEvent, this, Timeout.Infinite, Timeout.Infinite); }
private int GetFrameInfo(FrameInfo type, SpriteState state, SpriteDirection direction) { if (type == FrameInfo.Row) { return(frames[state][1] + (state == SpriteState.Die ? 0 : frames[direction][0])); } else if (type == FrameInfo.Number) { return(frames[state][0]); } else { return(-1); } }
public void Hit(int damageTaken, Vector2 hitPoint, LookingDirection hitDirection) { hitCount += 1; // play vfx VFXSpriteAnimation vfx = Instantiate(hitSpriteVFXPrefab, hitPoint, Quaternion.identity); SpriteDirection dir = vfx.GetComponent <SpriteDirection>(); if (dir != null) { dir.FaceDirection(SpriteDirection.OtherDirectionY(hitDirection)); } if (!magicianSummoned && hitCount >= hitsToSummonMagician) { magicianSummoned = true; SummonMagician(); } }
// Use this for initialization void Start() { _microgame = GetComponent <Microgame>(); _currentDirection = SpriteDirection.right; if (_microgame.Owner.PlayerNumber == PlayerID.One) { _YellowDancingImage.gameObject.SetActive(true); } else { _BlueDancingImage.gameObject.SetActive(true); } _HitsRemaining = _HitsRequired + Random.Range(0, _HitsVariance); // Get Main Camera height and width camHeight = _microgame.Camera.orthographicSize * 2f; camWidth = camHeight * Camera.main.aspect; }
public PlayerTurnState(Game game, int playerNum) : base(game) { this.playerNum = playerNum; state = LocalState.WaitForButton; playerSprite = new PlayerSprite(game); playerSprite.Sound = true; playerSprite.Direction = SpriteDirection.S; PlayerSprite.Small = true; playerSprite.X = game.MapWidth / 2 - Graphics.SMALLPLAYERWIDTH / 2; playerSprite.Y = game.MapHeight / 2 - Graphics.SMALLPLAYERHEIGHT / 2 - Graphics.MAPSTOREOFFSET; muleSprite = new MuleSprite(game); lastMuleDir = SpriteDirection.S; game.Players[playerNum].Highlight = false; smallScale = 100 / Graphics.STOREWIDTH * game.Graphics.MapScale; storeScale = smallScale; deptBottomActed = false; deptTopActed = false; storeTransLoc = StoreTransLoc.Middle; ticker = new Ticker(game, 100d); ticker.TimeUp += new TimeUpHandler(ticker_TimeUp); stateTimer.Change(750, 750); }
private void loadCharacter(Vector2 position, string characterID) { frames = new Dictionary <Enum, int[]>(); XDocument charDoc = XDocument.Load(AppDomain.CurrentDomain.BaseDirectory + @"Content/characters/" + characterID + ".xml"); //set speed values from xml file baseSpeed = double.Parse(charDoc.Descendants("Character").Elements("Speed").First().Value); speed = baseSpeed; //set draw rectangle from xml file size = VectorEx.FromArray(charDoc.Descendants("Character").Elements("Size").First().Value.Split(',')); this.position = position; //set current direction from xml file currentDirection = (SpriteDirection)Enum.Parse(typeof(SpriteDirection), charDoc.Descendants("Character").Elements("Direction").First().Value); //set frame list from xml file foreach (XElement element in charDoc.Descendants("Character").Elements("Frame")) { Enum frameEnum; if (element.Element("Enum").Attribute("type").Value == "SpriteState") { frameEnum = (SpriteState)Enum.Parse(typeof(SpriteState), element.Element("Enum").Value); } else { frameEnum = (SpriteDirection)Enum.Parse(typeof(SpriteDirection), element.Element("Enum").Value); } List <int> frameIndexes = new List <int>(); foreach (string index in element.Element("Value").Value.Split(',')) { frameIndexes.Add(int.Parse(index)); } frames.Add(frameEnum, frameIndexes.ToArray()); } }
public AnimatedTexture(Texture2D sourcetexture, Rectangle firstframe, SpriteDirection direction, int framecount, int FPS) { Initialize(sourcetexture, firstframe, direction, framecount, FPS); }
public void Move(int x, int y) { position.X += x; position.Y += y; if (x > 0) movementDirection = SpriteDirection.Right; else if (x < 0) movementDirection = SpriteDirection.Left; }
/// <summary> /// Creates list of all strucutures in area by reading from specified area id /// </summary> /// <param name="areaID">ID of area to load</param> /// <returns>List of drawable elements in array</returns> private void loadArea(string areaID) { XDocument doc = XDocument.Load(AppDomain.CurrentDomain.BaseDirectory + @"Content\areas\" + areaID + ".xml"); //create new lists for area drawElements = new List <IDrawable>(); entities = new List <Entity>(); sheets = new List <Spritesheet>(); //create new eventboxes, replacing old ones if necessary if (boxes != null) { boxes.ForEach(box => box.UnloadBox()); } boxes = new List <EventBox>(); //loads main menu menu = new Menu(doc.Descendants("Area").Elements("Menu").First().Value); foreach (XElement element in doc.Descendants("Area").Descendants("Sheets").Descendants("SheetID")) { sheets.Add(new Spritesheet(element.Value)); } if (doc.Descendants("Area").Elements("BGM").Count() > 0 && doc.Descendants("Area").Elements("BGM").First().Element("MusicID").Value != "None") //load bgm if is contained in xml { background = Content.Load <Song>("sound/music/" + doc.Descendants("Area").Elements("BGM").First().Element("MusicID").Value); if (MediaPlayer.State != MediaState.Playing || MediaPlayer.Queue.ActiveSong.Name != background.Name) { MediaPlayer.Play(background); MediaPlayer.Volume = .3f; MediaPlayer.IsRepeating = bool.Parse(doc.Descendants("Area").Elements("BGM").First().Element("Loop").Value); } } foreach (XElement element in doc.Descendants("Area").Descendants("Tile")) //load tiles { drawElements.Add(Tile.LoadFromXML(element, sheets)); } foreach (XElement element in doc.Descendants("Area").Descendants("Structure")) //load structures { drawElements.Add(Structure.LoadFromXML(element, sheets)); } foreach (XElement element in doc.Descendants("Area").Elements("Entity")) { EntityType type = (EntityType)Enum.Parse(typeof(EntityType), element.Element("Type").Value); SpriteDirection direction = (SpriteDirection)Enum.Parse(typeof(SpriteDirection), element.Element("Direction").Value); string entityID = element.Element("EntityID").Value; string name = element.Element("Name").Value; RectangleF bounds = RectangleF.FromArray(element.Element("Bounds").Value.Split(',')); string[] pos = element.Element("Position").Value.Split(','); Vector2 position = new Vector2(float.Parse(pos[0]), float.Parse(pos[1])); EntitySpawnEventArgs args = new EntitySpawnEventArgs(entityID, name, type, 1, direction, position, bounds); Spawn(User, args); } foreach (XElement element in doc.Descendants("Area").Descendants("Player").Elements("EventBox")) //load player event boxes { RectangleF rect = RectangleF.FromArray(element.Element("Box").Value.Split(',')); EventBox.Condition condition = null; if (element.Elements("Condition").Count() > 0) { string methodString = element.Element("Condition").Value; condition = (EventBox.Condition)Delegate.CreateDelegate(typeof(EventBox.Condition), this, methodString); } if (element.Element("Method").Value == "OnNewAreaEnter") { Vector2 position = VectorEx.FromArray(element.Element("Position").Value.Split(',')); NewAreaEventArgs args = new NewAreaEventArgs(element.Element("AreaID").Value, position); boxes.Add(new EventBox(User, rect, OnNewAreaEnter, args, condition)); } else if (element.Element("Method").Value == "Spawn") { int maxNum = int.Parse(element.Element("MaxNum").Value); Vector2 position = VectorEx.FromArray(element.Element("Position").Value.Split(',')); EntityType type = (EntityType)Enum.Parse(typeof(EntityType), element.Element("Type").Value); SpriteDirection direction = (SpriteDirection)Enum.Parse(typeof(SpriteDirection), element.Element("Direction").Value); EntitySpawnEventArgs args = new EntitySpawnEventArgs(element.Element("EntityID").Value, element.Element("Name").Value, type, maxNum, direction, position, RectangleF.FromArray(element.Element("Bounds").Value.Split(','))); boxes.Add(new EventBox(User, rect, Spawn, args, null)); } } }
void Start(){ maxMovementSpeed = movementSpeed; movementEnabled = true; direction = gameObject.GetComponentInChildren<SpriteDirection> (); }
public void Look(SpriteDirection direction) { CurrentDirection = direction; CurrentBitmapIndex = (Int32)direction * 3 + 1; }
public static CharacterMoveMessage DoNotPanMapOnMove(SpriteDirection direction, MapCharacter character) { return new CharacterMoveMessage(direction, character, false); }
public void SetDirection(SpriteDirection direction) { if (direction == SpriteDirection.Left) Effect = SpriteEffects.FlipHorizontally; else Effect = SpriteEffects.None; }
private void AddDirections(int currentX, int currentY, int currentSpriteX, int currentSpriteY, SpriteDirection spriteDirectionColumns, SpriteDirection spriteDirectionRows, Direction lastDirection) { var possibleDirections = GetPossibleDirections(currentX, currentY); if (possibleDirections.Any()) { var directions = GetRandomDirections(possibleDirections); foreach (var direction in directions) { AddSpriteNo(currentX, currentY, currentSpriteX, currentSpriteY, spriteDirectionColumns, spriteDirectionRows, lastDirection, direction); } } }
private LivableEntity SpDir(LivableEntity sprite, SpriteDirection dir) { sprite.Direction = dir; return(sprite); }
private void UpdateMovement() { var vel = playerRigidBody.velocity; var velx = Mathf.Round(vel.x); var vely = Mathf.Round(vel.y); if (velx == 0 && vely == 0) { switch (spriteDirection) { case SpriteDirection.Up: animationState = AnimationState.IdleUp; break; case SpriteDirection.Down: animationState = AnimationState.IdleDown; break; case SpriteDirection.Left: animationState = AnimationState.IdleLeft; break; case SpriteDirection.Right: animationState = AnimationState.IdleRight; break; } } else if (Mathf.Abs(vely) >= Mathf.Abs(velx)) { if (vely > 0) { spriteDirection = SpriteDirection.Up; animationState = AnimationState.WalkUp; } else { spriteDirection = SpriteDirection.Down; animationState = AnimationState.WalkDown; } } else if (Mathf.Abs(vely) < Mathf.Abs(velx)) { if (velx > 0) { spriteDirection = SpriteDirection.Right; animationState = AnimationState.WalkRight; } else { spriteDirection = SpriteDirection.Left; animationState = AnimationState.WalkLeft; } } else { switch (spriteDirection) { case SpriteDirection.Up: animationState = AnimationState.IdleUp; break; case SpriteDirection.Down: animationState = AnimationState.IdleDown; break; case SpriteDirection.Left: animationState = AnimationState.IdleLeft; break; case SpriteDirection.Right: animationState = AnimationState.IdleRight; break; } } }
private void AddSpriteNo(int currentX, int currentY, int currentSpriteX, int currentSpriteY, SpriteDirection spriteDirectionColumns, SpriteDirection spriteDirectionRows, Direction lastDirection, Direction newDirection) { // Calculate new SpriteX and SpriteY /* * if (newDirection == Direction.West || newDirection == Direction.East) * { * var newSpriteX = currentSpriteX + (int) spriteDirectionColumns; * * if (newDirection != lastDirection) { * spriteDirectionColumns = spriteDirectionColumns == SpriteDirection.Up ? SpriteDirection.Down : SpriteDirection.Up; * } else { * if (newSpriteX < 0 || newSpriteX > _noOfSpriteColumns - 1) * { * spriteDirectionColumns = spriteDirectionColumns == SpriteDirection.Up ? SpriteDirection.Down : SpriteDirection.Up; * newSpriteX = currentSpriteX + (int) spriteDirectionColumns; * } * } * currentSpriteX = newSpriteX; * } * else * { * var newSpriteY = currentSpriteY + (int) spriteDirectionRows; * * if (newDirection != lastDirection) { * spriteDirectionColumns = spriteDirectionColumns == SpriteDirection.Up ? SpriteDirection.Down : SpriteDirection.Up; * } else { * if (newSpriteY < 0 || newSpriteY > _noOfSpriteRows - 1) * { * spriteDirectionColumns = spriteDirectionColumns == SpriteDirection.Up ? SpriteDirection.Down : SpriteDirection.Up; * newSpriteY = currentSpriteY + (int) spriteDirectionRows; * } * } * * currentSpriteY = newSpriteY; * } */ switch (newDirection) { case Direction.West: currentX -= 1; currentSpriteX -= 1; break; case Direction.East: currentX += 1; currentSpriteX += 1; break; case Direction.North: currentY -= 1; currentSpriteY -= 1; break; case Direction.South: currentY += 1; currentSpriteY += 1; break; } if (Map [currentX, currentY] == -1) { var spriteNo = (currentSpriteY % _noOfSpriteRows) * _noOfSpriteColumns + (currentSpriteX % _noOfSpriteColumns); Map [currentX, currentY] = spriteNo; AddDirections(currentX, currentY, currentSpriteX, currentSpriteY, spriteDirectionColumns, spriteDirectionRows, newDirection); } }
public void Look(SpriteDirection direction) { SpriteSheet.Look(direction); }
public void Step(SpriteDirection direction) { switch (direction) { case SpriteDirection.Down: Row++; break; case SpriteDirection.Left: Column--; break; case SpriteDirection.Right: Column++; break; case SpriteDirection.Up: Row--; break; } SpriteSheet.Step(direction); }
// Use this for initialization void Start () { className = "DASH"; abilityCoolDown = 3f; Setup (); sprites = GetComponentInChildren<SpriteDirection> (); }
private void UpdateControl() { var vAxis = Input.GetAxis("Vertical"); var hAxis = Input.GetAxis("Horizontal"); if (Mathf.Abs(vAxis) > Mathf.Abs(hAxis)) { if (vAxis > 0) { spriteDirection = SpriteDirection.Up; animationState = AnimationState.WalkUp; } else { spriteDirection = SpriteDirection.Down; animationState = AnimationState.WalkDown; } } else if (Mathf.Abs(vAxis) < Mathf.Abs(hAxis)) { if (hAxis > 0) { spriteDirection = SpriteDirection.Right; animationState = AnimationState.WalkRight; } else { spriteDirection = SpriteDirection.Left; animationState = AnimationState.WalkLeft; } } else { switch (spriteDirection) { case SpriteDirection.Up: animationState = AnimationState.IdleUp; break; case SpriteDirection.Down: animationState = AnimationState.IdleDown; break; case SpriteDirection.Left: animationState = AnimationState.IdleLeft; break; case SpriteDirection.Right: animationState = AnimationState.IdleRight; break; } } if (Input.GetKey(KeyCode.Space)) { switch (spriteDirection) { case SpriteDirection.Up: animationState = AnimationState.AttackUp; break; case SpriteDirection.Down: animationState = AnimationState.AttackDown; break; case SpriteDirection.Left: animationState = AnimationState.AttackLeft; break; case SpriteDirection.Right: animationState = AnimationState.AttackRight; break; } } }
private void checkMuleMovement() { if (hasMule) { int incX = 0, incY = 0; if (playerSprite.Moving) { if (playerSprite.X + (playerSprite.Small ? Graphics.SMALLPLAYERWIDTH : Graphics.PLAYERWIDTH) < muleSprite.X - muleSprite.Speed) { incX = -1; } else if (playerSprite.X > muleSprite.X + (muleSprite.Small ? Graphics.SMALLMULEWIDTH : Graphics.MULEWIDTH) + muleSprite.Speed) { incX = 1; } if (playerSprite.Y + (playerSprite.Small ? Graphics.SMALLPLAYERHEIGHT : Graphics.PLAYERHEIGHT) < muleSprite.Y - muleSprite.Speed) { incY = -1; } else if (playerSprite.Y > muleSprite.Y + (muleSprite.Small ? Graphics.SMALLMULEHEIGHT : Graphics.MULEHEIGHT) + muleSprite.Speed) { incY = 1; } int playerXOffset = (playerSprite.X + (playerSprite.Small ? Graphics.SMALLPLAYERWIDTH : Graphics.PLAYERWIDTH) / 2) - (muleSprite.X + (muleSprite.Small ? Graphics.SMALLMULEWIDTH : Graphics.MULEWIDTH) / 2); int playerYOffset = (playerSprite.Y + (playerSprite.Small ? Graphics.SMALLPLAYERHEIGHT : Graphics.PLAYERHEIGHT) / 2) - (muleSprite.Y + (muleSprite.Small ? Graphics.SMALLMULEHEIGHT : Graphics.MULEHEIGHT) / 2); if (( playerSprite.Direction == SpriteDirection.E && playerXOffset > muleSprite.Speed ) || ( playerSprite.Direction == SpriteDirection.W && playerXOffset < -muleSprite.Speed )) { if (playerYOffset < -muleSprite.Speed) { incY = -1; } else if (playerYOffset > muleSprite.Speed) { incY = 1; } } if (( playerSprite.Direction == SpriteDirection.N && playerYOffset < -muleSprite.Speed ) || ( playerSprite.Direction == SpriteDirection.S && playerYOffset > muleSprite.Speed )) { if (playerXOffset < -muleSprite.Speed) { incX = -1; } else if (playerXOffset > muleSprite.Speed) { incX = 1; } } } if (incX == 0 && incY == 0) { if (muleSprite.Moving) { muleSprite.StopAnimation(); muleSprite.ChangeDirection(SpriteDirection.S); } } else { muleSprite.StartAnimation(); SpriteDirection dir = Sprite.GetDirection(incX, incY); if (muleSprite.Direction != dir) { muleSprite.ChangeDirection(dir); } lastMuleDir = dir; if (incX == 1) { muleSprite.MoveRight(); } else if (incX == -1) { muleSprite.MoveLeft(); } if (incY == 1) { muleSprite.MoveDown(); } else if (incY == -1) { muleSprite.MoveUp(); } } } }
public virtual void Initialize(Texture2D sourcetexture, Rectangle firstframe, SpriteDirection direction, int framecount, int FPS) { #if DEBUG // If we're not in debug let the initialize try anyways. worst case scenario it throws an exception. if (direction == SpriteDirection.right) valid = (sourcetexture != null && (firstframe.X + (firstframe.Width * framecount) <= sourcetexture.Width) && firstframe.Height <= sourcetexture.Height && FPS >= 1); else valid = (sourcetexture != null && (firstframe.Y + (firstframe.Height * framecount) <= sourcetexture.Height) && firstframe.Width <= sourcetexture.Height && FPS >= 1); if (!valid) throw new Exception("Woah tiger, something isn't right here. Sort your shit out."); #endif this.framecount = framecount; this.sourcetexture = sourcetexture; this.state = AnimationPlayState.play; this.framespace = (1.0 / (double)FPS); this.currentframe = 0; this.frametime = new TimeSpan(0, 0, 0, 0, 0); destrect = new Rectangle[framecount]; for (int i = 0; i < framecount; ++i) { destrect[i] = new Rectangle(); destrect[i].Width = firstframe.Width; destrect[i].Height = firstframe.Height; if (direction == SpriteDirection.right) { destrect[i].X = (firstframe.X + (i * firstframe.Width)); destrect[i].Y = firstframe.Y; } else { destrect[i].X = firstframe.X; destrect[i].Y = (firstframe.Y + (framecount * firstframe.Height)); } } }
private void CheckSpriteDirections(ref int currentSpriteX, ref int currentSpriteY, ref SpriteDirection spriteDirectionColumns, ref SpriteDirection spriteDirectionRows, Direction direction) { if (direction == Direction.West || direction == Direction.East) { var newSpriteX = currentSpriteX + (int)spriteDirectionColumns; if (newSpriteX < 0 || newSpriteX > _noOfSpriteColumns - 1) { spriteDirectionColumns = spriteDirectionColumns == SpriteDirection.Up ? SpriteDirection.Down : SpriteDirection.Up; newSpriteX = currentSpriteX + (int)spriteDirectionColumns; } currentSpriteX = newSpriteX; } else { var newSpriteY = currentSpriteY + (int)spriteDirectionRows; if (newSpriteY < 0 || newSpriteY > _noOfSpriteRows - 1) { spriteDirectionColumns = spriteDirectionColumns == SpriteDirection.Up ? SpriteDirection.Down : SpriteDirection.Up; newSpriteY = currentSpriteY + (int)spriteDirectionRows; } currentSpriteY = newSpriteY; } }
private void AddSpriteNoToMap(ref int currentX, ref int currentY, ref int currentSpriteX, ref int currentSpriteY, IEnumerable <Direction> directions, ref SpriteDirection spriteDirectionColumns, ref SpriteDirection spriteDirectionRows) { foreach (var direction in directions) { CheckSpriteDirections(ref currentSpriteX, ref currentSpriteY, ref spriteDirectionColumns, ref spriteDirectionRows, direction); switch (direction) { case Direction.West: currentX -= 1; break; case Direction.East: currentX += 1; break; case Direction.North: currentY -= 1; break; case Direction.South: currentX += 1; break; } Map[currentX, currentY] = currentSpriteY * _noOfSpriteColumns + currentSpriteX; } }
private void CalcDirections() { if (directions == Directions.None) { spriteDirections = new SpriteDirection[0]; down = left = right = up = downLeft = upLeft = upRight = downRight = false; return; } else if (directions == Directions.Four) { down = left = right = up = true; downLeft = upLeft = upRight = downRight = false; } else if (directions == Directions.Eight) { down = left = right = up = true; downLeft = upLeft = upRight = downRight = true; } List <SpriteDirection> newDirections = new List <SpriteDirection>(); newDirections.Clear(); if (down) { newDirections.Add(new SpriteDirection("D", 0f)); } if (downLeft) { newDirections.Add(new SpriteDirection("DL", 45f)); } if (left) { newDirections.Add(new SpriteDirection("L", 90f)); } if (upLeft) { newDirections.Add(new SpriteDirection("UL", 135f)); } if (up) { newDirections.Add(new SpriteDirection("U", 180f)); } if (upRight) { newDirections.Add(new SpriteDirection("UR", 225f)); } if (right) { newDirections.Add(new SpriteDirection("R", 270f)); } if (downRight) { newDirections.Add(new SpriteDirection("DR", 315f)); } if (newDirections.Count > 1) { for (int i = 0; i < newDirections.Count; i++) { int j = (i == newDirections.Count - 1) ? 0 : i + 1; float thisAngle = newDirections[i].angle; float nextAngle = newDirections[j].angle; if (nextAngle < thisAngle) { nextAngle += 360f; } float maxAngle = (thisAngle + nextAngle) / 2f; if (maxAngle > 360f) { maxAngle -= 360f; } newDirections[i] = new SpriteDirection(newDirections[i].suffix, newDirections[i].angle, maxAngle); } } spriteDirections = newDirections.ToArray(); }
protected CharacterMoveMessage(SpriteDirection direction, MapCharacter character, Boolean panMapWithCharacter) { Direction = direction; Character = character; PanMapWithCharacter = panMapWithCharacter; }