Skip to content

Commit

Permalink
add features about balls pocket and ami
Browse files Browse the repository at this point in the history
fix bugs about experience
3D effect optimize
collision optimize
  • Loading branch information
EricDDK committed Jun 3, 2018
1 parent 58b9210 commit e6143bc
Show file tree
Hide file tree
Showing 12 changed files with 519 additions and 204 deletions.
7 changes: 4 additions & 3 deletions gameBilliards/app/GameApp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ local gamename = "gameBilliards"

g_EightBallData = require("gameBilliards.app.define.EightBallDefine")

--require("gameBilliards.app.mgr.ballManager")
-- require("gameBilliards.app.define.GlobalDefine") --测试Layer用

require("gameBilliards.app.mgr.EightBallGameManager")
require("gameBilliards.app.mgr.ballManager")
require("gameBilliards.app.mgr.MathMgr")
require("gameBilliards.app.mgr.BilliardsAnimationManager")
require("gameBilliards.app.control.PhysicalControl")
Expand All @@ -16,11 +17,11 @@ function GameApp:ctor(...)
GameApp.super.ctor(self, ...)
end

function GameApp:run()
function GameApp:run(isResume)
local pScene = cc.Scene:createWithPhysics()
-- local layer = require(g_myGameName .. "/app/layer/testLayer").new()
-- local layer = require(gamename .. "/app/layer/gameBilliardsMainLayer").new()
local layer = require(gamename .. "/app/layer/EightBallLayer").new()
local layer = require(gamename .. "/app/layer/EightBallLayer").new(isResume)
if layer then
pScene:addChild(layer)
end
Expand Down
6 changes: 3 additions & 3 deletions gameBilliards/app/common/Ball3DRender.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ function Ball3DRender:ctor(nTag, rootBall)
local rigidBody = cc.Physics3DRigidBody:create(rbDes)
local component = cc.Physics3DComponent:create(rigidBody)
self:setTexture("gameBilliards/3d_ball/" .. nTag .. ".png")
self:setTag(8)
self:setTag(g_EightBallData.g_Border_Tag.texture3D)
self:setScale((rootBall:getContentSize().width / 2) / g_EightBallData.radius_3D)
self:setCameraMask(cc.CameraFlag.USER2)
self:setGlobalZOrder(0-nTag)
--这里如果想要真实台球摆放位置,用random设置角度
self:setRotation3D(cc.vec3(0.0,0.0,0.0))
--self:setRotation3D(cc.vec3(math.random(0, 180), math.random(0, 180), math.random(0, 180)))
--self:setRotation3D(cc.vec3(0.0,0.0,0.0))
self:setRotation3D(cc.vec3(math.random(0, 180), math.random(0, 180), math.random(0, 180)))
rigidBody:setAngularVelocity(cc.vec3(0.0, 0.0, 0.0))
end

Expand Down
6 changes: 3 additions & 3 deletions gameBilliards/app/common/Cue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ function Cue:receiveLauchBall(event, callback)
if self and not tolua.isnull(self) and m_RootBall and not tolua.isnull(m_RootBall) then
self:setCueLineCircleVisible(false)
self:resetPos()
EightBallGameManager:setCanRefreshBallAni(true)
m_RootBall:setPosition(cc.p(event.fPositionX, event.fPositionY))
m_RootBall:getPhysicsBody():setVelocity(cc.p(event.fVelocityX, event.fVelocityY))
m_RootBall:getPhysicsBody():setAngularVelocity(event.fAngularVelocity)
Expand All @@ -178,7 +179,7 @@ function Cue:receiveLauchBall(event, callback)
local posX, posY = mathMgr:getCuePosByRotate(cueRotate, event.Percent)
local radius = m_RootBall:getContentSize().width / 2

local func1 = cc.MoveTo:create(1, cc.p(radius + posX, radius + posY))
local func1 = cc.MoveTo:create(g_EightBallData.sendHitResultInterval, cc.p(radius + posX, radius + posY))
local func2 = cc.CallFunc:create( function()
_hitWhiteBall()
end )
Expand Down Expand Up @@ -215,12 +216,11 @@ local mCanSendSetCueMessage = true
--@ rootNode 游戏场景layer
--@ isEnded 如果是触摸停止事件必然发送
function Cue:sendSetCueMessage(angle, rootNode,isEnded)
if mCanSendSetCueMessage or isEnded then
if (mCanSendSetCueMessage or isEnded) and EBGameControl:getGameState() ~= g_EightBallData.gameState.practise then
local requestData = {
fAngle = tostring(angle),
UserID = player:getPlayerUserID()
}
dump(requestData)
EBGameControl:requestEightBallCmd(g_EIGHTBALL_REG_SETCUEINFO,requestData)
rootNode:runAction(cc.Sequence:create(cc.DelayTime:create(g_EightBallData.sendSetCueInterval), cc.CallFunc:create( function()
mCanSendSetCueMessage = true
Expand Down
47 changes: 30 additions & 17 deletions gameBilliards/app/common/EightBall.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local BallBase = require("gameBilliards.app.common.BallBase")
local EightBall = class("EightBall", BallBase)

-- 保存球状态
EightBall.mBallState = g_EightBallData.ballState.stop

-- 调整高光
function EightBall:adjustHighLight()
local _highLight = self:getChildByTag(g_EightBallData.g_Border_Tag.heighLight)
Expand All @@ -22,7 +25,7 @@ function EightBall:adjustBallSpeed(nTime)
end
end
if v ~= 0 then
local Texture = self:getChildByTag(8)
local Texture = self:getChildByTag(g_EightBallData.g_Border_Tag.texture3D)
if Texture then
Texture:adjust3DRolling(velocity,self:getPhysicsBody():getAngularVelocity())
end
Expand All @@ -48,17 +51,14 @@ function EightBall:resetForceAndEffect()
self:getPhysicsBody():setAngularVelocity(0)
self:clearWhiteBallContinuesForce()

local sprite3D = self:getChildByTag(8)
local sprite3D = self:getChildByTag(g_EightBallData.g_Border_Tag.texture3D)
if sprite3D and sprite3D:getPhysicsObj() then
sprite3D:getPhysicsObj():setAngularVelocity(cc.vec3(0.0, 0.0, 0.0))
end
if self:getTag() == g_EightBallData.g_Border_Tag.whiteBall then
local cueRotate = mathMgr:changeAngleTo0to360(self:getRotation())
self:setRotationOwn(cueRotate)
end
if self:getBallState() ~= g_EightBallData.ballState.inHole then
self:setBallState(g_EightBallData.ballState.stop)
end
end

-- 处理白球上的指示符视图
Expand All @@ -74,8 +74,8 @@ function EightBall:clearWhiteBallView()
end
end

-- 处理白球进洞
function EightBall:dealWhiteBallInHole()
-- 处理白球进洞(显示白球白手放置图案)
function EightBall:dealWhiteBallInHole(rootNode)
local whiteShadow = self:getChildByTag(g_EightBallData.g_Border_Tag.whiteShadow)
-- local moveHand = self:getChildByTag(g_EightBallData.g_Border_Tag.moveHand)
if whiteShadow then
Expand All @@ -88,15 +88,19 @@ function EightBall:dealWhiteBallInHole()
end
end

-- 球进洞
function EightBall:ballGoInHole(nTag)
--处理白球进入袋子
--白球不走这流程
function EightBall:dealBallInBag()
self:setScale(g_EightBallData.radius/(self:getContentSize().width/2))
self:resetForceAndEffect()
self:setBallState(g_EightBallData.ballState.inHole)
self:setPosition(g_EightBallData.inBagPos)
self:getPhysicsBody():applyForce(cc.p(-50000, -500000), cc.p(0, 0))
end

-- 重置球
function EightBall:resetBallState()
self:setScale(g_EightBallData.radius/(self:getContentSize().width/2))
self:setBallState(g_EightBallData.ballState.stop)
self:setRotationOwn(0)
if self:getTag() == 0 then
local cue = self:getChildByTag(g_EightBallData.g_Border_Tag.cue)
Expand All @@ -110,6 +114,7 @@ end

-- 构造函数
function EightBall:ctor(nTag)
--self.mBallState = g_EightBallData.ballState.stop
self:setTexture("gameBilliards/eightBall/eightBall_TransparentBall.png")
self:setScale(g_EightBallData.radius/(self:getContentSize().width/2))
self:setTag(nTag)
Expand Down Expand Up @@ -424,24 +429,32 @@ function EightBall:clearWhiteBallContinuesForce()
end

-- 保存球状态
local ballState = g_EightBallData.ballState.stop
function EightBall:setBallState(args)
ballState = args
function EightBall:setBallState(args,m_MainLayer)
self.mBallState = args
end

function EightBall:getBallState()
return ballState
return self.mBallState
end

-- 获取此球是否进洞
function EightBall:getIsInHole()
return ballState == g_EightBallData.ballState.inHole
or self:getPositionX() < 0 or self:getPositionX() > 968
or self:getPositionY() < 0 or self:getPositionY() > 547
return self:getBallState() == g_EightBallData.ballState.inHole
and (self:getPositionX() < 70 or self:getPositionX() > 910 or self:getPositionY() > 475 or self:getPositionY() < 70 )
end

--通过位置判断是否进洞
function EightBall:setIsInHoleByPos(posX,posY)
if posX < 70 or posY < 70 or posX > 910 or posY > 475 then
self:setBallState(g_EightBallData.ballState.inHole)
end
end

--封装一个
function EightBall:setRotationOwn(rotate)
if not rotate then
return
end
if self:getTag() == g_EightBallData.g_Border_Tag.whiteBall then
self:setRotation(rotate)
local whiteShadow = self:getChildByTag(g_EightBallData.g_Border_Tag.whiteShadow)
Expand Down
Loading

0 comments on commit e6143bc

Please sign in to comment.