I managed to make Link climb half a combo, but then he stops. I have a few questions regarding this:
Is there anything wrong with my isSolid Function?
How might I optimize my isSolid Function?
Is there anything wrong with my logic?
CODE
import "std.zh"
bool isSolid(int x, int y) {
int mask = Screen->ComboS[ComboAt(x,y)];
int xc; int yc;
xc = x % 16;
yc = y % 16;
if((xc >= 0) && (xc < 8)) {
if((yc >= 0) && (yc < 8)) {
return mask & 0001b;
} else {
return mask & 0010b;
}
} else {
if((yc >= 0) && (yc < 8)) {
return mask & 0100b;
} else {
return mask & 1000b;
}
}
}
global script InherentControls {
void run() {
while(true) {
//Inherent Jumping
if((Link->InputUp || Link->InputL) && (isSolid(Link->X,Link->Y+16) || isSolid(Link->X+8,Link->Y+16))) {
Link->Jump = 40;
Game->PlaySound(45);
}
//"Slope" Control
if(Link->InputRight && !isSolid(Link->X+16, Link->Y) && isSolid(Link->X+16, Link->Y+15)) {
Link->X ++;
Link->Y --;
}
if(Link->InputLeft && !isSolid(Link->X-1, Link->Y) && isSolid(Link->X-1, Link->Y+15)) {
Link->X --;
Link->Y --;
}
Link->InputUp = false;
Link->InputL = false;
Link->InputDown = false;
Waitframe();
}
}
}
bool isSolid(int x, int y) {
int mask = Screen->ComboS[ComboAt(x,y)];
int xc; int yc;
xc = x % 16;
yc = y % 16;
if((xc >= 0) && (xc < 8)) {
if((yc >= 0) && (yc < 8)) {
return mask & 0001b;
} else {
return mask & 0010b;
}
} else {
if((yc >= 0) && (yc < 8)) {
return mask & 0100b;
} else {
return mask & 1000b;
}
}
}
global script InherentControls {
void run() {
while(true) {
//Inherent Jumping
if((Link->InputUp || Link->InputL) && (isSolid(Link->X,Link->Y+16) || isSolid(Link->X+8,Link->Y+16))) {
Link->Jump = 40;
Game->PlaySound(45);
}
//"Slope" Control
if(Link->InputRight && !isSolid(Link->X+16, Link->Y) && isSolid(Link->X+16, Link->Y+15)) {
Link->X ++;
Link->Y --;
}
if(Link->InputLeft && !isSolid(Link->X-1, Link->Y) && isSolid(Link->X-1, Link->Y+15)) {
Link->X --;
Link->Y --;
}
Link->InputUp = false;
Link->InputL = false;
Link->InputDown = false;
Waitframe();
}
}
}
EDIT 2: I noticed that (I think) it only doesn't work on tiles with a single unwalkable fourth in a bottom corner of the combo's mask which for some reason, Link is not allowed to jump on. It has to do with my collision detector, doesn't it?