c1_lua/lua/app/module/battle/component/battle_unit_comp.lua
2023-04-11 20:52:14 +08:00

69 lines
1.7 KiB
Lua

local BattleConst = require "app/module/battle/battle_const"
local BattleUnitComp = class("BattleUnitComp", LuaComponent)
local UNIT_STATE = BattleConst.UNIT_STATE
local SIDE_ATK = BattleConst.SIDE_ATK
local SPINE_ANIMATION_NAME = BattleConst.SPINE_ANIMATION_NAME
function BattleUnitComp:ctor()
end
function BattleUnitComp:initPosition()
if self.unitEntity:getSide() == SIDE_ATK then
self.baseObject:setLocalPosition(-BattleConst.INIT_POS_X, 0, 0)
else
self.baseObject:setLocalPosition(BattleConst.INIT_POS_X, 0, 0)
end
end
function BattleUnitComp:playBorn()
self:playAnimation(SPINE_ANIMATION_NAME.IDLE, true, false)
end
function BattleUnitComp:_initBase()
self.isClear = false
self.isDead = false
end
function BattleUnitComp:initWithEntity(modelId, entity, battleController, target)
self.modelId = modelId
self.unitEntity = entity
self.battleController = battleController
self.target = target
self:_initBase()
self:initPosition()
self:playBorn()
end
function BattleUnitComp:hideOutsideScreen()
if self.unitEntity:getSide() == SIDE_ATK then
self.baseObject:setLocalPosition(-GConst.UI_SCREEN_WIDTH/2 - BattleConst.UNIT_BODY_WIDTH, 0, 0)
else
self.baseObject:setLocalPosition(GConst.UI_SCREEN_WIDTH/2 + BattleConst.UNIT_BODY_WIDTH, 0, 0)
end
end
function BattleUnitComp:playAnimation(name, loop, forceRefresh)
self.currAnimationName = name
self.baseObject:playAnimation(name, loop, forceRefresh)
end
function BattleUnitComp:tick(dt)
-- if self.isClear then
-- return
-- end
-- if self.isDead then
-- self:updateDead(dt)
-- return
-- end
-- if self.currState == UNIT_STATE.IDLE then
-- self:updateIdle(dt)
-- return
-- end
-- if self.currState == UNIT_STATE.ATTACK then
-- self:updateAttack(dt)
-- end
end
return BattleUnitComp