Merge branch 'master' of ssh.marcbarbier.fr:Marc/gamejam-polytech
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
+76
-16
@@ -1,4 +1,5 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include <math.h>
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
#include <SDL2/SDL_mixer.h>
|
#include <SDL2/SDL_mixer.h>
|
||||||
#include <SDL2/SDL_surface.h>
|
#include <SDL2/SDL_surface.h>
|
||||||
@@ -9,7 +10,7 @@
|
|||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
|
||||||
#define SPEED 1.f/10000000000
|
#define SLIDER_SPEED 1.f/5000
|
||||||
#define GRAVITY 10000.f
|
#define GRAVITY 10000.f
|
||||||
|
|
||||||
static Mix_Music * music;
|
static Mix_Music * music;
|
||||||
@@ -24,7 +25,8 @@ static const float startPersonPositionY = CAMERA_HEIGHT * 0.4f;
|
|||||||
static float personPositionX = startPersonPositionX;
|
static float personPositionX = startPersonPositionX;
|
||||||
static float personPositionY = startPersonPositionY;
|
static float personPositionY = startPersonPositionY;
|
||||||
|
|
||||||
static const float personVelocityX = 200;
|
static const float startPersonVelocityX = 200;
|
||||||
|
static float personVelocityX = 200;
|
||||||
static float personVelocityY = 0;
|
static float personVelocityY = 0;
|
||||||
|
|
||||||
float jetons = 0.f;
|
float jetons = 0.f;
|
||||||
@@ -41,14 +43,31 @@ RenderId_t victims[VICTIME_COUNT];
|
|||||||
|
|
||||||
#define ADAME_KEYFRAMES 7
|
#define ADAME_KEYFRAMES 7
|
||||||
RenderId_t adame[ADAME_KEYFRAMES];
|
RenderId_t adame[ADAME_KEYFRAMES];
|
||||||
float adame_accu = 0;
|
static float adame_accu = 0;
|
||||||
int adame_id;
|
static int adame_id;
|
||||||
bool kicked = false;
|
static bool kicked = false;
|
||||||
#define ADAME_SPEED 1.f/250
|
#define ADAME_SPEED 1.f/250
|
||||||
#define ADAME_SIZE 2.5f
|
#define ADAME_SIZE 2.5f
|
||||||
#define ADAME_Y round(CAMERA_HEIGHT * 0.30f)
|
#define ADAME_Y round(CAMERA_HEIGHT * 0.30f)
|
||||||
#define ADAME_X round(CAMERA_WIDTH * 0.01f)
|
#define ADAME_X round(CAMERA_WIDTH * 0.01f)
|
||||||
|
|
||||||
|
static RenderObject_t strengthBar;
|
||||||
|
static RenderId_t strengthBarId;
|
||||||
|
static float strength = 0.f;
|
||||||
|
static bool increaseStrength = true;
|
||||||
|
|
||||||
|
|
||||||
|
static float adameStrength = 2.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(){
|
static void playMusic(){
|
||||||
music = Mix_LoadMUS("./assets/music/jojo arab.mp3");
|
music = Mix_LoadMUS("./assets/music/jojo arab.mp3");
|
||||||
if(music == NULL) {
|
if(music == NULL) {
|
||||||
@@ -208,23 +227,58 @@ int game_staticRender(void){
|
|||||||
scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int game_render([[maybe_unused]] float delta){
|
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;
|
deltaAccu += delta;
|
||||||
|
|
||||||
if(!kicked && isSpaceKeypressed) {
|
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(strength != 0 && !kicked && isSpaceKeypressed) {
|
||||||
adame_accu += delta;
|
adame_accu += delta;
|
||||||
printf("%f\n", adame_accu);
|
printf("%f\n", adame_accu);
|
||||||
if(adame_accu >= ADAME_SPEED) {
|
if(adame_accu >= ADAME_SPEED / strength) {
|
||||||
scene_moveRenderObject(&gameScene, adame[adame_id], 0, CAMERA_HEIGHT * 2);
|
scene_moveRenderObject(&gameScene, adame[adame_id], 0, CAMERA_HEIGHT * 2);
|
||||||
if(adame_id == 6) {
|
if(adame_id == 6) {
|
||||||
scene_moveRenderObject(&gameScene, adame[0], ADAME_X, ADAME_Y);
|
scene_moveRenderObject(&gameScene, adame[0], ADAME_X, ADAME_Y);
|
||||||
@@ -264,8 +318,6 @@ int game_render([[maybe_unused]] float delta){
|
|||||||
scene_moveRenderObject(&gameScene, personId, personPositionX, personPositionY);
|
scene_moveRenderObject(&gameScene, personId, personPositionX, personPositionY);
|
||||||
|
|
||||||
|
|
||||||
// scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,16 +332,24 @@ void game_handleSpaceKeyInput(void){
|
|||||||
crashed = false;
|
crashed = false;
|
||||||
personPositionX = startPersonPositionX;
|
personPositionX = startPersonPositionX;
|
||||||
personPositionY = startPersonPositionY;
|
personPositionY = startPersonPositionY;
|
||||||
|
personVelocityX = startPersonVelocityX;
|
||||||
personVelocityY = 0;
|
personVelocityY = 0;
|
||||||
isSpaceKeypressed = false;
|
isSpaceKeypressed = false;
|
||||||
gameScene.x = 0;
|
gameScene.x = 0;
|
||||||
gameScene.y = 0;
|
gameScene.y = 0;
|
||||||
|
strengthBarSliderDistance = 0.f;
|
||||||
scene_moveRenderObject(&gameScene, scoreTextId, gameScene.x + 2, 0);
|
scene_moveRenderObject(&gameScene, scoreTextId, gameScene.x + 2, 0);
|
||||||
|
scene_moveRenderObject(&gameScene, strengthBarId, 0.30f * CAMERA_WIDTH, 0.9 * CAMERA_HEIGHT);
|
||||||
scene_moveRenderObject(&gameScene, personId, 0, CAMERA_HEIGHT * 2);
|
scene_moveRenderObject(&gameScene, personId, 0, CAMERA_HEIGHT * 2);
|
||||||
personId = victims[rand() % 4];
|
personId = victims[rand() % 4];
|
||||||
kicked=false;
|
kicked=false;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
isSpaceKeypressed = true;
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-2
@@ -8,7 +8,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
const RenderObject_t EMPTY_RENDER_OBJECT = { 0, 0, 0, 0, NULL, "Undefined" };
|
const RenderObject_t EMPTY_RENDER_OBJECT = { 0, 0.f, 0.f, 0.f, 0.f, 0.f, NULL, "Undefined" };
|
||||||
|
|
||||||
static int compartSort(const SceneObject_t * a, const SceneObject_t * b) {
|
static int compartSort(const SceneObject_t * a, const SceneObject_t * b) {
|
||||||
return a->renderObj.z - b->renderObj.z;
|
return a->renderObj.z - b->renderObj.z;
|
||||||
@@ -30,7 +30,17 @@ void scene_render(const Scene_t * scene) {
|
|||||||
round(object->renderObj.height * monitorSize.height)
|
round(object->renderObj.height * monitorSize.height)
|
||||||
};
|
};
|
||||||
|
|
||||||
int error = SDL_RenderCopyEx(renderer, object->cache, NULL, &rect, object->renderObj.angle_degre, NULL, SDL_FLIP_NONE);
|
int error;
|
||||||
|
|
||||||
|
if(object->renderObj.angle_x == FLT_MIN || object->renderObj.angle_y == FLT_MIN){
|
||||||
|
error = SDL_RenderCopyEx(renderer, object->cache, NULL, &rect, object->renderObj.angle_degre, NULL, SDL_FLIP_NONE);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
SDL_Point center;
|
||||||
|
center.x = object->renderObj.angle_x * rect.w;
|
||||||
|
center.x = object->renderObj.angle_y * rect.h;
|
||||||
|
error = SDL_RenderCopyEx(renderer, object->cache, NULL, &rect, object->renderObj.angle_degre, ¢er, SDL_FLIP_NONE);
|
||||||
|
}
|
||||||
if(error != 0) {
|
if(error != 0) {
|
||||||
fprintf(stderr, "Render error in object %d with error %s\n", object->id, SDL_GetError());
|
fprintf(stderr, "Render error in object %d with error %s\n", object->id, SDL_GetError());
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ typedef struct RenderObject {
|
|||||||
int z;
|
int z;
|
||||||
float width, height; //ratio between 0 & 1 of the monitor resolution
|
float width, height; //ratio between 0 & 1 of the monitor resolution
|
||||||
float angle_degre;
|
float angle_degre;
|
||||||
|
float angle_x, angle_y; // position for the center of the rotation
|
||||||
SDL_Surface * surface;
|
SDL_Surface * surface;
|
||||||
char name[40];
|
char name[40];
|
||||||
} RenderObject_t;
|
} RenderObject_t;
|
||||||
|
|||||||
Reference in New Issue
Block a user