Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 17 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ get_version_from_git()
set(breakhack_MAJOR_VERSION ${PROJECT_VERSION_MAJOR})
set(breakhack_MINOR_VERSION ${PROJECT_VERSION_MINOR})
set(breakhack_PATCH_VERSION ${PROJECT_VERSION_PATCH})
set(breakhack_VERSION ${PROJECT_VERSION})
set(breakhack_FULL_VERSION ${FULL_VERSION})
set(breakhack_RELEASE_TYPE "")

configure_file(
Expand Down Expand Up @@ -144,30 +146,27 @@ set(SDLIMAGE_WEBP OFF)
set(SDLIMAGE_XCF OFF)
set(SDLIMAGE_XPM OFF)
set(SDLIMAGE_XV OFF)
add_subdirectory(external/SDL_image)
set(SDL_IMAGE_INCLUDE_DIR lib/SDL_image/include)
add_subdirectory(external/SDL_image SYSTEM)
set(SDL_IMAGE_LIBRARY SDL3_image-static)

# opusfile caused issues in macos build and we don't need it anyways
set(SDLMIXER_OPUS OFF)
add_subdirectory(external/SDL_mixer)
set(SDL_MIXER_INCLUDE_DIR lib/SDL_mixer/include)
add_subdirectory(external/SDL_mixer SYSTEM)
set(SDL_MIXER_LIBRARY SDL3_mixer-static)

set(SDLTTF_VENDORED ON)
add_subdirectory(external/SDL_ttf)
set(SDL_TTF_INCLUDE_DIR lib/SDL_ttf/include)
add_subdirectory(external/SDL_ttf SYSTEM)
set(SDL_TTF_LIBRARY SDL3_ttf-static)

# Include lua lib
add_subdirectory(lib/lua-5.3.5)
add_subdirectory(lib/lua-5.3.5 SYSTEM)
set(LUA_LIBRARIES lua)
set(LUA_INCLUDE_DIR lib/lua-5.3.5/src)

# Include PHYSFS lib
set(PHYSFS_BUILD_SHARED off CACHE INTERNAL "" FORCE)
set(PHYSFS_BUILD_TEST off CACHE INTERNAL "" FORCE)
add_subdirectory(lib/physfs-3.0)
add_subdirectory(lib/physfs-3.0 SYSTEM)
include_directories(lib/physfs-3.0/src)
set(PHYSFS_LIBRARY physfs-static)
set(PHYSFS_INCLUDE_DIR physfs-3.0/src)
Expand Down Expand Up @@ -195,16 +194,12 @@ else ()
endif ()

set(INCLUDE_DIRS
${PROJECT_BINARY_DIR}
${SDL_INCLUDE_DIR}
${SDL_IMAGE_INCLUDE_DIR}
${SDL_TTF_INCLUDE_DIR}
${SDL_MIXER_INCLUDE_DIR}
${PHYSFS_INCLUDE_DIR}
${LUA_INCLUDE_DIR}
lib/sqlite3
lib/bh_random/src
lib/checksum/src
PRIVATE ${PROJECT_BINARY_DIR}
PRIVATE lib/sqlite3
PRIVATE lib/bh_random/src
PRIVATE lib/checksum/src
SYSTEM ${PHYSFS_INCLUDE_DIR}
SYSTEM ${LUA_INCLUDE_DIR}
)
# PROGRAMS:
add_executable(${PROJECT_NAME})
Expand All @@ -214,11 +209,7 @@ set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99)
target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIRS})

if (NOT MSVC)
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS
-std=gnu11 -pedantic -Wall -Wextra -Wshadow
-Wpointer-arith -Wcast-qual -Wstrict-prototypes
-Wmissing-prototypes -Wconversion -Wno-sign-conversion
)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wconversion -Wno-sign-conversion")
if (NOT APPLE)
add_definitions(-static -static-libgcc -static-libstdc++)
endif ()
Expand All @@ -235,15 +226,15 @@ set_source_files_properties(lib/sqlite3/sqlite3.c COMPILE_FLAGS -w)

target_link_libraries(${PROJECT_NAME}
${CMAKE_DL_LIBS} # Sqlite needs DL libs
bh_random
checksum
${SDL_LIBRARY}
${SDL_IMAGE_LIBRARY}
${SDL_TTF_LIBRARY}
${SDL_MIXER_LIBRARY}
${LUA_LIBRARIES}
${PHYSFS_LIBRARY}
bh_random
checksum
)
)

if (STEAM)
target_link_libraries(${PROJECT_NAME}
Expand Down
18 changes: 10 additions & 8 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
*/

#ifndef CONFIG_H_
#define CONFIG_H_
#define CONFIG_H_

#cmakedefine _WIN32 ${WIN32}

#define GAME_TITLE "@breakhack_GAME_TITLE@"
#define MAJOR_VERSION @breakhack_MAJOR_VERSION@
#define MINOR_VERSION @breakhack_MINOR_VERSION@
#define PATCH_VERSION @breakhack_PATCH_VERSION@
#define RELEASE_TYPE "@breakhack_RELEASE_TYPE@"
#define GAME_TITLE "@breakhack_GAME_TITLE@"
#define MAJOR_VERSION @breakhack_MAJOR_VERSION@
#define MINOR_VERSION @breakhack_MINOR_VERSION@
#define PATCH_VERSION @breakhack_PATCH_VERSION@
#define VERSION_STR "@breakhack_VERSION@"
#define VERSION_STR_FULL "@breakhack_FULL_VERSION@"
#define RELEASE_TYPE "@breakhack_RELEASE_TYPE@"


/* Checksums */
#define SO_LIBSTEAM_CHECKSUM @breakhack_STEAMAPI_SO_CHECKSUM@
#define DLL_LIBSTEAM_CHECKSUM @breakhack_STEAMAPI_DLL_CHECKSUM@
#define SO_LIBSTEAM_CHECKSUM @breakhack_STEAMAPI_SO_CHECKSUM@
#define DLL_LIBSTEAM_CHECKSUM @breakhack_STEAMAPI_DLL_CHECKSUM@

#endif // CONFIG_H_
6 changes: 5 additions & 1 deletion src/item_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ item_builder_build_key(unsigned int type)
static void
pickup_bloodlust(Item *item, Player *player)
{
(void) item;

gui_log("You drink a bloodlust potion. Rage pulses through your veins.");
player->effects.effect = POTION_BLOODLUST;
player->effects.damage_multiplier = 4;
Expand All @@ -208,9 +210,11 @@ pickup_bloodlust(Item *item, Player *player)
static void
pickup_frost(Item *item, Player *player)
{
(void) item;

gui_log("You drink a frost potion. Your skin is ice.");
player->effects.effect = POTION_FROST;
player->effects.damage_reduction = 2 * player->stats.lvl;
player->effects.damage_reduction = (uint8_t)(2 * player->stats.lvl);
sprite_set_color_mod(player->sprite, 94, 156, 255);
}

Expand Down
8 changes: 4 additions & 4 deletions src/loot.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,23 @@ get_drop_callback(DropType type)
}


static inline void drop_item(Sprite *sprite, Position *drop_positions, size_t
num_drop_positions, DropType type)
static inline void drop_item(Sprite *sprite, Position *drop_positions,
size_t num_drop_positions, DropType type)
{
/* Avoid FPE (division by zero) */
Position drop_pos;
if (num_drop_positions == 0) {
drop_pos = sprite->pos;
} else {
drop_pos = drop_positions[get_random(num_drop_positions - 1)];
drop_pos = drop_positions[get_random((uint32_t) num_drop_positions - 1)];
}

/* Create an interpolation dest */
Destination dest = {
.pos = drop_pos,
.angle = 0,
.dim = DIM(32, 32),
.time_ms = ITEM_DROP_TIME_MS + get_random(50),
.time_ms = (float)(ITEM_DROP_TIME_MS + get_random(50)),
.on_complete = get_drop_callback(type),
};

Expand Down
13 changes: 6 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,13 @@ static
bool initSDL(void)
{
debug("Initializing SDL");
SDL_SetAppMetadata(GAME_TITLE, VERSION_STR, "com.oliveshark.breakhack");
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD | SDL_INIT_HAPTIC))
{
error("Could not initiate SDL3: %s", SDL_GetError());
return false;
}

Dimension dim = getScreenDimensions();

debug("Initializing SDL_ttf");
if (!TTF_Init()) {
error("Unable to initiate ttf library: %s",
Expand All @@ -144,7 +143,11 @@ bool initSDL(void)
mixer_init();

char buffer[100] = { '\0' };
m_sprintf(buffer, 100, "%s %d.%d.%d %s", GAME_TITLE, MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, RELEASE_TYPE);
#ifdef DEBUG
m_sprintf(buffer, 100, "%s %s %s", GAME_TITLE, VERSION_STR_FULL, RELEASE_TYPE);
#else
m_sprintf(buffer, 100, "%s %s %s", GAME_TITLE, VERSION_STR, RELEASE_TYPE);
#endif
gWindow = SDL_CreateWindow(buffer,
SCREEN_WIDTH,
SCREEN_HEIGHT, 0);
Expand Down Expand Up @@ -204,10 +207,6 @@ bool initSDL(void)
SDL_StopTextInput(gWindow);
}

memset(buffer, '\0', 100);
sprintf(buffer, "%d.%d.%d", MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION);
SDL_SetAppMetadata(GAME_TITLE, buffer, "com.oliveshark.breakhack");

return true;
}

Expand Down
15 changes: 5 additions & 10 deletions src/monster.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#include "monster.h"
#include "random.h"
#include "gui.h"
#include "item.h"
#include "item_builder.h"
#include "map.h"
#include "particle_engine.h"
#include "defines.h"
Expand All @@ -38,7 +36,6 @@
#include "object.h"
#include "mixer.h"
#include "pos_heap.h"
#include "loot.h"

static void
monster_set_sprite_clip_for_current_state(Monster *m)
Expand Down Expand Up @@ -390,7 +387,7 @@ find_first_in_path(const Position *from, const Position *dest, const Position *s
next = from[current.x + current.y * MAP_ROOM_WIDTH];
}

Vector2d dir = { current.x - next.x, current.y - next.y };
Vector2d dir = { (float)(current.x - next.x), (float)(current.y - next.y) };
if (dir.x > 0)
return RIGHT;
else if (dir.x < 0)
Expand All @@ -402,7 +399,7 @@ find_first_in_path(const Position *from, const Position *dest, const Position *s
}

/* Manhattan distance */
#define MDIST(p1, p2) abs(p1.x - p2.x) + abs(p1.y - p2.y)
#define MDIST(p1, p2) (uint16_t)(abs(p1.x - p2.x) + abs(p1.y - p2.y))

/**
* \brief A* path finding algorithm
Expand All @@ -415,7 +412,6 @@ static Direction
get_optimal_move_towards(Monster *m, RoomMatrix *rm, const Position dest)
{
Direction ret_val = INVALID;
int x_dist, y_dist;
const Position start = position_to_matrix_coords(&m->sprite->pos);
const Vector2d directions[] = {
VECTOR2D_UP,
Expand Down Expand Up @@ -453,8 +449,8 @@ get_optimal_move_towards(Monster *m, RoomMatrix *rm, const Position dest)

for (size_t i = 0; i < 4; i++) {
Position next = {
current.x + directions[i].x,
current.y + directions[i].y,
current.x + (int) directions[i].x,
current.y + (int) directions[i].y,
};

if (!position_equals(&next, &dest)) {
Expand All @@ -465,7 +461,7 @@ get_optimal_move_towards(Monster *m, RoomMatrix *rm, const Position dest)
}
}

uint32_t temp_score = 1 + gScore[current.x + current.y * WIDTH];
uint16_t temp_score = 1 + gScore[current.x + current.y * WIDTH];
if (temp_score < gScore[next.x + next.y * WIDTH]) {
from[next.x + next.y * WIDTH] = current;
gScore[next.x + next.y * WIDTH] = temp_score;
Expand Down Expand Up @@ -661,7 +657,6 @@ monster_move(Monster *m, RoomMatrix *rm, Map *map)
}

Position originalMPos = position_to_matrix_coords(&m->sprite->pos);

SPACE_CLEAR_FLAG(&rm->spaces[originalMPos.x][originalMPos.y], TILE_OCCUPIED);
rm->spaces[originalMPos.x][originalMPos.y].monster = NULL;

Expand Down
8 changes: 4 additions & 4 deletions src/particle_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,10 @@ render_rect_particle(Particle *p, Camera *cam)
SDL_SetRenderDrawBlendMode(cam->renderer, p->blend_mode);

SDL_FRect box = {
pos.x,
pos.y,
p->particle.rect.dim.width,
p->particle.rect.dim.height
(float) pos.x,
(float) pos.y,
(float) p->particle.rect.dim.width,
(float) p->particle.rect.dim.height
};
SDL_SetRenderDrawColor(cam->renderer,
p->color.r,
Expand Down
13 changes: 0 additions & 13 deletions src/physfsrwops.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,6 @@ static SDL_IOStream *create_rwops(PHYSFS_File *handle)
return retval;
}


SDL_IOStream *PHYSFSIO_makeRWops(PHYSFS_File *handle)
{
SDL_IOStream *retval = NULL;
if (handle == NULL)
SDL_SetError("NULL pointer passed to PHYSFSIO_makeRWops().");
else
retval = create_rwops(handle);

return retval;
}


SDL_IOStream *PHYSFSIO_openRead(const char *fname)
{
return create_rwops(PHYSFS_openRead(fname));
Expand Down
8 changes: 4 additions & 4 deletions src/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static void
player_particle_bleed(Position pos, Dimension dim, void *userdata)
{
Player *p = userdata;
float perc = (float) p->stats.hp / p->stats.maxhp;
float perc = (float) p->stats.hp / (float) p->stats.maxhp;
Uint32 particle_count = (Uint32) (20.0f * perc);
particle_engine_bloodspray(pos, dim, particle_count);
}
Expand Down Expand Up @@ -568,9 +568,9 @@ player_create(class_t class, Camera *cam)
player->stateData.shopOwnerKiller = false;

ParticleEmitter *emitter = particle_emitter_create();
emitter->timestep = 2000;
emitter->timestep = 1000;
emitter->enabled = false;
emitter->particle_func = particle_engine_bleed;
emitter->particle_func = player_particle_bleed;
emitter->userdata = player;
player->bleed_emitter = emitter;

Expand Down Expand Up @@ -790,7 +790,7 @@ player_update(UpdateData *data)
animation_update(player->swordAnimation);

uint32_t damage_taken = player->stats.maxhp - player->stats.hp;
player->bleed_emitter->enabled = damage_taken >= player->stats.maxhp / 2;
player->bleed_emitter->enabled = (int) damage_taken >= player->stats.maxhp / 2;
}

static void
Expand Down
2 changes: 1 addition & 1 deletion src/pos_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void swap(Node *a, Node *b) {
*b = tmp;
}

static void heapify(PHeap *ph, int i)
static void heapify(PHeap *ph, size_t i)
{
if (ph->size <= 0) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/roommatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ typedef struct RoomSpace {
#define SPACE_IS_LIGHTSOURCE(space) ((space) && (space->flags & TILE_LIGHTSOURCE))
#define SPACE_IS_DAMAGING(space) ((space) && (space->flags & TILE_DAMAGE))
#define SPACE_SET_FLAG(space, flag) ((space) && ((space)->flags |= flag))
#define SPACE_CLEAR_FLAG(space, flag) ((space) && ((space)->flags &= ~flag))
#define SPACE_CLEAR_FLAG(space, flag) ((space)->flags &= ~flag)
#define SPACE_TOGGLE_FLAG(space, flag) ((space) && ((space)->flags ^= flag))

#define SPACE_IS_BLOCKED(space) (SPACE_IS_OCCUPIED(space) || (space)->monster)
Expand Down
4 changes: 2 additions & 2 deletions src/skill.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,8 @@ skill_backstab(Skill *skill, SkillData *data)

mixer_play_effect(SWING0 + get_random(2));

player_update_pos(data->player, data->direction.x * TILE_DIMENSION,
data->direction.y * TILE_DIMENSION);
player_update_pos(data->player, (uint32_t) data->direction.x * TILE_DIMENSION,
(uint32_t) data->direction.y * TILE_DIMENSION);
player_turn(data->player, &reverseDirection);
animation_run(data->player->swordAnimation);

Expand Down
Loading
Loading