From 0b2a29fe3bcfbebd169a9a5696f4e0a5a772098e Mon Sep 17 00:00:00 2001 From: Linus_Probert Date: Tue, 6 Feb 2018 16:47:45 +0100 Subject: [PATCH] Hilite current tile under mouse This is intended for spell usage once I get that in. --- src/main.c | 4 ++++ src/player.c | 2 +- src/player.h | 1 + src/roommatrix.c | 37 +++++++++++++++++++++++++++++++++++-- src/roommatrix.h | 5 +++++ 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index d3a86a7..225fbd0 100644 --- a/src/main.c +++ b/src/main.c @@ -167,6 +167,7 @@ bool handle_events(void) camera_follow_position(&gCamera, &gPlayer->sprite->pos); map_set_current_room(gMap, &gPlayer->sprite->pos); } + roommatrix_handle_event(gRoomMatrix, &event); pointer_handle_event(gPointer, &event); } @@ -230,6 +231,9 @@ run_game(void) map_render(gMap, &gCamera); particle_engine_render(&gCamera); player_render(gPlayer, &gCamera); + + if (gPlayer->class == MAGE || gPlayer->class == PALADIN) + roommatrix_render_mouse_square(gRoomMatrix, &gCamera); roommatrix_render_lightmap(gRoomMatrix, &gCamera); SDL_RenderSetViewport(gRenderer, &rightGuiViewport); diff --git a/src/player.c b/src/player.c index c801adb..9019732 100644 --- a/src/player.c +++ b/src/player.c @@ -257,6 +257,7 @@ player_create(class_t class, SDL_Renderer *renderer) player->misses = 0; player->gold = 0; player->potion_sips = 0; + player->class = class; char asset[100]; switch (class) { @@ -288,7 +289,6 @@ player_create(class_t class, SDL_Renderer *renderer) player->sprite->textures[0]->dim = (Dimension) { TILE_DIMENSION, TILE_DIMENSION }; player->handle_event = &handle_player_input; - player_load_texts(player, renderer); return player; diff --git a/src/player.h b/src/player.h index b024022..5e29954 100644 --- a/src/player.h +++ b/src/player.h @@ -30,6 +30,7 @@ typedef struct Player_t { unsigned int misses; double gold; unsigned int potion_sips; + class_t class; void (*handle_event)(struct Player_t*, RoomMatrix*, SDL_Event*); } Player; diff --git a/src/roommatrix.c b/src/roommatrix.c index 39622af..78a9d11 100644 --- a/src/roommatrix.c +++ b/src/roommatrix.c @@ -19,6 +19,20 @@ RoomMatrix* roommatrix_create() return m; } +void +roommatrix_handle_event(RoomMatrix *matrix, SDL_Event *event) +{ + if (event->type != SDL_MOUSEMOTION) + return; + + if (event->motion.x < GAME_VIEW_WIDTH + && event->motion.y < GAME_VIEW_HEIGHT) + { + matrix->mousePos.x = event->motion.x; + matrix->mousePos.y = event->motion.y; + } +} + void roommatrix_populate_from_map(RoomMatrix *rm, Map *m) { int i, j; @@ -160,6 +174,21 @@ roommatrix_build_lightmap(RoomMatrix *matrix) } } +void +roommatrix_render_mouse_square(RoomMatrix *matrix, Camera *cam) +{ + Position mmc = position_to_matrix_coords(&matrix->mousePos); + SDL_Rect box = (SDL_Rect) { + mmc.x*TILE_DIMENSION, + mmc.y*TILE_DIMENSION, + TILE_DIMENSION, + TILE_DIMENSION + }; + + SDL_SetRenderDrawColor(cam->renderer, 255, 255, 0, 90); + SDL_RenderFillRect(cam->renderer, &box); +} + void roommatrix_render_lightmap(RoomMatrix *matrix, Camera *cam) { @@ -170,14 +199,18 @@ roommatrix_render_lightmap(RoomMatrix *matrix, Camera *cam) light = 245 - matrix->spaces[i][j].light; if (light < 0) light = 0; - SDL_SetRenderDrawColor(cam->renderer, - 0, 0, 0, light); + else if (light > 245) + light = 245; + SDL_Rect box = (SDL_Rect) { i*TILE_DIMENSION, j*TILE_DIMENSION, TILE_DIMENSION, TILE_DIMENSION }; + + SDL_SetRenderDrawColor(cam->renderer, + 0, 0, 0, light); SDL_RenderFillRect(cam->renderer, &box); } } diff --git a/src/roommatrix.h b/src/roommatrix.h index b2b61b2..14e4df7 100644 --- a/src/roommatrix.h +++ b/src/roommatrix.h @@ -26,10 +26,13 @@ typedef struct { RoomSpace spaces[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT]; Position roomPos; Position playerRoomPos; + Position mousePos; } RoomMatrix; RoomMatrix* roommatrix_create(void); +void roommatrix_handle_event(RoomMatrix*, SDL_Event*); + void roommatrix_populate_from_map(RoomMatrix*, Map*); void roommatrix_update_with_player(RoomMatrix*, Player*); @@ -38,6 +41,8 @@ void roommatrix_add_lightsource(RoomMatrix*, Position*); void roommatrix_build_lightmap(RoomMatrix*); +void roommatrix_render_mouse_square(RoomMatrix*, Camera*); + void roommatrix_render_lightmap(RoomMatrix*, Camera*); void roommatrix_reset(RoomMatrix*);