109 lines
3.3 KiB
Lua
109 lines
3.3 KiB
Lua
local RiceSinglePlayerView = {}
|
||
local initSpeed = 20
|
||
local RidingSwardSence = ConfigManager.GetConfig(ConfigName.RidingSwardSence)
|
||
|
||
function RiceSinglePlayerView:New(gameObject)
|
||
local b = {}
|
||
b.gameObject = gameObject
|
||
b.transform = gameObject.transform
|
||
setmetatable(b, { __index = RiceSinglePlayerView })
|
||
return b
|
||
end
|
||
|
||
function RiceSinglePlayerView:InitComponent()
|
||
self.gameObject:GetComponent("RectTransform").sizeDelta = Vector2.New(10000,100)
|
||
self.player = Util.GetGameObject(self.gameObject,"Player")
|
||
self.playerTrans = self.player:GetComponent("RectTransform")
|
||
self.playerTrans.localPosition = Vector2.New(0,100)
|
||
self.curPosX = self.playerTrans.localPosition.x
|
||
self.speed = initSpeed
|
||
FixedUpdateBeat:Add(self.OnUpdate, self)--长按方法注册
|
||
end
|
||
|
||
--绑定事件(用于子类重写)
|
||
function RiceSinglePlayerView:BindEvent()
|
||
end
|
||
--添加事件监听(用于子类重写)
|
||
function RiceSinglePlayerView:AddListener()
|
||
end
|
||
|
||
--移除事件监听(用于子类重写)
|
||
function RiceSinglePlayerView:RemoveListener()
|
||
end
|
||
|
||
--设置游戏状态
|
||
function RiceSinglePlayerView:SetSinglePlayerState(_state)
|
||
local keyFrame = RidingSwardSence[self.data[1]].KeyFrame
|
||
self.keyFrameList = {}
|
||
for i = 1, #keyFrame do
|
||
self.keyFrameList[i] = {}
|
||
self.keyFrameList[i].pos = keyFrame[i][1]*initSpeed*30
|
||
self.keyFrameList[i].value = keyFrame[i][2]
|
||
end
|
||
for i,v in ipairs(self.keyFrameList) do
|
||
LogRed(string.format( "在:%s位置处效果:%s",v.pos,v.value))
|
||
end
|
||
self.isRunning = _state
|
||
end
|
||
|
||
--重置游戏
|
||
function RiceSinglePlayerView:ResetSinglePlayer()
|
||
self.isRunning = false
|
||
self.speed = initSpeed
|
||
self.playerTrans.localPosition = Vector2.New(0,100)
|
||
self.curPosX = self.playerTrans.localPosition.x
|
||
end
|
||
|
||
|
||
--upDate
|
||
function RiceSinglePlayerView:OnUpdate()
|
||
if self.isRunning then
|
||
if self.index == 1 then
|
||
LogYellow("self.speed:"..tostring(self.speed))
|
||
end
|
||
if self.curPosX >= 8500 then
|
||
YuJianXingManager.FinishResetGame()
|
||
else
|
||
self.curPosX = self.curPosX + self.speed
|
||
self.player.transform.localPosition = Vector2.New(self.curPosX,100)
|
||
-- for k,v in pairs(self.keyFrameList) do
|
||
|
||
for i,v in ipairs(self.keyFrameList) do
|
||
if self.curPosX >= v.pos then
|
||
if v == 1 then
|
||
self.speed = self.speed*1.2
|
||
table.remove( self.keyFrameList,i)
|
||
elseif v == 2 then
|
||
self.speed = self.speed*0.9
|
||
table.remove( self.keyFrameList,i)
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
--返回当前位置
|
||
function RiceSinglePlayerView:GetCurPosX()
|
||
return self.curPosX
|
||
end
|
||
|
||
--界面打开时调用(用于子类重写)
|
||
function RiceSinglePlayerView:OnOpen(_inedx,_data)
|
||
self.index = _inedx
|
||
self.data = _data
|
||
end
|
||
|
||
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
|
||
function RiceSinglePlayerView:OnShow()
|
||
end
|
||
|
||
function RiceSinglePlayerView:OnClose()
|
||
end
|
||
|
||
--界面销毁时调用(用于子类重写)
|
||
function RiceSinglePlayerView:OnDestroy()
|
||
FixedUpdateBeat:Remove(self.OnUpdate, self)
|
||
end
|
||
|
||
return RiceSinglePlayerView |