Author Topic: Stopped in what direction  (Read 4351 times)

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Stopped in what direction
« on: 2007-04-11, 12:09:20 PM »
I'm attempting to write a function that returns a SpriteBase.Direction indicating what direction, if any, the sprite has just been stopped from going.  For example, if they hit a wall, floor, or ceiling:

Code: [Select]
   public int DirectionStop()
   {
      Debug.Assert(this.isActive, "Attempted to execute DirectionStop on an inactive sprite");
      if (Blocked(Direction.Down) || IsRidingPlatform())
         if (oldY < y && dy == 0)
            return (int)Direction.Down;
      if (Blocked(Direction.Up))
         if (oldY > y && dy == 0)
            return (int)Direction.Up;
      if (Blocked(Direction.Left))
         if (oldX > x && dx == 0)
            return (int)Direction.Left;
      if (Blocked(Direction.Right))
         if (oldX < x && dx == 0)
            return (int)Direction.Right;
      return -1;
   }

This works in most cases (not counting dx-y/LocalDX-Y problems w/ platforms right now) except when moving along slopes.  It seems to consider whenever you're moving along a slope to be blocked.  Any idea why?  It's called after ReactToSolid and SnapToGround.
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Stopped in what direction
« Reply #1 on: 2007-04-11, 07:05:18 PM »
Maybe my definition of blocked was bad/unclear.  I think I defined it as "do you hit anything solid going in that direction?"

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Stopped in what direction
« Reply #2 on: 2007-04-11, 08:32:33 PM »
Well, do you have any suggestions?  I suppose I would have to write another function similar to blocked, but... thicker?  I can't think of a better word.
Edward Dassmesser

Jam0864

  • Contributor
  • Fanatic
  • **
  • Posts: 744
    • MSN Messenger - marmalade0864@hotmail.com
    • View Profile
    • Jam0864's Content Dump
    • Email
Re: Stopped in what direction
« Reply #3 on: 2007-04-11, 09:41:11 PM »
Well, do you have any suggestions?  I suppose I would have to write another function similar to blocked, but... thicker?  I can't think of a better word.
how about complex?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Stopped in what direction
« Reply #4 on: 2007-04-12, 05:57:35 AM »
How about "CanMove"?  (And I should clarify the description of "blocked")