Hello!
I am trying to create a health bar style timer that slowly decreases as you play the game. The game is a match memory card style game and each time you get two card matched, the health or time increases. If you don’t match all the cards and your health runs out, the game is over.
How do I implement this to function with a green health bar graphic? And where the heck to I put it?
here is my Main Lua
–Set Global width and height variables
_W = display.contentWidth;
_H = display.contentHeight;
–Hide status bar
display.setStatusBar(display.HiddenStatusBar);
display.setStatusBar(display.HiddenStatusBar)
local background = display.newImage (“background.png”)
– background music –
backgroundMusic = audio.loadStream(“billyJean.caf”)
backgroundMusicChannel = audio.play( backgroundMusic, { channel=0, loops=1, fadein=20000 } )
– Michaels Head Normal –
local MichaelNormal = display.newImage (“MichaelNormal.png”)
MichaelNormal.x = 130
MichaelNormal.y = 85
–Declare a totalButtons variable to track number of buttons on screen
local totalButtons = 0
–Declare variable to track button select
local secondSelect = 0
local checkForMatch = false
–Declare button, buttonCover, and buttonImages table
local button = {}
local buttonCover = {}
local buttonImages = {1,1, 2,2, 3,3, 4,4, 5,5, 6,6,}
–Notify player if match is found or not
local matchText = display.newText("", 0, 228, native.systemFont, 18)
matchText:setReferencePoint(display.CenterReferencePoint)
matchText:setTextColor(51, 255, 102)
matchText.x = _W/2
–Set starting point for button grid
x = -27
y = -80
–Set up game function
function game(object, event)
if(event.phase == “began”) then
if(checkForMatch == false and secondSelect == 0) then
–Flip over first button
buttonCover[object.number].isVisible = false;
lastButton = object
checkForMatch = true
elseif(checkForMatch == true) then
if(secondSelect == 0) then
–Flip over second button
buttonCover[object.number].isVisible = false;
secondSelect = 1;
–If buttons do not match, flip buttons over
if(lastButton.myName ~= object.myName) then
matchText.text = “Match Not Found!”;
timer.performWithDelay(800, function()
matchText.text = " ";
checkForMatch = false;
secondSelect = 0;
buttonCover[lastButton.number].isVisible = true;
buttonCover[object.number].isVisible = true;
local MichaelNormal = display.newImage (“MichaelSick.png”)
MichaelNormal.x = 130
MichaelNormal.y = 85
media.playEventSound(“imsorry.caf”)
end, 1)
–If buttons DO match, remove buttons
elseif(lastButton.myName == object.myName) then
matchText.text = “Match Found!”;
timer.performWithDelay(1250, function()
matchText.text = " ";
checkForMatch = false;
secondSelect = 0;
lastButton:removeSelf();
object:removeSelf();
buttonCover[lastButton.number]:removeSelf();
buttonCover[object.number]:removeSelf();
local MichaelNormal = display.newImage (“MichaelHealth.png”)
MichaelNormal.x = 130
MichaelNormal.y = 85
media.playEventSound(“good.caf”)
end, 1)
end
end
end
end
end
–Place buttons on screen
for count = 1,4 do
x = x + 75
y = 214
for insideCount = 1,3 do
y = y + 75
–Assign each image a random location on grid
temp = math.random(1,#buttonImages)
button[count] = display.newImage(buttonImages[temp] … “.png”);
–Position the button
button[count].x = x;
button[count].y = y;
–Give each a button a name
button[count].myName = buttonImages[temp]
button[count].number = totalButtons
–Remove button from buttonImages table
table.remove(buttonImages, temp)
–Set a cover to hide the button image
buttonCover[totalButtons] = display.newImage(“button.png”);
buttonCover[totalButtons].x = x; buttonCover[totalButtons].y = y;
totalButtons = totalButtons + 1
–Attach listener event to each button
button[count].touch = game
button[count]:addEventListener( “touch”, button[count], playfalse1 )
end
end
[import]uid: 94909 topic_id: 2576 reply_id: 59261[/import]