----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- -- ステータスバーを消す display.setStatusBar(display.HiddenStatusBar) -- 名前が長いので、変数に代入 local centerX = display.contentCenterX local centerY = display.contentCenterY local contentHeight = display.contentHeight local contentWidth = display.contentWidth -- 乱数(毎回違う数値にするため) math.randomseed(os.time()) -- 点数用 local scoreHeight = 30 -- 点数の表示高さ local allCnt = 0 -- 全表示数 local tapCnt = 0 -- タップできた数 ----------------------------------------------------------------------------------------- -- 関数名 : MakeMogura -- 内 容 : モグラオブジェクトの作成 -- 戻り値 : 無し ----------------------------------------------------------------------------------------- local function MakeMogura() print("MakeMogura") allCnt = allCnt + 1 -- モグラのサイズ local size = math.random(20, 30) -- モグラの表示位置 local x = math.random(size, contentWidth - size) local y = math.random(scoreHeight + size, contentHeight - size) -- 描画 local mogura = display.newCircle(x, y, size) ----------------------------------------------------------------------------------------- -- 関数名 : Timeout -- 内 容 : モグラオブジェクトのタイムアウト処理(削除) -- 戻り値 : 無し ----------------------------------------------------------------------------------------- local function Timeout() print("Timeout") if (mogura ~= nil) then print("delete") display.remove(mogura) mogura = nil end end -- フェードアウト処理 local fadeout = transition.fadeOut(mogura, {time = 2000, onComplete = Timeout}) ----------------------------------------------------------------------------------------- -- 関数名 : Tap -- 内 容 : モグラオブジェクトをタップしたときの処理 -- 戻り値 : true ----------------------------------------------------------------------------------------- local function OnTap() print("Tap") tapCnt = tapCnt + 1 -- フェードアウトの削除 if (fadeout ~= nil) then transition.cancel(fadeout) end -- オブジェクトの削除 if (mogura ~= nil) then display.remove(mogura) mogura = nil end return true end mogura:addEventListener("tap", OnTap) end -- スコア表示 local textScore = display.newText("0 / 0", centerX, scoreHeight * 0.5, native.systemFont, 30) ----------------------------------------------------------------------------------------- -- 関数名 : UpdateScore -- 内 容 : スコア表示更新 -- 戻り値 : 無し ----------------------------------------------------------------------------------------- local function UpdateScore() textScore.text = string.format("%d / %d", tapCnt, allCnt) end MakeMogura() timer.performWithDelay(3000, MakeMogura, -1) timer.performWithDelay(300, UpdateScore, -1)