2018-02-16 18:11:26 +01:00
|
|
|
/*
|
|
|
|
* BreakHack - A dungeone crawler RPG
|
|
|
|
* Copyright (C) 2018 Linus Probert <linus.probert@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-12-19 19:42:05 +01:00
|
|
|
#include <stdio.h>
|
2017-12-19 21:00:02 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2017-11-30 21:00:47 +01:00
|
|
|
#include "player.h"
|
2017-12-15 08:08:45 +01:00
|
|
|
#include "monster.h"
|
2017-12-19 21:00:02 +01:00
|
|
|
#include "util.h"
|
2018-01-23 14:11:03 +01:00
|
|
|
#include "gui.h"
|
2018-01-24 21:14:34 +01:00
|
|
|
#include "item.h"
|
2018-02-03 23:39:49 +01:00
|
|
|
#include "particle_engine.h"
|
2018-02-12 10:55:36 +01:00
|
|
|
#include "keyboard.h"
|
2018-02-15 14:00:59 +01:00
|
|
|
#include "mixer.h"
|
2018-02-15 14:45:20 +01:00
|
|
|
#include "random.h"
|
2018-03-08 00:58:26 +01:00
|
|
|
#include "projectile.h"
|
|
|
|
#include "texturecache.h"
|
2018-03-10 22:04:03 +01:00
|
|
|
#include "vector2d.h"
|
2018-05-15 11:16:56 +02:00
|
|
|
#include "actiontextbuilder.h"
|
2018-07-09 19:26:06 +02:00
|
|
|
#include "animation.h"
|
2018-08-06 00:28:23 +02:00
|
|
|
#include "trap.h"
|
2018-10-12 23:39:54 +02:00
|
|
|
#include "gamecontroller.h"
|
2019-03-10 00:15:47 +01:00
|
|
|
#include "event.h"
|
2017-11-30 21:00:47 +01:00
|
|
|
|
2018-08-29 14:26:07 +02:00
|
|
|
#ifdef STEAM_BUILD
|
|
|
|
#include "steam/steamworks_api_wrapper.h"
|
|
|
|
#endif // STEAM_BUILD
|
|
|
|
|
2019-05-09 10:16:38 +02:00
|
|
|
#define ENGINEER_STATS { 12, 12, 5, 7, 2, 1, 1, false, false }
|
|
|
|
#define MAGE_STATS { 12, 12, 5, 7, 1, 1, 1, false, false }
|
2018-08-04 23:52:52 +02:00
|
|
|
#define PALADIN_STATS { 12, 12, 8, 9, 3, 1, 1, false, false }
|
2018-10-18 22:34:48 +02:00
|
|
|
#define ROGUE_STATS { 9, 9, 6, 9, 4, 2, 1, false, false }
|
2018-08-04 23:52:52 +02:00
|
|
|
#define WARRIOR_STATS { 12, 12, 8, 9, 3, 1, 1, false, false }
|
2017-12-12 11:20:08 +01:00
|
|
|
|
2018-10-26 18:37:50 +02:00
|
|
|
static void
|
|
|
|
levelup(Player *player)
|
2018-01-30 15:16:14 +01:00
|
|
|
{
|
|
|
|
player->stats.lvl += 1;
|
2018-02-20 14:22:26 +01:00
|
|
|
player->stats.maxhp += 9;
|
2018-01-30 15:16:14 +01:00
|
|
|
player->stats.dmg += 5;
|
|
|
|
player->stats.atk += 1;
|
2018-01-31 13:52:11 +01:00
|
|
|
|
|
|
|
// Limit health to 3 rows of hearts
|
|
|
|
if (player->stats.maxhp > 72)
|
|
|
|
player->stats.maxhp = 72;
|
2018-02-01 09:04:19 +01:00
|
|
|
|
|
|
|
player->stats.hp = player->stats.maxhp;
|
2018-01-30 15:16:14 +01:00
|
|
|
}
|
|
|
|
|
2018-10-26 18:37:50 +02:00
|
|
|
void
|
|
|
|
player_levelup(Player *player)
|
|
|
|
{
|
|
|
|
mixer_play_effect(LEVEL_UP);
|
|
|
|
levelup(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
player_set_level(Player *p, Uint8 level)
|
|
|
|
{
|
|
|
|
while (p->stats.lvl < level)
|
|
|
|
levelup(p);
|
|
|
|
}
|
|
|
|
|
2018-01-31 16:55:48 +01:00
|
|
|
static unsigned int
|
2018-01-31 10:49:13 +01:00
|
|
|
next_level_threshold(unsigned int current_level)
|
|
|
|
{
|
2018-02-14 11:00:34 +01:00
|
|
|
unsigned int last_level = 0;
|
|
|
|
unsigned int padding = 0;
|
|
|
|
|
|
|
|
if (current_level > 0) {
|
|
|
|
last_level = next_level_threshold(current_level - 1);
|
|
|
|
padding = (current_level - 1) * 150;
|
|
|
|
}
|
|
|
|
|
|
|
|
return last_level + (current_level * 50) + padding;
|
2018-01-31 10:49:13 +01:00
|
|
|
}
|
|
|
|
|
2018-01-30 15:16:14 +01:00
|
|
|
static void
|
|
|
|
player_gain_xp(Player *player, unsigned int xp_gain)
|
|
|
|
{
|
2018-05-15 11:16:56 +02:00
|
|
|
char msg[10];
|
2018-05-15 14:12:38 +02:00
|
|
|
m_sprintf(msg, 10, "+%dxp", xp_gain);
|
2018-05-15 23:21:28 +02:00
|
|
|
actiontextbuilder_create_text(msg, C_GREEN, &player->sprite->pos);
|
2018-05-15 11:16:56 +02:00
|
|
|
|
2018-01-30 15:16:14 +01:00
|
|
|
player->xp += xp_gain;
|
2018-01-31 10:49:13 +01:00
|
|
|
if (player->xp >= next_level_threshold(player->stats.lvl)) {
|
2018-01-30 15:16:14 +01:00
|
|
|
player_levelup(player);
|
|
|
|
gui_log("You have reached level %u", player->stats.lvl);
|
2018-03-07 16:02:56 +01:00
|
|
|
gui_event_message("You reached level %u", player->stats.lvl);
|
2018-05-15 23:21:28 +02:00
|
|
|
actiontextbuilder_create_text("Level up", C_GREEN, &player->sprite->pos);
|
2018-01-30 15:16:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 17:05:13 +01:00
|
|
|
static void
|
2018-03-03 00:54:50 +01:00
|
|
|
action_spent(Player *p)
|
2018-03-02 17:05:13 +01:00
|
|
|
{
|
2018-03-25 23:30:26 +02:00
|
|
|
p->stat_data.steps++;
|
|
|
|
p->stat_data.total_steps++;
|
2018-03-02 17:05:13 +01:00
|
|
|
|
2018-09-13 23:45:33 +02:00
|
|
|
if (p->stat_data.steps >= p->stats.speed) {
|
|
|
|
for (size_t i = 0; i < PLAYER_SKILL_COUNT; ++i) {
|
|
|
|
if (p->skills[i] != NULL && p->skills[i]->resetCountdown > 0)
|
|
|
|
p->skills[i]->resetCountdown--;
|
|
|
|
}
|
2018-10-18 22:34:48 +02:00
|
|
|
if (p->phase_count > 0) {
|
2018-10-02 22:42:29 +02:00
|
|
|
p->phase_count--;
|
2018-10-19 08:35:35 +02:00
|
|
|
if (!p->phase_count) {
|
2018-10-18 22:34:48 +02:00
|
|
|
mixer_play_effect(FADE_IN);
|
|
|
|
}
|
|
|
|
}
|
2018-03-02 17:05:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-10 13:18:56 +02:00
|
|
|
static void
|
|
|
|
on_monster_collision(Player *player,
|
|
|
|
Monster *monster,
|
|
|
|
RoomMatrix *matrix,
|
|
|
|
Vector2d direction)
|
|
|
|
{
|
2019-05-14 10:26:28 +02:00
|
|
|
CombatResult result = stats_fight(&player->stats,
|
|
|
|
&monster->stats);
|
2018-08-10 13:18:56 +02:00
|
|
|
|
|
|
|
mixer_play_effect(SWING0 + get_random(2));
|
2019-05-14 10:26:28 +02:00
|
|
|
monster_hit(monster, result.dmg, result.critical);
|
2018-08-10 13:18:56 +02:00
|
|
|
animation_run(player->swordAnimation);
|
|
|
|
|
2019-05-14 10:26:28 +02:00
|
|
|
if (result.dmg > 0) {
|
2018-08-10 13:18:56 +02:00
|
|
|
gui_log("You hit %s for %u damage",
|
2019-05-14 10:26:28 +02:00
|
|
|
monster->lclabel, result.dmg);
|
2018-08-10 13:18:56 +02:00
|
|
|
player->stat_data.hits += 1;
|
|
|
|
mixer_play_effect(SWORD_HIT);
|
|
|
|
} else {
|
|
|
|
gui_log("You missed %s", monster->lclabel);
|
|
|
|
player->stat_data.misses += 1;
|
|
|
|
}
|
|
|
|
player_monster_kill_check(player, monster);
|
|
|
|
|
|
|
|
if (monster->stats.hp > 0) {
|
|
|
|
if (get_random(10) < player_has_artifact(player, PUSH_BACK)) {
|
|
|
|
gui_log("The force of your blow sends %s reeling",
|
|
|
|
monster->lclabel);
|
2018-09-10 22:27:26 +02:00
|
|
|
monster_push(monster, player, matrix, direction);
|
2018-08-10 13:18:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (get_random(10) < player_has_artifact(player, FEAR_INDUCING)) {
|
|
|
|
gui_log("%s shivers with fear at the sight of you",
|
|
|
|
monster->label);
|
2018-08-30 14:01:28 +02:00
|
|
|
if (monster->state.current != STUNNED)
|
2018-08-30 09:55:04 +02:00
|
|
|
monster_set_state(monster, SCARED, 3);
|
2018-08-10 13:18:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
action_spent(player);
|
|
|
|
}
|
|
|
|
|
2018-09-13 13:12:43 +02:00
|
|
|
static void
|
|
|
|
player_pickup_artifacts(Player *player, RoomSpace *space)
|
2017-12-05 15:03:20 +01:00
|
|
|
{
|
2018-09-13 13:12:43 +02:00
|
|
|
LinkedList *artifacts = space->artifacts;
|
|
|
|
while (artifacts) {
|
|
|
|
player_add_artifact(player, artifacts->data);
|
|
|
|
artifacts = artifacts->next;
|
2017-12-15 08:08:45 +01:00
|
|
|
}
|
2018-09-13 13:12:43 +02:00
|
|
|
}
|
2017-12-15 08:08:45 +01:00
|
|
|
|
2018-09-13 13:12:43 +02:00
|
|
|
static void
|
|
|
|
player_interact_objects(Player *player, RoomSpace *space)
|
|
|
|
{
|
|
|
|
LinkedList *objects = space->objects;
|
|
|
|
while (objects) {
|
|
|
|
object_damage(objects->data, player);
|
|
|
|
objects = objects->next;
|
2018-09-10 22:27:26 +02:00
|
|
|
}
|
2018-09-13 13:12:43 +02:00
|
|
|
}
|
2018-09-10 22:27:26 +02:00
|
|
|
|
2018-09-13 13:12:43 +02:00
|
|
|
static void
|
|
|
|
player_collect_items(Player *player, RoomSpace *space)
|
|
|
|
{
|
|
|
|
LinkedList *items = space->items;
|
|
|
|
while (items != NULL) {
|
|
|
|
Item *item = items->data;
|
|
|
|
items = items->next;
|
|
|
|
item_collected(item, player);
|
2018-05-15 14:12:38 +02:00
|
|
|
}
|
2018-09-13 13:12:43 +02:00
|
|
|
}
|
2018-05-15 14:12:38 +02:00
|
|
|
|
2018-09-13 13:12:43 +02:00
|
|
|
static void
|
|
|
|
player_interact_traps_and_pits(Player *player, RoomSpace *space)
|
|
|
|
{
|
|
|
|
if (space->lethal) {
|
|
|
|
player_set_falling(player);
|
2017-12-06 11:44:17 +01:00
|
|
|
}
|
|
|
|
|
2018-09-13 13:12:43 +02:00
|
|
|
if (space->trap) {
|
|
|
|
trap_activate(space->trap, player);
|
2018-01-24 21:14:34 +01:00
|
|
|
}
|
2018-09-13 13:12:43 +02:00
|
|
|
}
|
2018-01-24 21:14:34 +01:00
|
|
|
|
2018-09-13 13:12:43 +02:00
|
|
|
static bool
|
2018-09-28 14:57:43 +02:00
|
|
|
player_has_collided(Player *p, RoomSpace *space)
|
2018-09-13 13:12:43 +02:00
|
|
|
{
|
|
|
|
if (space->occupied)
|
|
|
|
return true;
|
2018-08-08 00:14:24 +02:00
|
|
|
|
2018-09-28 14:57:43 +02:00
|
|
|
return !p->phase_count && space->monster && space->monster->sprite->state != SPRITE_STATE_FALLING;
|
2018-09-13 13:12:43 +02:00
|
|
|
}
|
2018-08-13 13:11:32 +02:00
|
|
|
|
2018-09-13 13:12:43 +02:00
|
|
|
static bool
|
|
|
|
has_collided(Player *player, RoomMatrix *matrix, Vector2d direction)
|
|
|
|
{
|
|
|
|
Position roomCoord = position_to_room_coords(&player->sprite->pos);
|
|
|
|
if (roomCoord.x != matrix->roomPos.x || roomCoord.y != matrix->roomPos.y) {
|
|
|
|
return false;
|
2018-03-25 23:30:26 +02:00
|
|
|
}
|
|
|
|
|
2018-09-13 13:12:43 +02:00
|
|
|
Position matrixPos = position_to_matrix_coords(&player->sprite->pos);
|
|
|
|
RoomSpace *space = &matrix->spaces[matrixPos.x][matrixPos.y];
|
2018-08-06 00:28:23 +02:00
|
|
|
|
2018-09-28 14:57:43 +02:00
|
|
|
if (player_has_collided(player, space)) {
|
2018-09-13 13:12:43 +02:00
|
|
|
player->sprite->pos.x -= TILE_DIMENSION * (int)direction.x;
|
|
|
|
player->sprite->pos.y -= TILE_DIMENSION * (int)direction.y;
|
|
|
|
|
2018-10-14 21:38:56 +02:00
|
|
|
gamecontroller_rumble(0.30f, 100);
|
2018-09-13 13:12:43 +02:00
|
|
|
if (space->monster) {
|
|
|
|
on_monster_collision(player, space->monster, matrix, direction);
|
2019-03-19 21:54:58 +01:00
|
|
|
} else if (space->door && map_open_door(space->door, player)) {
|
|
|
|
// Door opened, pass
|
2018-09-13 13:12:43 +02:00
|
|
|
} else {
|
|
|
|
mixer_play_effect(BONK);
|
|
|
|
camera_shake(direction, 100);
|
2019-03-19 21:54:58 +01:00
|
|
|
if (space->door)
|
|
|
|
gui_log("Ouch! That door seems to be locked");
|
|
|
|
else
|
|
|
|
gui_log("Ouch! There is something in the way");
|
2018-09-13 13:12:43 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
player_collect_items(player, space);
|
|
|
|
player_pickup_artifacts(player, space);
|
2018-10-18 22:34:48 +02:00
|
|
|
|
|
|
|
// If not phased or phase will end this turn, react to traps and pits
|
|
|
|
if (!player->phase_count || (player->phase_count == 1 && player->stats.speed == (player->stat_data.steps + 1))) {
|
2018-09-28 14:57:43 +02:00
|
|
|
player_interact_objects(player, space);
|
|
|
|
player_interact_traps_and_pits(player, space);
|
|
|
|
}
|
2018-09-13 13:12:43 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-12-05 15:03:20 +01:00
|
|
|
}
|
|
|
|
|
2017-12-12 11:20:08 +01:00
|
|
|
static void
|
2018-03-15 16:30:41 +01:00
|
|
|
set_clip_for_direction(Player *player, Vector2d *direction)
|
2017-12-05 15:03:20 +01:00
|
|
|
{
|
2018-03-15 16:30:41 +01:00
|
|
|
if (vector2d_equals(*direction, VECTOR2D_LEFT))
|
|
|
|
player->sprite->clip.y = 16;
|
|
|
|
else if (vector2d_equals(*direction, VECTOR2D_RIGHT))
|
|
|
|
player->sprite->clip.y = 32;
|
|
|
|
else if (vector2d_equals(*direction, VECTOR2D_UP))
|
|
|
|
player->sprite->clip.y = 48;
|
|
|
|
else if (vector2d_equals(*direction, VECTOR2D_DOWN))
|
|
|
|
player->sprite->clip.y = 0;
|
2017-12-05 15:03:20 +01:00
|
|
|
}
|
|
|
|
|
2018-07-31 23:45:09 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-31 13:52:11 +01:00
|
|
|
static void
|
2018-03-15 16:30:41 +01:00
|
|
|
move(Player *player, RoomMatrix *matrix, Vector2d direction)
|
2017-12-05 15:03:20 +01:00
|
|
|
{
|
2018-07-31 23:45:09 +02:00
|
|
|
player_turn(player, &direction);
|
|
|
|
|
2018-10-14 22:20:54 +02:00
|
|
|
Position lastPos = position_to_matrix_coords(&player->sprite->pos);
|
|
|
|
|
2018-03-15 16:30:41 +01:00
|
|
|
player->sprite->pos.x += TILE_DIMENSION * (int) direction.x;
|
|
|
|
player->sprite->pos.y += TILE_DIMENSION * (int) direction.y;
|
2018-07-31 23:45:09 +02:00
|
|
|
|
2018-05-15 14:12:38 +02:00
|
|
|
if (!has_collided(player, matrix, direction)) {
|
2018-09-03 12:53:12 +02:00
|
|
|
action_spent(player);
|
2018-10-15 09:35:05 +02:00
|
|
|
RoomSpace *lastSpace = &matrix->spaces[lastPos.x][lastPos.y];
|
2018-10-15 22:19:23 +02:00
|
|
|
if (matrix->modifier->type == RMOD_TYPE_CRUMBLING &&
|
|
|
|
lastPos.x > 1 &&
|
2018-10-14 22:20:54 +02:00
|
|
|
lastPos.y > 1 &&
|
|
|
|
lastPos.x < 14 &&
|
2018-10-15 09:35:05 +02:00
|
|
|
lastPos.y < 10 &&
|
|
|
|
lastSpace->decoration == NULL &&
|
|
|
|
lastSpace->trap == NULL &&
|
2018-10-15 13:26:17 +02:00
|
|
|
lastSpace->objects == NULL &&
|
|
|
|
lastSpace->items == NULL
|
2018-10-15 09:35:05 +02:00
|
|
|
)
|
|
|
|
map_trigger_tile_fall(lastSpace->tile);
|
2018-03-15 16:30:41 +01:00
|
|
|
}
|
2017-12-05 15:03:20 +01:00
|
|
|
}
|
|
|
|
|
2018-02-28 22:31:38 +01:00
|
|
|
void
|
|
|
|
player_sip_health(Player *player)
|
2018-02-03 13:02:39 +01:00
|
|
|
{
|
2019-05-14 15:20:45 +02:00
|
|
|
bool hasSips = player->class == MAGE ?
|
|
|
|
player->potion_sips > 1 : player->potion_sips > 0;
|
|
|
|
|
|
|
|
if (hasSips) {
|
2018-02-03 13:02:39 +01:00
|
|
|
--player->potion_sips;
|
2019-05-14 15:20:45 +02:00
|
|
|
if (player->class == MAGE)
|
|
|
|
--player->potion_sips;
|
2018-02-03 13:02:39 +01:00
|
|
|
++player->stats.hp;
|
2018-02-15 14:45:20 +01:00
|
|
|
mixer_play_effect(BUBBLE0 + get_random(2));
|
2018-05-22 15:48:09 +02:00
|
|
|
gui_log("You take a sip from a health potion");
|
2018-05-15 23:21:28 +02:00
|
|
|
actiontextbuilder_create_text("+1", C_GREEN, &player->sprite->pos);
|
2018-02-03 13:02:39 +01:00
|
|
|
} else {
|
|
|
|
gui_log("You have nothing to sip");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-20 00:02:39 +02:00
|
|
|
static Vector2d
|
|
|
|
read_direction_from(Input *input)
|
|
|
|
{
|
|
|
|
if (input_key_is_pressed(input, KEY_LEFT))
|
|
|
|
return VECTOR2D_LEFT;
|
|
|
|
else if (input_key_is_pressed(input, KEY_RIGHT))
|
|
|
|
return VECTOR2D_RIGHT;
|
|
|
|
else if (input_key_is_pressed(input, KEY_UP))
|
|
|
|
return VECTOR2D_UP;
|
|
|
|
else if (input_key_is_pressed(input, KEY_DOWN))
|
|
|
|
return VECTOR2D_DOWN;
|
|
|
|
else
|
|
|
|
return VECTOR2D_NODIR;
|
|
|
|
}
|
|
|
|
|
2018-02-03 13:02:39 +01:00
|
|
|
static void
|
2018-05-20 00:02:39 +02:00
|
|
|
handle_next_move(UpdateData *data)
|
2017-11-30 21:00:47 +01:00
|
|
|
{
|
|
|
|
static unsigned int step = 1;
|
2018-03-15 16:30:41 +01:00
|
|
|
|
2018-05-20 00:02:39 +02:00
|
|
|
Player *player = data->player;
|
2018-08-13 13:11:32 +02:00
|
|
|
Position originPos = player->sprite->pos;
|
2018-07-06 22:30:28 +02:00
|
|
|
|
|
|
|
// Don't move when projectiles are still moving
|
|
|
|
if (linkedlist_size(player->projectiles) > 0)
|
|
|
|
return;
|
|
|
|
|
2018-09-09 12:43:17 +02:00
|
|
|
if (input_key_is_pressed(data->input, KEY_SPACE)) {
|
|
|
|
action_spent(data->player);
|
|
|
|
gui_log("You take a moment and stare at your feet");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-20 00:02:39 +02:00
|
|
|
RoomMatrix *matrix = data->matrix;
|
|
|
|
Vector2d nextDir = read_direction_from(data->input);
|
|
|
|
if (!vector2d_equals(nextDir, VECTOR2D_NODIR))
|
|
|
|
move(player, matrix, nextDir);
|
|
|
|
|
2018-08-13 13:11:32 +02:00
|
|
|
if (!position_equals(&originPos, &player->sprite->pos)
|
|
|
|
&& matrix->modifier->type == RMOD_TYPE_FIRE) {
|
|
|
|
Object *o = object_create_fire();
|
|
|
|
o->damage *= player->stats.lvl;
|
|
|
|
o->sprite->pos = originPos;
|
|
|
|
linkedlist_append(&data->map->objects, o);
|
|
|
|
}
|
|
|
|
|
2018-05-20 00:02:39 +02:00
|
|
|
map_room_modifier_player_effect(player, matrix, &nextDir, move);
|
2018-03-15 16:30:41 +01:00
|
|
|
|
2018-05-20 00:02:39 +02:00
|
|
|
if (!vector2d_equals(VECTOR2D_NODIR, nextDir)) {
|
2017-12-15 08:08:45 +01:00
|
|
|
player->sprite->clip.x = 16*step;
|
2018-02-03 13:02:39 +01:00
|
|
|
++step;
|
|
|
|
step = step % 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-01 06:13:43 +01:00
|
|
|
static void
|
|
|
|
use_skill(Skill *skill, SkillData *skillData)
|
|
|
|
{
|
|
|
|
skill->active = false;
|
|
|
|
skill->use(skill, skillData);
|
|
|
|
if (skill->actionRequired)
|
2018-09-03 12:53:12 +02:00
|
|
|
action_spent(skillData->player);
|
2018-03-01 06:13:43 +01:00
|
|
|
skill->resetCountdown = skill->resetTime;
|
|
|
|
}
|
|
|
|
|
2018-02-28 22:31:38 +01:00
|
|
|
static void
|
2018-05-20 00:02:39 +02:00
|
|
|
check_skill_activation(UpdateData *data)
|
2018-02-28 22:31:38 +01:00
|
|
|
{
|
|
|
|
// TODO(Linus): This could be "smarter"
|
2018-05-20 00:02:39 +02:00
|
|
|
Player *player = data->player;
|
|
|
|
Input *input = data->input;
|
|
|
|
RoomMatrix *matrix = data->matrix;
|
|
|
|
|
2018-02-28 22:31:38 +01:00
|
|
|
unsigned int selected = 0;
|
2018-05-20 00:02:39 +02:00
|
|
|
if (input_key_is_pressed(input, KEY_NUM1)) {
|
2018-02-28 22:31:38 +01:00
|
|
|
selected = 1;
|
2018-05-20 00:02:39 +02:00
|
|
|
} else if (input_key_is_pressed(input, KEY_NUM2)) {
|
2018-02-28 22:31:38 +01:00
|
|
|
selected = 2;
|
2018-05-20 00:02:39 +02:00
|
|
|
} else if (input_key_is_pressed(input, KEY_NUM3)) {
|
2018-02-28 22:31:38 +01:00
|
|
|
selected = 3;
|
2018-05-20 00:02:39 +02:00
|
|
|
} else if (input_key_is_pressed(input, KEY_NUM4)) {
|
2018-02-28 22:31:38 +01:00
|
|
|
selected = 4;
|
2018-05-20 00:02:39 +02:00
|
|
|
} else if (input_key_is_pressed(input, KEY_NUM5)) {
|
2018-02-28 22:31:38 +01:00
|
|
|
selected = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < PLAYER_SKILL_COUNT; ++i) {
|
|
|
|
if (!player->skills[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Skill *skill = player->skills[i];
|
2018-03-23 22:03:34 +01:00
|
|
|
if (skill->levelcap > player->stats.lvl)
|
|
|
|
continue;
|
2018-03-13 16:13:54 +01:00
|
|
|
if (skill->available && !skill->available(player))
|
2018-03-23 22:03:34 +01:00
|
|
|
continue;
|
2018-02-28 22:31:38 +01:00
|
|
|
skill->active = (selected - 1) == i && !skill->active && skill->resetCountdown == 0;
|
|
|
|
if (skill->active && skill->instantUse) {
|
|
|
|
SkillData skillData = { player, matrix, VECTOR2D_NODIR };
|
2018-03-01 06:13:43 +01:00
|
|
|
use_skill(skill, &skillData);
|
2018-02-28 22:31:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-20 00:02:39 +02:00
|
|
|
static bool
|
|
|
|
check_skill_trigger(UpdateData *data)
|
2018-02-28 22:31:38 +01:00
|
|
|
{
|
2018-05-20 00:02:39 +02:00
|
|
|
Player *player = data->player;
|
|
|
|
RoomMatrix *matrix = data->matrix;
|
|
|
|
Input *input = data->input;
|
|
|
|
|
2018-02-28 22:31:38 +01:00
|
|
|
int activeSkill = -1;
|
2018-03-01 06:04:12 +01:00
|
|
|
for (int i = 0; i < PLAYER_SKILL_COUNT; ++i) {
|
2018-02-28 22:31:38 +01:00
|
|
|
if (player->skills[i] && player->skills[i]->active) {
|
|
|
|
activeSkill = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (activeSkill < 0)
|
2018-05-20 00:02:39 +02:00
|
|
|
return false;
|
2018-02-28 22:31:38 +01:00
|
|
|
|
2018-05-20 00:02:39 +02:00
|
|
|
Vector2d nextDir = read_direction_from(input);
|
|
|
|
if (vector2d_equals(nextDir, VECTOR2D_NODIR))
|
|
|
|
return false;
|
2018-05-17 23:14:42 +02:00
|
|
|
|
2018-05-20 00:02:39 +02:00
|
|
|
SkillData skillData = { player, matrix, nextDir };
|
2018-03-01 06:13:43 +01:00
|
|
|
use_skill(player->skills[activeSkill], &skillData);
|
2018-02-28 22:31:38 +01:00
|
|
|
|
2018-05-20 00:02:39 +02:00
|
|
|
return true;
|
2017-11-30 21:00:47 +01:00
|
|
|
}
|
|
|
|
|
2018-07-09 19:26:06 +02:00
|
|
|
static void
|
|
|
|
build_sword_animation(Player *p, SDL_Renderer *renderer)
|
|
|
|
{
|
|
|
|
animation_load_texture(p->swordAnimation, "Extras/SwordSwing.png", renderer);
|
|
|
|
animation_set_frames(p->swordAnimation, (AnimationClip[]) {
|
|
|
|
{ 0, 0, 16, 16, 20 },
|
|
|
|
{ 16, 0, 16, 16, 20 },
|
|
|
|
{ 32, 0, 16, 16, 20 },
|
|
|
|
{ 48, 0, 16, 16, 20 },
|
|
|
|
{ 64, 0, 16, 16, 20 }
|
|
|
|
});
|
|
|
|
|
|
|
|
p->swordAnimation->loop = false;
|
|
|
|
p->swordAnimation->sprite->dim = GAME_DIMENSION;
|
|
|
|
p->swordAnimation->sprite->clip = (SDL_Rect) { 0, 0, 16, 16 };
|
|
|
|
p->swordAnimation->sprite->rotationPoint = (SDL_Point) { 16, 16 };
|
|
|
|
}
|
|
|
|
|
2017-12-12 11:20:08 +01:00
|
|
|
Player*
|
2018-08-20 14:30:31 +02:00
|
|
|
player_create(class_t class, Camera *cam)
|
2017-11-30 21:00:47 +01:00
|
|
|
{
|
2017-12-12 11:20:08 +01:00
|
|
|
Player *player = malloc(sizeof(Player));
|
|
|
|
player->sprite = sprite_create();
|
2018-07-06 22:30:28 +02:00
|
|
|
#ifdef DEBUG
|
|
|
|
player->daggers = 10;
|
2019-05-10 12:51:42 +02:00
|
|
|
player->gold = 500;
|
2018-07-06 22:30:28 +02:00
|
|
|
#else
|
2018-03-25 23:30:26 +02:00
|
|
|
player->daggers = 0;
|
2018-07-06 22:30:28 +02:00
|
|
|
#endif
|
2018-03-25 23:30:26 +02:00
|
|
|
player->stat_data.total_steps = 0;
|
|
|
|
player->stat_data.steps = 0;
|
|
|
|
player->stat_data.hits = 0;
|
|
|
|
player->stat_data.kills = 0;
|
|
|
|
player->stat_data.misses = 0;
|
|
|
|
player->xp = 0;
|
|
|
|
player->gold = 0;
|
|
|
|
player->potion_sips = 0;
|
2018-09-28 14:57:43 +02:00
|
|
|
player->phase_count = 0;
|
2018-03-25 23:30:26 +02:00
|
|
|
player->class = class;
|
|
|
|
player->state = ALIVE;
|
|
|
|
player->projectiles = linkedlist_create();
|
2019-02-20 18:08:13 +01:00
|
|
|
player->animationTimer = _timer_create();
|
2018-07-09 19:26:06 +02:00
|
|
|
player->swordAnimation = animation_create(5);
|
2018-08-21 12:30:44 +02:00
|
|
|
player->equipment.hasArtifacts = false;
|
2019-03-18 11:39:26 +01:00
|
|
|
player->equipment.keys = 0;
|
2019-02-28 20:37:19 +01:00
|
|
|
player->stateData.shopOwnerKiller = false;
|
2018-07-09 19:26:06 +02:00
|
|
|
|
2018-08-20 14:30:31 +02:00
|
|
|
build_sword_animation(player, cam->renderer);
|
2017-11-30 21:00:47 +01:00
|
|
|
|
2018-08-08 00:14:24 +02:00
|
|
|
memset(&player->skills,
|
|
|
|
0, PLAYER_SKILL_COUNT * sizeof(Skill*));
|
|
|
|
|
|
|
|
for (size_t i = 0; i < LAST_ARTIFACT_EFFECT; ++i)
|
|
|
|
player->equipment.artifacts[i].level = 0;
|
2018-02-28 22:31:38 +01:00
|
|
|
|
2017-12-12 11:20:08 +01:00
|
|
|
char asset[100];
|
2017-11-30 21:00:47 +01:00
|
|
|
switch (class) {
|
|
|
|
case ENGINEER:
|
2018-02-22 12:36:24 +01:00
|
|
|
m_strcpy(asset, 100, "Commissions/Engineer.png");
|
2017-12-19 19:42:05 +01:00
|
|
|
player->stats = (Stats) ENGINEER_STATS;
|
2017-11-30 21:00:47 +01:00
|
|
|
break;
|
|
|
|
case MAGE:
|
2018-02-22 12:36:24 +01:00
|
|
|
m_strcpy(asset, 100, "Commissions/Mage.png");
|
2017-12-19 19:42:05 +01:00
|
|
|
player->stats = (Stats) MAGE_STATS;
|
2019-05-14 15:20:45 +02:00
|
|
|
player->skills[0] = skill_create(VAMPIRIC_BLOW, cam);
|
2019-05-09 16:02:33 +02:00
|
|
|
player->skills[1] = skill_create(ERUPT, cam);
|
2019-05-09 10:16:38 +02:00
|
|
|
player->skills[2] = skill_create(BLINK, cam);
|
2017-11-30 21:00:47 +01:00
|
|
|
break;
|
|
|
|
case PALADIN:
|
2018-02-22 12:36:24 +01:00
|
|
|
m_strcpy(asset, 100, "Commissions/Paladin.png");
|
2017-12-19 19:42:05 +01:00
|
|
|
player->stats = (Stats) PALADIN_STATS;
|
2017-11-30 21:00:47 +01:00
|
|
|
break;
|
|
|
|
case ROGUE:
|
2018-02-22 12:36:24 +01:00
|
|
|
m_strcpy(asset, 100, "Commissions/Rogue.png");
|
2017-12-19 19:42:05 +01:00
|
|
|
player->stats = (Stats) ROGUE_STATS;
|
2018-09-13 15:28:03 +02:00
|
|
|
player->skills[0] = skill_create(BACKSTAB, cam);
|
|
|
|
player->skills[1] = skill_create(TRIP, cam);
|
2018-09-28 14:57:43 +02:00
|
|
|
player->skills[2] = skill_create(PHASE, cam);
|
2018-09-13 10:48:35 +02:00
|
|
|
player->daggers = 10;
|
2017-11-30 21:00:47 +01:00
|
|
|
break;
|
|
|
|
case WARRIOR:
|
2018-02-22 12:36:24 +01:00
|
|
|
m_strcpy(asset, 100, "Commissions/Warrior.png");
|
2017-12-19 19:42:05 +01:00
|
|
|
player->stats = (Stats) WARRIOR_STATS;
|
2018-08-20 14:30:31 +02:00
|
|
|
player->skills[0] = skill_create(FLURRY, cam);
|
|
|
|
player->skills[1] = skill_create(BASH, cam);
|
|
|
|
player->skills[2] = skill_create(CHARGE, cam);
|
2017-11-30 21:00:47 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-05-06 13:48:40 +02:00
|
|
|
player->skills[3] = skill_create(DAGGER_THROW, cam);
|
2018-08-20 14:30:31 +02:00
|
|
|
player->skills[4] = skill_create(SIP_HEALTH, cam);
|
2018-02-28 22:31:38 +01:00
|
|
|
|
2018-08-20 14:30:31 +02:00
|
|
|
sprite_load_texture(player->sprite, asset, 0, cam->renderer);
|
2017-12-12 11:20:08 +01:00
|
|
|
player->sprite->pos = (Position) { TILE_DIMENSION, TILE_DIMENSION };
|
2018-02-23 23:53:52 +01:00
|
|
|
player->sprite->dim = GAME_DIMENSION;
|
2017-12-14 12:01:05 +01:00
|
|
|
player->sprite->clip = (SDL_Rect) { 0, 0, 16, 16 };
|
2017-12-18 15:26:56 +01:00
|
|
|
|
2017-11-30 21:00:47 +01:00
|
|
|
return player;
|
|
|
|
}
|
2017-12-12 11:20:08 +01:00
|
|
|
|
2019-03-18 11:39:26 +01:00
|
|
|
void
|
|
|
|
player_reset_on_levelchange(Player *player)
|
|
|
|
{
|
|
|
|
player->sprite->pos = (Position) {
|
|
|
|
TILE_DIMENSION, TILE_DIMENSION };
|
|
|
|
player->equipment.keys = 0;
|
|
|
|
}
|
|
|
|
|
2018-01-31 13:52:11 +01:00
|
|
|
ExperienceData player_get_xp_data(Player *p)
|
|
|
|
{
|
|
|
|
ExperienceData data;
|
|
|
|
data.previousLevel = next_level_threshold(p->stats.lvl - 1);
|
|
|
|
data.current = p->xp;
|
|
|
|
data.nextLevel = next_level_threshold(p->stats.lvl);
|
|
|
|
data.level = p->stats.lvl;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2018-02-28 22:31:38 +01:00
|
|
|
void
|
|
|
|
player_monster_kill_check(Player *player, Monster *monster)
|
|
|
|
{
|
|
|
|
if (!monster)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (monster->stats.hp <= 0) {
|
|
|
|
unsigned int gained_xp = 5 * monster->stats.lvl;
|
2018-03-25 23:30:26 +02:00
|
|
|
player->stat_data.kills += 1;
|
2018-02-28 22:31:38 +01:00
|
|
|
mixer_play_effect(DEATH);
|
|
|
|
gui_log("You killed %s and gained %d xp",
|
|
|
|
monster->lclabel, gained_xp);
|
|
|
|
player_gain_xp(player, gained_xp);
|
2018-09-03 20:27:34 +02:00
|
|
|
|
|
|
|
#ifdef STEAM_BUILD
|
|
|
|
if (strcmp("The Shadow", monster->label) == 0)
|
|
|
|
steam_set_achievement(LIGHTS_ON);
|
|
|
|
else if (strcmp("The Hell Hound", monster->label) == 0)
|
|
|
|
steam_set_achievement(BAD_DOG);
|
|
|
|
else if (strcmp("Platino", monster->label) == 0)
|
|
|
|
steam_set_achievement(DRAGON_SLAYER);
|
|
|
|
else if (strcmp("The Cleric", monster->label) == 0)
|
|
|
|
steam_set_achievement(THE_DOCTOR_IS_OUT);
|
|
|
|
else if (strcmp("Linus, the Developer", monster->label) == 0)
|
|
|
|
steam_set_achievement(BUGGFIXER);
|
2018-09-06 20:12:37 +02:00
|
|
|
else if (strcmp("Ti, the Mage", monster->label) == 0)
|
|
|
|
steam_set_achievement(BUGGCREATOR);
|
2018-09-03 20:27:34 +02:00
|
|
|
#endif // STEAM_BUILD
|
2019-03-08 10:16:15 +01:00
|
|
|
if (strcmp("The Trader", monster->label) == 0) {
|
|
|
|
player->stateData.shopOwnerKiller = true;
|
|
|
|
}
|
2019-03-10 00:15:47 +01:00
|
|
|
|
|
|
|
Event event;
|
|
|
|
event.type = MONSTER_KILLED_EVENT;
|
|
|
|
event.monsterKilled.monster = monster;
|
|
|
|
event.monsterKilled.player = player;
|
|
|
|
event_trigger(&event);
|
2018-02-28 22:31:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-17 13:43:41 +01:00
|
|
|
void
|
2017-12-18 15:26:56 +01:00
|
|
|
player_hit(Player *p, unsigned int dmg)
|
|
|
|
{
|
|
|
|
if (dmg > 0) {
|
2018-02-03 23:39:49 +01:00
|
|
|
Position pos = p->sprite->pos;
|
|
|
|
pos.x += 8;
|
|
|
|
pos.y += 8;
|
2018-08-22 13:13:54 +02:00
|
|
|
particle_engine_bloodspray(pos, DIM(8, 8), dmg);
|
2018-02-16 14:16:21 +01:00
|
|
|
mixer_play_effect(PLAYER_HIT0 + get_random(2));
|
2018-05-15 11:16:56 +02:00
|
|
|
char msg[5];
|
|
|
|
m_sprintf(msg, 5, "-%d", dmg);
|
|
|
|
actiontextbuilder_create_text(msg,
|
2018-05-15 23:21:28 +02:00
|
|
|
C_RED,
|
2018-05-15 11:16:56 +02:00
|
|
|
&p->sprite->pos);
|
2018-10-12 23:39:54 +02:00
|
|
|
|
|
|
|
gamecontroller_rumble(0.50, 100);
|
2017-12-18 15:26:56 +01:00
|
|
|
} else {
|
2018-05-15 11:16:56 +02:00
|
|
|
actiontextbuilder_create_text("Dodged",
|
2018-05-15 23:21:28 +02:00
|
|
|
C_YELLOW,
|
2018-05-15 11:16:56 +02:00
|
|
|
&p->sprite->pos);
|
2017-12-18 15:26:56 +01:00
|
|
|
}
|
2018-05-15 11:16:56 +02:00
|
|
|
|
2017-12-18 15:26:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
player_render(Player *player, Camera *cam)
|
|
|
|
{
|
2018-09-28 14:57:43 +02:00
|
|
|
sprite_set_alpha(player->sprite, player->phase_count ? 150 : 255);
|
2017-12-18 15:26:56 +01:00
|
|
|
sprite_render(player->sprite, cam);
|
2018-03-08 00:58:26 +01:00
|
|
|
|
|
|
|
LinkedList *projectile = player->projectiles;
|
|
|
|
while (projectile) {
|
|
|
|
projectile_render(projectile->data, cam);
|
|
|
|
projectile = projectile->next;
|
|
|
|
}
|
2017-12-18 15:26:56 +01:00
|
|
|
}
|
2018-05-15 11:16:56 +02:00
|
|
|
|
2018-07-09 19:26:06 +02:00
|
|
|
void
|
|
|
|
player_render_toplayer(Player *player, Camera *camera)
|
|
|
|
{
|
|
|
|
animation_render(player->swordAnimation, camera);
|
2017-12-18 15:26:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
player_reset_steps(Player *p)
|
|
|
|
{
|
2018-03-25 23:30:26 +02:00
|
|
|
p->stat_data.steps = 0;
|
2017-12-18 15:26:56 +01:00
|
|
|
}
|
|
|
|
|
2018-10-24 22:18:56 +02:00
|
|
|
static void
|
|
|
|
reset_dagger_skill(Player *p)
|
|
|
|
{
|
|
|
|
p->skills[3]->resetCountdown = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
player_update(UpdateData *data)
|
2018-03-08 00:58:26 +01:00
|
|
|
{
|
2018-03-25 23:30:26 +02:00
|
|
|
Player *player = data->player;
|
2018-05-21 21:03:59 +02:00
|
|
|
if (player->stats.hp <= 0)
|
|
|
|
return;
|
2018-05-17 23:14:42 +02:00
|
|
|
|
2018-09-10 22:27:26 +02:00
|
|
|
sprite_update(player->sprite, data);
|
|
|
|
|
2018-05-20 00:02:39 +02:00
|
|
|
check_skill_activation(data);
|
2018-09-10 22:27:26 +02:00
|
|
|
if (player->sprite->state != SPRITE_STATE_FALLING && !check_skill_trigger(data))
|
2018-05-20 00:02:39 +02:00
|
|
|
handle_next_move(data);
|
2018-05-17 23:14:42 +02:00
|
|
|
|
2018-09-10 22:27:26 +02:00
|
|
|
if (player->sprite->state == SPRITE_STATE_FALLING && player->stats.hp > 0) {
|
|
|
|
if (player->sprite->dim.width <= 4) {
|
|
|
|
player->stats.hp = 0;
|
|
|
|
player->sprite->state = SPRITE_STATE_DEFAULT;
|
2018-03-25 23:30:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LinkedList *remaining = linkedlist_create();
|
|
|
|
while (player->projectiles) {
|
|
|
|
Projectile *p = linkedlist_pop(&player->projectiles);
|
2018-03-13 16:51:08 +01:00
|
|
|
projectile_update(p, data);
|
2018-03-25 23:30:26 +02:00
|
|
|
if (p->alive) {
|
|
|
|
linkedlist_push(&remaining, p);
|
2018-03-08 00:58:26 +01:00
|
|
|
} else {
|
2018-03-25 23:30:26 +02:00
|
|
|
projectile_destroy(p);
|
|
|
|
action_spent(player);
|
2018-10-24 22:18:56 +02:00
|
|
|
if (player->class == ROGUE)
|
|
|
|
reset_dagger_skill(player);
|
2018-03-08 00:58:26 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-25 23:30:26 +02:00
|
|
|
|
|
|
|
linkedlist_destroy(&player->projectiles);
|
|
|
|
player->projectiles = remaining;
|
2018-07-09 19:26:06 +02:00
|
|
|
|
|
|
|
animation_update(player->swordAnimation);
|
2018-03-08 00:58:26 +01:00
|
|
|
}
|
|
|
|
|
2018-08-08 00:14:24 +02:00
|
|
|
static void
|
|
|
|
player_reset(Player *player)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < LAST_ARTIFACT_EFFECT; ++i)
|
|
|
|
player->equipment.artifacts[i].level = 0;
|
2018-08-21 12:30:44 +02:00
|
|
|
player->equipment.hasArtifacts = false;
|
2018-08-08 00:14:24 +02:00
|
|
|
|
|
|
|
while (player->projectiles)
|
|
|
|
projectile_destroy(linkedlist_pop(&player->projectiles));
|
|
|
|
}
|
|
|
|
|
2017-12-12 11:20:08 +01:00
|
|
|
void
|
|
|
|
player_destroy(Player *player)
|
|
|
|
{
|
2018-08-08 00:14:24 +02:00
|
|
|
player_reset(player);
|
|
|
|
|
2017-12-12 11:20:08 +01:00
|
|
|
if (player->sprite)
|
|
|
|
sprite_destroy(player->sprite);
|
|
|
|
|
2018-07-09 19:26:06 +02:00
|
|
|
animation_destroy(player->swordAnimation);
|
2018-05-09 00:21:38 +02:00
|
|
|
timer_destroy(player->animationTimer);
|
|
|
|
|
2018-02-28 22:31:38 +01:00
|
|
|
for (size_t i = 0; i < PLAYER_SKILL_COUNT; ++i) {
|
|
|
|
if (player->skills[i])
|
|
|
|
skill_destroy(player->skills[i]);
|
|
|
|
player->skills[i] = NULL;
|
|
|
|
}
|
|
|
|
|
2017-12-12 11:20:08 +01:00
|
|
|
free(player);
|
|
|
|
}
|
2018-05-16 19:09:01 +02:00
|
|
|
|
|
|
|
bool
|
|
|
|
player_turn_over(Player *player)
|
|
|
|
{
|
|
|
|
return player->stat_data.steps >= player->stats.speed;
|
|
|
|
}
|
2018-08-08 00:14:24 +02:00
|
|
|
|
|
|
|
Uint32
|
|
|
|
player_has_artifact(Player *p, MagicalEffect effect)
|
|
|
|
{
|
|
|
|
return p->equipment.artifacts[effect].level;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
player_add_artifact(Player *p, Artifact *a)
|
|
|
|
{
|
2019-03-04 20:32:09 +01:00
|
|
|
if (a->price > p->gold) {
|
|
|
|
gui_log("You don't have enough gold to buy a %s",
|
|
|
|
a->info.name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-08 00:14:24 +02:00
|
|
|
if (a->collected)
|
|
|
|
return;
|
|
|
|
|
2019-03-04 20:32:09 +01:00
|
|
|
if (a->price) {
|
|
|
|
gui_log("You pay %d gold for %s", a->price, a->info.name);
|
|
|
|
p->gold -= a->price;
|
|
|
|
}
|
|
|
|
|
2018-08-09 13:58:16 +02:00
|
|
|
mixer_play_effect(MAGIC_PICKUP);
|
2018-08-08 00:14:24 +02:00
|
|
|
a->collected = true;
|
|
|
|
|
|
|
|
ArtifactData *ad = &p->equipment.artifacts[a->effect];
|
|
|
|
ad->name = a->info.name;
|
|
|
|
ad->desc = a->info.desc;
|
|
|
|
ad->level += a->level;
|
|
|
|
|
|
|
|
gui_log("You pick an ancient %s", ad->name);
|
|
|
|
gui_log("%s (%u)", ad->desc, ad->level);
|
2018-08-21 12:30:44 +02:00
|
|
|
p->equipment.hasArtifacts = true;
|
2018-08-08 00:14:24 +02:00
|
|
|
}
|
2018-08-30 11:13:50 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
player_set_falling(Player *player)
|
|
|
|
{
|
2018-09-10 22:23:45 +02:00
|
|
|
mixer_play_effect(FALL0 + get_random(1));
|
2018-09-12 08:03:28 +02:00
|
|
|
player->sprite->clip = CLIP16(0, 0);
|
2018-09-10 22:27:26 +02:00
|
|
|
player->sprite->state = SPRITE_STATE_FALLING;
|
2018-08-30 11:13:50 +02:00
|
|
|
}
|