On Tuesday, 26 February 2013 16:02:31 UTC+2,
sirpigme...@googlemail.com wrote:
> On Tuesday, February 26, 2013 10:42:42 AM UTC, Mikera wrote:
> > On Tuesday, 26 February 2013 17:23:06 UTC+8,
sirpigme...@googlemail.com wrote:
> >
> > > Anybody know of any ASCII roguelikes with round towers in them? I'm
> > > writing a game where you climb a sorcerers tower and i'd like to see
> > > how someone else might have done it... in case i'm missing some obvious,
> > > simple way to do it.
> >
> > The algorithm is pretty easy: just test if (x-cx)^2 + (y-cy)^2 < r^2 for
> > a tower with centre (cx,cy) and radius r. This defines which squares are
> > in the interior of the tower. You can then make a "wall" around the
> > interior space of the tower by filling outwards one square in all
> > directions.
> >
> > For a tower which slowly gets thinner as you climb upwards, just decrease
> > r on each level.
>
> Cheers, I was looking at circle algorithm stuff and that's the best i've
> seen it explained so far. Although i think I may need an ellipse instead of
> a circle because with my ASCII graphics each 'square' is taller than it is
> wide, (that is so # walls join up better horizontally) so a circle would
> come out looking a bit flat. I'm sure I can tweak it...
Here is code to fill elliptic area:
w2 = width*width;
h2 = height*height;
h2w2 = h2*w2;
for ( int y=-height; y<=height; y++ )
{
y2w2 = y*y*w2;
for ( int x=-width; x<=width; x++ )
{
if ( x*x*h2 + y2w2 <= h2w2 )
setInside(center.x+x, center.y+y);
}
}
Here is code that tests if point is inside elliptic area:
x = center.x - point.x;
y = center.y - point.y;
if(x*x*height*height+y*y*width*width <= height*height*width*width)
return true;
> I'm just using a data file with the the walls and floor tiles marked out
> at the moment, it works fine but its a bit inelegant...
If it works fine then why to repair it?
> I don't know if i'll be changing the towers size or not yet as the hero
> is going to be able to scale the walls... but its good to have this stuff
> in the bag if I need it.
Full bag is always good ... indeed. ;)