• Create Account

### #ActualDuckerDuck

Posted 20 June 2012 - 06:27 AM

Hello,
I'm currently trying to get familiar with SDL and C++, and i've been working on a little project involing a very basic game engine.
What I want to do at the moment is to implement a simple portal system. I have two portals, if my player steps on one of them he teleports to the other and vice versa. The problem is that, when using the portal, the collsion detection of the other portal interferese, and teleports the player infinitly from portal to portal. I wanted to fix this by adding a small delay before the portal is usable again, but somehow the function I wrote makes the game crash.
Here is the code i'm using:

To set the delay:
void Core::setPortalDelay(int time){
Uint32 now;
now = SDL_GetTicks();

while (now < time){
PortalDelay = true;
}
if (now > time){
PortalDelay = false;
now = 0;
}
}


and to teleport the player:

if (CheckCol(PlayerLocation,rPortal1Loc) == true && PortalDelay == false){
PlayerLocation.x = rPortal2Loc.x;
PlayerLocation.y = rPortal2Loc.y;
setPortalDelay(2000);
}
if (CheckCol(PlayerLocation,rPortal2Loc) == true && PortalDelay == false){
PlayerLocation.x = rPortal1Loc.x;
PlayerLocation.y = rPortal1Loc.y;
setPortalDelay(2000);
}

Thanks,
DuckerDuck

### #1DuckerDuck

Posted 20 June 2012 - 06:26 AM

Hello,
I'm currently trying to get familiar with SDL and C++, and i've been working on a little project involing a very basic game engine.
What I want to do at the moment is to implement a simple portal system. I have to portals, if my player steps on one of them he teleports to the other and vice versa. The problem is that, when using the portal, the collsion detection of the other portal interferese, and teleports the player infinitly from portal to portal. I wanted to fix this by adding a small delay before the portal is usable again, but somehow the function I wrote makes the game crash.
Here is the code i'm using:

To set the delay:
void Core::setPortalDelay(int time){
Uint32 now;
now = SDL_GetTicks();

while (now < time){
PortalDelay = true;
}
if (now > time){
PortalDelay = false;
now = 0;
}
}


and to teleport the player:

if (CheckCol(PlayerLocation,rPortal1Loc) == true && PortalDelay == false){
PlayerLocation.x = rPortal2Loc.x;
PlayerLocation.y = rPortal2Loc.y;
setPortalDelay(2000);
}
if (CheckCol(PlayerLocation,rPortal2Loc) == true && PortalDelay == false){
PlayerLocation.x = rPortal1Loc.x;
PlayerLocation.y = rPortal1Loc.y;
setPortalDelay(2000);
}

Thanks,
DuckerDuck

PARTNERS