Hilite current tile under mouse
This is intended for spell usage once I get that in.
This commit is contained in:
parent
22f6d36375
commit
0b2a29fe3b
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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*);
|
||||
|
|
Loading…
Reference in New Issue