Skip to content
Snippets Groups Projects
Commit 16d829e4 authored by belkhiritaha's avatar belkhiritaha
Browse files

Merge branch 'render' into main

parents d8011458 888cb2f8
No related branches found
No related tags found
No related merge requests found
File deleted
...@@ -126,9 +126,8 @@ void manageMovement(){ ...@@ -126,9 +126,8 @@ void manageMovement(){
int selectStateHover(){ int selectStateHover(){
int stateHover = 0; int stateHover = 0;
int distance = sqrt(pow(abs(mousePosition.x-player.x), 2)+pow(abs(mousePosition.y-player.y), 2)); int distance = sqrt(pow(abs(mousePosition.x - player.x/CELLSIZE), 2)+pow(abs(mousePosition.y - player.y/CELLSIZE), 2));
printf("distance : %d\n", distance); if(distance <= 1){
if(distance <= 2){
stateHover = 1; stateHover = 1;
} }
return stateHover; return stateHover;
......
...@@ -17,6 +17,9 @@ SDL_Texture * treeTexture; ...@@ -17,6 +17,9 @@ SDL_Texture * treeTexture;
SDL_Surface * hoverSurface; SDL_Surface * hoverSurface;
SDL_Texture * hoverTexture; SDL_Texture * hoverTexture;
SDL_Surface * noHoverSurface;
SDL_Texture * noHoverTexture;
SDL_Surface * playerSurface; SDL_Surface * playerSurface;
SDL_Texture * playerTexture; SDL_Texture * playerTexture;
...@@ -109,8 +112,13 @@ void drawMap(){ ...@@ -109,8 +112,13 @@ void drawMap(){
SDL_RenderCopy(renderer, treeTexture, NULL, &rect); SDL_RenderCopy(renderer, treeTexture, NULL, &rect);
} }
if (mousePosition.x == j && mousePosition.y == i){ if (mousePosition.x == j && mousePosition.y == i){
if (selectStateHover()){
SDL_RenderCopy(renderer, hoverTexture, NULL, &rect); SDL_RenderCopy(renderer, hoverTexture, NULL, &rect);
} }
else {
SDL_RenderCopy(renderer, noHoverTexture, NULL, &rect);
}
}
rect.x += CELLSIZE; rect.x += CELLSIZE;
} }
rect.x = (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2; rect.x = (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2;
...@@ -154,6 +162,9 @@ void mainLoop(){ ...@@ -154,6 +162,9 @@ void mainLoop(){
hoverSurface = IMG_Load("Res/hover.png"); hoverSurface = IMG_Load("Res/hover.png");
hoverTexture = SDL_CreateTextureFromSurface(renderer, hoverSurface); hoverTexture = SDL_CreateTextureFromSurface(renderer, hoverSurface);
noHoverSurface = IMG_Load("Res/noHover.png");
noHoverTexture = SDL_CreateTextureFromSurface(renderer, noHoverSurface);
playerSurface = IMG_Load("Res/character_spritesheet.png"); playerSurface = IMG_Load("Res/character_spritesheet.png");
playerTexture = SDL_CreateTextureFromSurface(renderer, playerSurface); playerTexture = SDL_CreateTextureFromSurface(renderer, playerSurface);
...@@ -177,6 +188,7 @@ void mainLoop(){ ...@@ -177,6 +188,7 @@ void mainLoop(){
SDL_FreeSurface(playButtonSurface); SDL_FreeSurface(playButtonSurface);
SDL_FreeSurface(playButtonHoverSurface); SDL_FreeSurface(playButtonHoverSurface);
SDL_FreeSurface(backgroundSidesSurface); SDL_FreeSurface(backgroundSidesSurface);
SDL_FreeSurface(noHoverSurface);
unsigned int a = SDL_GetTicks(); unsigned int a = SDL_GetTicks();
unsigned int b = SDL_GetTicks(); unsigned int b = SDL_GetTicks();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment