| OLD | NEW |
| 1 -- Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 -- Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 -- Use of this source code is governed by a BSD-style license that can be | 2 -- Use of this source code is governed by a BSD-style license that can be |
| 3 -- found in the LICENSE file. | 3 -- found in the LICENSE file. |
| 4 | 4 |
| 5 -- Main entry points of the lua game engine. | 5 -- Main entry points of the lua game engine. |
| 6 -- Currently this file exposed 3 functions to the C++ code during | 6 -- Currently this file exposed 3 functions to the C++ code during |
| 7 -- startup: | 7 -- startup: |
| 8 -- - LoadGame (called my game_manager to load game.def) | 8 -- - LoadGame (called my game_manager to load game.def) |
| 9 -- - LoadLevel (called by level_layer to load a level) | 9 -- - LoadLevel (called by level_layer to load a level) |
| 10 -- | 10 -- |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 end | 162 end |
| 163 | 163 |
| 164 -- Load background image | 164 -- Load background image |
| 165 if game_obj.assets.background_image then | 165 if game_obj.assets.background_image then |
| 166 local winsize = CCDirector:sharedDirector():getWinSize() | 166 local winsize = CCDirector:sharedDirector():getWinSize() |
| 167 local sprite = CCSprite:create(game_obj.assets.background_image) | 167 local sprite = CCSprite:create(game_obj.assets.background_image) |
| 168 sprite:setPosition(ccp(winsize.width/2, winsize.height/2)) | 168 sprite:setPosition(ccp(winsize.width/2, winsize.height/2)) |
| 169 layer:addChild(sprite) | 169 layer:addChild(sprite) |
| 170 end | 170 end |
| 171 | 171 |
| 172 -- Load sprites | |
| 173 for _, sprite_def in ipairs(level_obj.sprites) do | |
| 174 RegisterObjectDef(sprite_def) | |
| 175 sprite_def.node = drawing.CreateSprite(sprite_def) | |
| 176 layer:addChild(sprite_def.node, 1, sprite_def.tag) | |
| 177 LoadScript(sprite_def) | |
| 178 end | |
| 179 | |
| 180 -- Load shapes | 172 -- Load shapes |
| 181 if level_obj.shapes then | 173 local function LoadShapes(shapes) |
| 182 for _, shape_def in ipairs(level_obj.shapes) do | 174 for _, shape_def in ipairs(shapes) do |
| 183 RegisterObjectDef(shape_def) | 175 if #shape_def > 0 then |
| 184 shape_def.node = drawing.CreateShape(shape_def) | 176 LoadShapes(shape_def) |
| 185 LoadScript(shape_def) | 177 else |
| 178 RegisterObjectDef(shape_def) |
| 179 shape_def.node = drawing.CreateShape(shape_def) |
| 180 LoadScript(shape_def) |
| 181 end |
| 186 end | 182 end |
| 187 end | 183 end |
| 188 | 184 |
| 185 if level_obj.shapes then |
| 186 LoadShapes(level_obj.shapes) |
| 187 end |
| 188 |
| 189 -- Load custom level script | 189 -- Load custom level script |
| 190 level_obj.node = level_obj.layer | 190 level_obj.node = level_obj.layer |
| 191 LoadScript(level_obj) | 191 LoadScript(level_obj) |
| 192 | 192 |
| 193 if game_obj.script.Update then | 193 if game_obj.script.Update then |
| 194 level_obj.layer:scheduleUpdateWithPriorityLua(GameUpdate, 0) | 194 level_obj.layer:scheduleUpdateWithPriorityLua(GameUpdate, 0) |
| 195 end | 195 end |
| 196 | 196 |
| 197 layer:registerScriptTouchHandler(touch_handler.TouchHandler) | 197 layer:registerScriptTouchHandler(touch_handler.TouchHandler) |
| 198 StartLevel(level_number) | 198 StartLevel(level_number) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 CallCollisionHandler(tag1, tag2, 'OnContactEnded') | 255 CallCollisionHandler(tag1, tag2, 'OnContactEnded') |
| 256 end | 256 end |
| 257 | 257 |
| 258 function StartLevel(level_number) | 258 function StartLevel(level_number) |
| 259 -- only call handlers if the objects in question have tags | 259 -- only call handlers if the objects in question have tags |
| 260 -- that are known to the currently running level | 260 -- that are known to the currently running level |
| 261 if game_obj.script.StartLevel then | 261 if game_obj.script.StartLevel then |
| 262 game_obj.script.StartLevel(level_number) | 262 game_obj.script.StartLevel(level_number) |
| 263 end | 263 end |
| 264 end | 264 end |
| OLD | NEW |