Minor fixes

- Make skills correctly turn the player
- Don't repopulate the matrix on every frame only on turn change
This commit is contained in:
Linus Probert 2018-07-31 23:45:09 +02:00
parent 4819eda1dd
commit 1124e88df0
6 changed files with 72 additions and 69 deletions

View File

@ -328,6 +328,15 @@ initMainMenu(void)
mixer_play_music(MENU_MUSIC);
}
static void
repopulate_roommatrix(void)
{
roommatrix_populate_from_map(gRoomMatrix, gMap);
roommatrix_add_lightsource(gRoomMatrix,
&gPlayer->sprite->pos);
roommatrix_build_lightmap(gRoomMatrix);
}
static void
resetGame(void)
{
@ -354,6 +363,7 @@ resetGame(void)
map_set_current_room(gMap, &gPlayer->sprite->pos);
camera_follow_position(gCamera, &gPlayer->sprite->pos);
repopulate_roommatrix();
}
static bool
@ -484,11 +494,6 @@ run_game_update(void)
map_clear_dead_monsters(gMap, gPlayer);
map_clear_collected_items(gMap);
roommatrix_populate_from_map(gRoomMatrix, gMap);
roommatrix_add_lightsource(gRoomMatrix,
&gPlayer->sprite->pos);
roommatrix_build_lightmap(gRoomMatrix);
populateUpdateData(&updateData, deltaTime);
if (playerLevel != gPlayer->stats.lvl) {
@ -513,10 +518,12 @@ run_game_update(void)
if (player_turn_over(gPlayer)) {
currentTurn = MONSTER;
player_reset_steps(gPlayer);
repopulate_roommatrix();
}
} else if (currentTurn == MONSTER) {
if (map_move_monsters(gMap, gRoomMatrix)) {
currentTurn = PLAYER;
repopulate_roommatrix();
}
}
}

View File

@ -186,12 +186,41 @@ set_clip_for_direction(Player *player, Vector2d *direction)
player->sprite->clip.y = 0;
}
void
player_turn(Player *player, Vector2d *direction)
{
set_clip_for_direction(player, direction);
if (!vector2d_equals(*direction, VECTOR2D_NODIR))
player->swordAnimation->sprite->pos = player->sprite->pos;
if (vector2d_equals(*direction, VECTOR2D_UP)) {
player->swordAnimation->sprite->pos.y -= 32;
player->swordAnimation->sprite->angle = -90;
player->swordAnimation->sprite->flip = SDL_FLIP_NONE;
} else if (vector2d_equals(*direction, VECTOR2D_DOWN)) {
player->swordAnimation->sprite->pos.y += 32;
player->swordAnimation->sprite->angle = 90;
player->swordAnimation->sprite->flip = SDL_FLIP_NONE;
} else if (vector2d_equals(*direction, VECTOR2D_LEFT)) {
player->swordAnimation->sprite->pos.x -= 32;
player->swordAnimation->sprite->angle = 0;
player->swordAnimation->sprite->flip = SDL_FLIP_HORIZONTAL;
} else if (vector2d_equals(*direction, VECTOR2D_RIGHT)) {
player->swordAnimation->sprite->pos.x += 32;
player->swordAnimation->sprite->angle = 0;
player->swordAnimation->sprite->flip = SDL_FLIP_NONE;
}
}
static void
move(Player *player, RoomMatrix *matrix, Vector2d direction)
{
set_clip_for_direction(player, &direction);
player_turn(player, &direction);
player->sprite->pos.x += TILE_DIMENSION * (int) direction.x;
player->sprite->pos.y += TILE_DIMENSION * (int) direction.y;
if (!has_collided(player, matrix, direction)) {
player_step(player);
}
@ -249,27 +278,6 @@ handle_next_move(UpdateData *data)
++step;
step = step % 4;
}
if (!vector2d_equals(nextDir, VECTOR2D_NODIR))
player->swordAnimation->sprite->pos = player->sprite->pos;
if (vector2d_equals(nextDir, VECTOR2D_UP)) {
player->swordAnimation->sprite->pos.y -= 32;
player->swordAnimation->sprite->angle = -90;
player->swordAnimation->sprite->flip = SDL_FLIP_NONE;
} else if (vector2d_equals(nextDir, VECTOR2D_DOWN)) {
player->swordAnimation->sprite->pos.y += 32;
player->swordAnimation->sprite->angle = 90;
player->swordAnimation->sprite->flip = SDL_FLIP_NONE;
} else if (vector2d_equals(nextDir, VECTOR2D_LEFT)) {
player->swordAnimation->sprite->pos.x -= 32;
player->swordAnimation->sprite->angle = 0;
player->swordAnimation->sprite->flip = SDL_FLIP_HORIZONTAL;
} else if (vector2d_equals(nextDir, VECTOR2D_RIGHT)) {
player->swordAnimation->sprite->pos.x += 32;
player->swordAnimation->sprite->angle = 0;
player->swordAnimation->sprite->flip = SDL_FLIP_NONE;
}
}
static void

View File

@ -95,6 +95,9 @@ player_render(Player*, Camera*);
void
player_render_toplayer(Player*, Camera*);
void
player_turn(Player*, Vector2d *dir);
void
player_destroy(Player*);

View File

@ -25,6 +25,29 @@
#include "item.h"
#include "update_data.h"
static void
roommatrix_reset(RoomMatrix *m)
{
RoomSpace *space;
int i, j;
for (i = 0; i < MAP_ROOM_WIDTH; ++i) {
for (j = 0; j < MAP_ROOM_HEIGHT; ++j) {
space = &m->spaces[i][j];
space->occupied = false;
space->lethal = false;
space->lightsource = false;
space->light = 0;
space->monster = NULL;
space->player = NULL;
while (space->items != NULL)
linkedlist_pop(&space->items);
}
}
m->roomPos = (Position) { 0, 0 };
m->playerRoomPos = (Position) { 1, 1 };
}
RoomMatrix* roommatrix_create(void)
{
int i, j;
@ -242,29 +265,6 @@ roommatrix_render_lightmap(RoomMatrix *matrix, Camera *cam)
}
}
void
roommatrix_reset(RoomMatrix *m)
{
RoomSpace *space;
int i, j;
for (i = 0; i < MAP_ROOM_WIDTH; ++i) {
for (j = 0; j < MAP_ROOM_HEIGHT; ++j) {
space = &m->spaces[i][j];
space->occupied = false;
space->lethal = false;
space->lightsource = false;
space->light = 0;
space->monster = NULL;
space->player = NULL;
while (space->items != NULL)
linkedlist_pop(&space->items);
}
}
m->roomPos = (Position) { 0, 0 };
m->playerRoomPos = (Position) { 1, 1 };
}
void roommatrix_destroy(RoomMatrix *m)
{
// Clear the list but don't destroy the items

View File

@ -67,8 +67,6 @@ void roommatrix_render_mouse_square(RoomMatrix*, Camera*);
void roommatrix_render_lightmap(RoomMatrix*, Camera*);
void roommatrix_reset(RoomMatrix*);
void roommatrix_destroy(RoomMatrix*);
#endif // ROOMMATRIX_H_

View File

@ -34,19 +34,6 @@
#include "item.h"
#include "animation.h"
static void
set_player_clip_for_direction(Player *player, Vector2d *direction)
{
if (direction->y > 0) // Down
player->sprite->clip.y = 0;
else if (direction->y < 0) // Up
player->sprite->clip.y = 48;
else if (direction->x < 0) // Left
player->sprite->clip.y = 16;
else if (direction->x > 0) // Right
player->sprite->clip.y = 32;
}
static Skill *
create_default(const char *s_label, Sprite *s)
{
@ -74,15 +61,15 @@ skill_use_flurry(Skill *skill, SkillData *data)
targetPos.x += (int) data->direction.x;
targetPos.y += (int) data->direction.y;
set_player_clip_for_direction(data->player, &data->direction);
player_turn(data->player, &data->direction);
if (!position_in_roommatrix(&targetPos)) {
return false;
}
animation_run(data->player->swordAnimation);
Monster *monster = data->matrix->spaces[targetPos.x][targetPos.y].monster;
mixer_play_effect(TRIPPLE_SWING);
animation_run(data->player->swordAnimation);
if (monster) {
gui_log("You attack %s with a flurry of strikes", monster->lclabel);
unsigned int hitCount = 0;
@ -162,7 +149,7 @@ skill_throw_dagger(Skill *skill, SkillData *data)
p->sprite->angle = -270;
}
set_player_clip_for_direction(data->player, &data->direction);
player_turn(data->player, &data->direction);
mixer_play_effect(SWOOSH);
p->sprite->pos = data->player->sprite->pos;
@ -265,7 +252,7 @@ skill_charge(Skill *skill, SkillData *data)
player->sprite->pos.x += (steps * TILE_DIMENSION) * (int) data->direction.x;
player->sprite->pos.y += (steps * TILE_DIMENSION) * (int) data->direction.y;
Position playerDestinationPos = player->sprite->pos;
set_player_clip_for_direction(data->player, &data->direction);
player_turn(data->player, &data->direction);
// Add motion particles
bool horizontal = data->direction.x != 0;