The scripts for calculating frames is really long and spread over multiple script blocks, so I'll just do the main script.
Code: Select all
## NPC Extra data 0: Enemy health
## NPC Extra data 1: Enemy hurtframes
## NPC Extra data 2: Knockback direction
## NPC Slice Extra 0: Attack cooldown
## NPC Slice Extra 1: Attack animation frames
## NPC Slice Extra 2: Invincibility frames
## NPC Script Argument: Attack power - read NPC (ref, NPCstat:script argument)
script, check hit frames, begin
variable (ref, next, killed, power)
ref := next npc reference
while (ref) do (
next := next npc reference(ref)
power := read NPC (ref, NPCstat:script argument)
if (player iframes < 1 && slice collide (get npc slice(ref), player hitbox)) then (
if (power > 0) then (damage player(ref))
)
if (player attacking && slice collide (get npc slice(ref), sword)) then (
if (get slice extra(get npc slice(ref), extra 2) < 1 && power > 0) then (
killed := damage enemy (ref)
)
)
if (not(killed) && npc extra (ref, extra 1) > 0) then (
switch (npc extra (ref, extra 2)) do (
case (north) do (
if (check npc wall (ref, north)) then (
set npc extra (ref, extra 1, 0)
) else (put npc (ref, npc pixel x(ref), npc pixel y(ref) --5))
)
case (east) do (
if (check npc wall (ref, east)) then (
set npc extra (ref, extra 1, 0)
) else (put npc (ref, npc pixel x(ref) +5, npc pixel y(ref)))
)
case (south) do (
if (check npc wall (ref, south)) then (
set npc extra (ref, extra 1, 0)
) else (put npc (ref, npc pixel x(ref), npc pixel y(ref) +5))
)
case (west) do (
if (check npc wall (ref, west)) then (
set npc extra (ref, extra 1, 0)
) else (put npc (ref, npc pixel x(ref) --5, npc pixel y(ref)))
)
)
set npc extra (ref, extra 1, npc extra (ref, extra 1) -- 1)
if (npc extra(ref, extra 1) < 1) then (
set NPC moves (ref, true)
)
)
if (not(killed) && get slice extra(get npc slice(ref), extra 2) > 0) then (
update enemy flash (ref)
)
ref := next
)
if (player hurtframe > 0) then (
switch (player hurtdir) do (
case (north) do (
if (check hero wall (me, north)) then (
player hurtframe := 0
put hero (me, hero x (me) * 20, hero y (me) * 20)
)
else (put hero (me, hero pixel x (me), hero pixel y (me) --4))
)
case (east) do (
if (check hero wall (me, east)) then (
player hurtframe := 0
put hero (me, hero x (me) * 20, hero y (me) * 20)
)
else (put hero (me, hero pixel x (me) +4, hero pixel y (me)))
)
case (south) do (
if (check hero wall (me, south)) then (
player hurtframe := 0
put hero (me, hero x (me) * 20, hero y (me) * 20)
)
else (put hero (me, hero pixel x (me), hero pixel y (me) +4))
)
case (west) do (
if (check hero wall (me, west)) then (
player hurtframe := 0
put hero (me, hero x (me) * 20, hero y (me) * 20)
)
else (put hero (me, hero pixel x (me) --4, hero pixel y (me)))
)
)
decrement (player hurtframe)
if (player hurtframe < 1) then (
resume player
)
)
if (player iframes > 0) then (update player flash)
end