Adame animation

This commit is contained in:
Marc
2023-01-22 16:10:52 +01:00
parent 3d4e0c8750
commit 503acf669c
2 changed files with 95 additions and 2 deletions
+95 -1
View File
@@ -2,6 +2,7 @@
#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>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include "scaller.h" #include "scaller.h"
@@ -35,8 +36,19 @@ static int victimHeight;
#define VICTIME_COUNT 4 #define VICTIME_COUNT 4
#define VICTIME_SIZE 0.5f
RenderId_t victims[VICTIME_COUNT]; RenderId_t victims[VICTIME_COUNT];
#define ADAME_KEYFRAMES 7
RenderId_t adame[ADAME_KEYFRAMES];
float adame_accu = 0;
int adame_id;
bool kicked = false;
#define ADAME_SPEED 1.f/250
#define ADAME_SIZE 2.5f
#define ADAME_Y round(CAMERA_HEIGHT * 0.30f)
#define ADAME_X round(CAMERA_WIDTH * 0.01f)
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) {
@@ -120,9 +132,74 @@ int game_staticRender(void){
scaller(person4.surface, 0.5f, &person4.width, &person4.height); scaller(person4.surface, 0.5f, &person4.width, &person4.height);
victims[3] = scene_addRenderObject(&gameScene, person4, 0, CAMERA_HEIGHT * 2); victims[3] = scene_addRenderObject(&gameScene, person4, 0, CAMERA_HEIGHT * 2);
SDL_Surface* adame1 = IMG_Load("./assets/img/adame_1.png");
RenderObject_t adameObject1 = EMPTY_RENDER_OBJECT;
strcpy(adameObject1.name, "adameObject1");
adameObject1.z = 9;
adameObject1.surface = adame1;
adameObject1.width = 0.25f;
scaller(adameObject1.surface, ADAME_SIZE, &adameObject1.width, &adameObject1.height);
adame[0] = scene_addRenderObject(&gameScene, adameObject1, 0, CAMERA_HEIGHT * 2);
SDL_Surface* adame2 = IMG_Load("./assets/img/adame_2.png");
RenderObject_t adameObject2 = EMPTY_RENDER_OBJECT;
strcpy(adameObject2.name, "adameObject2");
adameObject2.z = 9;
adameObject2.surface = adame2;
adameObject2.width = 0.25f;
scaller(adameObject2.surface, ADAME_SIZE, &adameObject2.width, &adameObject2.height);
adame[1] = scene_addRenderObject(&gameScene, adameObject2, 0, CAMERA_HEIGHT * 2);
SDL_Surface* adame3 = IMG_Load("./assets/img/adame_3.png");
RenderObject_t adameObject3 = EMPTY_RENDER_OBJECT;
strcpy(adameObject3.name, "adameObject3");
adameObject3.z = 9;
adameObject3.surface = adame3;
adameObject3.width = 0.25f;
scaller(adameObject3.surface, ADAME_SIZE, &adameObject3.width, &adameObject3.height);
adame[2] = scene_addRenderObject(&gameScene, adameObject3, 0, CAMERA_HEIGHT * 2);
SDL_Surface* adame4 = IMG_Load("./assets/img/adame_4.png");
RenderObject_t adameObject4 = EMPTY_RENDER_OBJECT;
strcpy(adameObject4.name, "adameObject4");
adameObject4.z = 9;
adameObject4.surface = adame4;
adameObject4.width = 0.25f;
scaller(adameObject4.surface, ADAME_SIZE, &adameObject4.width, &adameObject4.height);
adame[3] = scene_addRenderObject(&gameScene, adameObject4, 0, CAMERA_HEIGHT * 2);
SDL_Surface* adame5 = IMG_Load("./assets/img/adame_5.png");
RenderObject_t adameObject5 = EMPTY_RENDER_OBJECT;
strcpy(adameObject5.name, "adameObject5");
adameObject5.z = 9;
adameObject5.surface = adame5;
adameObject5.width = 0.25f;
scaller(adameObject5.surface, ADAME_SIZE, &adameObject5.width, &adameObject5.height);
adame[4] = scene_addRenderObject(&gameScene, adameObject5, 0, CAMERA_HEIGHT * 2);
SDL_Surface* adame6 = IMG_Load("./assets/img/adame_6.png");
RenderObject_t adameObject6 = EMPTY_RENDER_OBJECT;
strcpy(adameObject6.name, "adameObject6");
adameObject6.z = 9;
adameObject6.surface = adame6;
adameObject6.width = 0.25f;
scaller(adameObject6.surface, ADAME_SIZE, &adameObject6.width, &adameObject6.height);
adame[5] = scene_addRenderObject(&gameScene, adameObject6, 0, CAMERA_HEIGHT * 2);
SDL_Surface* adame7 = IMG_Load("./assets/img/adame_7.png");
RenderObject_t person7 = EMPTY_RENDER_OBJECT;
strcpy(person7.name, "person7");
person7.z = 9;
person7.surface = adame7;
person7.width = 0.25f;
scaller(person7.surface, ADAME_SIZE, &person7.width, &person7.height);
adame[6] = scene_addRenderObject(&gameScene, person7, 0, CAMERA_HEIGHT * 2);
adame_id = 0;
victimHeight = person1.height; victimHeight = person1.height;
personId = victims[rand() % 4]; personId = victims[rand() % 4];
scene_moveRenderObject(&gameScene, adame[0], ADAME_X, ADAME_Y);
scoreText = EMPTY_RENDER_OBJECT; scoreText = EMPTY_RENDER_OBJECT;
strcpy(scoreText.name, "scoreText"); strcpy(scoreText.name, "scoreText");
@@ -144,9 +221,25 @@ int game_render([[maybe_unused]] float delta){
deltaAccu += delta; deltaAccu += delta;
if(!kicked && isSpaceKeypressed) {
adame_accu += delta;
printf("%f\n", adame_accu);
if(adame_accu >= ADAME_SPEED) {
scene_moveRenderObject(&gameScene, adame[adame_id], 0, CAMERA_HEIGHT * 2);
if(adame_id == 6) {
scene_moveRenderObject(&gameScene, adame[0], ADAME_X, ADAME_Y);
adame_id = 0;
kicked = true;
} else {
adame_id++;
scene_moveRenderObject(&gameScene, adame[adame_id], ADAME_X, ADAME_Y);
adame_accu = 0;
}
}
}
// if(!crashed && deltaAccu >= SPEED && isSpaceKeypressed){ // if(!crashed && deltaAccu >= SPEED && isSpaceKeypressed){
if(!crashed && isSpaceKeypressed){ if(!crashed && kicked){
const float distance = personVelocityX * delta; const float distance = personVelocityX * delta;
personPositionX += distance; personPositionX += distance;
gameScene.x = personPositionX - startPersonPositionX; gameScene.x = personPositionX - startPersonPositionX;
@@ -194,6 +287,7 @@ void game_handleSpaceKeyInput(void){
scene_moveRenderObject(&gameScene, scoreTextId, gameScene.x + 2, 0); scene_moveRenderObject(&gameScene, scoreTextId, gameScene.x + 2, 0);
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;
} }
else{ else{
isSpaceKeypressed = true; isSpaceKeypressed = true;
-1
View File
@@ -18,7 +18,6 @@ void scene_render(const Scene_t * scene) {
MonitorSize_t monitorSize = renderer_getMonitorSize(); MonitorSize_t monitorSize = renderer_getMonitorSize();
for(int i = 0; i < scene->objectCount; i++) { for(int i = 0; i < scene->objectCount; i++) {
printf("Rendering %d, %s\n", scene->objects[i].id, scene->objects[i].renderObj.name);
const SceneObject_t * object = &scene->objects[i]; const SceneObject_t * object = &scene->objects[i];
float x = (object->x - scene->x) / CAMERA_WIDTH; float x = (object->x - scene->x) / CAMERA_WIDTH;
float y = (object->y - scene->y) / CAMERA_HEIGHT; float y = (object->y - scene->y) / CAMERA_HEIGHT;