Hello, I am developing a similar game “Fruit Ninja”, but I have some problems when making changes to the scoring system:
-When cut 1 object at the same tame, score = 1
-When cut 2 objects at the same tame, score = 4
-When cut 3 objects at the same tame, score = 9
-When cut 4 objects at the same tame, score = 16
-When cut …
I leave the code that I have to see that you advise me to solve this problem:
[code]
local function gameListener(event)
setScore()
print(event.phase)
if event.phase == “began” then
playerPoints = playerPoints + 1
end
if event.phase == “moved” then
local timePassed = system.getTimer() - prevTime
–print(“time passed:”,timePassed)
prevTime = prevTime + timePassed
if timePassed < 1000 then
hitCount = hitCount + 2
print(“Hitcount-BUCLE:”, hitCount)
–print(“mes petit de 2000”, timePassed)
print(playerPoints)
else
if timePassed > 1000 then
print(“Fin, timePassed:(tot a 0)”,timePassed)
hitCount = hitCount * 2
print(“Punts actuals:”, playerPoints)
hitCount)
playerPoints = playerPoints + hitCount
setScore()
hitCount = 0
end
end
end
scoreDisplay.text = “” … playerPoints
end
function shootObject(type)
local object = type == “bullet” and getRandomBullet() or getBomb()
bulletGroup:insert(object)
object.x = _W / 2
object.y = _H + object.height * 2
bulletProp.radius = object.height / 2
physics.addBody(object, “dynamic”, bulletProp)
if(type == “bullet”) then
object.objectType = “bullet”
object:addEventListener(“touch”, function(event)
gameListener(event)
chopBullet(object) end)
else
object.objectType = “bomb”
local bombTouchFunction
bombTouchFunction = function(event) explodeBomb(object, bombTouchFunction); end
object:addEventListener(“touch”, bombTouchFunction)
end
– Apply linear velocity
local yVelocity = getRandomValue(minVelocityY, maxVelocityY) * -1 – Need to multiply by -1 so the bullet shoots up
local xVelocity = getRandomValue(minVelocityX, maxVelocityX)
object:setLinearVelocity(xVelocity, yVelocity)
– Apply angular velocity (the speed and direction the bullet rotates)
local minAngularVelocity = getRandomValue(minAngularVelocity, maxAngularVelocity)
local direction = (math.random() < .5) and -1 or 1
minAngularVelocity = minAngularVelocity * direction
object.angularVelocity = minAngularVelocity
end
[code]
[import]uid: 137547 topic_id: 24398 reply_id: 324398[/import]
[import]uid: 52491 topic_id: 24398 reply_id: 98940[/import]