Skip to content

Commit

Permalink
thing direction
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinhack committed May 5, 2024
1 parent 756dc2b commit 70a1071
Show file tree
Hide file tree
Showing 10 changed files with 280 additions and 62 deletions.
Binary file modified data/gfx.tgz
Binary file not shown.
15 changes: 12 additions & 3 deletions src/level_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,20 @@ static void level_display_z_layer(Levelp l, int x, int y, int slot, int z, bool
br.x = tl.x + pix_width;
br.y = tl.y + pix_height;

//
// Flippable?
//
if (tp_is_animated_can_hflip_get(tp)) {
if (thing_is_dir_left(t) || thing_is_dir_tl(t) || thing_is_dir_bl(t)) {
std::swap(tl.x, br.x);
}
}

if (deco) {
level_display_tile(l, tp, tile_index + 47, tl, br, point(0, 0));
} else {
level_display_tile(l, tp, tile_index, tl, br, point(0, 0));
tile_index += 47;
}

level_display_tile(l, tp, tile_index, tl, br, point(0, 0));
}

void level_display(Levelp l)
Expand Down
9 changes: 9 additions & 0 deletions src/level_thing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
#include <sstream>
#include <string.h>

Tpp tp(Thingp t)
{
if (t->tp_id) {
return tp_find(t->tp_id);
}

return nullptr;
}

Thingp level_thing_get(Levelp l, int x, int y, uint8_t slot, Tpp *out)
{
TRACE_NO_INDENT();
Expand Down
78 changes: 50 additions & 28 deletions src/my_thing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
#define THING_ID_GET_X(id) ((id & THING_ID_X_MASK) >> (THING_ID_Y_BITS))
#define THING_ID_GET_Y(id) ((id & THING_ID_Y_MASK))

enum {
THING_DIR_NONE,
THING_DIR_DOWN,
THING_DIR_UP,
THING_DIR_LEFT,
THING_DIR_RIGHT,
THING_DIR_TL,
THING_DIR_BL,
THING_DIR_TR,
THING_DIR_BR,
};

typedef struct Thing_ {
ThingId id;
uint16_t tp_id;
Expand Down Expand Up @@ -56,41 +68,51 @@ typedef struct Thing_ {
//
int16_t pix_x;
int16_t pix_y;
uint8_t dir_up : 1;
uint8_t dir_down : 1;
uint8_t dir_left : 1;
uint8_t dir_right : 1;
//
// Direction
//
uint8_t dir;
} Thing;

void thing_id_set(Thingp t, ThingId id);
ThingId thing_id_get(Thingp t);
void thing_tp_id_set(Thingp t, uint16_t tp_id);
uint16_t thing_tp_id_get(Thingp t);
void thing_tick_set(Thingp t, uint16_t tick);
uint16_t thing_tick_get(Thingp t);
void thing_x_set(Thingp t, int8_t x);
Tpp tp(Thingp t);
bool thing_is_dir_down(Thingp t);
bool thing_is_dir_tr(Thingp t);
bool thing_is_dir_tl(Thingp t);
bool thing_is_dir_br(Thingp t);
bool thing_is_dir_bl(Thingp t);
bool thing_is_dir_left(Thingp t);
bool thing_is_dir_right(Thingp t);
bool thing_is_dir_up(Thingp t);
float thing_thing_dt_get(Thingp t);
int16_t thing_pix_x_get(Thingp t);
int16_t thing_pix_y_get(Thingp t);
int16_t thing_speed_get(Thingp t);
int8_t thing_old_x_get(Thingp t);
int8_t thing_old_y_get(Thingp t);
int8_t thing_x_get(Thingp t);
void thing_y_set(Thingp t, int8_t y);
int8_t thing_y_get(Thingp t);
ThingId thing_id_get(Thingp t);
uint16_t thing_tick_get(Thingp t);
uint16_t thing_tp_id_get(Thingp t);
void thing_dir_tr_set(Thingp t, uint8_t);
void thing_dir_tl_set(Thingp t, uint8_t);
void thing_dir_br_set(Thingp t, uint8_t);
void thing_dir_bl_set(Thingp t, uint8_t);
void thing_dir_down_set(Thingp t, uint8_t);
void thing_dir_left_set(Thingp t, uint8_t);
void thing_dir_right_set(Thingp t, uint8_t);
void thing_dir_up_set(Thingp t, uint8_t);
void thing_id_set(Thingp t, ThingId id);
void thing_old_x_set(Thingp t, int8_t old_x);
int8_t thing_old_x_get(Thingp t);
void thing_old_y_set(Thingp t, int8_t old_y);
int8_t thing_old_y_get(Thingp t);
void thing_speed_set(Thingp t, int16_t speed);
int16_t thing_speed_get(Thingp t);
void thing_thing_dt_set(Thingp t, float thing_dt);
float thing_thing_dt_get(Thingp t);
void thing_pix_x_set(Thingp t, int16_t pix_x);
int16_t thing_pix_x_get(Thingp t);
void thing_pix_y_set(Thingp t, int16_t pix_y);
int16_t thing_pix_y_get(Thingp t);
void thing_dir_up_set(Thingp t, uint8_t dir_up);
uint8_t thing_dir_up_get(Thingp t);
void thing_dir_down_set(Thingp t, uint8_t dir_down);
uint8_t thing_dir_down_get(Thingp t);
void thing_dir_left_set(Thingp t, uint8_t dir_left);
uint8_t thing_dir_left_get(Thingp t);
void thing_dir_right_set(Thingp t, uint8_t dir_right);
uint8_t thing_dir_right_get(Thingp t);
void thing_speed_set(Thingp t, int16_t speed);
void thing_thing_dt_set(Thingp t, float thing_dt);
void thing_tick_set(Thingp t, uint16_t tick);
void thing_tp_id_set(Thingp t, uint16_t tp_id);
void thing_x_set(Thingp t, int8_t x);
void thing_y_set(Thingp t, int8_t y);
void thing_set_dir_from_delta(Thingp, int dx, int dy);

#endif
3 changes: 3 additions & 0 deletions src/my_tp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ const char *to_short_string(Tpp tp);
bool tp_is_animated_can_hflip_get(Tpp tp);
void tp_is_animated_can_hflip_set(Tpp tp, bool val);

bool tp_is_animated_no_dir_get(Tpp tp);
void tp_is_animated_no_dir_set(Tpp tp, bool val);

bool tp_is_blit_centered_get(Tpp tp);
void tp_is_blit_centered_set(Tpp tp, bool val);

Expand Down
54 changes: 23 additions & 31 deletions src/thing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@
#include "my_tile.hpp"
#include "my_tp.hpp"

float thing_thing_dt_get(Thingp t) { return t->thing_dt; }
int16_t thing_pix_x_get(Thingp t) { return t->pix_x; }
int16_t thing_pix_y_get(Thingp t) { return t->pix_y; }
int16_t thing_speed_get(Thingp t) { return t->speed; }
int8_t thing_old_x_get(Thingp t) { return t->old_x; }
int8_t thing_old_y_get(Thingp t) { return t->old_y; }
int8_t thing_x_get(Thingp t) { return t->x; }
int8_t thing_y_get(Thingp t) { return t->y; }
ThingId thing_id_get(Thingp t) { return t->id; }
uint16_t thing_tick_get(Thingp t) { return t->tick; }
uint16_t thing_tp_id_get(Thingp t) { return t->tp_id; }
void thing_id_set(Thingp t, ThingId id) { t->id = id; }
void thing_old_x_set(Thingp t, int8_t old_x) { t->old_x = old_x; }
void thing_old_y_set(Thingp t, int8_t old_y) { t->old_y = old_y; }
void thing_pix_x_set(Thingp t, int16_t pix_x) { t->pix_x = pix_x; }
void thing_pix_y_set(Thingp t, int16_t pix_y) { t->pix_y = pix_y; }
void thing_speed_set(Thingp t, int16_t speed) { t->speed = speed; }
void thing_thing_dt_set(Thingp t, float thing_dt) { t->thing_dt = thing_dt; }
void thing_tick_set(Thingp t, uint16_t tick) { t->tick = tick; }
void thing_tp_id_set(Thingp t, uint16_t tp_id) { t->tp_id = tp_id; }
void thing_x_set(Thingp t, int8_t x) { t->x = x; }
void thing_y_set(Thingp t, int8_t y) { t->y = y; }

Thingp level_thing_init(Levelp l, Tpp tp, int x, int y)
{
TRACE_NO_INDENT();
Expand Down Expand Up @@ -42,34 +65,3 @@ 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; }
uint16_t thing_tp_id_get(Thingp t) { return t->tp_id; }
void thing_tick_set(Thingp t, uint16_t tick) { t->tick = tick; }
uint16_t thing_tick_get(Thingp t) { return t->tick; }
void thing_x_set(Thingp t, int8_t x) { t->x = x; }
int8_t thing_x_get(Thingp t) { return t->x; }
void thing_y_set(Thingp t, int8_t y) { t->y = y; }
int8_t thing_y_get(Thingp t) { return t->y; }
void thing_old_x_set(Thingp t, int8_t old_x) { t->old_x = old_x; }
int8_t thing_old_x_get(Thingp t) { return t->old_x; }
void thing_old_y_set(Thingp t, int8_t old_y) { t->old_y = old_y; }
int8_t thing_old_y_get(Thingp t) { return t->old_y; }
void thing_speed_set(Thingp t, int16_t speed) { t->speed = speed; }
int16_t thing_speed_get(Thingp t) { return t->speed; }
void thing_thing_dt_set(Thingp t, float thing_dt) { t->thing_dt = thing_dt; }
float thing_thing_dt_get(Thingp t) { return t->thing_dt; }
void thing_pix_x_set(Thingp t, int16_t pix_x) { t->pix_x = pix_x; }
int16_t thing_pix_x_get(Thingp t) { return t->pix_x; }
void thing_pix_y_set(Thingp t, int16_t pix_y) { t->pix_y = pix_y; }
int16_t thing_pix_y_get(Thingp t) { return t->pix_y; }
void thing_dir_up_set(Thingp t, uint8_t dir_up) { t->dir_up = dir_up; }
uint8_t thing_dir_up_get(Thingp t) { return t->dir_up; }
void thing_dir_down_set(Thingp t, uint8_t dir_down) { t->dir_down = dir_down; }
uint8_t thing_dir_down_get(Thingp t) { return t->dir_down; }
void thing_dir_left_set(Thingp t, uint8_t dir_left) { t->dir_left = dir_left; }
uint8_t thing_dir_left_get(Thingp t) { return t->dir_left; }
void thing_dir_right_set(Thingp t, uint8_t dir_right) { t->dir_right = dir_right; }
uint8_t thing_dir_right_get(Thingp t) { return t->dir_right; }
Loading

0 comments on commit 70a1071

Please sign in to comment.