This commit is contained in:
Marc
2023-01-22 16:59:08 +01:00
parent 7e5fb1c83a
commit 1bea67f658
5 changed files with 251 additions and 235 deletions
+1
View File
@@ -6,6 +6,7 @@ endif()
if(CMAKE_BUILD_TYPE MATCHES DEBUG)
add_link_options(-fsanitize=address)
add_definitions(DEBUG)
endif()
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wmaybe-uninitialized -Wno-unused-variable")
Binary file not shown.
Binary file not shown.
+39 -24
View File
@@ -6,11 +6,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include "scaller.h"
#include "scene.h"
#include "text.h"
#include "input.h"
#define SLIDER_SPEED 1.f/5000
#define GRAVITY 10000.f
static Mix_Music * music;
@@ -64,26 +66,31 @@ static float strengthBarSliderDistance = 0.f;
static RenderId_t strengthBarSliderId;
static bool increaseStrengthBarSlider = true;
#define STEROIDS_POSITION CAMERA_WIDTH * 0.4f
#define SLIDER_SPEED (1.f/5000 / (adameStrength *0.5f))
void game_handleFKeyInput(void);
RenderId_t steroidText;
static void playMusic(){
music = Mix_LoadMUS("./assets/music/jojo arab.mp3");
music = Mix_LoadMUS("./assets/music/game.wav");
if(music == NULL) {
fprintf(stderr, "Jojo arab not found!\n");
fprintf(stderr, "Game audio not found!\n");
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){
input_listenKeyDown(SDL_SCANCODE_F, game_handleFKeyInput);
playMusic();
srand(time(NULL));
@@ -223,7 +230,7 @@ int game_staticRender(void){
scoreText = EMPTY_RENDER_OBJECT;
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);
text_renderText(&scoreText, 50, 0.5f, black, "./assets/fonts/Quinquefive.ttf", 40, "jetons: %lu", (unsigned long)jetons);
scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
@@ -244,21 +251,16 @@ int game_staticRender(void){
strengthBarSlider.height = 0.05f;
strengthBarSliderId = scene_addRenderObject(&gameScene, strengthBarSlider, 0.30f * CAMERA_WIDTH, 0.89f * CAMERA_HEIGHT);
text_renderText(&scoreText, 50, 1.f, black, "./assets/fonts/Quinquefive.ttf", 20, "Press F to buy steroids for 200J");
steroidText = scene_addRenderObject(&gameScene, scoreText, STEROIDS_POSITION, 0);
return 0;
}
int game_render([[maybe_unused]] float delta){
int game_render(float delta){
deltaAccu += delta;
if(!isSpaceKeypressed && !crashed && deltaAccu >= SLIDER_SPEED){
// if(increaseStrength && strength >= 2.f)
// increaseStrength = false;
// else if(increaseStrength)
// strength += 0.1;
// else if(!increaseStrength && strength <= 0.f)
// increaseStrength = true;
// else
// strength -= 0.1;
if(increaseStrengthBarSlider && strengthBarSliderDistance >= 0.50f)
increaseStrengthBarSlider = false;
else if(increaseStrengthBarSlider){
@@ -302,22 +304,22 @@ int game_render([[maybe_unused]] float delta){
personPositionY += personVelocityY * delta;
jetons += distance;
if(jetons > (float)ULONG_MAX)
jetons = (float)ULONG_MAX;
scene_moveRenderObject(&gameScene, scoreTextId, gameScene.x + 2, 0);
if(personPositionY + CAMERA_HEIGHT * victimHeight >= CAMERA_HEIGHT - 18){
crashed = true;
scene_removeRenderObject(&gameScene, scoreTextId);
SDL_Color black = {0, 0, 0, 255};
text_renderText(&scoreText, 50, 0.5f, black, "./assets/fonts/Quinquefive.ttf", 40, "jetons: %d", (unsigned)jetons);
text_renderText(&scoreText, 50, 0.5f, black, "./assets/fonts/Quinquefive.ttf", 40, "jetons: %lu", (unsigned long)jetons);
scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
}
}
scene_moveRenderObject(&gameScene, steroidText, STEROIDS_POSITION + gameScene.x, 0);
scene_moveRenderObject(&gameScene, personId, personPositionX, personPositionY);
return 0;
}
@@ -326,8 +328,22 @@ void game_remove(void){
Mix_FreeMusic(music);
}
void game_handleFKeyInput(void) {
printf("coucou %f\n", jetons);
if(jetons > 200) {
jetons -= 200;
adameStrength += 0.5f;
scene_removeRenderObject(&gameScene, scoreTextId);
SDL_Color black = {0, 0, 0, 255};
text_renderText(&scoreText, 50, 0.5f, black, "./assets/fonts/Quinquefive.ttf", 40, "jetons: %lu", (unsigned long)jetons);
scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
}
}
void game_handleSpaceKeyInput(void){
#ifdef DEBUG
if(isSpaceKeypressed == true && !crashed)return;
#endif
if(crashed){
crashed = false;
personPositionX = startPersonPositionX;
@@ -350,6 +366,5 @@ void game_handleSpaceKeyInput(void){
personVelocityX *= strength * adameStrength;
scene_moveRenderObject(&gameScene, strengthBarId, 0, CAMERA_HEIGHT * 2);
scene_moveRenderObject(&gameScene, strengthBarSliderId, 0, CAMERA_HEIGHT * 2);
}
}
+1 -1
View File
@@ -1,5 +1,6 @@
#include "input.h"
#include <SDL2/SDL_scancode.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
@@ -81,4 +82,3 @@ void input_removeKeyUpListener(SDL_Scancode code, keyEvent_t handler) {
}
eventKeyUp_counts[code]--;
}