Answer the question
In order to leave comments, you need to log in
(SDL2 + C) Creating a game level with tiles in a 2D platformer game and collision detect, ways?
I'm trying to make a 2D platformer in C with SDL2, I settled on creating a level and checking for collisions, in general, how to do this is clear, I can draw one object and make it collide with another, but I need to draw a large level, and here is the complexity.
At first there was a question of how, in fact, to create a level, platforms on which the character will run. My level consists of many tiles of 20x20 pixels in size, I chose the method from Google with a two-dimensional array, in which there will be p and b, p - empty, b - block. Next, two loops are made with a pass through each element of the array, and if the element is equal to b, then a block is drawn there, something like this:
for (int y = 0; y < arrow_size; y++){
for (int x = 0; x < arrow_size; x++){
if(my_level[y][x] == 'b'){
SDL_Rect block_info = {(x * 20), (y * 20), 20, 20)
SDL_RenderCopy(render,block_texture, NULL, &block_info);
}
}
}
Answer the question
In order to leave comments, you need to log in
When pressing the movement key, check if there is a wall block there. If not, move the character; if there is, don't move.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question