import "std.zh"//D0-cset of portal1
//D1-cset of portal2
item script PORTAL_item{
void run(int cset, int cset2){
int portal_data = 10;
ffc portal1 = Screen->LoadFFC(29);
ffc portal2 = Screen->LoadFFC(28);
if(!((portal1->Data >= portal_data) && (portal1->Data <= portal_data+7))){
Game->PlaySound(11);
if(Link->Dir == 0) {
portal1->X = Link->X;
portal1->Y = Link->Y - 16;
portal1->Vy = -2;
portal1->Vx = 0;
portal1->Data = portal_data;
portal1->CSet = cset;
}
if(Link->Dir == 1) {
portal1->X = Link->X;
portal1->Y = Link->Y + 16;
portal1->Vy = 2;
portal1->Vx = 0;
portal1->Data = portal_data+1;
portal1->CSet = cset;
}
if(Link->Dir == 2) {
portal1->X = Link->X - 16;
portal1->Y = Link->Y;
portal1->Vx = -2;
portal1->Vy = 0;
portal1->Data = portal_data+2;
portal1->CSet = cset;
}
if(Link->Dir == 3) {
portal1->X = Link->X + 16;
portal1->Y = Link->Y;
portal1->Vx = 2;
portal1->Vy = 0;
portal1->Data = portal_data+3;
portal1->CSet = cset;
}
}
else{
if(!((portal2->Data >= portal_data) && (portal2->Data <= portal_data+7))){
Game->PlaySound(11);
if(Link->Dir == 0) {
portal2->X = Link->X;
portal2->Y = Link->Y - 16;
portal2->Vy = -2;
portal2->Vx = 0;
portal2->Data = portal_data;
portal2->CSet = cset2;
}
if(Link->Dir == 1) {
portal2->X = Link->X;
portal2->Y = Link->Y + 16;
portal2->Vy = 2;
portal2->Vx = 0;
portal2->Data = portal_data+1;
portal2->CSet = cset2;
}
if(Link->Dir == 2) {
portal2->X = Link->X - 16;
portal2->Y = Link->Y;
portal2->Vx = -2;
portal2->Vy = 0;
portal2->Data = portal_data+2;
portal2->CSet = cset2;
}
if(Link->Dir == 3) {
portal2->X = Link->X + 16;
portal2->Y = Link->Y;
portal2->Vx = 2;
portal2->Vy = 0;
portal2->Data = portal_data+3;
portal2->CSet = cset2;
}
}
}
}
}
int portal_warp_delay = 0;
//---------for FFC 29-----------------
//==========D0 - THE FFC SLOT THIS SCRIPT IS IN (29!!!!!!!!....currently)
//==========D1 - "ffc slot of "OTHER ffc script(28!!!!!!!!!!!!!!!!!)
// -----REVERSE FOR FFC 28! ie: D0 - 28 D1 -29......Sorry for the angry looking notes :O
ffc script PORTAL_ffc{
void run(int this_ffc_number, int other_ffc_number){
ffc this_ffc = Screen->LoadFFC(this_ffc_number);
ffc other_ffc = Screen->LoadFFC(other_ffc_number);
int portal_data = 10;
int portal_set = 0;
int portal_position = 0;
bool portal_open = false;
int enemy_number = 0;
npc enemy;
while(true){
if(portal_warp_delay > 0){ portal_warp_delay--;}
if( (this->Data >= portal_data) && (this->Data <=portal_data+3) ){
if( (this_ffc->Vx < 0) && ((!is_walkable(this_ffc->X - 8, this_ffc->Y))) ){ portal_open = true;}
if( (this_ffc->Vx > 0) && ((!is_walkable(this_ffc->X + 8, this_ffc->Y))) ){ portal_open = true;}
if( (this_ffc->Vy < 0) && ((!is_walkable(this_ffc->X, this_ffc->Y - 8))) ){ portal_open = true;}
if( (this_ffc->Vy > 0) && ((!is_walkable(this_ffc->X, this_ffc->Y + 8))) ){ portal_open = true;}
}
if(portal_open){ this_ffc->Data = portal_data+4; this_ffc->Vx = 0; this_ffc->Vy = 0;}
if(portal_set == 0){
if(other_ffc->Data >= portal_data + 4){
if(portal_warp_delay == 0){
if ( (Link->X <= this_ffc->X + 10)&&(Link->X >= this_ffc->X -10)&&
(Link->Y <= this_ffc->Y + 10)&&(Link->Y >= this_ffc->Y -10) ){
portal_warp_delay = 60;
Link->X = other_ffc->X;
Link->Y = other_ffc->Y;
Game->PlaySound(11);
}
enemy_number = Screen->NumNPCs();
while(enemy_number > 0){
enemy = Screen->LoadNPC(enemy_number);
if ( (this_ffc->X - 10 < enemy->X) && (this_ffc->X + 10 > enemy->X) &&
(this_ffc->Y - 10 < enemy->Y) && (this_ffc->Y + 10 > enemy->Y) ){
enemy->X = other_ffc->X; enemy->Y = other_ffc->Y;
}
enemy_number--;
}
}
}
}
Waitframe();
}
}
bool is_walkable(int x, int y)
{
return Screen->ComboS[x+y*16]==0;
}
}