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

added player, and walk animation

parent b5f76afd
No related branches found
No related tags found
No related merge requests found
travail_de_groupe/chef_oeuvre/Res/character.png

616 B

travail_de_groupe/chef_oeuvre/Res/character_spritesheet.png

1.06 KiB

No preview for this file type
......@@ -4,6 +4,8 @@ int hover[2];
int x;
int y;
int Keys[10];
void gestMenu(){
SDL_Event event;
while (SDL_PollEvent(&event)){
......@@ -20,6 +22,50 @@ void gestMenu(){
running = 0;
continue;
case SDLK_UP:
Keys[0] = 0;
break;
case SDLK_DOWN:
Keys[1] = 0;
break;
case SDLK_LEFT:
Keys[2] = 0;
break;
case SDLK_RIGHT:
Keys[3] = 0;
break;
default:
continue;
}
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
running = 0;
continue;
case SDLK_UP:
Keys[0] = 1;
break;
case SDLK_DOWN:
Keys[1] = 1;
break;
case SDLK_LEFT:
Keys[2] = 1;
break;
case SDLK_RIGHT:
Keys[3] = 1;
break;
default:
continue;
}
......@@ -28,7 +74,6 @@ void gestMenu(){
case SDL_MOUSEMOTION:
x = (event.motion.x - (ScreenDimension.w - (MAPSIZE * CELLSIZE)) / 2) / CELLSIZE;
y = (event.motion.y - 0) / CELLSIZE;
printf("%d %d\n", x, y);
hover[0] = x;
hover[1] = y;
continue;
......
......@@ -6,6 +6,7 @@
#include "render.h"
extern int hover[2];
extern int Keys[10];
void *EventLoop(void *arg);
......
......@@ -8,6 +8,7 @@ int main(){
running = 1;
game_state = GAME;
readMapFromFile("map.txt");
initPlayer();
MainLoop();
......
......@@ -17,6 +17,7 @@
#include "render.h"
#include "gest_event.h"
#include "map.h"
#include "player.h"
#define MENU 0
......
#include "player.h"
Player_t player;
void initPlayer(){
player.x = 0;
player.y = 0;
player.water_level = 0;
}
void GestMovement(){
if(Keys[0] == 1){
player.y--;
}
if(Keys[1] == 1){
player.y++;
}
if(Keys[2] == 1){
player.x--;
}
if(Keys[3] == 1){
player.x++;
}
}
#ifndef PLAYER_H
#define PLAYER_H
#include "main.h"
typedef struct Player{
int x;
int y;
int water_level;
} Player_t;
extern Player_t player;
void initPlayer();
#endif
\ No newline at end of file
......@@ -15,6 +15,9 @@ SDL_Texture * treeTexture;
SDL_Surface * hoverSurface;
SDL_Texture * hoverTexture;
SDL_Surface * playerSurface;
SDL_Texture * playerTexture;
void CreateWindow(){
if (SDL_Init(SDL_INIT_VIDEO) != 0){
......@@ -70,10 +73,20 @@ void drawMap(){
}
}
void drawPlayer(){
SDL_Rect rect;
rect.h = CELLSIZE;
rect.w = CELLSIZE;
rect.x = player.x * CELLSIZE + (ScreenDimension.w - (MAPSIZE * CELLSIZE)) / 2;
rect.y = player.y * CELLSIZE;
SDL_Rect destRect = {32 * (SDL_GetTicks()/200%4), 0, 32, 32};
SDL_RenderCopyEx(renderer, playerTexture, &destRect, &rect, 0, NULL, SDL_FLIP_NONE);
}
void drawGame(){
SDL_RenderClear(renderer);
drawMap();
drawPlayer();
SDL_RenderPresent(renderer);
}
......@@ -89,8 +102,13 @@ void MainLoop(){
hoverSurface = IMG_Load("Res/hover.png");
hoverTexture = SDL_CreateTextureFromSurface(renderer, hoverSurface);
playerSurface = IMG_Load("Res/character_spritesheet.png");
playerTexture = SDL_CreateTextureFromSurface(renderer, playerSurface);
SDL_FreeSurface(grassSurface);
SDL_FreeSurface(treeSurface);
SDL_FreeSurface(hoverSurface);
SDL_FreeSurface(playerSurface);
unsigned int a = SDL_GetTicks();
unsigned int b = SDL_GetTicks();
......
......@@ -3,6 +3,7 @@
#include "main.h"
#include "gest_event.h"
#include "player.h"
#define FPS_TO_GET 60
#define CELLSIZE (ScreenDimension.h / MAPSIZE)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment