From 7355280ea53d0f1d47d994768e3a34d0c41e8a02 Mon Sep 17 00:00:00 2001 From: Forest Belton Date: Wed, 29 Sep 2021 18:43:10 -0400 Subject: [PATCH] Add player state --- src/map.c | 15 ++++++++------- src/map.h | 8 ++++---- src/player.c | 3 +++ src/player.h | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 src/player.c create mode 100644 src/player.h diff --git a/src/map.c b/src/map.c index 90185b8..46e2a9d 100644 --- a/src/map.c +++ b/src/map.c @@ -3,6 +3,7 @@ #include #include "game.h" +#include "player.h" #include "sdk/hardware.h" #include "vram.h" @@ -30,7 +31,8 @@ void map_load(map_t *map) { rSCX = INIT_SCX; rSCY = INIT_SCY; - // TODO: Update player state + PLAYER.x = (MAP.spawn_x - MAP.camera_x) * 8; + PLAYER.y = (MAP.spawn_y - MAP.camera_y) * 8; memcpy(VRAM_TILE_PTR(TILE_INDEX_BACKGROUND), (uint8_t *)MAP.tile_ptr, MAP.tile_size); @@ -56,12 +58,11 @@ void map_update(void) { pending_row_dest = 0; } - // TODO: Make it work - /* if (pending_col_dest != 0) { - vram_enqueue_mem_xfer(pending_col_dest, &pending_col[0], - sizeof pending_col); - pending_col_dest = 0; - } */ + if (pending_col_dest != 0) { + vram_enqueue_mem_xfer(XFER_TYPE_COL, pending_col_dest, &pending_col[0], + sizeof pending_col); + pending_col_dest = 0; + } } static void map_enqueue_row(uint16_t vram_ptr, int8_t x0, int8_t y0) { diff --git a/src/map.h b/src/map.h index 7cd1f03..d21b4ae 100644 --- a/src/map.h +++ b/src/map.h @@ -12,10 +12,10 @@ typedef struct { uint16_t collision_ptr; int8_t map_width; int8_t map_height; - uint8_t spawn_x; - uint8_t spawn_y; - uint8_t camera_x; - uint8_t camera_y; + int8_t spawn_x; + int8_t spawn_y; + int8_t camera_x; + int8_t camera_y; } map_t; extern map_t MAP; //!< The current game map diff --git a/src/player.c b/src/player.c new file mode 100644 index 0000000..ad7746f --- /dev/null +++ b/src/player.c @@ -0,0 +1,3 @@ +#include "player.h" + +player_t PLAYER; diff --git a/src/player.h b/src/player.h new file mode 100644 index 0000000..76ba0bf --- /dev/null +++ b/src/player.h @@ -0,0 +1,19 @@ +#ifndef IS_PLAYER_H_ +#define IS_PLAYER_H_ + +#include + +#define PLAYER_INV_SIZE 32 + +typedef struct { + uint8_t x; + uint16_t y; + uint16_t vy; + uint8_t dir; + uint8_t state; + // TODO: Define inventory if there's time +} player_t; + +extern player_t PLAYER; + +#endif