-- GameView is a combination of view and controller
@H_502_1@local @H_502_1@GameView @H_502_1@= class@H_502_1@("GameView"@H_502_1@,cc@H_502_1@.load@H_502_1@("mvc"@H_502_1@).ViewBase@H_502_1@)
BugBase @H_502_1@= import@H_502_1@("..models.BugBase"@H_502_1@)
BugAnt @H_502_1@= "..models.BugAnt"@H_502_1@)
BugSpider @H_502_1@= "..models.BugSpider"@H_502_1@)
BugSprite @H_502_1@= ".BugSprite"@H_502_1@)
DeadBugSprite @H_502_1@= ".DeadBugSprite"@H_502_1@)
GameView@H_502_1@.HOLE_POSITION @H_502_1@= p@H_502_1@(display@H_502_1@.cx @H_502_1@- 30@H_502_1@,43)">cy @H_502_1@- 75@H_502_1@)
INIT_LIVES @H_502_1@= 99999
@H_502_1@ADD_BUG_INTERVAL_MIN @H_502_1@= 1
@H_502_1@ADD_BUG_INTERVAL_MAX @H_502_1@= 3
@H_502_1@
@H_502_1@IMAGE_FILENAMES @H_502_1@= {}
IMAGE_FILENAMES@H_502_1@[BugBase@H_502_1@.BUG_TYPE_ANT@H_502_1@] = "BugAnt.png"
@H_502_1@BUG_TYPE_SPIDER@H_502_1@] = "BugSpider.png"
@H_502_1@
@H_502_1@BUG_ANIMATION_TIMES @H_502_1@= {}
BUG_ANIMATION_TIMES@H_502_1@[0.15
@H_502_1@0.1
@H_502_1@ZORDER_BUG @H_502_1@= 100
@H_502_1@ZORDER_DEAD_BUG @H_502_1@= 50
@H_502_1@events @H_502_1@= {
PLAYER_DEAD_EVENT @H_502_1@= "PLAYER_DEAD_EVENT"@H_502_1@,
}
function @H_502_1@GameView@H_502_1@:start@H_502_1@()
self@H_502_1@:scheduleUpdate@H_502_1@(handler@H_502_1@(self@H_502_1@,self@H_502_1@.step@H_502_1@))
return @H_502_1@self
@H_502_1@end
@H_502_1@
@H_502_1@stop@H_502_1@()
unscheduleUpdate@H_502_1@()
step@H_502_1@(dt@H_502_1@)
if @H_502_1@lives_ @H_502_1@<= 0 @H_502_1@then return end
@H_502_1@@H_502_1@addBugInterval_ @H_502_1@= addBugInterval_ @H_502_1@- dt
@H_502_1@@H_502_1@addBugInterval_ @H_502_1@<= then
@H_502_1@addBugInterval_ @H_502_1@= math@H_502_1@.random@H_502_1@(GameView@H_502_1@.ADD_BUG_INTERVAL_MIN@H_502_1@,GameView@H_502_1@.ADD_BUG_INTERVAL_MAX@H_502_1@)
addBug@H_502_1@()
for @H_502_1@_@H_502_1@,bug @H_502_1@in @H_502_1@pairs@H_502_1@(bugs_@H_502_1@) do
@H_502_1@@H_502_1@bug@H_502_1@:if @H_502_1@getModel@H_502_1@():getDist@H_502_1@() <= bugEnterHole@H_502_1@(bug@H_502_1@)
end
@H_502_1@ return @H_502_1@getLives@H_502_1@()
lives_
@H_502_1@getKills@H_502_1@()
kills_
@H_502_1@bugType @H_502_1@= BugBase@H_502_1@.BUG_TYPE_ANT
@H_502_1@@H_502_1@if @H_502_1@random@H_502_1@(1@H_502_1@,255)">2@H_502_1@) % 2 @H_502_1@== BUG_TYPE_SPIDER
@H_502_1@ local @H_502_1@bugModel
@H_502_1@@H_502_1@bugType @H_502_1@== BugBase@H_502_1@.BUG_TYPE_ANT @H_502_1@bugModel @H_502_1@= BugAnt@H_502_1@:create@H_502_1@()
else
@H_502_1@bugModel @H_502_1@= BugSpider@H_502_1@:bug @H_502_1@= BugSprite@H_502_1@:create@H_502_1@(GameView@H_502_1@.bugType@H_502_1@],153)">bugModel@H_502_1@)
:start@H_502_1@(GameView@H_502_1@.HOLE_POSITION@H_502_1@)
:addTo@H_502_1@(bugsNode_@H_502_1@,43)">ZORDER_BUG@H_502_1@)
bugs_@H_502_1@[bug@H_502_1@] = bug
@H_502_1@bugEnterHole@H_502_1@(bug@H_502_1@)
bugs_@H_502_1@[bug@H_502_1@] = nil
@H_502_1@
@H_502_1@@H_502_1@bug@H_502_1@:fadeOut@H_502_1@({time @H_502_1@= 0.5@H_502_1@,removeSelf @H_502_1@= true@H_502_1@})
:scaleTo@H_502_1@({scale @H_502_1@= 0.3@H_502_1@})
:rotateTo@H_502_1@({rotation @H_502_1@= 360@H_502_1@,255)">720@H_502_1@)})
lives_ @H_502_1@= lives_ @H_502_1@- @H_502_1@livesLabel_@H_502_1@:setString@H_502_1@(lives_@H_502_1@)
audio@H_502_1@.playSound@H_502_1@("BugEnterHole.wav"@H_502_1@)
dispatchEvent@H_502_1@({name @H_502_1@= GameView@H_502_1@.events@H_502_1@.PLAYER_DEAD_EVENT@H_502_1@})
bugDead@H_502_1@(bug@H_502_1@)
imageFilename @H_502_1@= GameView@H_502_1@.IMAGE_FILENAMES@H_502_1@[getType@H_502_1@()]
DeadBugSprite@H_502_1@:create@H_502_1@(imageFilename@H_502_1@)
:2.0@H_502_1@,43)">delay @H_502_1@= move@H_502_1@(getPosition@H_502_1@())
:rotate@H_502_1@(getRotation@H_502_1@() + 120@H_502_1@)
:ZORDER_DEAD_BUG@H_502_1@)
removeSelf@H_502_1@()
kills_ @H_502_1@= kills_ @H_502_1@+ @H_502_1@"BugDead.wav"@H_502_1@)
onCreate@H_502_1@()
lives_ @H_502_1@= GameView@H_502_1@.INIT_LIVES
@H_502_1@@H_502_1@kills_ @H_502_1@= 0
@H_502_1@bugs_ @H_502_1@= {}
addBugInterval_ @H_502_1@= -- add touch layer
@H_502_1@@H_502_1@newLayer@H_502_1@()
:onTouch@H_502_1@(onTouch@H_502_1@))
:self@H_502_1@)
-- add background image
@H_502_1@newSprite@H_502_1@("PlaySceneBg.jpg"@H_502_1@)
:move@H_502_1@(center@H_502_1@)
:-- add bugs node
@H_502_1@@H_502_1@bugsNode_ @H_502_1@= newNode@H_502_1@():-- add lives icon and label
@H_502_1@"Star.png"@H_502_1@)
:left @H_502_1@+ 50@H_502_1@,43)">top @H_502_1@- 50@H_502_1@)
:self@H_502_1@)
livesLabel_ @H_502_1@= Label@H_502_1@:createWithSystemFont@H_502_1@(lives_@H_502_1@,0)">"Arial"@H_502_1@,255)">32@H_502_1@)
:90@H_502_1@,128)">-- create animation for bugs
@H_502_1@@H_502_1@for @H_502_1@bugType@H_502_1@,153)">filename @H_502_1@pairs@H_502_1@(GameView@H_502_1@.IMAGE_FILENAMES@H_502_1@) @H_502_1@-- load image
@H_502_1@texture @H_502_1@= loadImage@H_502_1@(filename@H_502_1@)
frameWidth @H_