Jump to content

  • Log In with Google      Sign In   
  • Create Account

DuckerDuck

Member Since 20 Jun 2012
Offline Last Active Jun 28 2012 10:05 AM

Topics I've Started

[SDL] SDL_Rect array

26 June 2012 - 06:05 AM

Hello,
At the moment i'm trying implement plaforms in my 2d platformer. I want to store the platform data in an array of SDL_Rects. This is what I have:

In my header:
private:
		SDL_Rect rPlatformArray[20];//maximum platforms in a level is 20 (for now)

This is how I change the array data:

if (type == 4){
  rPlatformArray[NumberOfPlatforms].x = x;
  rPlatformArray[NumberOfPlatforms].y = y;
  rPlatformArray[NumberOfPlatforms].h = h;
  rPlatformArray[NumberOfPlatforms].w = w;
  NumberOfPlatforms++;
}

And for rendering:

for (int i = 0; i <= NumberOfPlatforms;i++){
  SDL_FillRect(screen,&rPlatformArray[i],0xFFFFFF);
}

The problem seems to occur when I try to run the second code block.
There are no compile errors, only as soon as the game starts it crashes.


Can you help me?
Thanks,
DuckerDuck

[SDL] Timer problem

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 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

PARTNERS