Skip to content
Snippets Groups Projects
Commit a9f2d27e authored by Taha Belkhiri's avatar Taha Belkhiri
Browse files

added king walk animation

parent a902fdb9
No related branches found
No related tags found
No related merge requests found
No preview for this file type
#include "gest_event.h"
void gestMenu(){
void gestGame(){
SDL_Event event;
while (SDL_PollEvent(&event)){
switch(event.type)
......@@ -33,8 +33,8 @@ void gestMenu(){
void *EventLoop(void *arg){
while(running){
switch(game_state){
case MENU : gestMenu();break;
//case GAME : gestGame();break;
//case MENU : gestMenu();break;
case GAME : gestGame();break;
default:printf("game state fault");break;
}
}
......
......@@ -13,6 +13,15 @@ SDL_Texture * character_walk_texture;
SDL_Texture * character_jump_texture;
SDL_Texture * character_attack_texture;
int character_walk_w;
int character_walk_h;
int character_jump_w;
int character_jump_h;
int character_attack_w;
int character_attack_h;
void CreateWindow(){
SDL_DisplayMode ScreenDimension;
......@@ -46,13 +55,32 @@ void CreateWindow(){
}
void Game(){
void Game(int step){
SDL_RenderClear(renderer);
SDL_Rect character_walk_rect;
character_walk_rect.x = step;
character_walk_rect.y = 0;
character_walk_rect.w = 100;
character_walk_rect.h = 250;
if (step < 100){
SDL_Rect destRect;
destRect.w = character_walk_w/8;
destRect.h = character_walk_h;
destRect.x = (destRect.w * step)%character_walk_w;
destRect.y = 0;
SDL_RenderCopyEx(renderer, character_walk_texture, &destRect, &character_walk_rect, 0, NULL, SDL_FLIP_NONE);
}
SDL_RenderPresent(renderer);
SDL_Delay(100);
}
void MainLoop(){
CreateWindow();
int step = 0;
character_walk_surface = IMG_Load("Res/king_run_spritesheet.png");
character_jump_surface = IMG_Load("Res/king_jump_spritesheet.png");
......@@ -66,6 +94,10 @@ void MainLoop(){
SDL_FreeSurface(character_jump_surface);
SDL_FreeSurface(character_attack_surface);
SDL_QueryTexture(character_walk_texture, NULL, NULL, &character_walk_w, &character_walk_h);
SDL_QueryTexture(character_jump_texture, NULL, NULL, &character_jump_w, &character_jump_h);
SDL_QueryTexture(character_attack_texture, NULL, NULL, &character_attack_w, &character_attack_h);
unsigned int a = SDL_GetTicks();
unsigned int b = SDL_GetTicks();
double delta = 0;
......@@ -83,7 +115,8 @@ void MainLoop(){
b = a;
switch (game_state){
case GAME:
Game();
Game(step);
step++;
break;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment