CJC
05-18-2008, 11:44 PM
I'm having some trouble with the collision in the following script, as well as a few other things... I was hoping to get some perspective from more skilled scripters.
import "std.zh"
// ==========================================
// Dash - This script handles the dash boots.
// ==========================================
const int dashitem = 55; //Sets the item ID required in the inventory
//to dash with the "R" button. The default
//is 55, which are the boots.
bool isSolid;
bool dashLeft;
bool dashRight;
bool dashUp;
bool dashDown;
ffc script Dash{
void run(){
while(true){
if(Link->InputR){
if(Link->Item[dashitem]){ //[[If you do not wish to require an item to dash,
//Remove this line and the one labeled below]]
if(Link->Dir==0){ //This is Up
if((!isSolid(Link->X+1, Link->Y-1)) || (!isSolid(Link->X+8, Link->Y-1)) && (dashUp==false)) {
//This checks if the tile ahead is clear, then starts the dash
dashUp = true;
}
else{ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
if((isSolid(Link->X+1, Link->Y-1)) || (isSolid(Link->X+8, Link->Y-1)) && (dashUp==true)) {
dashUp = false;
Link->Dir = 1;
Link->Y = Link->Y++;
}
}
}
if(Link->Dir==1){ //This is Down
if((!isSolid(Link->X+1, Link->Y+16)) || (!isSolid(Link->X+8, Link->Y+16)) && (dashDown==false)) {
//This checks if the tile ahead is clear, then starts the dash
dashDown = true;
}
else{ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
if((isSolid(Link->X+1, Link->Y+16)) || (isSolid(Link->X+8, Link->Y+16)) && (dashDown==true)) {
dashDown = false;
Link->Dir = 0;
Link->Y = Link->Y--;
}
}
}
if(Link->Dir==2){ //This is Left
if((!isSolid(Link->X-1, Link->Y+1)) || (!isSolid(Link->X-1, Link->Y+8)) && (dashLeft==false)) {
//This checks if the tile ahead is clear, then starts the dash
dashLeft = true;
}
else{ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
if((isSolid(Link->X-1, Link->Y+1)) || (isSolid(Link->X-1, Link->Y+8)) && (dashLeft==true)) {
dashLeft = false;
Link->Dir = 3;
Link->X = Link->X++;
}
}
}
if(Link->Dir==3){ //This is Right
if((!isSolid(Link->X+16, Link->Y+1)) || (!isSolid(Link->X+16, Link->Y+8)) && (dashRight==false)) {
//This checks if the tile ahead is clear, then starts the dash
dashRight = true;
}
else{ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
if((isSolid(Link->X+16, Link->Y+1)) || (isSolid(Link->X+16, Link->Y+8)) && (dashRight==true)) {
dashRight = false;
Link->Dir = 2;
Link->X = Link->X--;
}
}
}
} //[[If you remove the item tag, remove this line]]
Link->InputR = false; // This is necessary to stop R from
// flipping your selected item.
}
Waitframe();
} // end of while loop
} // end of void run
bool dashUp(){
if((Link->InputDown) || (!Link->InputR)) { //This stops an upward dash if the player presses down or releases "R"
return false;
}
else {
Link->Y = Link->Y--;
Link->InputLeft = false;
Link->InputRight = false;
Link->InputL = false;
Link->InputUp = false;
}
}
bool dashDown(){
if((Link->InputUp) || (!Link->InputR)) { //This stops a downward dash if the player presses up or releases "R"
return false;
}
else {
Link->Y = Link->Y++;
Link->InputLeft = false;
Link->InputRight = false;
Link->InputL = false;
Link->InputDown = false;
}
}
bool dashLeft(){
if((Link->InputRight) || (!Link->InputR)) { //This stops a leftward dash if the player presses right or releases "R"
return false;
}
else {
Link->X = Link->X--;
Link->InputUp = false;
Link->InputDown = false;
Link->InputL = false;
Link->InputLeft = false;
}
}
bool Right(){
if((Link->InputLeft) || (!Link->InputR)) { //This stops a rightward dash if the player presses left or releases "R"
return false;
}
else {
Link->X = Link->X++;
Link->InputUp = false;
Link->InputDown = false;
Link->InputL = false;
Link->InputRight = false;
}
}
bool isSolid(int x, int y) { //This detects the solidity of a combo
if(x<0 || x>255 || y<0 || y>175)
return false;
int mask=1111b;
if(x%16<8)
mask&=0011b;
else
mask&=1100b;
if(y%16<8)
mask&=0101b;
else
mask&=1010b;
return (!(Screen->ComboS[ComboAt(x, y)]&mask)==0);
}// end of isSolid
}
I'm having trouble with my collision detection; I want it to check if the tile ahead in the direction Link is moving is solid, but for some reason the dash stops when he is within one space of ANY solid combo (Which is incredibly frustrating).
Also, when he does stop from reaching an unwalkable combo, he will not perform the actions I coded (Which currently consists of "Turn around" and "Move back slightly", though it will include sound and dummy item remover once the dash itself functions properly.)
Other issues I'm having with my script:
In side-scrolling screens, if a dash is performed from the air Link floats up to the nearest unwalkable ceiling and spasms there until "R" is released. I think I might be able to halt this with a "Link->Jump < 0" check, but I am unsure if that is the most efficient method.
I want it to play a sound for the duration of truth on any of the Dash bools, but I am clueless as to how that can be achieved.
If possible, I would like to place an Lweapon (The sword) one tile in front of Link as he is dashing (Also, in the direction he is dashing). Again, I have no idea how to do this.
I want it to play a different sound when Link is halted in his dash by a solid combo (Which also involves the knockback code, which I complained about earlier).
Please help!
import "std.zh"
// ==========================================
// Dash - This script handles the dash boots.
// ==========================================
const int dashitem = 55; //Sets the item ID required in the inventory
//to dash with the "R" button. The default
//is 55, which are the boots.
bool isSolid;
bool dashLeft;
bool dashRight;
bool dashUp;
bool dashDown;
ffc script Dash{
void run(){
while(true){
if(Link->InputR){
if(Link->Item[dashitem]){ //[[If you do not wish to require an item to dash,
//Remove this line and the one labeled below]]
if(Link->Dir==0){ //This is Up
if((!isSolid(Link->X+1, Link->Y-1)) || (!isSolid(Link->X+8, Link->Y-1)) && (dashUp==false)) {
//This checks if the tile ahead is clear, then starts the dash
dashUp = true;
}
else{ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
if((isSolid(Link->X+1, Link->Y-1)) || (isSolid(Link->X+8, Link->Y-1)) && (dashUp==true)) {
dashUp = false;
Link->Dir = 1;
Link->Y = Link->Y++;
}
}
}
if(Link->Dir==1){ //This is Down
if((!isSolid(Link->X+1, Link->Y+16)) || (!isSolid(Link->X+8, Link->Y+16)) && (dashDown==false)) {
//This checks if the tile ahead is clear, then starts the dash
dashDown = true;
}
else{ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
if((isSolid(Link->X+1, Link->Y+16)) || (isSolid(Link->X+8, Link->Y+16)) && (dashDown==true)) {
dashDown = false;
Link->Dir = 0;
Link->Y = Link->Y--;
}
}
}
if(Link->Dir==2){ //This is Left
if((!isSolid(Link->X-1, Link->Y+1)) || (!isSolid(Link->X-1, Link->Y+8)) && (dashLeft==false)) {
//This checks if the tile ahead is clear, then starts the dash
dashLeft = true;
}
else{ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
if((isSolid(Link->X-1, Link->Y+1)) || (isSolid(Link->X-1, Link->Y+8)) && (dashLeft==true)) {
dashLeft = false;
Link->Dir = 3;
Link->X = Link->X++;
}
}
}
if(Link->Dir==3){ //This is Right
if((!isSolid(Link->X+16, Link->Y+1)) || (!isSolid(Link->X+16, Link->Y+8)) && (dashRight==false)) {
//This checks if the tile ahead is clear, then starts the dash
dashRight = true;
}
else{ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
if((isSolid(Link->X+16, Link->Y+1)) || (isSolid(Link->X+16, Link->Y+8)) && (dashRight==true)) {
dashRight = false;
Link->Dir = 2;
Link->X = Link->X--;
}
}
}
} //[[If you remove the item tag, remove this line]]
Link->InputR = false; // This is necessary to stop R from
// flipping your selected item.
}
Waitframe();
} // end of while loop
} // end of void run
bool dashUp(){
if((Link->InputDown) || (!Link->InputR)) { //This stops an upward dash if the player presses down or releases "R"
return false;
}
else {
Link->Y = Link->Y--;
Link->InputLeft = false;
Link->InputRight = false;
Link->InputL = false;
Link->InputUp = false;
}
}
bool dashDown(){
if((Link->InputUp) || (!Link->InputR)) { //This stops a downward dash if the player presses up or releases "R"
return false;
}
else {
Link->Y = Link->Y++;
Link->InputLeft = false;
Link->InputRight = false;
Link->InputL = false;
Link->InputDown = false;
}
}
bool dashLeft(){
if((Link->InputRight) || (!Link->InputR)) { //This stops a leftward dash if the player presses right or releases "R"
return false;
}
else {
Link->X = Link->X--;
Link->InputUp = false;
Link->InputDown = false;
Link->InputL = false;
Link->InputLeft = false;
}
}
bool Right(){
if((Link->InputLeft) || (!Link->InputR)) { //This stops a rightward dash if the player presses left or releases "R"
return false;
}
else {
Link->X = Link->X++;
Link->InputUp = false;
Link->InputDown = false;
Link->InputL = false;
Link->InputRight = false;
}
}
bool isSolid(int x, int y) { //This detects the solidity of a combo
if(x<0 || x>255 || y<0 || y>175)
return false;
int mask=1111b;
if(x%16<8)
mask&=0011b;
else
mask&=1100b;
if(y%16<8)
mask&=0101b;
else
mask&=1010b;
return (!(Screen->ComboS[ComboAt(x, y)]&mask)==0);
}// end of isSolid
}
I'm having trouble with my collision detection; I want it to check if the tile ahead in the direction Link is moving is solid, but for some reason the dash stops when he is within one space of ANY solid combo (Which is incredibly frustrating).
Also, when he does stop from reaching an unwalkable combo, he will not perform the actions I coded (Which currently consists of "Turn around" and "Move back slightly", though it will include sound and dummy item remover once the dash itself functions properly.)
Other issues I'm having with my script:
In side-scrolling screens, if a dash is performed from the air Link floats up to the nearest unwalkable ceiling and spasms there until "R" is released. I think I might be able to halt this with a "Link->Jump < 0" check, but I am unsure if that is the most efficient method.
I want it to play a sound for the duration of truth on any of the Dash bools, but I am clueless as to how that can be achieved.
If possible, I would like to place an Lweapon (The sword) one tile in front of Link as he is dashing (Also, in the direction he is dashing). Again, I have no idea how to do this.
I want it to play a different sound when Link is halted in his dash by a solid combo (Which also involves the knockback code, which I complained about earlier).
Please help!