Talk:RPG Map
From GPWiki
The wiki is now hosted by GameDev.NET at wiki.gamedev.net. All gpwiki.org content has been moved to the new server. However, the GPWiki forums are still active! Come say hello. ??? Can you use psuedo closer to C++ Please. The style below is confusing ???
[edit] pseudo codeMaybe we should make our own GPwiki language neutral syntax? I don't know what else to do. --sdw 11:47, 28 Mar 2005 (EST)
[edit] it is confusing...There's a couple things that don't make sense to me as I'm not a user of whatever language this was written in.
I think if those things were explained it would go quite a ways in putting this tutorial in a more pseudocode/language-neutral form.
[edit] Make a decisionWhy in the lower portion of the page do the psudocode sniplets switch back and fourth between 32 and TileWidth and TileHeight? TileWidth and TileHeight should replace all occurances of "32". [edit] C++ versionNice article! It's nothing wrong with the pseudo-code, I took my time to translate it into pure C++ however. I'm going to use similiar code for my RPG later so it doesn't matter for me and there seems to be some people here who wants it as well. The only thing I added was the struct Rect since I don't know of any predefined ones in C++. I made a quick translation so tell me if anything is wrong with it (or simply edit it :)). I hope the author doesn't have anything against that i'm using his code like this. If you want me to remove it, tell me and I'll remove this post :) C++ Version (struct Rect = additional code) struct Tile { long sX; long sY; bool bBlocked; }; struct Rect { int Left; int Top; int Right; int Bottom; } enum {MapWidth = 80, MapHeight = 80 }; Tile Map[MapWidth][MapHeight]; enum {TileWidth = 32, TileHeight = 32 }; enum {ResolutionWidth = 640, ResoultionHeight = 480 }; Rect r; for (long x=0;x<ResolutionWidth/TileWidth;x++) { for (long y=0;y<ResolutionHeight/TileHeight;y++) { r.Left = Map[x][y].sX; r.Top = Map[x][y].sY; r.Right = r.Left + TileWidth; r.Bottom = r.Top + TileHeight; Draw(x*TileWidth, y*TileHeight, r); // r = rect area of the bitmap it should draw } } struct Point { long X; long Y; }; Point Camera; Rect r; for (long x=Camera.X/TileWidth;x<(Camera.X + ResolutionWidth)/TileWidth;x++) { for (long y=Camera.Y/TileHeight; y<(Camera.Y + ResolutionHeight) / TileHeight; y++) { r.Left = Map[x][y].sX; r.Top = Map[x][y].sY; r.Right = r.Left + TileWidth; r.Bottom = r.Top + TileHeight; Draw(x*TileWidth - Camera.X, y*TileHeight - Camera.y, r); // r = rect area of the bitmap it should draw } } if (Camera.X < 0) Camera.X = 0; if (Camera.X + ResolutionWidth > MapWidth * TileWidth) Camera.X = MapWidth * TileWidth - ResolutionWidth; if (Camera.Y < 0) Camera.Y = 0; if (Camera.Y + ResolutionHeight > MapHeight * TileHeight) Camera.Y = MapHeight * TileHeight - ResolutionHeight; Looks like VB 2005 to me. |


