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

ajout d'un hover

parent 8c297261
Branches
No related tags found
No related merge requests found
travail_de_groupe/chef_oeuvre/Res/hover.png

782 B

File added
#include "gest_event.h"
int hover[2];
int x;
int y;
void gestMenu(){
SDL_Event event;
......@@ -22,6 +25,14 @@ void gestMenu(){
}
break;
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;
default:
continue;
}
......
......@@ -5,6 +5,8 @@
#include "main.h"
#include "render.h"
extern int hover[2];
void *EventLoop(void *arg);
#endif
\ No newline at end of file
......@@ -12,6 +12,9 @@ SDL_Texture * grassTexture;
SDL_Surface * treeSurface;
SDL_Texture * treeTexture;
SDL_Surface * hoverSurface;
SDL_Texture * hoverTexture;
void CreateWindow(){
if (SDL_Init(SDL_INIT_VIDEO) != 0){
......@@ -57,6 +60,9 @@ void drawMap(){
if(map[i][j] == 1){
SDL_RenderCopy(renderer, treeTexture, NULL, &rect);
}
if (hover[0] == j && hover[1] == i){
SDL_RenderCopy(renderer, hoverTexture, NULL, &rect);
}
rect.x += CELLSIZE;
}
rect.x = (ScreenDimension.w - (MAPSIZE * CELLSIZE)) / 2;
......@@ -64,6 +70,7 @@ void drawMap(){
}
}
void drawGame(){
SDL_RenderClear(renderer);
drawMap();
......@@ -79,6 +86,9 @@ void MainLoop(){
treeSurface = IMG_Load("Res/tree.png");
treeTexture = SDL_CreateTextureFromSurface(renderer, treeSurface);
hoverSurface = IMG_Load("Res/hover.png");
hoverTexture = SDL_CreateTextureFromSurface(renderer, hoverSurface);
SDL_FreeSurface(grassSurface);
SDL_FreeSurface(treeSurface);
......
......@@ -9,8 +9,9 @@
extern SDL_Window *window;
extern SDL_Renderer *renderer;
extern SDL_DisplayMode ScreenDimension;
void drawHover(int x, int y);
void MainLoop();
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment