PDA

View Full Version : Unearthing old projects... and my arsenal is not sufficient



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!

Gleeok
05-19-2008, 04:38 PM
if(Link->InputR && Link->Item[]){
if((Link->InputUp)&&
(isSolid(Link->X, Link->Y-2))&&
(isSolid(Link->X+8, Link->Y-2))&&
(isSolid(Link->X+15, Link->Y-2))){
Link->Y--;
}
else if((Link->InputDown)&&
(isSolid(Link->X, Link->Y+17))&&
(isSolid(Link->X+8, Link->Y+17))&&
(isSolid(Link->X+15, Link->Y+17))
){
Link->Y++;
}
else if((Link->InputLeft)&&
(isSolid(Link->X-2, Link->Y+8))&&
(isSolid(Link->X-2, Link->Y+15))
){
Link->X--;
}
else if((Link->InputRight)&&
(isSolid(Link->X+17, Link->Y+8))&&
(isSolid(Link->X+17, Link->Y+15))
){
Link->X++;
}
}

This should fix your solidity problems. No need to thank me, I basically ripped it off of C- way back when. XD As for the sword, I'm not sure we can spawn those:


const int LW_SWORD = 1; // This cannot be created

Although sticking an ffc in front of link that damages enemies is easy enough, if you choose that route.

CJC
05-19-2008, 07:14 PM
OMG!


...OMG OMG OMG!


IT WORKS!


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){
while(!Link->InputR) Waitframe();
if(!Link->Item[dashitem]) Waitframe();
else if(Link->InputR){
if((Link->InputUp) &&
(!isSolid(Link->X, Link->Y-2)) &&
(!isSolid(Link->X+8, Link->Y-2)) &&
(!isSolid(Link->X+15, Link->Y-2))){ //This is Up
Link->Y = Link->Y-2;
}
else if(Link->InputUp){ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
Link->Dir = 1;
Link->Y = Link->Y+4;
}
else if((Link->InputDown) &&
(!isSolid(Link->X, Link->Y+17)) &&
(!isSolid(Link->X+8, Link->Y+17)) &&
(!isSolid(Link->X+15, Link->Y+17))){ //This is Down
Link->Y = Link->Y+2;
}
else if(Link->InputDown){//This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
Link->Dir = 0;
Link->Y = Link->Y-4;
}
else if((Link->InputLeft) &&
(!isSolid(Link->X-2, Link->Y)) &&
(!isSolid(Link->X-2, Link->Y+8)) &&
(!isSolid(Link->X-2, Link->Y+15))){ //This is Left
Link->X = Link->X-2;
}
else if(Link->InputLeft){ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
Link->Dir = 3;
Link->X = Link->X+4;
}
else if((Link->InputRight) &&
(!isSolid(Link->X+17, Link->Y)) &&
(!isSolid(Link->X+17, Link->Y+8)) &&
(!isSolid(Link->X+17, Link->Y+15))){ //This is Left
Link->X = Link->X+2;
}
else if(Link->InputRight){ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
Link->Dir = 2;
Link->X = Link->X-4;
}
Link->InputR = false; // This is necessary to stop R from
// flipping your selected item.
}
} // end of while loop
} // end of void run

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
}


The boots roughly double movement speed while R is held, but only if they are contained in your inventory.


Wow... this is really exciting.

Thank you thank you thank you!


Okay... gotta calm down, there's more to do.
I need to add a dummy item for running animation (And remove it when running stops), but I can handle that pretty well.
I also want it to loop a particular sound while he's moving quickly, and then stop playing said sound when he's turned around by the second "else if" in each direction.


Wow... let's see what else we can do with this!


EDIT: We have a new problem.

The dash works fine. However, my dash requires that when the facing changes, Link looks like he falls over.

At the moment the script is working fairly well. However, I've encountered an input problem that could be a glitch or a code error.

If the player releases the "R" button before releasing their direction, the dash anima item is not removed and the Link tile modifiers are not removed. Because my tiles animate Link falling over when he hits a wall, he looks really silly if the modifier isn't removed.

Below is the code.



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;

ffc script Dash{

void run(){

int DashAnimaR = 172; //Set the dummy item with the tile mod for your dash sprites when moving right
int DashAnimaL = 173; //Set the dummy item with the tile mod for your dash sprites when moving left
int DashAnimaU = 174; //Set the dummy item with the tile mod for your dash sprites when moving up
int DashAnimaD = 175; //Set the dummy item with the tile mod for your dash sprites when moving down

while(true){
while(!Link->InputR) Waitframe();
if(!Link->Item[dashitem]) Waitframe();
else if((Link->InputUp) && (Link->InputR)){
if((!isSolid(Link->X, Link->Y-2)) && (!isSolid(Link->X+8, Link->Y-2)) && (!isSolid(Link->X+15, Link->Y-2))){ //This is Up
Link->Item[DashAnimaU] = true;
Link->Item[DashAnimaD] = false;
Link->Item[DashAnimaL] = false;
Link->Item[DashAnimaR] = false;
Link->Y = Link->Y-2;
}
else{ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
Link->Dir = 1;
Link->Y = Link->Y+4;
Link->Item[DashAnimaU] = false;
}
}
else if((Link->InputDown) && (Link->InputR)){
if((!isSolid(Link->X, Link->Y+17)) && (!isSolid(Link->X+8, Link->Y+17)) && (!isSolid(Link->X+15, Link->Y+17))){ //This is Down
Link->Y = Link->Y+2;
}
else{ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
Link->Dir = 0;
Link->Y = Link->Y-4;
Link->Item[DashAnimaD] = false;
}
}
else if((Link->InputLeft) && (Link->InputR)){
if((!isSolid(Link->X-2, Link->Y)) && (!isSolid(Link->X-2, Link->Y+8)) && (!isSolid(Link->X-2, Link->Y+15))){ //This is Left
Link->Item[DashAnimaL] = true;
Link->Item[DashAnimaR] = false;
Link->Item[DashAnimaU] = false;
Link->Item[DashAnimaD] = false;
Link->X = Link->X-2;
}
else{ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
Link->Dir = 3;
Link->X = Link->X+4;
Link->Item[DashAnimaL] = false;
}
}
else if((Link->InputRight) && (Link->InputR)){
if((!isSolid(Link->X+17, Link->Y)) && (!isSolid(Link->X+17, Link->Y+8)) && (!isSolid(Link->X+17, Link->Y+15))){ //This is Left
Link->Item[DashAnimaR] = true;
Link->Item[DashAnimaL] = false;
Link->Item[DashAnimaU] = false;
Link->Item[DashAnimaD] = false;
Link->X = Link->X+2;
}
else{ //This stops the dash if the tile is not clear, turns Link around, and knocks him away from the tile
Link->Dir = 2;
Link->X = Link->X-4;
Link->Item[DashAnimaR] = false;
}
}
else{
Link->Item[DashAnimaD] = false; //Turns off down dashing sprites when not moving
Link->Item[DashAnimaU] = false; //Turns off up dashing sprites when not moving
Link->Item[DashAnimaR] = false; //Turns off right dashing sprites when not moving
Link->Item[DashAnimaL] = false; //Turns off left dashing sprites when not moving
}
Link->InputR = false; // Turn off item cycling in the subscreen editor, please?
} // end of while loop
} // end of void run

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
}