diff --git a/lua/app/module/battle/battle_const.lua b/lua/app/module/battle/battle_const.lua index d74769c2..527c8a58 100644 --- a/lua/app/module/battle/battle_const.lua +++ b/lua/app/module/battle/battle_const.lua @@ -16,6 +16,8 @@ BattleConst.SIDE_DEF = 2 BattleConst.SKILL_TYPE_ACTIVE = 1 BattleConst.SKILL_SELECT_COUNT = 3 BattleConst.DEFAULT_FACTOR = 10000 +BattleConst.INIT_POS_X = 200 +BattleConst.UNIT_BODY_WIDTH = 100 -- 为方便存储,这里使用字符串 BattleConst.BATTLE_TYPE = { @@ -35,6 +37,10 @@ BattleConst.UNIT_STATE = { DEAD = 4, -- 死亡 } +BattleConst.SPINE_ANIMATION_NAME = { + IDLE = "idle", +} + ---- 格子类型 BattleConst.GRID_TYPE = { EMPTY = 0, diff --git a/lua/app/module/battle/component/battle_hero_comp.lua b/lua/app/module/battle/component/battle_hero_comp.lua index 7fc88cdf..efa66e27 100644 --- a/lua/app/module/battle/component/battle_hero_comp.lua +++ b/lua/app/module/battle/component/battle_hero_comp.lua @@ -14,8 +14,4 @@ function BattleHeroComp:initBase() self.currState = UNIT_STATE.INIT end -function BattleHeroComp:initPosition() - self.baseObject:setLocalPosition(0, 0, 0) -end - return BattleHeroComp \ No newline at end of file diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 94b1651d..2863958c 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -3,12 +3,22 @@ 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() - self.baseObject:setLocalPosition(0, 0, 0) + 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() @@ -23,6 +33,20 @@ function BattleUnitComp:initWithEntity(modelId, entity, battleController, target 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) diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index f9312921..860dae0c 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -133,6 +133,9 @@ function BattleController:initAllUnits(callback) local heroComp = spineObject:addLuaComponent(BattleConst.TYPEOF_LUA_COMP.BATTLE_HERO_COMPONENT) heroComp:initWithEntity(modelId, v, self) self.atkUnits[v:getMatchType()] = heroComp + if not v:getIsMainUnit() then + heroComp:hideOutsideScreen() + end onloadFinished() end) end diff --git a/lua/app/userdata/battle/team/battle_team_entity.lua b/lua/app/userdata/battle/team/battle_team_entity.lua index a6ab75de..5d87c085 100644 --- a/lua/app/userdata/battle/team/battle_team_entity.lua +++ b/lua/app/userdata/battle/team/battle_team_entity.lua @@ -28,6 +28,7 @@ function BattleTeamEntity:init(side, data) self.members[unitData.matchType] = unit self.membersCount = self.membersCount + 1 if self.mainHero == nil then + unit:setIsMainUnit(true) self.mainHero = unit end end diff --git a/lua/app/userdata/battle/team/battle_unit_entity.lua b/lua/app/userdata/battle/team/battle_unit_entity.lua index 08914b0e..fa778c73 100644 --- a/lua/app/userdata/battle/team/battle_unit_entity.lua +++ b/lua/app/userdata/battle/team/battle_unit_entity.lua @@ -43,4 +43,16 @@ function BattleUnitEntity:getMatchType() return self.unitData.matchType end +function BattleUnitEntity:getSide() + return self.side +end + +function BattleUnitEntity:setIsMainUnit(isMainUnit) + self.isMainUnit = isMainUnit +end + +function BattleUnitEntity:getIsMainUnit() + return self.isMainUnit +end + return BattleUnitEntity \ No newline at end of file