From: Lukas Krickl Date: Sat, 17 Jan 2026 15:44:02 +0000 (+0100) Subject: attr: added hp calculation X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=d5f2cb9d688f43de7f8981522464b5482705895b;p=gbrg%2F.git attr: added hp calculation --- diff --git a/src/attributes.s b/src/attributes.s index 335e788..bf753fc 100644 --- a/src/attributes.s +++ b/src/attributes.s @@ -1,10 +1,58 @@ + ; generall attributes are either returned + ; in a (8 bit stats) or bc (16 bit stats) + attr_null: attrdef 0, 0, 0, 0, 0 attr_bat: attrdef 1, 0, 0, 0, 0 + ; gets the max hp for an actor + ; hp formula: + ; 4*stam + ; inputs: + ; de: actor + ; returns: + ; bc: max hp +act_attr_get_max_hp: + ld a, [de] + cp a, ACT_T_PLAYER + jp nz, @npc ; not a player + + + +@npc: + call act_attr_get_stam + ld hl, 0 + ld de, 4 +@mul: + add hl, de + dec a + jr nz, @mul REL + + push hl + pop bc ; bc = hp max + + ret + + ; get actor stamina + ; inputs: + ; de: actor + ; returns: + ; a: stamina +act_attr_get_stam: + ld a, [de] + cp a, ACT_T_PLAYER + jp nz, @npc ; not a player + +@npc: + call act_load_attr_table + ld hl, attr_stam + add hl, bc + ld a, [hl] ; a = stamina + ret + ; gets strength attribute ; of a given actor ; inputs: diff --git a/src/defs.s b/src/defs.s index 61ae288..1f9e0d9 100644 --- a/src/defs.s +++ b/src/defs.s @@ -64,6 +64,7 @@ .de act_p0, 1 ; state parameter .de act_state, 1 + ; hp/mp stored in BE .de act_hp, 2 .de act_mp, 2 ; currently active buff id diff --git a/src/player.s b/src/player.s index 97eafe4..1202ccd 100644 --- a/src/player.s +++ b/src/player.s @@ -49,6 +49,15 @@ player_init: ; set default view ld a, 3 ld [player_viewradius], a + + ; set current hp + ld de, player + call act_attr_get_max_hp + ld a, b + ld [player+act_hp], a + ld a, c + ld [player+act_hp+1], a + ret