add score
This commit is contained in:
+33
-9
@@ -3,6 +3,7 @@
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#include <SDL2/SDL_surface.h>
|
||||
#include "scaller.h"
|
||||
#include "text.h"
|
||||
|
||||
#define SPEED 1.f/10000000000
|
||||
#define GRAVITY 10000.f
|
||||
@@ -24,6 +25,8 @@ static float personPositionY = startPersonPositionY;
|
||||
static const float personVelocityX = 200;
|
||||
static float personVelocityY = 0;
|
||||
|
||||
float jetons = 0.f;
|
||||
|
||||
|
||||
static void playMusic(){
|
||||
music = Mix_LoadMUS("./assets/music/jojo arab.mp3");
|
||||
@@ -32,12 +35,12 @@ static void playMusic(){
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(Mix_PlayMusic(music, 0) != 0){
|
||||
printf("Music sound could not be played!\n"
|
||||
"SDL_Error: %s\n", Mix_GetError());
|
||||
Mix_FreeMusic(music);
|
||||
running = false;
|
||||
}
|
||||
// if(Mix_PlayMusic(music, 0) != 0){
|
||||
// printf("Music sound could not be played!\n"
|
||||
// "SDL_Error: %s\n", Mix_GetError());
|
||||
// Mix_FreeMusic(music);
|
||||
// running = false;
|
||||
// }
|
||||
}
|
||||
|
||||
int game_staticRender(void){
|
||||
@@ -93,19 +96,29 @@ int game_render([[maybe_unused]] float delta){
|
||||
person.surface = personSurface;
|
||||
person.width = 0.25f;
|
||||
scaller(person.surface, 0.05f, &person.width, &person.height);
|
||||
// if(!crashed && deltaAccu >= SPEED && isSpaceKeypressed){
|
||||
if(!crashed && isSpaceKeypressed){
|
||||
personPositionX += personVelocityX * delta;
|
||||
const float distance = personVelocityX * delta;
|
||||
personPositionX += distance;
|
||||
gameScene.x = personPositionX - startPersonPositionX;
|
||||
|
||||
personVelocityY += GRAVITY * delta;
|
||||
|
||||
personPositionY += personVelocityY * delta;
|
||||
if(personPositionY + CAMERA_HEIGHT * person.height >= CAMERA_HEIGHT - 2) crashed = true;
|
||||
|
||||
jetons += distance;
|
||||
}
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&gameScene, person, personPositionX, personPositionY);
|
||||
++menuObjectsSize;
|
||||
|
||||
|
||||
RenderObject_t scoreText;
|
||||
strcpy(scoreText.name, "scoreText");
|
||||
SDL_Color black = {0, 0, 0, 255};
|
||||
text_renderText(&scoreText, 50, 0.5f, black, "./assets/fonts/Quinquefive.ttf", 40, "jetons: %d", (unsigned)jetons);
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
|
||||
++menuObjectsSize;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -117,5 +130,16 @@ void game_remove(void){
|
||||
|
||||
|
||||
void game_handleSpaceKeyInput(void){
|
||||
isSpaceKeypressed = true;
|
||||
if(crashed){
|
||||
crashed = false;
|
||||
personPositionX = startPersonPositionX;
|
||||
personPositionY = startPersonPositionY;
|
||||
personVelocityY = 0;
|
||||
isSpaceKeypressed = false;
|
||||
gameScene.x = 0;
|
||||
gameScene.y = 0;
|
||||
}
|
||||
else{
|
||||
isSpaceKeypressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user