Skip to content

Commit

Permalink
Health Bar Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cadaguti committed Nov 25, 2020
1 parent 70540b5 commit 2b6042c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 30 deletions.
8 changes: 3 additions & 5 deletions game/crystal/en/ram.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions game/crystal/es/ram.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions game/crystal/main.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions game/yellow/main.lua
Original file line number Diff line number Diff line change
@@ -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

Expand Down
24 changes: 4 additions & 20 deletions pokemon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2b6042c

Please sign in to comment.