Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/app/combat/PlayerHP.affine
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ fn max(a: Int, b: Int) -> Int {
// CON is a 0-200 scaling factor; baseline 100 → 1000 (= 100.0 HP in tenths).
fn make(con: Int) -> Player {
let max_hp = 800 + 2 * con;
{
hp: { current: max_hp, max: max_hp },
iframes: { remaining_ms: 0 },
knockback: { vel_x: 0, vel_y: 0, remaining_ms: 0 }
#{
hp: #{ current: max_hp, max: max_hp },
iframes: #{ remaining_ms: 0 },
knockback: #{ vel_x: 0, vel_y: 0, remaining_ms: 0 }
}
}

Expand All @@ -97,10 +97,10 @@ fn take_damage(p: Player, amount: Int, source: Pos, player: Pos) -> Player {
} else {
let new_current = max(0, p.hp.current - amount);
let direction = if player.x >= source.x { 1 } else { 0 - 1 };
{
hp: { current: new_current, max: p.hp.max },
iframes: { remaining_ms: iframe_duration_ms() },
knockback: {
#{
hp: #{ current: new_current, max: p.hp.max },
iframes: #{ remaining_ms: iframe_duration_ms() },
knockback: #{
vel_x: direction * knockback_speed(),
vel_y: knockback_pop_y(),
remaining_ms: knockback_duration_ms()
Expand All @@ -121,19 +121,19 @@ fn update(p: Player, dt_ms: Int) -> UpdateResult {
0
};
let emit_velocity = if p.knockback.remaining_ms > 0 {
{ x: p.knockback.vel_x, y: p.knockback.vel_y }
#{ x: p.knockback.vel_x, y: p.knockback.vel_y }
} else {
{ x: 0, y: 0 }
#{ x: 0, y: 0 }
};
let new_kb = if new_kb_remaining <= 0 {
{ vel_x: 0, vel_y: 0, remaining_ms: 0 }
#{ vel_x: 0, vel_y: 0, remaining_ms: 0 }
} else {
{ vel_x: p.knockback.vel_x, vel_y: p.knockback.vel_y, remaining_ms: new_kb_remaining }
#{ vel_x: p.knockback.vel_x, vel_y: p.knockback.vel_y, remaining_ms: new_kb_remaining }
};
{
player: {
#{
player: #{
hp: p.hp,
iframes: { remaining_ms: new_iframe },
iframes: #{ remaining_ms: new_iframe },
knockback: new_kb
},
velocity: emit_velocity
Expand Down
Loading