I can see much flack coming for this. But yeah, I still need help. I thought making a new thread was in order, since this code might get confused with the other I posted.
I have some code here. I've never done this before. I'll start slow. Variables/predefined processors etc. you should know:
#define WIDTH 640
#define HEIGHT 480
#define TILEW 32
#define TILEH 32
#define MAP_ACROSS 31
#define MAP_DOWN 33
#define MAPW MAP_ACROSS * TILEW
#define MAPH MAP_DOWN * TILEH
#define BOTTOM MAPH-HEIGHT
#define LEFT MAPW-WIDTH
int scrollx=LEFT, scrolly=BOTTOM;
|1||if(scrolly < 0) scrolly = 0;|
|2||if(scrolly > BOTTOM) scrolly = BOTTOM;|
|3||if(scrollx < 0) scrollx = 0;|
|4||if(scrollx > LEFT) scrollx = LEFT;|
|7|| //border/edge detection|
|8|| if (link->x > SCREEN_W-22)|
|10|| link->x = 0;|
|11|| scrollx += SCREEN_W;|
|12|| } |
|13|| else if (link->x < 0)|
|15|| link->x = SCREEN_W-22;|
|16|| scrollx -= SCREEN_W;|
|17|| } |
|18|| else if (link->y > SCREEN_H-24)|
|20|| link->y = 0;|
|21|| scrolly += SCREEN_H;|
|24|| else if (link->y < 0)|
|27|| link->y = SCREEN_H-24; |
|28|| scrolly -=SCREEN_H;|
Problems with this: An error occurs when you try to go all the way up. You start at the bottom, you go up and the map changes fine, then you try to go up once more, and instead of map change, the error occurs and app. has to be closed. I think I know why this is. I'm not sure I understand all of the math, I tried to follow the book:
MAPH = MAP_DOWN * TILEH = 33*32 = 1056. Since I use SCREEN_H (=480) to scroll vertically, we can see that 1056-480=576. That's fine. Now 576-480=96. Not fine. It might be trying to increment by SCREEN_H for the last time, but goes out of bounds. Might this be the case? If so, how come something similar doesn't happen to scrollx (it works)... AND what can I do about this?
I also realize that if say, if(scrollx < 0) scrollx = 0 holds TRUE, then link still changes position. I'd like to change this after the above problem is solved.
Basically, I'm really stuck here. I've tried a couple of things (which I'd rather not mention here, since those details might be confusing). I"m just looking to get rid of that error, and fix the 2nd problem I've mentioned. I REALLY need the help, I'd really appreciate it. TIA.
P.S. I realize the code isn't necessarily clean, I appologize.
P.S.S. Were you guys this stuck with little things when you started game programming?