Ye Olde Blah

ShiningSource.org => General Programming Forum => Topic started by: Oren on June 15, 2010, 07:48:08 am



Title: Range Algorithms
Post by: Oren on June 15, 2010, 07:48:08 am
Can anyone help me in this department. I've tried pulling apart some of the code from Shining Aid, but there's too many classes and I can't seem to pinpoint them. I'll keep looking, but if anyone could help me figure out how to implement the range tiles, that would be awesome.

  #
#o#
  #

     #
  ###
##o##
  ###
    #

EDIT: Nevermind, I'm an idiot. I figured it out. lol


Title: Re: Range Algorithms
Post by: Ty on June 19, 2010, 08:01:17 pm
What was the solution in the end? I can put it in Shining Aid if you'd like :)


Title: Re: Range Algorithms
Post by: Devlyn on July 01, 2010, 06:44:27 am
This is a buggy version that results in an infinite loop. However, if you can prevent it from walking the same squares twice it will work properly (just add a few if-statements regarding that ;).).


Code:
Walk(Xo,Yo,Xo,Yo);

int distanceof(x1,y1,x2,y2) {
  return abs(x1-x2) + abs(y1-y2);
}

Walk(x,y,Xo,Yo) {
  if (distanceof(x,y,Xo,Yo) < range) {
    //square is in range. Set some marker here to store this fact.

    //Walk on.
    Walk(x+1,y+1,Xo,Yo);
    Walk(x-1,y+1,Xo,Yo);
    Walk(x+1,y-1,Xo,Yo);
    Walk(x-1,y-1,Xo,Yo);
  }
  return;
}