Talk:RPG Map

From GDWiki

Jump to: navigation, search

??? Can you use psuedo closer to C++ Please. The style below is confusing ???


Yeah. Should this be VB? VB may be the easiest to understand of all the languages, but shouldn't it be evened a bit toward the C style syntax? This *is* a language agnostic...--Snoolas 11:20, 28 Mar 2005 (EST)

Contents

[edit] pseudo code

Maybe we should make our own GPwiki language neutral syntax? I don't know what else to do. --sdw 11:47, 28 Mar 2005 (EST)

Hm.. I don't really find this pseudo code confusing. I mean, it's either going to have to be BASIC-ish or C-ish, right? I don't know if there's a universally accepted standard. If there is, we should use it, but if not, I think we should leave this up to the author's discretion. Ryan Clark 11:51, 28 Mar 2005 (EST)
Google says: [1] and [2].

[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.


With r .Left = Map(x,y).sX .Top = Map(x,y).sY .Right = .Left + TileWidth .Bottom = .Top + TileHeight End With


What is a with statement? How is this being used? what is "." for in statements like .left and map(x,y).sy  ?

I think if those things were explained it would go quite a ways in putting this tutorial in a more pseudocode/language-neutral form.

With is just a way for VB programmers to be lazy, really. All of the statements inside of the with block really mean "r.Left = Map(x,y).sX", etc. You don't know what . is? Anyway, . means that this belongs to this object. Left is a property of r, so to use it, you have to ask r first. It's kind of like citing your sources. --Dial-Up 22:12, 15 Aug 2005 (EDT)

[edit] Make a decision

Why 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++ version

Nice 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.