I have been coding in Corna for a couple of weeks and i have followed Cheetomeskeeto’s videos about his game orb smasher “http://www.youtube.com/watch?v=6TsDdLY7VXk.” He eventually uses the director.lua to turn it into a fully functional game “https://developer.coronalabs.com/code/director-class-10” but now that is outdated and i get errors trying to follow it.
It would be awesome if someone helped me out and put it into storyboard, all im looking for is a reload button. I have included my main file below, thanks in advance!!!
–constants
_W = display.contentWidth;
_H = display.contentHeight;
mRand = math.random;
o = 0;
time_remain = 10;
time_up = false;
total_orbs = 20;
ready = false;
q=0
–sounds to play
local sound_track = audio.loadStream(“music/American Authors - Best Day Of My Life.mp3”);
local pop_sound = audio.loadSound(“music/pop.wav”);
local win_sound = audio.loadSound(“music/youwin.wav”);
local loose_sound = audio.loadSound(“music/youloose.wav”);
local one_sound = audio.loadSound(“music/1.wav”);
local two_sound = audio.loadSound(“music/2.wav”);
local three_sound = audio.loadSound(“music/3.wav”);
local go_sound = audio.loadSound(“music/go.wav”);
local display_txt = display.newText(“Ready”, 0, 0, native.systemFont,45/2);
–display_txt.yScale = .5;
–display_txt.xScale = .5;
display_txt.x = 50;
display_txt.y = _H-20;
local countdowntxt = display.newText(“10”, 0, 0, native.systemFont,45/2);
–countdowntxt.yScale = .5;
–countdowntxt.xScale = .5;
countdowntxt.x = _W-20;
countdowntxt.y = _H-20;
–function btn:touch(e)
--if(e.phase == ended)then
--storyboard.reloadScene()
--end
–end
–btn:addEventListener(“touch”, btn)
local function winLose(condition)
if(condition == “win”) then
display_txt.text = " You Win!!";
elseif(condition == “loose”)then
display_txt.text = “You Lose”;
end
end
local function trackOrbs(obj)
obj:removeSelf();
o = o-1;
--all dots are removed
if(time_up ~= true) then
if(o == 0) then
audio.play(win_sound);
timer.cancel(gametmr);
winLose(“win”);
display_txt.x = _W/2;
display_txt.y = _H/2;
countdowntxt.text = “Try Again”;
countdowntxt.x = _W/2;
countdowntxt.y = 300;
end
end
end
local function countDown(e)
if(time_remain == 10) then
ready=true;
countdowntxt.text=“GO!”;
--audio.play(sound_track, {loops = -1});
end
time_remain = time_remain - 1;
display_txt.text = time_remain;
if(time_remain == 0) then
time_up = true;
if(o ~= 0)then
audio.play(loose_sound);
display_txt.text = “You Lose”;
display_txt.x = _W/2
display_txt.y = _H/2
ready = false
countdowntxt.text = “Try Again”
countdowntxt.x = _W/2
countdowntxt.y = _H/-50
end
end
end
local function spawnOrb()
local orb = display.newImage(“images/orb.png”, 45, 45);
orb.x = mRand(50, _W-50);
orb.y = mRand(50, _H-50);
q = q+1
function orb:touch(e)
if(ready == true) then
if(time_up ~= true) then
if(e.phase == “ended”)then
--play the pop sound
audio.play(pop_sound);
--remove orbs
trackOrbs(self);
end
end
end
return true;
end
o = o+1;
orb:addEventListener(“touch”, orb);
if(o == total_orbs)then
gametmr = timer.performWithDelay(1000, countDown, 10);
else
ready = false;
end
if(q == 5)then
audio.play(three_sound);
three = display.newText(“3”, 0, 0, native.systemFont,200);
--display_txt.yScale = .5;
--display_txt.xScale = .5;
three.x = _W/2;
three.y = _H/2;
--three:removeSelf
end
if(q == 10)then
audio.play(two_sound);
two = display.newText(“2”, 0, 0, native.systemFont,200);
--display_txt.yScale = .5;
--display_txt.xScale = .5;
two.x = _W/2;
two.y = _H/2;
--three:removeSelf
three:removeSelf();
end
if(q == 15)then
audio.play(one_sound);
one = display.newText(“1”, 0, 0, native.systemFont,200);
--display_txt.yScale = .5;
--display_txt.xScale = .5;
one.x = _W/2;
one.y = _H/2;
two:removeSelf();
end
if(q == 19)then
audio.play(go_sound);
go = display.newText(“GO!!”, 0, 0, native.systemFont,150);
--display_txt.yScale = .5;
--display_txt.xScale = .5;
go.x = _W/2;
go.y = _H/2;
one:removeSelf();
end
if(q == 20)then
go:removeSelf();
end
end
tmr = timer.performWithDelay(200, spawnOrb, total_orbs);