Add possibility to retrieve thrown daggers.
This commit is contained in:
parent
ac180d1efb
commit
d6c21745cd
15
src/main.c
15
src/main.c
|
@ -45,6 +45,7 @@
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
#include "skillbar.h"
|
#include "skillbar.h"
|
||||||
#include "texturecache.h"
|
#include "texturecache.h"
|
||||||
|
#include "update_data.h"
|
||||||
|
|
||||||
typedef enum Turn_t {
|
typedef enum Turn_t {
|
||||||
PLAYER,
|
PLAYER,
|
||||||
|
@ -65,6 +66,7 @@ static double renderScale = 1.0;
|
||||||
static Menu *mainMenu = NULL;
|
static Menu *mainMenu = NULL;
|
||||||
static Menu *inGameMenu = NULL;
|
static Menu *inGameMenu = NULL;
|
||||||
static Timer *menuTimer = NULL;
|
static Timer *menuTimer = NULL;
|
||||||
|
static UpdateData gUpdateData;
|
||||||
static GameState gGameState;
|
static GameState gGameState;
|
||||||
static Camera gCamera;
|
static Camera gCamera;
|
||||||
static SDL_Rect gameViewport;
|
static SDL_Rect gameViewport;
|
||||||
|
@ -207,6 +209,9 @@ startGame(void *unused)
|
||||||
gPlayer = player_create(WARRIOR, gRenderer);
|
gPlayer = player_create(WARRIOR, gRenderer);
|
||||||
mixer_play_music(GAME_MUSIC0 + get_random(2));
|
mixer_play_music(GAME_MUSIC0 + get_random(2));
|
||||||
resetGame();
|
resetGame();
|
||||||
|
gUpdateData.player = gPlayer;
|
||||||
|
gUpdateData.map = gMap;
|
||||||
|
gUpdateData.matrix = gRoomMatrix;
|
||||||
gui_clear_message_log();
|
gui_clear_message_log();
|
||||||
gui_log("The Dungeon Crawl begins!");
|
gui_log("The Dungeon Crawl begins!");
|
||||||
gui_event_message("Welcome to the dungeon!");
|
gui_event_message("Welcome to the dungeon!");
|
||||||
|
@ -348,12 +353,6 @@ init(void)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
loadMedia(void)
|
|
||||||
{
|
|
||||||
gPlayer = player_create(WARRIOR, gRenderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
handle_main_events(SDL_Event *event)
|
handle_main_events(SDL_Event *event)
|
||||||
{
|
{
|
||||||
|
@ -461,7 +460,7 @@ run_game(void)
|
||||||
|
|
||||||
gui_update_player_stats(gGui, gPlayer, gMap, gRenderer);
|
gui_update_player_stats(gGui, gPlayer, gMap, gRenderer);
|
||||||
particle_engine_update(deltaTime);
|
particle_engine_update(deltaTime);
|
||||||
player_update(gPlayer, gRoomMatrix, deltaTime);
|
player_update(&gUpdateData);
|
||||||
|
|
||||||
roommatrix_update_with_player(gRoomMatrix, gPlayer);
|
roommatrix_update_with_player(gRoomMatrix, gPlayer);
|
||||||
if (currentTurn == PLAYER) {
|
if (currentTurn == PLAYER) {
|
||||||
|
@ -595,6 +594,7 @@ void run(void)
|
||||||
oldTime = currentTime;
|
oldTime = currentTime;
|
||||||
currentTime = SDL_GetTicks();
|
currentTime = SDL_GetTicks();
|
||||||
deltaTime = (float) ((currentTime - oldTime) / 1000.0);
|
deltaTime = (float) ((currentTime - oldTime) / 1000.0);
|
||||||
|
gUpdateData.deltatime = deltaTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -647,7 +647,6 @@ int main(int argc, char *argv[])
|
||||||
if (!init())
|
if (!init())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
loadMedia();
|
|
||||||
run();
|
run();
|
||||||
close();
|
close();
|
||||||
PHYSFS_deinit();
|
PHYSFS_deinit();
|
||||||
|
|
14
src/player.c
14
src/player.c
|
@ -368,7 +368,7 @@ player_create(class_t class, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
Player *player = malloc(sizeof(Player));
|
Player *player = malloc(sizeof(Player));
|
||||||
player->sprite = sprite_create();
|
player->sprite = sprite_create();
|
||||||
player->daggers = 10;
|
player->daggers = 0;
|
||||||
player->total_steps = 0;
|
player->total_steps = 0;
|
||||||
player->steps = 0;
|
player->steps = 0;
|
||||||
player->xp = 0;
|
player->xp = 0;
|
||||||
|
@ -507,22 +507,22 @@ player_reset_steps(Player *p)
|
||||||
player_print(p);
|
player_print(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void player_update(Player *player, RoomMatrix *rm, float deltatime)
|
void player_update(UpdateData *data)
|
||||||
{
|
{
|
||||||
if (!player->projectiles)
|
if (!data->player->projectiles)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LinkedList *last, *current, *next;
|
LinkedList *last, *current, *next;
|
||||||
last = NULL;
|
last = NULL;
|
||||||
current = player->projectiles;
|
current = data->player->projectiles;
|
||||||
next = NULL;
|
next = NULL;
|
||||||
|
|
||||||
while (current) {
|
while (current) {
|
||||||
Projectile *p = current->data;
|
Projectile *p = current->data;
|
||||||
projectile_update(p, player, rm, deltatime);
|
projectile_update(p, data);
|
||||||
if (!p->alive) {
|
if (!p->alive) {
|
||||||
if (last == NULL)
|
if (last == NULL)
|
||||||
player->projectiles = current->next;
|
data->player->projectiles = current->next;
|
||||||
else
|
else
|
||||||
last->next = current->next;
|
last->next = current->next;
|
||||||
|
|
||||||
|
@ -533,7 +533,7 @@ void player_update(Player *player, RoomMatrix *rm, float deltatime)
|
||||||
current->next = NULL;
|
current->next = NULL;
|
||||||
linkedlist_destroy(¤t);
|
linkedlist_destroy(¤t);
|
||||||
current = next;
|
current = next;
|
||||||
action_spent(player);
|
action_spent(data->player);
|
||||||
} else {
|
} else {
|
||||||
last = current;
|
last = current;
|
||||||
current = current->next;
|
current = current->next;
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
|
|
||||||
#define PLAYER_SKILL_COUNT 5
|
#define PLAYER_SKILL_COUNT 5
|
||||||
|
|
||||||
|
// Foward declare
|
||||||
|
struct UpdateData_t;
|
||||||
|
|
||||||
enum PlayerClass { ENGINEER, MAGE, PALADIN, ROGUE, WARRIOR };
|
enum PlayerClass { ENGINEER, MAGE, PALADIN, ROGUE, WARRIOR };
|
||||||
typedef enum PlayerClass class_t;
|
typedef enum PlayerClass class_t;
|
||||||
|
|
||||||
|
@ -78,7 +81,7 @@ void
|
||||||
player_reset_steps(Player*);
|
player_reset_steps(Player*);
|
||||||
|
|
||||||
void
|
void
|
||||||
player_update(Player*, RoomMatrix*, float deltatime);
|
player_update(struct UpdateData_t *);
|
||||||
|
|
||||||
void
|
void
|
||||||
player_render(Player*, Camera*);
|
player_render(Player*, Camera*);
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
#include "item_builder.h"
|
#include "item_builder.h"
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
|
#include "update_data.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
onDaggerRender(Sprite *s)
|
onDaggerRender(Sprite *s)
|
||||||
|
@ -66,10 +67,10 @@ projectile_create(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
projectile_update(Projectile *p, Player *player, RoomMatrix *rm, float deltatime)
|
projectile_update(Projectile *p, UpdateData *data)
|
||||||
{
|
{
|
||||||
p->sprite->pos.x += (int) (p->velocity.x * deltatime);
|
p->sprite->pos.x += (int) (p->velocity.x * data->deltatime);
|
||||||
p->sprite->pos.y += (int) (p->velocity.y * deltatime);
|
p->sprite->pos.y += (int) (p->velocity.y * data->deltatime);
|
||||||
|
|
||||||
if (timer_get_ticks(p->lifetime) > 2000)
|
if (timer_get_ticks(p->lifetime) > 2000)
|
||||||
p->alive = false;
|
p->alive = false;
|
||||||
|
@ -81,7 +82,7 @@ projectile_update(Projectile *p, Player *player, RoomMatrix *rm, float deltatime
|
||||||
collisionPos.y += TILE_DIMENSION;
|
collisionPos.y += TILE_DIMENSION;
|
||||||
|
|
||||||
Position roomPos = position_to_matrix_coords(&collisionPos);
|
Position roomPos = position_to_matrix_coords(&collisionPos);
|
||||||
RoomSpace *space = &rm->spaces[roomPos.x][roomPos.y];
|
RoomSpace *space = &data->matrix->spaces[roomPos.x][roomPos.y];
|
||||||
if (!space->occupied)
|
if (!space->occupied)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -89,24 +90,17 @@ projectile_update(Projectile *p, Player *player, RoomMatrix *rm, float deltatime
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (space->monster) {
|
if (space->monster) {
|
||||||
Uint32 dmg = stats_fight(&player->stats, &space->monster->stats);
|
Uint32 dmg = stats_fight(&data->player->stats, &space->monster->stats);
|
||||||
if (dmg > 0) {
|
if (dmg > 0) {
|
||||||
gui_log("Your dagger pierced %s for %u damage", space->monster->lclabel, dmg);
|
gui_log("Your dagger pierced %s for %u damage", space->monster->lclabel, dmg);
|
||||||
mixer_play_effect(SWORD_HIT);
|
mixer_play_effect(SWORD_HIT);
|
||||||
player->hits += 1;
|
data->player->hits += 1;
|
||||||
}
|
}
|
||||||
/*
|
if (get_random(2) == 0) {
|
||||||
* TODO(Linus): This can be fixed so that daggers
|
|
||||||
* can be retrieved. Probably best to create an "UpdateData" container that
|
|
||||||
* can be sent as arguments down the update queue.
|
|
||||||
|
|
||||||
if (get_random(1) == 0) {
|
|
||||||
debug("Adding dagger item");
|
|
||||||
Item *item = item_builder_build_item(DAGGER, 1);
|
Item *item = item_builder_build_item(DAGGER, 1);
|
||||||
item->sprite->pos = space->monster->sprite->pos;
|
item->sprite->pos = space->monster->sprite->pos;
|
||||||
linkedlist_append(&map->items, item);
|
linkedlist_append(&data->map->items, item);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
monster_hit(space->monster, dmg);
|
monster_hit(space->monster, dmg);
|
||||||
}
|
}
|
||||||
p->alive = false;
|
p->alive = false;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "vector2d.h"
|
#include "vector2d.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "roommatrix.h"
|
#include "roommatrix.h"
|
||||||
|
#include "update_data.h"
|
||||||
|
|
||||||
#define DAGGER_VELOCITY 500
|
#define DAGGER_VELOCITY 500
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ Projectile *
|
||||||
projectile_create(void);
|
projectile_create(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
projectile_update(Projectile*, struct Player_t*, RoomMatrix *rm, float deltatime);
|
projectile_update(Projectile*, UpdateData *);
|
||||||
|
|
||||||
void
|
void
|
||||||
projectile_render(Projectile*, Camera*);
|
projectile_render(Projectile*, Camera*);
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UPDATE_DATA_H_
|
||||||
|
#define UPDATE_DATA_H_
|
||||||
|
|
||||||
|
#include "player.h"
|
||||||
|
#include "map.h"
|
||||||
|
#include "roommatrix.h"
|
||||||
|
|
||||||
|
typedef struct UpdateData_t {
|
||||||
|
Player *player;
|
||||||
|
Map *map;
|
||||||
|
RoomMatrix *matrix;
|
||||||
|
float deltatime;
|
||||||
|
} UpdateData;
|
||||||
|
|
||||||
|
#endif // UPDATE_DATA_H_
|
Loading…
Reference in New Issue