Hello!
This is the first time i use SDL in my software life
. I have seen alot of videos to help me structure my mind to think correctly when using this library.
I am currently doing a little game in C using this library for my assignment and the game is essentially the replica of superhexagon. (https://www.superhexagon.com/)
In my project, i use sdl2.h :
#include <SDL.h> #include <SDL_image.h> #include <SDL2_gfxPrimitives.h>
I’ve structured the project for it to contain :
- assets → all sorts of images for my menu
- src → main.c, application.c, menu.c, game.c, spritesheet.c, sdl2.h, Makefile + all the header files
I alredy have understood how to handle events with switch that i have implemented in my menu and a basic form of it in game.c. My program can enter in a “playing” phase when i click on play end come back to the “menu” phase.
example:
//------------------------------------------------------- //We are payng game->state = PLAYING; SDL_Event event; SDL_bool GameRunning = SDL_TRUE; while (GameRunning) //while the player didnt loose, the game is running { while (SDL_PollEvent(&event)) { /* code */ switch (event.type) { //when a key is pressed case SDL_KEYDOWN: //Detecting the pressed key switch (event.key.keysym.sym) { case SDLK_LEFT: printf("Left key pressed\n"); break; case SDLK_RIGHT: printf("Right key pressed\n"); break; default: break; } break; //when a key is unpressed case SDL_KEYUP: switch (event.key.keysym.sym) { case SDLK_LEFT: printf("Left key up\n"); break; case SDLK_RIGHT: printf("Right key up\n"); break; default: break; } break; //if the user quit the game case SDL_QUIT: //The game is over GameRunning = SDL_FALSE; game->state = GAME_OVER; break; default: break; } } }
But except that, i am a little lost when i try to render some arcs (my teacher said to start rendering my objects before i start animating them). I have to use sdl_gfx.
I’ve read the documentation to see how to animate stuff but its hard to have a general view of the steps to follow. For example :
filledCircleRGBA(game->renderer,SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 10,255, 255, 255, 255)
arcRGBA( game->renderer, SCREEN_WIDTH/2, SCREEN_HEIGHT/2, 100, 0, 80, 255, 255, 255, 255 );
//i want to animate this little triangle around my circle, how??
filledTrigonRGBA (game->renderer, CURSOR_POSITION_X-10, CURSOR_POSITION_Y, CURSOR_POSITION_X+10, CURSOR_POSITION_Y, CURSOR_POSITION_X, CURSOR_POSITION_Y+10, 255, 255, 255, 255);
SDL_RenderPresent(game->renderer);
Thank you and sorry for my english (i speak french)

I want to understand how animation works when i render elements using gfx functions…Is it even possible? or do i have to do a type of converson to a movable structure like load the drawn elements into a SDL_Surface first??