It is currently Tue Nov 13, 2018 8:39 am

 All times are UTC - 7 hours

 Page 1 of 1 [ 9 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Wrap-around game mapsPosted: Thu Apr 20, 2006 8:17 am

Joined: Sat Jul 09, 2005 6:03 am
Posts: 85
I have a question about wrap-around maps (maps with no edge clipping). How do you test if a point on that type of map is in a specific rectangular area?

Top

 Post subject: Posted: Thu Apr 20, 2006 11:31 am

Joined: Sat Jul 09, 2005 6:03 am
Posts: 85
I'll explain more.

In my little RPG project, map coordinates are always from (0-map_width-1,0-map_height-1), even on the world map which wraps around. To test if other entities are on screen or to test which random encounter region the player is in, I need to test if a point lies in a given rectangle.

The problem is when the testing rectangle is intersected by the map's edges. Normal testing won't work and I've racked my brain trying to think of a solution for it.

Top

 Post subject: Posted: Thu Apr 20, 2006 11:43 am

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20761
Location: NE Indiana, USA (NTSC)
You test against the rectangle on one side of the map, and then you move the rectangle to the other side of the map and test against that.

In which directions does your map wrap? If it wraps both N-S and E-W, then your planet is not a sphere; it's a torus.

Top

 Post subject: Posted: Thu Apr 20, 2006 11:58 am

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10959
Location: Rio de Janeiro - Brazil
I was going to say something similar: break up the rectangle in smaller rectangles when it goes over the edge of the map. And you test both new rectangles. If the map wraps on both axes you'll be testing 4 rectangles in the worst case.

EDIT: You could probably use the concept of "logical address" and "physical address". Do all the calculations based on the logical address, but when/if you need to read any data from the map you convert the logical address to a physical one.

Top

 Post subject: Posted: Thu Apr 20, 2006 12:08 pm

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1849
I would avoid this scenario altogether and just not have rectanges which cross over the edge of the map.

If you want to have a enemy region rect to cross over the edge of the map for some strange reason -- instead of breaking it into two at runtime and checking each rect -- break it into two when you're designing the map and just have two region rects with the same properties -- neither of which go beyond map boundaries.

Only way I can see something like this being a problem is if you want region rects move around in-game... but I don't see any reason for that.

Top

 Post subject: Posted: Thu Apr 20, 2006 12:21 pm

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10959
Location: Rio de Janeiro - Brazil
From what I understood the rectangles do move. He said he wanted to check if "other entities are on screen", so I think one of these rectangles represents the screen, wich would move.

I still didn't get exactly how the engine works, but maybe there is a better overall method to do this, wich doesnt involve rectangles.

Top

 Post subject: Posted: Thu Apr 20, 2006 12:34 pm

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1849
OOooh, okay, that makes sense. My mistake. Whoops ^^

Top

 Post subject: Posted: Fri Apr 21, 2006 12:39 am

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 4104
Just test four times. Normal test, then test with x-width, then test with y-height, then test with x-width and y-height.

Rectangles that go off the left or top edge should have width/height added to their x/y position if it is negative.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

Top

 Post subject: Posted: Fri Apr 21, 2006 5:23 am

Joined: Sat Jul 09, 2005 6:03 am
Posts: 85
Thank you everyone for your help. I've come up with alittle rectangle testing routine that, as far as I can tell, works great (from testing I did).

Code:
.proc map_test_rec      ; In :
; rx = Rectangle's Top Left x pos
; ry = Rectangle's Top Left y pos
; width = Width of rectangle
; height = Height of rectangle
; tx = Test point x
; ty = Test point y
; Out : a/z = 1 inside a/z = 0 outside

; map_twidth and map_theight are the tile sized
; dimensions of the current map

lda rx
clc
cmp map_twidth
bcc no_clipped_width

sbc map_twidth
cmp tx
bcs test_ver

bcc test_left

no_clipped_width:

cmp tx
bcc not_inside

test_left:

lda tx
cmp rx
bcc not_inside

test_ver:

lda ry
clc
cmp map_theight
bcc no_clipped_height

sbc map_theight
cmp ty
bcs is_inside
bcc test_up

no_clipped_height:

cmp ty
bcc not_inside

test_up:

lda ty
cmp ry
bcc not_inside

is_inside:

lda #1
rts

not_inside:

lda #0
rts

.endproc

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 9 posts ]

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: No registered users and 3 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki