public override void Update(GameTime gameTime) { base.Update(gameTime); if (Controller != null) { Controller.Update(gameTime); } if (!movedLastFrame && MovementState == MovementState.None) { Face(Facing); } if (movement != Vector2.Zero) { Vector2 facing = Facing.ToVector2(); float speed = this.MovementSpeed.GetSpeed(); float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; this.movement += facing * speed * elapsed; if (this.movement.X < 0 && this.Facing == Facing.Left) { this.movement.X = 0; } if (this.movement.X > 0 && this.Facing == Facing.Right) { this.movement.X = 0; } if (this.movement.Y < 0 && this.Facing == Facing.Up) { this.movement.Y = 0; } if (this.movement.Y > 0 && this.Facing == Facing.Down) { this.movement.Y = 0; } movedLastFrame = true; this.Moving.SafeInvoke(this, EventArgs.Empty); if (movement == Vector2.Zero) { movedLastFrame = false; this.MovementState = MovementState.None; EndMoving.SafeInvoke(this, EventArgs.Empty); } } for (int i = 0; i < Effects.Count; i++) { IEffect effect = Effects[i]; if (!effect.Alive) { Effects.RemoveAt(i--); } effect.Update(gameTime); } }
public bool CanMove(Facing dir, int amount) { int tileX = (int)this.Position.X / 16; int tileY = (int)this.Position.Y / 16; Vector2 directionalVector = dir.ToVector2(); tileX += (int)directionalVector.X * amount; tileY += (int)directionalVector.Y * amount; //GameConsole.WriteLine("CanMove at xt: {0}, yt: {0}", tileX, tileY); return(this.CanMove(tileX, tileY)); }
public IEnumerator MoveDirection(Facing direction, float dist) { return MoveDirection(direction.ToVector2(), dist); }
public bool CanMove(Facing dir, int amount) { int tileX = (int) this.Position.X / 16; int tileY = (int) this.Position.Y / 16; Vector2 directionalVector = dir.ToVector2(); tileX += (int) directionalVector.X * amount; tileY += (int) directionalVector.Y * amount; //GameConsole.WriteLine("CanMove at xt: {0}, yt: {0}", tileX, tileY); return this.CanMove(tileX, tileY); }
public virtual void ForceMove(Facing dir, MovementSpeed speed) { if (MovementState == MovementState.None) { this.Initialize(); BeginMoving.SafeInvoke(this, EventArgs.Empty); if (this.Facing != dir) FacingChanged.SafeInvoke(this, new FacingChangedArgs(this.Facing, dir)); this.Facing = dir; switch (dir) { case Facing.Up: if (speed == MovementSpeed.Walking) Animator.Play("walking-up"); else if (speed == MovementSpeed.Running) Animator.Play("running-up"); break; case Facing.Down: if (speed == MovementSpeed.Walking) Animator.Play("walking-down"); else if (speed == MovementSpeed.Running) Animator.Play("running-down"); break; case Facing.Left: if (speed == MovementSpeed.Walking) Animator.Play("walking-left"); else if (speed == MovementSpeed.Running) Animator.Play("running-left"); break; case Facing.Right: if (speed == MovementSpeed.Walking) Animator.Play("walking-right"); else if (speed == MovementSpeed.Running) Animator.Play("running-right"); break; } this.movement = -(dir.ToVector2() * new Vector2(16, 16)); this.MovementSpeed = speed; this.MovementState = MovementState.Walking; this.Position -= this.movement; } }
public virtual void ForceMove(Facing dir, MovementSpeed speed) { if (MovementState == MovementState.None) { this.Initialize(); BeginMoving.SafeInvoke(this, EventArgs.Empty); if (this.Facing != dir) { FacingChanged.SafeInvoke(this, new FacingChangedArgs(this.Facing, dir)); } this.Facing = dir; switch (dir) { case Facing.Up: if (speed == MovementSpeed.Walking) { Animator.Play("walking-up"); } else if (speed == MovementSpeed.Running) { Animator.Play("running-up"); } break; case Facing.Down: if (speed == MovementSpeed.Walking) { Animator.Play("walking-down"); } else if (speed == MovementSpeed.Running) { Animator.Play("running-down"); } break; case Facing.Left: if (speed == MovementSpeed.Walking) { Animator.Play("walking-left"); } else if (speed == MovementSpeed.Running) { Animator.Play("running-left"); } break; case Facing.Right: if (speed == MovementSpeed.Walking) { Animator.Play("walking-right"); } else if (speed == MovementSpeed.Running) { Animator.Play("running-right"); } break; } this.movement = -(dir.ToVector2() * new Vector2(16, 16)); this.MovementSpeed = speed; this.MovementState = MovementState.Walking; this.Position -= this.movement; } }