Collision Detection - 2D side scroller
Posted: Thu Nov 25, 2021 6:29 am
Hi Everyone
Awesome forum! I've been getting a lot of information here but now I'm stuck and hope someone here can assist me.
I'm currently busy creating a 2D side scroller (like Shinobi, Sonic etc).
I've worked through the Sonic example in the samples folder of SGDK and I've worked through this tutorial: https://under-prog.ru/en/sgdk-creating- ... a-genesis/ for collision detection.
The tutorial creates a 2D array and each value in the array represents a tile on the stage. The values are 0 for blocking and 1 for allowed movement. Then when the code that moves the sprite runs, it first checks if the sprite is going to move into space it is allowed to:
leftTile, RightTile, TopTile and bottomTile is just the corner tiles of the sprite.
I tried then to apply the collision detection to the Sonic example and ran into the problem that I cannot create a 2D array for a stage that is 160 x 1280 tiles big. If I create the array as a global variable the code does not compile and if I create it inside my stage_1() function then I get an "illegal instruction" error once the stage tries to load.
What I found interesting is that I can create the array and even have the following:
And the code will compille and game will run, I'm guessing the compiler is clever enough to realise the if statement does not do anything and just skips compiling that code into the ROM?
So my question is: What is the right way to code collision detection in 2D side scrollers that have stages that are bigger then just a screen or two's width?
I am assuming this is a RAM space issue, how can I then load the array into RAM for a big stage? My code is failing even with a 30 x 100 array (which is very small for a stage in any case)
Awesome forum! I've been getting a lot of information here but now I'm stuck and hope someone here can assist me.
I'm currently busy creating a 2D side scroller (like Shinobi, Sonic etc).
I've worked through the Sonic example in the samples folder of SGDK and I've worked through this tutorial: https://under-prog.ru/en/sgdk-creating- ... a-genesis/ for collision detection.
The tutorial creates a 2D array
Code: Select all
u8 level[row][col] //size of whole stage
Code: Select all
for(s16 i=leftTile; i <=rightTile; i++)
{
for(s16 j=topTile; j <=bottomTile; j++)
{
if(level [j][i] == 0) {
return FALSE;
}
}
}
return TRUE;
I tried then to apply the collision detection to the Sonic example and ran into the problem that I cannot create a 2D array for a stage that is 160 x 1280 tiles big. If I create the array as a global variable the code does not compile and if I create it inside my stage_1() function then I get an "illegal instruction" error once the stage tries to load.
What I found interesting is that I can create the array and even have the following:
Code: Select all
if(level [j][i] == 0) {
//return FALSE;
int dummy = 0;
}
So my question is: What is the right way to code collision detection in 2D side scrollers that have stages that are bigger then just a screen or two's width?
I am assuming this is a RAM space issue, how can I then load the array into RAM for a big stage? My code is failing even with a 30 x 100 array (which is very small for a stage in any case)