Re: ideal way of creating a map parcer?

I don't seem to have my latest attempt at optimizing 2D geometry functions on me at the moment, but you probably want to check for rectangle collisions. (This might not be the case--it really depends on how your engine is set up--but it's still useful to have.)

To check your rooms for overlap, you'd just test their bounding rectangles for collision. Then move one of them. (Warning: it's dangerous to use while loops for this, in the case where you've run out of space and try to add rooms anyway. You don't want to do it without a loop, however, otherwise you might move one room only to have it land on top of a different room.)

(If you can't describe your rooms as rectangles in your engine, this probably won't be much help.)

There are two simple ways to do rectangle collision detection. (Well, 4, if you want to distinguish whether the edges count as overlap.)

First, using a corner (if positive y is north, it'd be so uthwest):

bool colliderect_corner(double x1, double y1, double width1, double height1, double x2, double y2, double width2, double height2) {
    double x3=x1+width1;
    double x4=x2+width2;
    double y3=y1+height1;
    double y4=y2+height2;
    return (
        ((x2>=x1 and x2<=x3) or (x4>=x1 and x4<=x3)) and
        ((y2>=y1 and y2<=y3) or (y4>=y1 and y4<=y3))
        );
}

The other version uses the center, and is ever-so-slightly faster:

bool colliderect_center(double x1, double y1, double width1, double height1, double x2, double y2, double width2, double height2) {
    return (
        (absolute(x2-x1)*2<=(width1+width2)) and
        (absolute(y2-y1)*2<=(height1+height2))
    );
}

(If you want to use half width and half height as the parameters, you can remove the *2s from that function. This is probably not important unless you're doing this thousands of times a second, which you won't be for map design.)



_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Omar Alvarado via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Victorious via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : SoundMUD via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ctoth via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : dhruv via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : dhruv via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector

Reply via email to