[Resolved] Bonus score when drag (cut) HELP

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]

OOI if you print timePassed is it returning the correct value? [import]uid: 52491 topic_id: 24398 reply_id: 98710[/import]

peach pellen: yes the timePassed return a correct values but the problem is a delay time when sum total score generated in a bucle, sum all at once after a time [import]uid: 137547 topic_id: 24398 reply_id: 98732[/import]

Hey Roger,

Here is an example of how you might manage this - this code is to be run on its own and not in your project but may help, please try it and see the print statements;

[lua]local bg = display.newRect( 0, 0, 320, 480 )
bg:setFillColor(0, 215, 255)

local score = 0
local combo = 0
local prevCombo = 0

local function getPoints()
score = score+1
combo=combo+1
prevCombo = combo
local function resetCombo()
if combo <= prevCombo then
print ("Combo: "…combo)
combo = 0
end
end
if comboTimer then timer.cancel(comboTimer) end
comboTimer = timer.performWithDelay(1000, resetCombo, 1)
end
bg:addEventListener(“tap”, getPoints)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 24398 reply_id: 98940[/import]

Fantastic!!! I could solve the problem, thanks to you Peach!

See you soon

Roger
[import]uid: 137547 topic_id: 24398 reply_id: 98991[/import]

No worries Roger, always happy to help!

Peach :slight_smile: [import]uid: 52491 topic_id: 24398 reply_id: 99066[/import]