From 2b6042c032293bb398f99e571c657c3c05ba5963 Mon Sep 17 00:00:00 2001 From: Juan CG Date: Wed, 25 Nov 2020 02:32:59 +0100 Subject: [PATCH] Health Bar Fix --- game/crystal/en/ram.lua | 8 +++----- game/crystal/es/ram.lua | 8 +++----- game/crystal/main.lua | 2 ++ game/yellow/main.lua | 2 ++ pokemon.lua | 24 ++++-------------------- 5 files changed, 14 insertions(+), 30 deletions(-) diff --git a/game/crystal/en/ram.lua b/game/crystal/en/ram.lua index 7cb7c72..9059aa8 100644 --- a/game/crystal/en/ram.lua +++ b/game/crystal/en/ram.lua @@ -1,8 +1,8 @@ RAM_SCREEN = 0x8800 RAM_IN_BATTLE = 0xd22d RAM_TEXT = 0xc4a0 +RAM_CURRENT_ENEMY_HEALTH = 0xd216 RAM_OVERWORLD_MAP = 0xc800 -RAM_MENU_HEADER = 0xcf81 RAM_PLAYER_NAME = 0xd47d RAM_MOM_NAME = 0xd488 RAM_RIVAL_NAME = 0xd493 @@ -13,6 +13,8 @@ RAM_MAP_NUMBER = 0xdcb6 RAM_PLAYER_Y = 0xdcb7 RAM_PLAYER_X = 0xdcb8 RAM_MAP_HEADER = 0xd19d +RAM_MAP_HEIGHT = RAM_MAP_HEADER + 1 +RAM_MAP_WIDTH = RAM_MAP_HEADER + 2 RAM_MAP_SCRIPT_HEADER_BANK = RAM_MAP_HEADER+6 RAM_MAP_EVENT_HEADER_POINTER = RAM_MAP_HEADER+9 RAM_MAP_CONNECTIONS = RAM_MAP_HEADER+11 @@ -30,10 +32,6 @@ RAM_MAP_EAST_CONNECTION_START_POINTER = RAM_MAP_EAST_CONNECTION + 4 RAM_MAP_EAST_CONNECTION_SIZE = RAM_MAP_EAST_CONNECTION + 6 RAM_MAP_OBJECTS = 0xd71e RAM_LIVE_OBJECTS = RAM_MAP_OBJECTS+0x100 -RAM_MAP_HEADER = 0xd19d -RAM_MAP_HEIGHT = RAM_MAP_HEADER + 1 -RAM_MAP_WIDTH = RAM_MAP_HEADER + 2 -RAM_STANDING_TILE = 0xd4e4 RAM_COLLISION_BANK = 0xd1df RAM_COLLISION_ADDR = 0xd1e0 RAM_OBJECT_STRUCTS = 0xd4fe diff --git a/game/crystal/es/ram.lua b/game/crystal/es/ram.lua index 8f768df..a4681fb 100644 --- a/game/crystal/es/ram.lua +++ b/game/crystal/es/ram.lua @@ -2,7 +2,7 @@ RAM_SCREEN = 0x8800 RAM_IN_BATTLE = 0xd22d RAM_TEXT = 0xc4a0 RAM_OVERWORLD_MAP = 0xc800 -RAM_MENU_HEADER = 0xcf81 +RAM_CURRENT_ENEMY_HEALTH = 0xd216 RAM_PLAYER_NAME = 0xd47d RAM_MOM_NAME = 0xd488 RAM_RIVAL_NAME = 0xd493 @@ -13,6 +13,8 @@ RAM_MAP_NUMBER = 0xdcb6 RAM_PLAYER_Y = 0xdcb7 RAM_PLAYER_X = 0xdcb8 RAM_MAP_HEADER = 0xd19d +RAM_MAP_HEIGHT = RAM_MAP_HEADER + 1 +RAM_MAP_WIDTH = RAM_MAP_HEADER + 2 RAM_MAP_SCRIPT_HEADER_BANK = RAM_MAP_HEADER+6 RAM_MAP_EVENT_HEADER_POINTER = RAM_MAP_HEADER+9 RAM_MAP_CONNECTIONS = RAM_MAP_HEADER+11 @@ -30,10 +32,6 @@ RAM_MAP_EAST_CONNECTION_START_POINTER = RAM_MAP_EAST_CONNECTION + 4 RAM_MAP_EAST_CONNECTION_SIZE = RAM_MAP_EAST_CONNECTION + 6 RAM_MAP_OBJECTS = 0xd71e RAM_LIVE_OBJECTS = RAM_MAP_OBJECTS+0x100 -RAM_MAP_HEADER = 0xd19d -RAM_MAP_HEIGHT = RAM_MAP_HEADER + 1 -RAM_MAP_WIDTH = RAM_MAP_HEADER + 2 -RAM_STANDING_TILE = 0xd4e4 RAM_COLLISION_BANK = 0xd1df RAM_COLLISION_ADDR = 0xd1e0 RAM_OBJECT_STRUCTS = 0xd4fe diff --git a/game/crystal/main.lua b/game/crystal/main.lua index 6fcbe25..b73dcd6 100644 --- a/game/crystal/main.lua +++ b/game/crystal/main.lua @@ -1,5 +1,7 @@ SCROLL_INDICATOR_POSITION = 359 HEALTH_BAR = "\x60\x61" +HEALTH_BAR_LIMIT = 0x6b +ENEMY_MAX_HEALTH = 2 BOULDER_SPRITE = 0x5a old_kbd_col = nil old_kbd_row = nil diff --git a/game/yellow/main.lua b/game/yellow/main.lua index 9467327..6f73318 100644 --- a/game/yellow/main.lua +++ b/game/yellow/main.lua @@ -1,5 +1,7 @@ SCROLL_INDICATOR_POSITION = 239 HEALTH_BAR = "\x71\x62" +HEALTH_BAR_LIMIT = 0x6c +ENEMY_MAX_HEALTH = 14 BOULDER_SPRITE = 0x49 kbd_pos = nil diff --git a/pokemon.lua b/pokemon.lua index c53f931..d8887f2 100644 --- a/pokemon.lua +++ b/pokemon.lua @@ -960,29 +960,13 @@ end end end -BAR_LENGTH = 6 function get_enemy_health() -local function read_bar(addr) -local count --- no bar here -if memory.readbyte(addr+BAR_LENGTH) ~= 0x6c then -return nil -end -local total = 0 -for i = 0, BAR_LENGTH - 1 do -if memory.readbyte(addr+i) == 0x6a then -total = total +1 -end -end -return total -end -local enemy = read_bar(RAM_TEXT+(2*20)+4) -if enemy == nil then -return nil -else +if memory.readbyte(RAM_TEXT+(2*20)+10) == HEALTH_BAR_LIMIT then local current = memory.readword(RAM_CURRENT_ENEMY_HEALTH) -local total = memory.readword(RAM_CURRENT_ENEMY_HEALTH+14) +local total = memory.readword(RAM_CURRENT_ENEMY_HEALTH+ENEMY_MAX_HEALTH) return string.format("%0.2f%%", current/total*100) +else +return nil end end