I only know C, no other language.
How do I use a linked list to store projectiles in sdl2?
My bullet currently has an sdl_image, has been queried and has the following properties:
//Bullet is visible
.plasma_rect[0].x = 0,
.plasma_rect[0].y = 0,
.plasma_rect[0].h = 50,
.plasma_rect[0].w = 50,
//Bullet is not visible
.plasma_rect[1].x = 0,
.plasma_rect[1].y = 100,
.plasma_rect[1].h = 50,
.plasma_rect[1].w = 50,
//Player x&y velocity, xvol *3 of player is used as speed of bullet
.player_xvol = 5,
.player_yvol = 5,
How the bullet shoots in the main loop:
update_sprite(&game);
directionbullet(&game);
SDL_RenderClear(game.renderer);
SDL_RenderCopy(game.renderer, game.background_image, NULL, NULL);
SDL_RenderCopyEx(game.renderer, game.player_image, NULL, &game.player_rect, angle, NULL, SDL_FLIP_NONE);
//int i is set globally as 1 initially, but changes to 0 when spacebar is pressed
if(i == 1) {
SDL_RenderCopyEx(game.renderer, game.plasma_image, &game.plasma_rect[i], &game.bullet_dist, angle - 90, NULL, SDL_FLIP_NONE);
}
if(i == 0) {
if(count == 0) {
game.plasma_rect[i].x = game.player_rect.x;
game.plasma_rect[i].y = game.player_rect.y;
weapons_handling(&game);
//angle is calculated in "update_sprite" function, bullet angle is calculated only once here right before it shoots, so that the bullet texture will be facing the direction of the sprite.
bulangle = angle - 90;
count++;
}
SDL_RenderCopyEx(game.renderer, game.plasma_image, NULL, &game.plasma_rect[i], bulangle, NULL, SDL_FLIP_NONE);
if(check(&game)) {
i = 1;
count = 0;
//calculated in "directionbullet" function
Vx = 0;
Vy = 0;
}
}
SDL_RenderPresent(game.renderer);
SDL_Delay(16);
However, doing this only allows me to fire one bullet, wait until the bullet sprite exits view of the screen, then fire again. How do I use a linked list or some other data structure to achieve multiple projectiles firing based on the amount of times I click spacebar without having to wait. I am very new to this, I might not even be asking the right questions, please bare with me.