Map size variables...
Displaying 1-15 of 15 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Omni

Well, there's not a functional way to read the width and height, both in tiles and pixels, of a map.

Might there be a mapwidth and mapheight in the next verge release?

Posted on 2004-07-09 17:32:00

Kildorf

I second this. We neeeds it.

Posted on 2004-07-09 17:56:00

RageCage

I 3rd it. I've been witing for a while to have those variables for AStar.

Posted on 2004-07-09 19:56:08

Omni

Kay, I figured it out.

I would have posted this much earlier after lunch, but I had work and my wireless network was down.

Here are some perfect and useful workarounds.


int GetMapPixelWidth() //Get the width in pixels of the map..
{
int done = 1; //When we're done...
//Set the variables to come back to...
int prevxwin=xwin, prevcam = cameratracking;
int lastxwin; //Keep track of Xwin...
lastxwin--;
xwin = 0; //Start xwin.
cameratracking = 0; //Manual cameratracking.
while (done)
{
xwin++;
//If xwin goes past the edge of the map, it will stop
//increasing. We use this final value,
//together with the screen resolution,
//for the width of the map.
if (xwin == lastxwin)
{
done = 0;
}
lastxwin = xwin;
//Log(str(xwin));
Render();
//Not calling ShowPage()...speeds it up.
//ShowPage();
}
xwin = prevxwin; //Reset variables.
cameratracking = prevcam;
//Return pixel width of map. Add the screen size,
//because xwin stops increasing when there
//is still a whole screen of real-estate left
//before the map ends.
return lastxwin + ImageWidth(screen);
}

int GetMapPixelHeight() //Get the height in pixels of the map.
{
int done = 1;
int prevywin=ywin, prevcam = cameratracking;
int lastywin;
lastywin--;
ywin = 0;
cameratracking = 0;
while (done)
{
ywin++;
//This runs on the same principle as
//GetMapPixelWidth(). After increasing
//to the edge of the map, ywin will
//stop increasing. Get the final value.
if (ywin == lastywin)
{
done = 0;
}
lastywin = ywin;
//Log(str(ywin));
Render();
//ShowPage();
}
ywin = prevywin;
cameratracking = prevcam;
//Return the final ywin position
//plus the screen height to make up
//for the last screen of the map.
return lastywin + ImageHeight(screen);
}


They work well.

Posted on 2004-07-10 02:48:51

Omni

The above functions are not slow at all, since they don't actually call ShowPage(). I do believe Render() must be called, because it must check to see if xwin and ywin are in bounds.

You may want to just store the width and height from these variables instead of calling it over and over again.

Posted on 2004-07-10 02:50:41

Buckermann

Omni,
that is a nifty function. How did you figured out that xwin/ywin will stop increasing at the end of a map?

Posted on 2004-07-10 08:17:44

Gayo

Dunno about him, but I found that out the hard way when faking a "follow this non-player entity" function. it totally screwed up my blitentityframes. I can use this to fix it, though! Horray.

Posted on 2004-07-10 08:35:41

Buckermann

Omni,
another question:
is there a reason why you use xwin++ and ywin++?
I tried xwin += 16 and ywin += 16 and it seems like it works too (and much faster). As long as the tilesize is hardcoded to 16x16 this should work.
Or is there a obvious reason for single incrementation I'm to stupid to see?

Posted on 2004-07-10 10:45:13

Kildorf

Omni, awesome idea; I'd never thought to use the behaviour that was messing me up (xwin/ywin not increasing past the edge of the map) to defeat itself. :)

I think I've managed to cut it down a little, though. ^_^ Why make an incrementing loop when you can just set it to something that you know will be greater than or equal to the size of the map?


int mapsizeX, mapsizeY;

void getMapDimensions() {
int oldcam = cameratracking;
cameratracking = 0;
xwin = 16000000; ywin = 16000000;
Render();
mapsizeX = (xwin+imageWidth(screen))/16;
mapsizeY = (ywin+imageHeight(screen))/16;
cameratracking = oldcam;
}

I make the assumption here that no maps are more than 1,000,000 tiles square; if that doesn't sit well with you, figure out the maximum value of an int in Verge and use that. I was originally going to do this myself, but my MAXINT def seems broken for some reason.

Just call that at every mapload, and baboom; you've got some globals with the map size. I've actually checked this before posting (I had to check it more than once because (as anyone who saw my briefly visible nodeshell knows) I am an idiot. I have been having really bad luck with dispensing advice recently), and it works.

Posted on 2004-07-10 14:55:01 (last edited on 2004-07-10 15:09:52)

Omni

I figured out how xwin and ywin behaved when I was working on my older map scaling/rotation library for V2...and to do that I needed to learn to translate xwin/ywin to the screen and position map layers. In doing so I realized that:

1. Xwin and Ywin start at 0, the upper left corner of the map.
2. Xwin and Ywin do not increment when under player control until the player reaches the center of the screen (in 320 width screen, a 160 area).
3. Xwin and Ywin stop decreasing when the lower right hand corner of the map is in the lower right hand corner of the screen. So they stop decreasing not at mapwidth, mapheight, but at mapwidth-screenwidth, mapheight-screenheight.

The reason why I only use xwin++ and ywin++ is because...well, actually, I did use xwin+=10 etc...on my machine when I was first testing it. But this caused the final width to be off by 10 pixels.

The reason is because xwin and ywin stop incrementing when they reach the edge of the map...and when I increased it by 10, my logs originally didn't show it being truncated, since I logged before Rendering(). It was the original width+10.

So I just used 1, since there's no speed barrier.

But according to Kildorf's post, Render() does indeed truncate the values. Good. Kildorf's is good :)

Posted on 2004-07-10 15:23:25 (last edited on 2004-07-10 15:25:01)

blues_zodiakos

If you need it, there are two small functions in my particle system demo that convert x and y map coordinates to screen coordinates, and two functions to determine if the map coordinates you give it are within the viewing area (both are resolution independent, I believe). It's really simple code, don't remember how fast it is though. Just thought I'd say something. :D

Posted on 2004-07-10 23:57:18

Interference22

Quote:Originally posted by Blues Zodiakos

If you need it, there are two small functions in my particle system demo that convert x and y map coordinates to screen coordinates, and two functions to determine if the map coordinates you give it are within the viewing area (both are resolution independent, I believe). It's really simple code, don't remember how fast it is though. Just thought I'd say something. :D


I have something similar in the code for something I'm working on that takes the mouse co-ordinates and can tell you what TileXY the mouse is hovered over etc.

Posted on 2004-07-12 00:22:40

Overkill

Map to screen is easy:

RectFill(map_locx-xwin,map_locy-ywin,map_locx-xwin+16,map_locy-ywin+16,RGB($33,$66,$FF),screen);


Yeah.

Posted on 2004-07-12 00:30:37 (last edited on 2004-07-12 00:31:30)

Interference22

Quote:Originally posted by overkill

Map to screen is easy:

RectFill(map_locx-xwin,map_locy-ywin,map_locx-xwin+16,map_locy-ywin+16,RGB($33,$66,$FF),screen);


Yeah.



Er, sorry to have to ask, but what exactly does that DO?

Posted on 2004-07-12 00:32:29 (last edited on 2004-07-12 00:32:30)

Omni

It gains a screen position from the map position.

Xwin is the upper left hand corner of the map displayed on the screen. Subtracting it gives you an offset for map positions based on the map's current position.

Then, give it a location.

For example, if map_locx was 30 (blit the rect to 30, y on the map in pixels), and xwin is 100 (position 100, y is in the upper-left hand corner of the screen), then 30-100 = -70 (the rect will need to be placed at -70, y on the screen to be at position 30 on the map).

Posted on 2004-07-12 00:46:25


Displaying 1-15 of 15 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.