Skip to content

Commit

Permalink
jrpg-fight: add taunt
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Gatto <[email protected]>
  • Loading branch information
cosmo-ray committed May 5, 2024
1 parent 51edfea commit 2f49932
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/script/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ BIND_EII(ywCanvasMoveObjXY, 3, 0);

BIND_EII(ywPosSetInts, 3, 0);

BIND_EII(ywPosSubXY, 3, 0);
BIND_EII(ywPosAddXY, 3, 0);
BIND_EII(ywPosMultXY, 3, 0);

Expand Down
38 changes: 38 additions & 0 deletions modules/jrpg-fight/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ local chooseTargetFunc = nil

local print_dmg_nbr = nil

local print_taunt = nil
local print_taunt_timer = 0

local cur_player = 0

local enemy_idx = 0
Expand Down Expand Up @@ -467,6 +470,7 @@ local function attackCallback(main, eve)
combatDmg(main, cur_anim)
ySoundPlayLoop(main.sound.punch)
else
startTauntAnim(main, target, "miss")
startEffectTime(target, main.wrong_txt, 10)
end

Expand Down Expand Up @@ -529,6 +533,16 @@ function fightAction(entity, eve)
return YEVE_ACTION
end

if yIsNNil(print_taunt) then
if print_taunt_timer < 0 then
local canvas = getCanvas(entity)
canvas:remove(print_taunt)
print_taunt = nil
else
print_taunt_timer = print_taunt_timer - ywidTurnTimer()
end
end

if yIsNNil(print_dmg_nbr) then
if print_dmg_nbr_timer < 1 then
local canvas = getCanvas(entity)
Expand Down Expand Up @@ -682,8 +696,16 @@ function combatDmgInternal(main, target, dmg)
new_life = max_life:to_int()
end
if dmg > 0 then
if new_life > 0 then
if new_life > max_life / 2 then
startTauntAnim(main, target, "weak_atk")
else
startTauntAnim(main, target, "strong_atk")
end
end
startEffectTime(target, main.explosion_txt, 30)
elseif dmg < 0 then
startTauntAnim(main, target, "heal")
startEffectTime(target, main.heart_txt)
end

Expand Down Expand Up @@ -922,6 +944,20 @@ function printTextAnim(main, cur_anim)
return Y_TRUE
end

function startTauntAnim(main, guy, type_taunt)
local pos = ywPosSubXY(Entity.new_copy(guy.canvas.pos), 30, 10)
local taunt = yeGetRandomElem(ygGet("taunts." .. type_taunt))
local canvas = getCanvas(main)
local txt_c = canvas:new_text(ywPosX(pos),
ywPosY(pos), taunt,
"rgba: 224 208 66").ent
if yIsNNil(print_taunt) then
canvas:remove(print_taunt)
end
print_taunt = txt_c
print_taunt_timer = 700000
end

function startTextAnim(main, txt)
local anim = Entity.new_array()
if main[txt_anim_field:to_string()] then
Expand Down Expand Up @@ -1357,6 +1393,8 @@ function fightKboum(ent)
ySoundPause(fight_widget.sound.punch)
dead_anim_deaths = nil
fight_widget = nil
print_taunt = nil
print_dmg_nbr = nil
end

function try_mk_array_of_guys(guys)
Expand Down
4 changes: 4 additions & 0 deletions modules/jrpg-fight/start.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"file" : "../Universal-LPC-spritesheet/",
"type" : "module"
},
{
"path" : "YIRL_MODULES_PATH/taunts/",
"type" : "module"
},
{
"file" : "animation.lua",
"type" : "lua"
Expand Down
3 changes: 2 additions & 1 deletion modules/taunts/start.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"miss": [
"Hello, I'm HERE !",
"Did you try to hit me ?",
"You blind ?",
"Lol"
],
"weak_atk": [
"lol, do you really think that hurt ?",
"do you think that hurt ?",
"Are you massaging me ?",
"Why are you caressing me"
],
Expand Down
10 changes: 8 additions & 2 deletions scripts-dependancies/object-wrapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,14 @@ function Canvas:new_texture(x, y, text, srcRect)
return CanvasObj.wrapp(ret)
end

function Canvas:new_text(x, y, txt)
local ret = ywCanvasNewText(self.ent, x, y, txt)
function Canvas:new_text(x, y, txt, color)
local ret
print("color", color)
if color == nil then
ret = ywCanvasNewText(self.ent, x, y, txt)
else
ret = ywCanvasNewTextExt(self.ent, x, y, txt, color)
end
return CanvasObj.wrapp(ret)
end

Expand Down

0 comments on commit 2f49932

Please sign in to comment.