strength bar
This commit is contained in:
+69
-11
@@ -1,4 +1,5 @@
|
||||
#include "game.h"
|
||||
#include <math.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#include <SDL2/SDL_surface.h>
|
||||
@@ -6,7 +7,7 @@
|
||||
#include "scene.h"
|
||||
#include "text.h"
|
||||
|
||||
#define SPEED 1.f/10000000000
|
||||
#define SLIDER_SPEED 1.f/500
|
||||
#define GRAVITY 10000.f
|
||||
|
||||
static Mix_Music * music;
|
||||
@@ -21,7 +22,8 @@ static const float startPersonPositionY = CAMERA_HEIGHT * 0.4f;
|
||||
static float personPositionX = startPersonPositionX;
|
||||
static float personPositionY = startPersonPositionY;
|
||||
|
||||
static const float personVelocityX = 200;
|
||||
static const float startPersonVelocityX = 200;
|
||||
static float personVelocityX = 200;
|
||||
static float personVelocityY = 0;
|
||||
|
||||
float jetons = 0.f;
|
||||
@@ -31,6 +33,22 @@ static RenderId_t personId;
|
||||
RenderObject_t scoreText;
|
||||
static RenderId_t scoreTextId = -1;
|
||||
|
||||
static RenderObject_t strengthBar;
|
||||
static RenderId_t strengthBarId;
|
||||
static float strength = 0.f;
|
||||
static bool increaseStrength = true;
|
||||
|
||||
|
||||
static float adameStrength = 1.f; // this value is not const as it will be possible to improve the strenght of Adame.
|
||||
|
||||
static RenderObject_t strengthBarSlider;
|
||||
static float strengthBarSliderDistance = 0.f;
|
||||
static RenderId_t strengthBarSliderId;
|
||||
static bool increaseStrengthBarSlider = true;
|
||||
|
||||
|
||||
|
||||
|
||||
static void playMusic(){
|
||||
music = Mix_LoadMUS("./assets/music/jojo arab.mp3");
|
||||
if(music == NULL) {
|
||||
@@ -91,20 +109,54 @@ int game_staticRender(void){
|
||||
scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
|
||||
|
||||
|
||||
SDL_Surface* strengthBarSurface = IMG_Load("./assets/img/strengthBar.png");
|
||||
strcpy(strengthBar.name, "strengthBar");
|
||||
strengthBar.z = 100;
|
||||
strengthBar.surface = strengthBarSurface;
|
||||
strengthBar.width = 0.50f;
|
||||
strengthBar.height = 0.025f;
|
||||
strengthBarId = scene_addRenderObject(&gameScene, strengthBar, 0.30f * CAMERA_WIDTH, 0.9f * CAMERA_HEIGHT);
|
||||
|
||||
|
||||
SDL_Surface* strengthBarSliderSurface = IMG_Load("./assets/img/building.png");
|
||||
strcpy(strengthBarSlider.name, "strengthBarSlider");
|
||||
strengthBarSlider.z = 101;
|
||||
strengthBarSlider.surface = strengthBarSliderSurface;
|
||||
strengthBarSlider.width = 0.005f;
|
||||
strengthBarSlider.height = 0.05f;
|
||||
strengthBarSliderId = scene_addRenderObject(&gameScene, strengthBarSlider, 0.30f * CAMERA_WIDTH, 0.89f * CAMERA_HEIGHT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int game_render([[maybe_unused]] float delta){
|
||||
//for(unsigned i = 0; i < menuObjectsSize; ++i){
|
||||
// scene_removeRenderObject(&gameScene, menuObjects[i]);
|
||||
//}
|
||||
// if(scoreTextId > 0)
|
||||
// scene_removeRenderObject(&gameScene, scoreTextId);
|
||||
|
||||
|
||||
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){
|
||||
strengthBarSliderDistance += 0.005f;
|
||||
scene_moveRenderObject(&gameScene, strengthBarSliderId, 0.30f * CAMERA_WIDTH + strengthBarSliderDistance * CAMERA_WIDTH, 0.89f * CAMERA_HEIGHT);
|
||||
}
|
||||
else if(!increaseStrengthBarSlider && strengthBarSliderDistance <= 0.0001f)
|
||||
increaseStrengthBarSlider = true;
|
||||
else{
|
||||
strengthBarSliderDistance -= 0.005f;
|
||||
scene_moveRenderObject(&gameScene, strengthBarSliderId, 0.30f * CAMERA_WIDTH + strengthBarSliderDistance * CAMERA_WIDTH, 0.89f * CAMERA_HEIGHT);
|
||||
}
|
||||
|
||||
deltaAccu = 0;
|
||||
}
|
||||
// if(!crashed && deltaAccu >= SPEED && isSpaceKeypressed){
|
||||
if(!crashed && isSpaceKeypressed){
|
||||
const float distance = personVelocityX * delta;
|
||||
@@ -131,8 +183,6 @@ int game_render([[maybe_unused]] float delta){
|
||||
scene_moveRenderObject(&gameScene, personId, personPositionX, personPositionY);
|
||||
|
||||
|
||||
// scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -147,13 +197,21 @@ void game_handleSpaceKeyInput(void){
|
||||
crashed = false;
|
||||
personPositionX = startPersonPositionX;
|
||||
personPositionY = startPersonPositionY;
|
||||
personVelocityX = startPersonVelocityX;
|
||||
personVelocityY = 0;
|
||||
isSpaceKeypressed = false;
|
||||
gameScene.x = 0;
|
||||
gameScene.y = 0;
|
||||
strengthBarSliderDistance = 0.f;
|
||||
scene_moveRenderObject(&gameScene, scoreTextId, gameScene.x + 2, 0);
|
||||
scene_moveRenderObject(&gameScene, strengthBarId, 0.30f * CAMERA_WIDTH, 0.9f * CAMERA_HEIGHT);
|
||||
}
|
||||
else{
|
||||
isSpaceKeypressed = true;
|
||||
strength = - 32 * powf(fabs(strengthBarSliderDistance - 0.5f/2), 2) + 2;
|
||||
personVelocityX *= strength * adameStrength;
|
||||
scene_moveRenderObject(&gameScene, strengthBarId, 0, CAMERA_HEIGHT * 2);
|
||||
scene_moveRenderObject(&gameScene, strengthBarSliderId, 0, CAMERA_HEIGHT * 2);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user