Hello, I’m a newbie and I am working on a side scrolling rhythm game.
The section where I am having trouble wrapping my head around now is getting the current score to trigger an event, which is prompting a spritesheet to count to the next frame. I found a code with similar concept by Rob Miracle, which is a health bar code. I was trying to modify it, but I messed it up instead, so I restarted that part again.
Basically what I want is:
Every +20 of currentScore, Balloon count=1.
So the ballon expands the more score the player gets.
I have parts of the code here, let me know what I can do, or if there is a more efficient way, please do teach me:
[lua]
local currentScore
–Inflating Balloon Spritesheet options
local boptions = { width=82, height=113, numFrames=12 }
local balloon= (“images/balloonexpand.png”)
local balloonSheet = graphics.newImageSheet( balloon, boptions )
balloon.anchorX = 0.0
balloon.anchorY = 0.0
balloon.x = display.contentCenterX -27
balloon.y = display.contentCenterY -170
local balloonSprite = display.newSprite( balloonSheet)
–Health bar code for tweaking
local lifeIcons = {}
local lives = 5
local maxLives = 5
lifeBar[0] = display.newSprite(“balloonSheet, {name=“balloon”, start=1, count=1, time=0}”)
lifeBar[1] = display.newSprite(“balloonSheet, {name=“balloon”, start=2, count=1, time=0}”)
lifeBar[2] = display.newSprite(“balloonSheet, {name=“balloon”, start=3, count=1, time=0}”)
lifeBar[3] = display.newSprite(“balloonSheet, {name=“balloon”, start=4, count=1, time=0}”)
lifeBar[4] = display.newSprite(“balloonSheet, {name=“balloon”, start=5, count=1, time=0}”)
lifeBar[5] = display.newSprite(“balloonSheet, {name=“balloon”, start=6, count=1, time=0}”)
local i
for i = 1, maxLives do
lifeBar[i].x = 10
lifeBar[i].y = 30
lifeBar[i].isVisible = false
end
lifeBar[lives].isVisible = true
if lives > 0 then
lifeBar[lives].isVisible = false
lives = lives - 1
lifeBar[lives].isVisible = true
end
–Increase CurrentScore per enemy touch
local function handleEnemyTouch( event )
if event.phase == “began” then
media.playEventSound( clickedSound )
pop = display.newImage(“images/pop.png”, event.x,event.y)
event.target: removeSelf( )
currentScore = currentScore + 10
currentScoreDisplay.text = string.format( “%06d”, currentScore )
local function removePop( event )
pop:removeSelf( )
end
timer.performWithDelay(100, removePop)
end
end
[/lua]
Thank you!