Add possibility to retrieve thrown daggers.

This commit is contained in:
Linus_Probert 2018-03-13 16:51:08 +01:00
parent ac180d1efb
commit d6c21745cd
6 changed files with 62 additions and 32 deletions

View File

@ -45,6 +45,7 @@
#include "random.h"
#include "skillbar.h"
#include "texturecache.h"
#include "update_data.h"
typedef enum Turn_t {
PLAYER,
@ -65,6 +66,7 @@ static double renderScale = 1.0;
static Menu *mainMenu = NULL;
static Menu *inGameMenu = NULL;
static Timer *menuTimer = NULL;
static UpdateData gUpdateData;
static GameState gGameState;
static Camera gCamera;
static SDL_Rect gameViewport;
@ -207,6 +209,9 @@ startGame(void *unused)
gPlayer = player_create(WARRIOR, gRenderer);
mixer_play_music(GAME_MUSIC0 + get_random(2));
resetGame();
gUpdateData.player = gPlayer;
gUpdateData.map = gMap;
gUpdateData.matrix = gRoomMatrix;
gui_clear_message_log();
gui_log("The Dungeon Crawl begins!");
gui_event_message("Welcome to the dungeon!");
@ -348,12 +353,6 @@ init(void)
return result;
}
static void
loadMedia(void)
{
gPlayer = player_create(WARRIOR, gRenderer);
}
static bool
handle_main_events(SDL_Event *event)
{
@ -461,7 +460,7 @@ run_game(void)
gui_update_player_stats(gGui, gPlayer, gMap, gRenderer);
particle_engine_update(deltaTime);
player_update(gPlayer, gRoomMatrix, deltaTime);
player_update(&gUpdateData);
roommatrix_update_with_player(gRoomMatrix, gPlayer);
if (currentTurn == PLAYER) {
@ -595,6 +594,7 @@ void run(void)
oldTime = currentTime;
currentTime = SDL_GetTicks();
deltaTime = (float) ((currentTime - oldTime) / 1000.0);
gUpdateData.deltatime = deltaTime;
}
}
@ -647,7 +647,6 @@ int main(int argc, char *argv[])
if (!init())
return 1;
loadMedia();
run();
close();
PHYSFS_deinit();

View File

@ -368,7 +368,7 @@ player_create(class_t class, SDL_Renderer *renderer)
{
Player *player = malloc(sizeof(Player));
player->sprite = sprite_create();
player->daggers = 10;
player->daggers = 0;
player->total_steps = 0;
player->steps = 0;
player->xp = 0;
@ -507,22 +507,22 @@ player_reset_steps(Player *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;
LinkedList *last, *current, *next;
last = NULL;
current = player->projectiles;
current = data->player->projectiles;
next = NULL;
while (current) {
Projectile *p = current->data;
projectile_update(p, player, rm, deltatime);
projectile_update(p, data);
if (!p->alive) {
if (last == NULL)
player->projectiles = current->next;
data->player->projectiles = current->next;
else
last->next = current->next;
@ -533,7 +533,7 @@ void player_update(Player *player, RoomMatrix *rm, float deltatime)
current->next = NULL;
linkedlist_destroy(&current);
current = next;
action_spent(player);
action_spent(data->player);
} else {
last = current;
current = current->next;

View File

@ -29,6 +29,9 @@
#define PLAYER_SKILL_COUNT 5
// Foward declare
struct UpdateData_t;
enum PlayerClass { ENGINEER, MAGE, PALADIN, ROGUE, WARRIOR };
typedef enum PlayerClass class_t;
@ -78,7 +81,7 @@ void
player_reset_steps(Player*);
void
player_update(Player*, RoomMatrix*, float deltatime);
player_update(struct UpdateData_t *);
void
player_render(Player*, Camera*);

View File

@ -26,6 +26,7 @@
#include "gui.h"
#include "item_builder.h"
#include "random.h"
#include "update_data.h"
static void
onDaggerRender(Sprite *s)
@ -66,10 +67,10 @@ projectile_create(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.y += (int) (p->velocity.y * deltatime);
p->sprite->pos.x += (int) (p->velocity.x * data->deltatime);
p->sprite->pos.y += (int) (p->velocity.y * data->deltatime);
if (timer_get_ticks(p->lifetime) > 2000)
p->alive = false;
@ -81,7 +82,7 @@ projectile_update(Projectile *p, Player *player, RoomMatrix *rm, float deltatime
collisionPos.y += TILE_DIMENSION;
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)
return;
@ -89,24 +90,17 @@ projectile_update(Projectile *p, Player *player, RoomMatrix *rm, float deltatime
return;
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) {
gui_log("Your dagger pierced %s for %u damage", space->monster->lclabel, dmg);
mixer_play_effect(SWORD_HIT);
player->hits += 1;
data->player->hits += 1;
}
/*
* 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");
if (get_random(2) == 0) {
Item *item = item_builder_build_item(DAGGER, 1);
item->sprite->pos = space->monster->sprite->pos;
linkedlist_append(&map->items, item);
linkedlist_append(&data->map->items, item);
}
*/
monster_hit(space->monster, dmg);
}
p->alive = false;

View File

@ -25,6 +25,7 @@
#include "vector2d.h"
#include "timer.h"
#include "roommatrix.h"
#include "update_data.h"
#define DAGGER_VELOCITY 500
@ -47,7 +48,7 @@ Projectile *
projectile_create(void);
void
projectile_update(Projectile*, struct Player_t*, RoomMatrix *rm, float deltatime);
projectile_update(Projectile*, UpdateData *);
void
projectile_render(Projectile*, Camera*);

33
src/update_data.h Normal file
View File

@ -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_