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 -- Example/default game logic. This code displays the level selection | 5 -- Example/default game logic. This code displays the level selection |
6 -- menu and triggers the loading of individual levels. | 6 -- menu and triggers the loading of individual levels. |
7 | 7 |
8 | 8 |
9 local util = require 'util' | 9 local util = require 'util' |
10 local gui = require 'gui' | 10 local gui = require 'gui' |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 local menu = CCMenu:create() | 45 local menu = CCMenu:create() |
46 | 46 |
47 local icon = CCSprite:create(game_obj.assets.level_icon) | 47 local icon = CCSprite:create(game_obj.assets.level_icon) |
48 local icon_size = icon:getContentSize() | 48 local icon_size = icon:getContentSize() |
49 local label_pos = CCPointMake(icon_size.width/2, icon_size.height/2) | 49 local label_pos = CCPointMake(icon_size.width/2, icon_size.height/2) |
50 | 50 |
51 local function LevelSelected(tag) | 51 local function LevelSelected(tag) |
52 local level_number = tag | 52 local level_number = tag |
53 util.Log('LevelSelected: ' .. level_number) | 53 util.Log('LevelSelected: ' .. level_number) |
54 GameManager:sharedManager():LoadLevel(level_number) | 54 GameManager:sharedManager():LoadLevel(level_number) |
55 print(game_obj.game_mode) | |
56 end | 55 end |
57 | 56 |
58 -- For each level create a menu item and a textual label | 57 -- For each level create a menu item and a textual label |
59 for i=1,#game_obj.levels do | 58 for i=1,#game_obj.levels do |
60 local label_string = string.format("%d", i) | 59 local label_string = string.format("%d", i) |
61 local item = CCMenuItemImage:create(game_obj.assets.level_icon, | 60 local item = CCMenuItemImage:create(game_obj.assets.level_icon, |
62 game_obj.assets.level_icon_selected) | 61 game_obj.assets.level_icon_selected) |
63 menu:addChild(item) | 62 menu:addChild(item) |
64 item:setTag(i) | 63 item:setTag(i) |
65 item:registerScriptTapHandler(LevelSelected) | 64 item:registerScriptTapHandler(LevelSelected) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 }, | 125 }, |
127 }, | 126 }, |
128 } | 127 } |
129 local menu = gui.CreateMenu(menu_def) | 128 local menu = gui.CreateMenu(menu_def) |
130 layer:addChild(menu) | 129 layer:addChild(menu) |
131 | 130 |
132 director:runWithScene(scene) | 131 director:runWithScene(scene) |
133 end | 132 end |
134 | 133 |
135 return handlers | 134 return handlers |
OLD | NEW |