2015-07-08 10:11:17 +08:00
|
|
|
require "cocos.init"
|
2015-09-21 14:02:42 +08:00
|
|
|
require "ComponentTest/gameoverscene"
|
2015-07-08 10:11:17 +08:00
|
|
|
|
2015-07-07 09:51:18 +08:00
|
|
|
local scene = {
|
|
|
|
-- add a new enemy every second
|
|
|
|
durationOfAddEnemy = 1.0,
|
|
|
|
-- how long past after last time of adding a new enemy
|
|
|
|
totalDt = 0,
|
2015-07-08 10:11:17 +08:00
|
|
|
numEnemyDestroyed = 0,
|
|
|
|
enemies = {},
|
|
|
|
|
|
|
|
onEnter = function(self)
|
2015-09-21 14:02:42 +08:00
|
|
|
ccexp.AudioEngine:play2d("background-music-aac.mp3", true)
|
2015-07-08 10:11:17 +08:00
|
|
|
end,
|
2015-07-07 09:51:18 +08:00
|
|
|
|
|
|
|
update = function(self, dt)
|
|
|
|
self.totalDt = self.totalDt + dt
|
|
|
|
if self.totalDt > self.durationOfAddEnemy then
|
|
|
|
self:addNewEnemy()
|
|
|
|
self.totalDt = 0
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
addNewEnemy = function(self)
|
|
|
|
local owner = self:getOwner()
|
2015-09-21 14:02:42 +08:00
|
|
|
local enemy = cc.Sprite:create("components/Target.png")
|
|
|
|
local enemyLuaComponent = cc.ComponentLua:create("src/ComponentTest/enemy.lua")
|
2015-07-07 09:51:18 +08:00
|
|
|
enemy:addComponent(enemyLuaComponent)
|
|
|
|
owner:addChild(enemy)
|
2015-07-08 10:11:17 +08:00
|
|
|
table.insert(self.enemies, enemy)
|
2015-07-07 09:51:18 +08:00
|
|
|
end,
|
2015-07-08 10:11:17 +08:00
|
|
|
|
|
|
|
looseGame = function(node)
|
|
|
|
local scene = GameOverScene.create("You Lose :[")
|
|
|
|
cc.Director:getInstance():replaceScene(scene)
|
|
|
|
end,
|
|
|
|
|
|
|
|
inscreaseCount = function(self)
|
|
|
|
self.numEnemyDestroyed = self.numEnemyDestroyed + 1
|
|
|
|
if self.numEnemyDestroyed >=5 then
|
|
|
|
local scene = GameOverScene.create("You Win!")
|
|
|
|
cc.Director:getInstance():replaceScene(scene)
|
|
|
|
end
|
|
|
|
end
|
2015-07-07 09:51:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return scene
|