From 26827a30a8eee0a926d66eafce37e43458d3bfa7 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 4 Nov 2025 05:39:47 +0100 Subject: [PATCH] tiles: tiles now have an owner id Reworked tile types to take tile owner into account Reworked UI to take tile owner into account --- src/defs.s | 26 +++++++++++++++++++----- src/levels.s | 8 ++++---- src/macros.inc | 9 +++++---- src/tiles.s | 55 ++++++++++++++++++++------------------------------ src/ui.s | 30 ++++++++++++++++++++++++++- src/wram.s | 1 + 6 files changed, 82 insertions(+), 47 deletions(-) diff --git a/src/defs.s b/src/defs.s index d9ff0c4..59504d7 100644 --- a/src/defs.s +++ b/src/defs.s @@ -66,19 +66,35 @@ .de map_tiles, MAP_W * MAP_H .de map_size, 0 - ; tile type struct + ; tile type enum .se 0 .de TT_EMPTY, 1 -.de TT_PLAYER, 1 -.de TT_PLAYER_HIVE, 1 -.de TT_ENEMY, 1 -.de TT_ENEMY_HIVE, 1 +.de TT_USED, 1 +.de TT_HIVE, 1 .de TT_FOOD, 1 + ; tile index enum + ; order of tile defs in tiles.s +.se 0 +.de TI_EMPTY, 1 +.de TI_PLAYER_USED, 1 +.de TI_PLAYER_HIVE, 1 +.de TI_ENEMY_USED, 1 +.de TI_ENEMY_HIVE, 1 +.de TI_FOOD, 1 + + ; owner enum +.se 0 +.de TO_NULL, 1 +.de TO_PLAYER, 1 +.de TO_ENEMY, 1 + ; tile struct .se 0 .de t_type, 1 .de t_flags, 1 + ; owning actor +.de t_owner, 1 ; based on type .de t_resource, 1 ; 2 bytes of custom state storage diff --git a/src/levels.s b/src/levels.s index cd8bb8d..4605f21 100644 --- a/src/levels.s +++ b/src/levels.s @@ -6,16 +6,16 @@ level_def_to_tile: dw tile_food ; tile grass -.def int TGS = TT_EMPTY +.def int TGS = TI_EMPTY ; tile player hive -.def int TPH = TT_PLAYER_HIVE +.def int TPH = TI_PLAYER_HIVE ; tile enemy hive -.def int TEH = TT_ENEMY_HIVE +.def int TEH = TI_ENEMY_HIVE ; tile food -.def int TFD = TT_FOOD +.def int TFD = TI_FOOD ; level definitions ; levels always have a header diff --git a/src/macros.inc b/src/macros.inc index 0961802..8ed25f1 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -171,13 +171,14 @@ $1: ; inputs: ; $1: type ; $2: flags - ; $3: resource count - ; $4: tile gfx + ; $3: tile owner + ; $4: resource count + ; $5: tile gfx #macro tiledef - .db $1, $2, $3 + .db $1, $2, $3, $4 ; p0 and state .db 0, 0 - .db $4 + .db $5 #endmacro ; defines a new actor diff --git a/src/tiles.s b/src/tiles.s index 63b7d9f..b87ac05 100644 --- a/src/tiles.s +++ b/src/tiles.s @@ -16,58 +16,47 @@ tile_update: ; for each tile tile_update_table: dw tile_update_empty - dw tile_update_player - dw tile_update_player_hive - dw tile_update_enemy - dw tile_update_enemy_hive + dw tile_update_used + dw tile_update_hive dw tile_update_food strz str_empty, "EMPTY " -strz str_player_hive, "YOUR HIVE " -strz str_enemy_hive, "HIVE " -strz str_player, "PLAYER " -strz str_enemy, "ENEMY " +strz str_hive, "HIVE " +strz str_used, "HILL " strz str_food, "FOOD " ; mapping of tile ids to ; the tile names tile_str_table: dw str_empty - dw str_player - dw str_player_hive - dw str_enemy - dw str_enemy_hive + dw str_used + dw str_hive dw str_food - - ; updates empty tile + ; gets the controlling actor of a tile + ; returns NULL if TO_NULL is set ; inputs: ; de: tile -tile_update_empty: +tile_get_actor: + ; TODO: ret - - ; updates player controlled tile - ; inputs: - ; de: tile -tile_update_player: - ret - - ; updates player hive + + ; updates empty tile ; inputs: ; de: tile -tile_update_player_hive: +tile_update_empty: ret - ; updates enemy tile + ; updates controlled tile ; inputs: ; de: tile -tile_update_enemy: +tile_update_used: ret - ; updates enemy hive + ; updates hive ; inputs: ; de: tile -tile_update_enemy_hive: +tile_update_hive: ret ; updates food tile @@ -77,7 +66,7 @@ tile_update_food: ret ; maps from tile ids - ; to tile presets + ; to tile presets (tile index) tile_id_table: dw tile_grass dw tile_grass @@ -88,13 +77,13 @@ tile_id_table: tile_grass: - tiledef TT_EMPTY, 0, 0, GFX_GRASS + tiledef TT_EMPTY, 0, TO_NULL, 0, GFX_GRASS tile_player_hive: - tiledef TT_PLAYER_HIVE, 0, 0, GFX_PHIVE + tiledef TT_HIVE, 0, TO_PLAYER, 0, GFX_PHIVE tile_enemy_hive: - tiledef TT_ENEMY_HIVE, 0, 0, GFX_EHIVE + tiledef TT_HIVE, 0, TO_ENEMY, 0, GFX_EHIVE tile_food: - tiledef TT_FOOD, 0, 0, GFX_FOOD + tiledef TT_FOOD, 0, 0, TO_NULL, GFX_FOOD diff --git a/src/ui.s b/src/ui.s index e6cd8b6..f703abd 100644 --- a/src/ui.s +++ b/src/ui.s @@ -80,6 +80,8 @@ ui_draw_tile_name: ld a, [current_tile+1] ld l, a + push hl + ld a, [hl] ; load type add a, a ; * 2 for offset @@ -95,12 +97,38 @@ ui_draw_tile_name: ld a, b ld l, a - ld de, UI_TILE_NAME + ld de, UI_TILE_NAME+2 call puts ld hl, ui_draw_nop call ui_request_draw + + ; draw owner + pop hl + ld de, t_owner + add hl, de + + ld a, [hl] + cp a, TO_NULL + jr nz, @not_null REL + + ld a, 0xF4 ; ' ' + ld [UI_TILE_NAME], a ret +@not_null: + + cp a, TO_PLAYER + jr nz, @not_player REL + ld a, 0xE9 ; P + ld [UI_TILE_NAME], a + ret +@not_player: + + ld a, 0xDE ; E + ld [UI_TILE_NAME], a + ret + + ; draws the entire UI ; only call during blank diff --git a/src/wram.s b/src/wram.s index dda0720..9222cf9 100644 --- a/src/wram.s +++ b/src/wram.s @@ -78,6 +78,7 @@ map: .adv 2 ; ptr to current tile to be updated tile_curr: .adv 2 tiles: .adv t_size * MAP_TILES +tiles_end: .adv 0 ui_draw_routine: .adv 2 -- 2.30.2