Skip to content

Commit

Permalink
file combine
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinhack committed Apr 28, 2024
1 parent 580d080 commit d755d8f
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 168 deletions.
4 changes: 2 additions & 2 deletions src/level_display_dungeon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "my_tile.hpp"
#include "my_tp.hpp"

void level_display_dungeon_tile(Levelp l, Tpp tp, uint16_t tile_index, point tl, point br, point offset)
static void level_display_dungeon_tile(Levelp l, Tpp tp, uint16_t tile_index, point tl, point br, point offset)
{
auto tile = tile_index_to_tile(tile_index);
if (! tile) {
Expand All @@ -30,7 +30,7 @@ void level_display_dungeon_tile(Levelp l, Tpp tp, uint16_t tile_index, point tl,
}
}

void level_display_dungeon_z_layer(Levelp l, int x, int y, int slot, int z, bool deco)
static void level_display_dungeon_z_layer(Levelp l, int x, int y, int slot, int z, bool deco)
{
int dw = TILE_WIDTH;
int dh = TILE_HEIGHT;
Expand Down
2 changes: 1 addition & 1 deletion src/level_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void level_thing_player_move_delta(Levelp l, int dx, int dy)
return;
}

if (level_thing_can_move(l, t, t->x + dx, t->y + dy)) {
if (level_thing_can_move_to(l, t, t->x + dx, t->y + dy)) {
level_thing_move(l, t, t->x + dx, t->y + dy);

level_tick_begin_requested(l, "player moved");
Expand Down
2 changes: 1 addition & 1 deletion src/level_tick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void level_tick_begin(Levelp l)
l->requested_auto_scroll = true;
}

void level_tick_begin_requested(Levelp l, const std::string &why)
void level_tick_begin_requested(Levelp l, const char *why)
{
TRACE_NO_INDENT();

Expand Down
8 changes: 2 additions & 6 deletions src/my_level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "my_game_defs.hpp"
#include "my_minimal.hpp"
#include "my_point.hpp"
#include "my_thing.hpp"

//
Expand Down Expand Up @@ -140,7 +139,7 @@ bool level_is_oob(Levelp, int x, int y);
bool level_is_same_type(Levelp, int x, int y, Tpp);
bool level_set_id(Levelp, int x, int y, uint8_t z, Id);
bool level_set_tile(Levelp, int x, int y, uint8_t z, Tilep);
bool level_thing_can_move(Levelp, Thingp, int, int);
bool level_thing_can_move_to(Levelp, Thingp, int, int);
bool level_thing_player_move_request(Levelp, bool up, bool down, bool left, bool right);
bool level_tick_is_in_progress(Levelp);
Id level_get_id(Levelp, int x, int y, uint8_t z);
Expand All @@ -161,9 +160,6 @@ void level_assign_tiles(Levelp);
void level_bounds_set(Levelp);
void level_destructor(Levelp l);
void level_display_dungeon(Levelp);
void level_display_dungeon_tile(Levelp, Tpp, Tilep, point tl, point br, point offset);
void level_display_dungeon_tile(Levelp, Tpp, uint16_t, point tl, point br, point offset);
void level_display_dungeon_z_layer(Levelp, int x, int y, int slot, int z, bool deco);
void level_display(Levelp);
void level_dungeon_create_and_place(Levelp);
void level_map_set(Levelp, const char *);
Expand All @@ -184,7 +180,7 @@ void level_thing_pop(Levelp, Thingp);
void level_thing_push(Levelp, Thingp);
void level_thing_update(Levelp, Thingp);
void level_tick_begin(Levelp);
void level_tick_begin_requested(Levelp, const std::string &why);
void level_tick_begin_requested(Levelp, const char *);
void level_tick_body(Levelp, float dt);
void level_tick_end_requested(Levelp);
void level_tick(Levelp);
Expand Down
16 changes: 16 additions & 0 deletions src/thing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "my_callstack.hpp"
#include "my_level.hpp"
#include "my_tile.hpp"
#include "my_tp.hpp"

Thingp level_thing_init(Levelp l, Tpp tp, int x, int y)
{
Expand All @@ -27,6 +28,21 @@ Thingp level_thing_init(Levelp l, Tpp tp, int x, int y)
return t;
}

void level_thing_update(Level *l, Thingp t)
{
TRACE_NO_INDENT();

auto tp = level_thing_tp(l, t);

t->speed = tp_speed_get(tp);
}

Tpp level_thing_tp(Level *l, Thingp t)
{
TRACE_NO_INDENT();
return tp_find(t->tp_id);
}

void thing_id_set(Thingp t, ThingId id) { t->id = id; }
ThingId thing_id_get(Thingp t) { return t->id; }
void thing_tp_id_set(Thingp t, uint16_t tp_id) { t->tp_id = tp_id; }
Expand Down
33 changes: 0 additions & 33 deletions src/thing_can_move_to.cpp

This file was deleted.

21 changes: 0 additions & 21 deletions src/thing_interpolate.cpp

This file was deleted.

97 changes: 97 additions & 0 deletions src/thing_move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

#include "my_callstack.hpp"
#include "my_level.hpp"
#include "my_main.hpp"
#include "my_minimal.hpp"
#include "my_tile.hpp"
#include "my_tp.hpp"

#include <string.h>

void level_thing_move(Levelp l, Thingp t, int new_x, int new_y)
{
if (level_is_oob(l, new_x, new_y)) {
Expand All @@ -30,3 +34,96 @@ void level_thing_move(Levelp l, Thingp t, int new_x, int new_y)

level_thing_push(l, t);
}

bool level_thing_can_move_to(Levelp l, Thingp t, int new_loc_x, int new_loc_y)
{
if (level_is_oob(l, new_loc_x, new_loc_y)) {
return false;
}

if ((new_loc_x == t->x) && (new_loc_y == t->y)) {
return true;
}

auto my_tp = level_thing_tp(l, t);

FOR_ALL_TPS_AT(l, it, it_tp, new_loc_x, new_loc_y)
{
if (tp_is_player_get(my_tp) && tp_is_obs_player_get(it_tp)) {
return false;
}

if (tp_is_monst_get(my_tp) && tp_is_obs_monst_get(it_tp)) {
return false;
}
}

return true;
}

void level_thing_interpolate(Level *l, Thingp t, float dt)
{
if ((t->old_x == t->x) && (t->old_y == t->y)) {
return;
}

float pix_x = (float) t->old_x + (((float) (t->x - t->old_x)) * dt);
float pix_y = (float) t->old_y + (((float) (t->y - t->old_y)) * dt);

t->pix_x = pix_x * TILE_WIDTH;
t->pix_y = pix_y * TILE_HEIGHT;
}

void level_thing_push(Levelp l, Thingp t)
{
TRACE_NO_INDENT();

int16_t x = t->pix_x / TILE_WIDTH;
int16_t y = t->pix_y / TILE_HEIGHT;

if (level_is_oob(l, x, y)) {
return;
}

for (auto slot = 0; slot < MAP_SLOTS; slot++) {
auto o = &l->obj[ x ][ y ][ slot ];
if (o->id == t->id) {
return;
}
}

for (auto slot = 0; slot < MAP_SLOTS; slot++) {
auto o = &l->obj[ x ][ y ][ slot ];
if (! o->id) {
o->id = t->id;
auto tp = tp_find(t->tp_id);
auto tile = tp_first_tile(tp);
if (tile) {
o->tile = tile_global_index(tile);
}
return;
}
}

ERR("out of thing slots");
}

void level_thing_pop(Levelp l, Thingp t)
{
TRACE_NO_INDENT();

uint8_t x = t->pix_x / TILE_WIDTH;
uint8_t y = t->pix_y / TILE_HEIGHT;

if (level_is_oob(l, x, y)) {
return;
}

for (auto slot = 0; slot < MAP_SLOTS; slot++) {
auto o = &l->obj[ x ][ y ][ slot ];
if (o->id == t->id) {
memset(o, 0, sizeof(*o));
return;
}
}
}
30 changes: 0 additions & 30 deletions src/thing_pop.cpp

This file was deleted.

45 changes: 0 additions & 45 deletions src/thing_push.cpp

This file was deleted.

13 changes: 0 additions & 13 deletions src/thing_tp.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions src/thing_update.cpp

This file was deleted.

0 comments on commit d755d8f

Please sign in to comment.