Strength
This commit is contained in:
@@ -6,6 +6,7 @@ endif()
|
|||||||
|
|
||||||
if(CMAKE_BUILD_TYPE MATCHES DEBUG)
|
if(CMAKE_BUILD_TYPE MATCHES DEBUG)
|
||||||
add_link_options(-fsanitize=address)
|
add_link_options(-fsanitize=address)
|
||||||
|
add_definitions(DEBUG)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wmaybe-uninitialized -Wno-unused-variable")
|
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
@@ -6,11 +6,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <limits.h>
|
||||||
#include "scaller.h"
|
#include "scaller.h"
|
||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
|
|
||||||
#define SLIDER_SPEED 1.f/5000
|
|
||||||
#define GRAVITY 10000.f
|
#define GRAVITY 10000.f
|
||||||
|
|
||||||
static Mix_Music * music;
|
static Mix_Music * music;
|
||||||
@@ -64,26 +66,31 @@ static float strengthBarSliderDistance = 0.f;
|
|||||||
static RenderId_t strengthBarSliderId;
|
static RenderId_t strengthBarSliderId;
|
||||||
static bool increaseStrengthBarSlider = true;
|
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(){
|
static void playMusic(){
|
||||||
music = Mix_LoadMUS("./assets/music/jojo arab.mp3");
|
music = Mix_LoadMUS("./assets/music/game.wav");
|
||||||
if(music == NULL) {
|
if(music == NULL) {
|
||||||
fprintf(stderr, "Jojo arab not found!\n");
|
fprintf(stderr, "Game audio not found!\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(Mix_PlayMusic(music, 0) != 0){
|
if(Mix_PlayMusic(music, 0) != 0){
|
||||||
// printf("Music sound could not be played!\n"
|
printf("Music sound could not be played!\n"
|
||||||
// "SDL_Error: %s\n", Mix_GetError());
|
"SDL_Error: %s\n", Mix_GetError());
|
||||||
// Mix_FreeMusic(music);
|
Mix_FreeMusic(music);
|
||||||
// running = false;
|
running = false;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int game_staticRender(void){
|
int game_staticRender(void){
|
||||||
|
input_listenKeyDown(SDL_SCANCODE_F, game_handleFKeyInput);
|
||||||
playMusic();
|
playMusic();
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
@@ -223,7 +230,7 @@ int game_staticRender(void){
|
|||||||
scoreText = EMPTY_RENDER_OBJECT;
|
scoreText = EMPTY_RENDER_OBJECT;
|
||||||
strcpy(scoreText.name, "scoreText");
|
strcpy(scoreText.name, "scoreText");
|
||||||
SDL_Color black = {0, 0, 0, 255};
|
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);
|
scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
|
||||||
|
|
||||||
|
|
||||||
@@ -244,21 +251,16 @@ int game_staticRender(void){
|
|||||||
strengthBarSlider.height = 0.05f;
|
strengthBarSlider.height = 0.05f;
|
||||||
strengthBarSliderId = scene_addRenderObject(&gameScene, strengthBarSlider, 0.30f * CAMERA_WIDTH, 0.89f * CAMERA_HEIGHT);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int game_render([[maybe_unused]] float delta){
|
int game_render(float delta){
|
||||||
deltaAccu += delta;
|
deltaAccu += delta;
|
||||||
|
|
||||||
if(!isSpaceKeypressed && !crashed && deltaAccu >= SLIDER_SPEED){
|
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)
|
if(increaseStrengthBarSlider && strengthBarSliderDistance >= 0.50f)
|
||||||
increaseStrengthBarSlider = false;
|
increaseStrengthBarSlider = false;
|
||||||
else if(increaseStrengthBarSlider){
|
else if(increaseStrengthBarSlider){
|
||||||
@@ -302,22 +304,22 @@ int game_render([[maybe_unused]] float delta){
|
|||||||
|
|
||||||
personPositionY += personVelocityY * delta;
|
personPositionY += personVelocityY * delta;
|
||||||
jetons += distance;
|
jetons += distance;
|
||||||
|
if(jetons > (float)ULONG_MAX)
|
||||||
|
jetons = (float)ULONG_MAX;
|
||||||
scene_moveRenderObject(&gameScene, scoreTextId, gameScene.x + 2, 0);
|
scene_moveRenderObject(&gameScene, scoreTextId, gameScene.x + 2, 0);
|
||||||
|
|
||||||
if(personPositionY + CAMERA_HEIGHT * victimHeight >= CAMERA_HEIGHT - 18){
|
if(personPositionY + CAMERA_HEIGHT * victimHeight >= CAMERA_HEIGHT - 18){
|
||||||
crashed = true;
|
crashed = true;
|
||||||
scene_removeRenderObject(&gameScene, scoreTextId);
|
scene_removeRenderObject(&gameScene, scoreTextId);
|
||||||
SDL_Color black = {0, 0, 0, 255};
|
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);
|
scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scene_moveRenderObject(&gameScene, steroidText, STEROIDS_POSITION + gameScene.x, 0);
|
||||||
scene_moveRenderObject(&gameScene, personId, personPositionX, personPositionY);
|
scene_moveRenderObject(&gameScene, personId, personPositionX, personPositionY);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,8 +328,22 @@ void game_remove(void){
|
|||||||
Mix_FreeMusic(music);
|
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){
|
void game_handleSpaceKeyInput(void){
|
||||||
|
#ifdef DEBUG
|
||||||
|
if(isSpaceKeypressed == true && !crashed)return;
|
||||||
|
#endif
|
||||||
if(crashed){
|
if(crashed){
|
||||||
crashed = false;
|
crashed = false;
|
||||||
personPositionX = startPersonPositionX;
|
personPositionX = startPersonPositionX;
|
||||||
@@ -350,6 +366,5 @@ void game_handleSpaceKeyInput(void){
|
|||||||
personVelocityX *= strength * adameStrength;
|
personVelocityX *= strength * adameStrength;
|
||||||
scene_moveRenderObject(&gameScene, strengthBarId, 0, CAMERA_HEIGHT * 2);
|
scene_moveRenderObject(&gameScene, strengthBarId, 0, CAMERA_HEIGHT * 2);
|
||||||
scene_moveRenderObject(&gameScene, strengthBarSliderId, 0, CAMERA_HEIGHT * 2);
|
scene_moveRenderObject(&gameScene, strengthBarSliderId, 0, CAMERA_HEIGHT * 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,6 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <SDL2/SDL_scancode.h>
|
#include <SDL2/SDL_scancode.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@@ -81,4 +82,3 @@ void input_removeKeyUpListener(SDL_Scancode code, keyEvent_t handler) {
|
|||||||
}
|
}
|
||||||
eventKeyUp_counts[code]--;
|
eventKeyUp_counts[code]--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user