[ Login | Register ]

The Shining Source

« previous next »
Pages: [1] Print
Range Algorithms   (Read 14019 times)
Old Post June 15, 2010, 07:48:08 am
#1
Blahian *

Posts: 19

Logged
Range Algorithms
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


Old Post June 19, 2010, 08:01:17 pm
#2
Ty
Administrator
Shining Sideburns *

Posts: 837

Logged
Re: Range Algorithms
What was the solution in the end? I can put it in Shining Aid if you'd like Smiley


New Post July 01, 2010, 06:44:27 am
#3
Administrator
Shining Spammer *

Posts: 1,208

Logged
Re: Range Algorithms
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 Wink.).


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;
}


Devlyn

Great news for Shining fangame developers! Wink

Correcting your non-working <img> tags since 1982 Wink


Pages: [1] Print 
« previous next »
Jump to:  

Powered by SMF 1.1.21 | SMF © 2013, Simple Machines