├── .gitignore ├── Classes ├── AppDelegate.js ├── Auxiliary │ ├── Array.js │ └── Utils.js ├── Config │ ├── Global.js │ ├── Location.js │ └── Themes.js ├── Controllers │ ├── BackgroundController.js │ ├── EnvironmentsController.js │ ├── LevelController.js │ ├── PropertiesController.js │ ├── TrophiesActionsController.js │ └── TrophiesController.js ├── Information │ ├── BackgroundInformation │ │ ├── BackgroundInformation.js │ │ └── Backgrounds.js │ ├── Environments │ │ ├── Cloud.js │ │ ├── Footprints.js │ │ ├── JumpShadow.js │ │ └── LightCircle.js │ ├── PropertiesInformation │ │ ├── Double.js │ │ ├── Hp.js │ │ ├── Magnet.js │ │ ├── PropertiesInformation.js │ │ └── Triple.js │ ├── TilesInformation │ │ ├── BasicTile.js │ │ ├── GenerateTrophies.js │ │ ├── IsBounded.js │ │ ├── IsValid.js │ │ ├── TileInformation.js │ │ └── Tiles.js │ ├── TrackInformation.js │ └── TrophiesInformation │ │ ├── Coin.js │ │ └── TrophiesInformation.js ├── Models │ ├── Background.js │ ├── BackgroundTile.js │ ├── Character.js │ ├── Property.js │ ├── Tile.js │ ├── Track.js │ ├── Trophies.js │ └── Trophy.js ├── Panels │ ├── PauseLayer.js │ ├── ScoreItem.js │ └── ScoreLayer.js └── Scenes │ ├── About.js │ ├── GameOver.js │ └── MainMenu.js ├── README.md ├── Resource.js ├── Resources ├── JumpPrints │ ├── Thumbs.db │ ├── inner_red.png │ ├── inner_white.png │ ├── inner_yellow.png │ ├── outer_purple.png │ └── outer_white.png ├── Thumbs.db ├── about_page.png ├── background_1.png ├── background_2.png ├── bean.png ├── beans.png ├── beans_blue.png ├── beans_red.png ├── cloud_1.png ├── cloud_2.png ├── cloud_3.png ├── cloud_4.png ├── distance.png ├── double.png ├── double_bg.png ├── footprint_1.png ├── footprint_2.png ├── footprint_3.png ├── footprint_4.png ├── footprint_5.png ├── game-over.png ├── gameover-bg.jpg ├── hp.png ├── hp_down.png ├── hp_up.png ├── invalid.png ├── light_point1.png ├── light_point2.png ├── light_point3.png ├── light_point4.png ├── magnet.png ├── menu.png ├── menubg.jpg ├── no_hp.png ├── numbers.png ├── pause.png ├── runner1.png ├── runner2.png ├── runner3.png ├── score.png ├── shadow.png ├── tile_1.jpg ├── tile_10.jpg ├── tile_11.jpg ├── tile_12.png ├── tile_2.jpg ├── tile_3.jpg ├── tile_4.jpg ├── tile_5.jpg ├── tile_6.jpg ├── tile_7.jpg ├── tile_8.jpg ├── tile_9.jpg ├── title.png ├── triple.png ├── triple_bg.png └── trophies.png ├── TODO.md ├── cocos2d-html5-canvasmenu-min.js ├── cocos2d.js ├── index.html └── test └── testPic.js /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | -------------------------------------------------------------------------------- /Classes/AppDelegate.js: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | Copyright (c) 2010-2012 cocos2d-x.org 3 | Copyright (c) 2008-2010 Ricardo Quesada 4 | Copyright (c) 2011 Zynga Inc. 5 | 6 | http://www.cocos2d-x.org 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | ****************************************************************************/ 26 | 27 | var cc = cc = cc || {}; 28 | 29 | /** 30 | @brief The cocos2d Application. 31 | 32 | The reason for implement as private inheritance is to hide some interface call by CCDirector. 33 | */ 34 | cc.AppDelegate = cc.Application.extend({ 35 | ctor:function () { 36 | this._super(); 37 | }, 38 | /** 39 | @brief Implement for initialize OpenGL instance, set source path, etc... 40 | */ 41 | initInstance:function () { 42 | return true; 43 | }, 44 | 45 | /** 46 | @brief Implement CCDirector and CCScene init code here. 47 | @return true Initialize success, app continue. 48 | @return false Initialize failed, app terminate. 49 | */ 50 | applicationDidFinishLaunching:function () { 51 | // initialize director 52 | var pDirector = cc.Director.sharedDirector(); 53 | 54 | // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices. 55 | // pDirector->enableRetinaDisplay(true); 56 | 57 | // turn on display FPS 58 | pDirector.setDisplayFPS(true); 59 | 60 | // pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); 61 | 62 | // set FPS. the default value is 1.0/60 if you don't call this 63 | pDirector.setAnimationInterval(1.0 / 60); 64 | 65 | // create a scene. it's an autorelease object 66 | var pScene = MainMenu.scene(); 67 | //var pScene = GameLayer.scene(); 68 | 69 | // run 70 | pDirector.runWithScene(pScene); 71 | return true; 72 | }, 73 | 74 | /** 75 | @brief The function be called when the application enter background 76 | @param the pointer of the application 77 | */ 78 | applicationDidEnterBackground:function () { 79 | cc.Director.sharedDirector().pause(); 80 | }, 81 | 82 | /** 83 | @brief The function be called when the application enter foreground 84 | @param the pointer of the application 85 | */ 86 | applicationWillEnterForeground:function () { 87 | cc.Director.sharedDirector().resume(); 88 | } 89 | }); -------------------------------------------------------------------------------- /Classes/Auxiliary/Array.js: -------------------------------------------------------------------------------- 1 | //return the element is n array or not 2 | Array.prototype.isContain = function(e) { 3 | 4 | return this.indexOf(e) != -1; 5 | 6 | } 7 | 8 | Array.prototype.copy = function() { 9 | 10 | var rst = []; 11 | for (var i = 0; i < this.length; ++i) 12 | rst.push(this[i]); 13 | 14 | return rst; 15 | 16 | } 17 | 18 | Array.prototype.exclude = function(e) { 19 | 20 | var rst = []; 21 | for (var i = 0; i < this.length; ++i) { 22 | if (e != this[i]) 23 | rst.push(this[i]); 24 | } 25 | 26 | return rst; 27 | 28 | } 29 | 30 | Array.prototype.randomPick = function() { 31 | 32 | var index = Math.floor(Math.random() * this.length); 33 | return this[index]; 34 | 35 | } 36 | 37 | Array.prototype.deleteElementByIndex = function(e) { 38 | 39 | var end = this.length - 1; 40 | var temp = this[e]; 41 | this[e] = this[end]; 42 | this[end] = temp; 43 | this.pop(); 44 | 45 | return this; 46 | 47 | } 48 | 49 | Array.prototype.pushArray = function(arr) { 50 | 51 | for (var i = 0; i < arr.length; ++i) 52 | this.push(arr[i]); 53 | 54 | } -------------------------------------------------------------------------------- /Classes/Auxiliary/Utils.js: -------------------------------------------------------------------------------- 1 | 2 | var Utils = Utils || {} 3 | 4 | /** 5 | * Util.Range defines a convenient data structure for describe 6 | * an interval which is consisted of two bounds, say the begin 7 | * and the end. It has the following form: 8 | * 9 | * [ begin, end ] 10 | * 11 | */ 12 | Utils.Range = function(begin, end) { 13 | 14 | this.begin = begin; 15 | this.end = end; 16 | 17 | } 18 | 19 | Utils.Range.prototype = { 20 | 21 | // Determines whether the given position is in the range or not. 22 | isContain: function(pos) { 23 | 24 | return pos >= this.begin && pos <= this.end; 25 | 26 | }, 27 | 28 | // Scale the range. 29 | scale: function(s) { 30 | 31 | this.begin *= s; 32 | this.end *= s; 33 | 34 | return this; 35 | 36 | }, 37 | 38 | // Decide whether the distance is larger than the magnitude of the 39 | // range or not. 40 | gt: function(distance) { 41 | 42 | return distance < this.magnitude(); 43 | 44 | }, 45 | 46 | // Decide whether the distance is shorter than the magnitude of the 47 | // range or not. 48 | lt: function(distance) { 49 | 50 | return distance > this.magnitude(); 51 | 52 | }, 53 | 54 | // Calculate the magnitude of the range. 55 | magnitude: function() { 56 | 57 | return this.end - this.begin; 58 | 59 | }, 60 | 61 | } 62 | 63 | /** 64 | * Utils.Ranges defines a set of ranges. Though we can simple use an 65 | * array to store the ranges, we still find it convenient to wrap it 66 | * in this way. It has the following structure: 67 | * 68 | * [ 69 | * Range1(begin, end), 70 | * Range2(begin, end), 71 | * : 72 | * : 73 | * : 74 | * RangeN(begin, end) 75 | * ] 76 | */ 77 | Utils.Ranges = function(ranges) { 78 | 79 | this.ranges = this.init(ranges); 80 | 81 | } 82 | 83 | Utils.Ranges.prototype = { 84 | 85 | /** 86 | * Here the cumulative array is used. For example: 87 | * 88 | * [ 40, 30, 20, 10 ] 89 | * 90 | * becomes: 91 | * 92 | * [ 0, 40, 70, 90, 100 ] 93 | */ 94 | init: function(ranges) { 95 | 96 | var acc = ranges[0]; 97 | var rs = [new Utils.Range(0, acc)]; 98 | 99 | for (var i = 0; i < ranges.length - 1; ++i) { 100 | 101 | rs.push(new Utils.Range(acc, acc + ranges[i + 1])); 102 | acc += ranges[i + 1]; 103 | 104 | } 105 | 106 | return rs; 107 | 108 | }, 109 | 110 | // Returns the index of the range which contains the given position. 111 | // Otherwise, returns -1 instead. 112 | locateIndex: function(pos) { 113 | 114 | for (var i = 0; i < this.ranges.length; ++i) { 115 | if (this.ranges[i].isContain(pos)) 116 | return i; 117 | } 118 | 119 | return -1; 120 | 121 | }, 122 | 123 | } 124 | 125 | Utils.Random = { 126 | 127 | range: function(begin, end) { 128 | 129 | return begin + Math.random() * (end - begin); 130 | 131 | }, 132 | 133 | rangeInteger: function(begin, end) { 134 | 135 | return Math.floor(begin + Math.random() * (end - begin)); 136 | 137 | }, 138 | 139 | } 140 | 141 | Utils.copy = function(obj) { 142 | 143 | var newObj = {} 144 | 145 | for (attr in obj) { 146 | newObj[attr] = obj[attr]; 147 | } 148 | 149 | return newObj; 150 | 151 | } 152 | 153 | Utils.sum = function(arr) { 154 | 155 | var s = 0; 156 | for (var i = 0; i < arr.length; ++i) 157 | s += arr[i]; 158 | 159 | return s; 160 | 161 | } 162 | 163 | Utils.Rect = function(bufferX, bufferY) { 164 | 165 | this.rangeX = new Utils.Range(-bufferX, bufferX); 166 | this.rangeY = new Utils.Range(-bufferY, bufferY); 167 | 168 | } 169 | 170 | Utils.Rect.prototype = { 171 | 172 | isContain: function(x, y) { 173 | 174 | return this.rangeX.isContain(x) && this.rangeY.isContain(y); 175 | 176 | }, 177 | 178 | } 179 | -------------------------------------------------------------------------------- /Classes/Config/Global.js: -------------------------------------------------------------------------------- 1 | var KEYS = []; 2 | 3 | var TILE_BACKGROUND = { 4 | 5 | SIZE: 1440, 6 | 7 | } 8 | 9 | var TRACK = { 10 | 11 | WIDTH : TILE_BACKGROUND.SIZE / 6, 12 | LEFT_COORDINATE : WIN_SIZE.width / 2 - TILE_BACKGROUND.SIZE / 9, 13 | RIGHT_COORDINATE : WIN_SIZE.width / 2 + TILE_BACKGROUND.SIZE / 9, 14 | 15 | }; 16 | 17 | var ROUTE = { 18 | 19 | LEFT : 1, 20 | MIDDLE : 2, 21 | RIGHT : 3, 22 | WIDTH : TRACK.WIDTH / 3, 23 | 24 | }; 25 | 26 | 27 | /** 28 | * _____________________________ 29 | * /\ | 30 | * |<----------------------- 31 | * TRACK.WIDTH | TILE.TURN_BUFFER | 32 | * | | | 33 | * ___\/______________ |<------- CHARACTER_TURN_BUFFER 34 | * | | | 35 | * | | | 36 | * | | | 37 | * | |<----------------------- 38 | * | | 39 | * | | 40 | */ 41 | var TILE = { 42 | 43 | SIZE: TILE_BACKGROUND.SIZE, 44 | VELOCITY: 600, 45 | LOAD_BUFFER: 60, //TILE_BACKGROUND.SIZE / 15, 46 | LOAD_DURATION: 10, 47 | TURN_BUFFER: new Utils.Range(-TRACK.WIDTH / 2, TRACK.WIDTH / 3), 48 | 49 | ANCHORPOINT: { 50 | X: 0.5, 51 | Y: 0.5, 52 | } 53 | 54 | }; 55 | 56 | var CHARACTER = { 57 | 58 | TAG: 0, 59 | MOVE_VELOCITY: 300, 60 | JUMP_DISTANCE: 600, 61 | SPEED: 60, 62 | LAND_BUFFER: 30, 63 | HP_INCREASE_DURATION: 5, 64 | MAX_HP: 2, 65 | TURN_BUFFER: new Utils.Range(-TRACK.WIDTH, TRACK.WIDTH / 3), 66 | 67 | SPRITE_WIDTH: 75, 68 | SPRITE_HEIGHT: 113, 69 | 70 | STATUS: { 71 | RUNNING: 'RUNNING', 72 | ABOUT_TO_JUMP: 'ABOUT_TO_JUMP', 73 | JUMPING: 'JUMPING', 74 | }, 75 | 76 | }; 77 | 78 | 79 | var ACTION = { 80 | 81 | BOTH_DIRECTION : 'ACTION_BOTH_DIRECTION', 82 | GO_STRAIGHT : 'ACTION_GO_STRAIGHT', 83 | MOVE_LEFT : 'ACTION_MOVE_LEFT', 84 | MOVE_RIGHT : 'ACTION_MOVE_RIGHT', 85 | TURN_LEFT : 'ACTION_TURN_LEFT', 86 | TURN_RIGHT : 'ACTION_TURN_RIGHT', 87 | 88 | }; 89 | 90 | var PROPERTY = { 91 | 92 | TAG_OFFSET: 5000, 93 | GENERATE_DURATION: 2, 94 | 95 | TYPE: { 96 | 97 | DOUBLE: 'PROPERTY_DOUBLE', 98 | TRIPLE: 'PROPERTY_TRIPLE', 99 | MAGNET: 'PROPERTY_MAGNET', 100 | HP : 'PROPERTY_HP', 101 | 102 | }, 103 | 104 | POOL: { 105 | 106 | PROPERTY_OCCURENCE_RATES: [20, 20, 30, 30], 107 | PROPERTY_OCCURENCE_RATES_SUM: 100, 108 | PROPERTIES_TYPE: ['PROPERTY_TRIPLE', 109 | 'PROPERTY_HP', 110 | 'PROPERTY_DOUBLE', 111 | 'PROPERTY_MAGNET', 112 | ], 113 | 114 | }, 115 | 116 | ANCHORPOINT: { 117 | X: 0.5, 118 | Y: 0.5, 119 | } 120 | 121 | }; 122 | 123 | var TROPHY = { 124 | 125 | TAG_OFFSET: 10000, 126 | 127 | ABSORB_VELOCITY: 15, 128 | SCALE: 4, 129 | SCALE_TIME: 0.2, 130 | FADEOUT_TIME: 0.8, 131 | 132 | REMOVE_BUFFERX: 20, 133 | REMOVE_BUFFERY: 50, 134 | 135 | GET_BUFFERX: 0, 136 | GET_BUFFERY: 60, 137 | 138 | SPRITE_WIDTH: 50, 139 | SPRITE_HEIGHT: 50, 140 | 141 | TYPE: { 142 | 143 | COIN: 'TROPHY_COIN', 144 | 145 | }, 146 | 147 | }; 148 | 149 | var TROPHIES = { 150 | 151 | ANCHORPOINT: { 152 | X: 0.5, 153 | Y: 0.5, 154 | }, 155 | 156 | ROTATE_TIME: 0.1, 157 | ROTATE_ANGLE: 90, 158 | 159 | }; 160 | 161 | var BACKGROUND = { 162 | 163 | TAG: 15000, 164 | VELOCITY: 100, 165 | 166 | }; 167 | 168 | var BOUND = { 169 | 170 | SOLID: 'BOUND_SOLID', 171 | FRAGILE: 'BOUND_FRAGILE', 172 | 173 | }; 174 | 175 | var TYPE = { 176 | 177 | TRACK: 'TRACK_TYPE', 178 | CHARACTER: 'CHARACTER_TYPE', 179 | TROPHY: 'TROPHY_TYPE', 180 | 181 | }; 182 | 183 | var Z_ORDER = { 184 | 185 | BACKGROUND: 0, 186 | TILE: 1, 187 | TROPHIES: 2, 188 | PROPERTY: 2, 189 | ENVIRONMENT: 3, 190 | CHARACTER: 4, 191 | 192 | TROPHY: 5, 193 | 194 | SCORE_LAYER: 100, 195 | PAUSE_BUTTON: 200, 196 | 197 | }; 198 | 199 | var GAMEOVER = { 200 | 201 | TYPE: { 202 | CROSS_BORDER: 'CROSS_BORDER', 203 | NO_HP : 'NO_HP', 204 | }, 205 | 206 | }; 207 | 208 | var MAX_TROPHY_NUM = 20; 209 | var MAX_SCORE_DIGITS_NUM = 5; 210 | var NUMBER_SPRITE_WIDTH = 24; 211 | var NUMBER_SPRITE_HEIGHT = 40; 212 | 213 | 214 | /* use for test*/ 215 | var PAUSE_BUTTON_BUFFER = 32; 216 | 217 | var RESET = function() { 218 | 219 | EnvironmentsController.reset(); 220 | LevelController.reset(); 221 | PropertiesController.reset(); 222 | TrophiesController.reset(); 223 | TrophiesActionsController.reset(); 224 | 225 | }; 226 | -------------------------------------------------------------------------------- /Classes/Config/Location.js: -------------------------------------------------------------------------------- 1 | var LOCATION = { 2 | 3 | GAME_LAYER: { 4 | 5 | TROPHIES: { 6 | X: WIN_SIZE.width * 13 / 28, 7 | Y: WIN_SIZE.height * 670 / 720, 8 | }, 9 | 10 | DISTANCE: { 11 | X: WIN_SIZE.width * 13 / 28 - 6, 12 | Y: WIN_SIZE.height * 625 / 720, 13 | }, 14 | 15 | }, 16 | 17 | GAMEOVER_LAYER: { 18 | 19 | TROPHIES: { 20 | X: WIN_SIZE.width / 2 * 122 / 240, 21 | Y: WIN_SIZE.height / 2 - 20, 22 | }, 23 | 24 | DISTANCE: { 25 | X: WIN_SIZE.width / 2 * 113 / 240, 26 | Y: WIN_SIZE.height / 2 - 60, 27 | }, 28 | 29 | SCORE: { 30 | X: WIN_SIZE.width / 2 * 183 / 240, 31 | Y: WIN_SIZE.height / 2 - 100, 32 | }, 33 | 34 | }, 35 | 36 | PAUSE: { 37 | 38 | BUTTON: { 39 | X: WIN_SIZE.width * 9 / 10, 40 | Y: 30, 41 | }, 42 | 43 | LAYER: { 44 | X: WIN_SIZE.width / 2, 45 | Y: WIN_SIZE.height / 2, 46 | }, 47 | 48 | }, 49 | 50 | TILE: { 51 | 52 | FIRST: { 53 | X: WIN_SIZE.width / 2, 54 | Y: WIN_SIZE.height, 55 | }, 56 | 57 | NOTFIRST: { 58 | X: WIN_SIZE.width / 2, 59 | Y: WIN_SIZE.height + TILE.SIZE / 2, 60 | }, 61 | 62 | }, 63 | 64 | TROPHIES: { 65 | 66 | INIT: { 67 | X: -WIN_SIZE.width / 2, 68 | Y: 0, 69 | }, 70 | 71 | MOVETO: { 72 | X: 0, 73 | Y: -TILE.SIZE, 74 | }, 75 | 76 | }, 77 | 78 | }; 79 | 80 | -------------------------------------------------------------------------------- /Classes/Config/Themes.js: -------------------------------------------------------------------------------- 1 | var THEMES = { 2 | 3 | validate: function(currentTheme, tileIndex) { 4 | 5 | var isChanged = true; 6 | var nextTheme = currentTheme; 7 | 8 | if (tileIndex == 7) 9 | nextTheme = this.THEME_2; 10 | else if (tileIndex == 10) 11 | nextTheme = this.THEME_1; 12 | // else if (tileIndex == 12) 13 | // nextTheme = this.THEME_1; 14 | else 15 | isChanged = false; 16 | 17 | return { 18 | isChanged: isChanged, 19 | nextTheme: nextTheme, 20 | }; 21 | 22 | }, 23 | 24 | getThemeByTileIndex: function(index) { 25 | 26 | if ((1 <= index && index <= 6) || index == 10) 27 | return this.THEME_1; 28 | if ((7 <= index && index <= 9) || index == 11) 29 | return this.THEME_2; 30 | if (index <= 12 && index <= 12) 31 | return this.THEME_3; 32 | 33 | }, 34 | 35 | THEME_1: { 36 | 37 | NAME: 'TRANQUIL FOREST', 38 | TILE_OCCURENCE_RATES: [40, 30, 20, 10], 39 | TILE_OCCURENCE_RATES_SUM: 100, 40 | LEVEL_FUNCTION: new Utils.Ranges([5, 10, 15, 20, 25]), 41 | TILE_POOL: [ 42 | [1, 7], 43 | [4], 44 | [2, 3], 45 | [5, 6], 46 | ], 47 | 48 | }, 49 | 50 | THEME_2: { 51 | 52 | NAME: 'MISTERIOUS BUSH', 53 | TILE_OCCURENCE_RATES: [20, 40, 40], 54 | TILE_OCCURENCE_RATES_SUM: 100, 55 | LEVEL_FUNCTION: new Utils.Ranges([5, 10, 15, 20, 25]), 56 | TILE_POOL: [ 57 | [10], 58 | [8, 9], 59 | [11], 60 | ], 61 | 62 | }, 63 | 64 | THEME_3: { 65 | 66 | NAME: 'TEST THEME', 67 | TILE_OCCURENCE_RATES: [100], 68 | TILE_OCCURENCE_RATES_SUM: 100, 69 | LEVEL_FUNCTION: new Utils.Ranges([5, 10, 15, 20, 25]), 70 | TILE_POOL: [ 71 | [12], 72 | ], 73 | BACKGROUND_POOL: [ 74 | [2], 75 | [1], 76 | ] 77 | 78 | }, 79 | 80 | } 81 | -------------------------------------------------------------------------------- /Classes/Controllers/BackgroundController.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * BackgroundController.js is used to controller the moving backgrounds 4 | * behind the tiles. Although this is not the general version of layer 5 | * controller, it is made for manipulating many backgrounds which move 6 | * with different velocities. 7 | * 8 | * Background controller selects background according to the current theme. 9 | * Each theme has a set of default backgrounds. The whole background 10 | * mechanism can be described as follows: 11 | * 12 | * (1) The background controller gets the current theme. 13 | * (2) The background controller generates the backgrounds according to the 14 | * current theme. 15 | * (3) The backgrounds move. 16 | * (4) When the current theme changes, background stops the moving backgrounds. 17 | */ 18 | 19 | var BackgroundController = { 20 | 21 | /** 22 | * Actually, backgrounds does not mean there are so many backgrounds. Its 23 | * actual meaning is that the background has so many layers. Each element 24 | * in the array is a layer of the current background. 25 | */ 26 | backgrounds: [], 27 | previousTheme: THEMES.THEME_1, 28 | 29 | /** 30 | * When the theme changes, first detect whether it has background or not. 31 | * if it has background, then call the initBackgrounds to initialize the 32 | * multi-layer background object. 33 | */ 34 | changeBackgrounds: function(theme, track) { 35 | 36 | if (this.previousTheme.NAME != theme.NAME) { 37 | 38 | if (theme.hasOwnProperty('BACKGROUND_POOL')) 39 | this.addBackgrounds(theme.BACKGROUND_POOL, track); 40 | else 41 | this.removeBackgrounds(track); 42 | 43 | this.previousTheme = theme; 44 | 45 | } 46 | 47 | }, 48 | 49 | addBackgrounds: function(backgroundPool, track) { 50 | 51 | for (var i = 0; i < backgroundPool.length; ++i) { 52 | var bg = new Background(backgroundPool[i]); 53 | this.backgrounds.push(bg); 54 | 55 | track.addChild(bg, Z_ORDER.BACKGROUND); 56 | } 57 | 58 | }, 59 | 60 | removeBackgrounds: function(track) { 61 | 62 | for (var i = 0; i < this.backgrounds.length; ++i) 63 | track.removeChild(this.backgrounds[i]); 64 | 65 | this.backgrounds = []; 66 | 67 | }, 68 | 69 | reset: function() { 70 | 71 | this.backgrounds = []; 72 | 73 | }, 74 | 75 | }; 76 | -------------------------------------------------------------------------------- /Classes/Controllers/EnvironmentsController.js: -------------------------------------------------------------------------------- 1 | 2 | var EnvironmentsController = { 3 | 4 | environments: [], 5 | 6 | addTo: function(environment, track) { 7 | 8 | track.addChild(environment, Z_ORDER.ENVIRONMENT); 9 | this.environments.push(environment); 10 | 11 | }, 12 | 13 | evolve: function(character, flag) { 14 | 15 | for (var i = 0; i < this.environments.length; ++i) 16 | this.environments[i].evolve(character, flag); 17 | 18 | }, 19 | 20 | reset: function() { 21 | 22 | this.environments = []; 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Classes/Controllers/LevelController.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Level Controller has two main responsibilities: 4 | * 5 | * (1) Enhances the velocity with the time passes. 6 | * (2) Generates the tiles sequence with different levels 7 | * according to current tile index. 8 | * 9 | * 10 | * Generating the tile sequence. 11 | * 12 | * The goal of generating the tile sequence is to generate a sequence 13 | * of tile index according to the tile occurence rates. Some of the 14 | * terms are explained as follow: 15 | * 16 | * # TILE_OCCURENCE_RATES 17 | * 18 | * It shows how frequently the tiles appear. 19 | * For example, [40, 30, 20, 10] means that tile1 has the 40% 20 | * chances to appear while tile2 has the opportunity of 30% and 21 | * so on. 22 | * 23 | * # TILE_POOL 24 | * 25 | * Tile pool organizes all of the tiles in a level-cluster way. 26 | * For example, the tils with the same level are put in the same 27 | * bucket. Hence, the pool is in the following way: 28 | * 29 | * [ 30 | * [ 1 ], 31 | * [ 4 ], 32 | * [ 2, 3 ], 33 | * [ 5, 6 ], 34 | * ] 35 | * 36 | * # Rates Variation 37 | * 38 | * Since with the game goes on, the difficulty of the game enhances. 39 | * One of the reflections of the difficulty is that the occurence 40 | * frequency of the harder tile increases, which means that the tiles' 41 | * occurences rates may vary. So the following algorithm defines how 42 | * the rates vary. 43 | * 44 | * iter1: [ 40, 30, 20, 10 ] 45 | * iter2: [ 39, 29, 19, 13 ] 46 | * iter3: [ 38, 28, 18, 16 ], [ 37, 27, 20, 16 ] 47 | * iter4: [ 36, 26, 19, 19 ], [ 35, 25, 21, 19 ], [ 34, 26, 21, 19 ] 48 | * 49 | * The procedure is describe as follows: 50 | * 51 | * (1) Get iteration time according to the currentTileIndex. 52 | * (2) Update tile occurence rate. 53 | * (3) Generate tile according to the occurence rates. 54 | * 55 | */ 56 | var LevelController = { 57 | 58 | velocity : TILE.VELOCITY, 59 | trophyVelocity: TROPHY.ABSORB_VELOCITY, 60 | characterSpeed: CHARACTER.SPEED, 61 | 62 | levels : 4, 63 | iteration : 0, 64 | theme : THEMES.THEME_1, 65 | rates : THEMES.THEME_1.TILE_OCCURENCE_RATES.copy(), 66 | 67 | updateVelocity: function() { 68 | 69 | this.velocity += 1; 70 | this.trophyVelocity += 0.05; 71 | this.characterSpeed += 0.005; 72 | 73 | }, 74 | 75 | reset: function() { 76 | 77 | this.velocity = TILE.VELOCITY; 78 | this.trophyVelocity = TROPHY.ABSORB_VELOCITY; 79 | this.characterSpeed = CHARACTER.SPEED; 80 | 81 | this.levels = 4; 82 | this.iteration = 0; 83 | this.theme = THEMES.THEME_1; 84 | this.rates = this.theme.TILE_OCCURENCE_RATES.copy(); 85 | 86 | }, 87 | 88 | // If the level upgrades, then update the rates. Otherwise, nothing 89 | // is needed to be done. 90 | updateLevel: function(currentTileIndex) { 91 | 92 | var currentIteration; 93 | 94 | currentIteration = this.levelFunction(currentTileIndex); 95 | 96 | // Never repeat updating the rates. Update the rates only when 97 | // the iteration time changes. 98 | if (this.iteration == currentIteration) 99 | return; 100 | else { 101 | this.updateRates(); 102 | this.iteration = currentIteration; 103 | } 104 | 105 | }, 106 | 107 | levelFunction: function(x) { 108 | 109 | return this.theme.LEVEL_FUNCTION.locateIndex(x); 110 | 111 | }, 112 | 113 | updateRates: function() { 114 | 115 | var last; 116 | 117 | for (var i = 0; i < this.iteration; ++i) { 118 | 119 | last = (this.rates.length - 1) - i; 120 | for (var j = 0; j < last; ++j) 121 | this.rates[j]--; 122 | this.rates[last] += last; 123 | 124 | } 125 | 126 | }, 127 | 128 | generateTileIndex: function(ranges) { 129 | 130 | var rand = Math.floor(Math.random() * this.theme.TILE_OCCURENCE_RATES_SUM); 131 | var bucketIndex = ranges.locateIndex(rand); 132 | 133 | var tileIndex = Math.floor(Math.random() * this.theme.TILE_POOL[bucketIndex].length); 134 | var nextTile = this.theme.TILE_POOL[bucketIndex][tileIndex]; 135 | 136 | var validateResult = THEMES.validate(this.theme, nextTile); 137 | if (validateResult.isChanged) { 138 | this.theme = validateResult.nextTheme; 139 | this.rates = this.theme.TILE_OCCURENCE_RATES.copy(); 140 | } 141 | 142 | return nextTile; 143 | 144 | }, 145 | 146 | generateTiles: function(n, currentTileIndex, oldTiles) { 147 | 148 | 149 | if (currentTileIndex > 1 && currentTileIndex % TILE.LOAD_DURATION != 0) 150 | return; 151 | 152 | var tiles = []; 153 | var index, ranges; 154 | 155 | this.updateLevel(currentTileIndex); 156 | 157 | for (var i = 0; i < n; ++i) { 158 | 159 | ranges = new Utils.Ranges(this.rates); 160 | index = this.generateTileIndex(ranges); 161 | tiles.push(index); 162 | 163 | } 164 | 165 | oldTiles.pushArray(tiles); 166 | 167 | }, 168 | 169 | }; 170 | -------------------------------------------------------------------------------- /Classes/Controllers/PropertiesController.js: -------------------------------------------------------------------------------- 1 | 2 | var PropertiesController = { 3 | 4 | //currentProperty: null, 5 | activeProperties: [], 6 | 7 | add: function(property) { 8 | 9 | this.activeProperties.push(property); 10 | 11 | }, 12 | 13 | generate: function(trophies) { 14 | 15 | var randomNum = Math.ceil(Math.random() * PROPERTY.GENERATE_DURATION); 16 | 17 | if (randomNum != PROPERTY.GENERATE_DURATION) 18 | return null; 19 | 20 | var occupiedRoute = trophies.getCurrentRoute(); 21 | var type = this.generateType(); 22 | var property = Property.create(this.availableRoute(occupiedRoute), type); 23 | 24 | return property; 25 | 26 | }, 27 | 28 | availableRoute: function(occupiedRoute) { 29 | 30 | var routes = [ROUTE.LEFT, ROUTE.MIDDLE, ROUTE.RIGHT]; 31 | return routes.exclude(occupiedRoute).randomPick(); 32 | 33 | }, 34 | 35 | generateType: function() { 36 | 37 | var propertyType = null; 38 | 39 | var rates = PROPERTY.POOL.PROPERTY_OCCURENCE_RATES.copy(); 40 | var ranges = new Utils.Ranges(rates); 41 | 42 | var random = Math.floor(Math.random() * PROPERTY.POOL.PROPERTY_OCCURENCE_RATES_SUM); 43 | var bucketIndex = ranges.locateIndex(random); 44 | 45 | propertyType = PROPERTY.POOL.PROPERTIES_TYPE[bucketIndex]; 46 | 47 | return propertyType; 48 | 49 | }, 50 | 51 | 52 | updateActiveProperties: function(trophy, character) { 53 | 54 | for (var i = 0; i < this.activeProperties.length; ++i) { 55 | 56 | var propertyType = this.activeProperties[i].propertyInformation.type; 57 | switch(propertyType) { 58 | 59 | case TYPE.TROPHY: 60 | trophy = this.activeProperties[i].propertyInformation.uglify(trophy); 61 | this.activeProperties[i].decorate(trophy); 62 | break; 63 | case TYPE.CHARACTER: 64 | this.activeProperties[i].decorate(character); 65 | break; 66 | 67 | } 68 | 69 | } 70 | 71 | }, 72 | 73 | updatePropertiesLife: function(trophy, character) { 74 | 75 | for (var i = 0; i < this.activeProperties.length; ++i) { 76 | 77 | this.activeProperties[i].updateLife(); 78 | if (this.activeProperties[i].propertyInformation.life <= 0) { 79 | 80 | var propertyType = this.activeProperties[i].propertyInformation.type; 81 | switch(propertyType) { 82 | 83 | case TYPE.TROPHY: 84 | trophy = this.activeProperties[i].propertyInformation.uglify(trophy); 85 | break; 86 | case TYPE.CHARACTER: 87 | character = this.activeProperties[i].propertyInformation.uglify(character); 88 | break; 89 | 90 | } 91 | 92 | this.activeProperties[i].propertyInformation.reset(); 93 | this.activeProperties.deleteElementByIndex(i--); 94 | 95 | } 96 | 97 | } 98 | 99 | }, 100 | 101 | reset: function() { 102 | 103 | this.activeProperties = []; 104 | Double.reset(); 105 | Hp.reset(); 106 | Magnet.reset(); 107 | 108 | } 109 | 110 | }; -------------------------------------------------------------------------------- /Classes/Controllers/TrophiesActionsController.js: -------------------------------------------------------------------------------- 1 | 2 | var TrophiesActionsController = { 3 | 4 | velocity: TROPHY.ABSORB_VELOCITY, 5 | sprites: [], 6 | currentTrophies: null, 7 | 8 | add: function(sprite) { 9 | 10 | this.sprites.push(sprite); 11 | 12 | }, 13 | 14 | changeCurrentTrophies: function(trophies) { 15 | 16 | this.currentTrophies = trophies; 17 | 18 | }, 19 | 20 | moveToCharacter: function(character, tile) { 21 | 22 | if (this.currentTrophies == null) 23 | return ; 24 | 25 | var characterX = character.getPosition().x; 26 | var characterY = character.getPosition().y + CHARACTER.SPRITE_HEIGHT / 2; 27 | 28 | var trophiesY = tile.getPosition().y - TILE.SIZE / 2; 29 | characterY -= trophiesY; 30 | 31 | for (var i = 0; i < this.sprites.length; ++i) { 32 | 33 | var spriteX = this.sprites[i].getPosition().x; 34 | var spriteY = this.sprites[i].getPosition().y; 35 | 36 | var xDistance = characterX - spriteX; 37 | var yDistance = characterY - spriteY; 38 | var distance = Math.sqrt(yDistance * yDistance + xDistance * xDistance); 39 | xDistance /= distance; 40 | yDistance /= distance; 41 | 42 | var spriteAimX = spriteX + this.velocity * xDistance; 43 | var spriteAimY = spriteY + this.velocity * yDistance; 44 | 45 | this.sprites[i].setPosition(cc.ccp(spriteAimX, spriteAimY)); 46 | 47 | if (new Utils.Rect(TROPHY.REMOVE_BUFFERX, TROPHY.REMOVE_BUFFERY).isContain(spriteAimX - characterX, spriteAimY - characterY)) { 48 | 49 | this.sprites[i].isGot = true; 50 | this.sprites[i].runAction(cc.Sequence.create( 51 | cc.ScaleTo.create(TROPHY.SCALE_TIME, TROPHY.SCALE), 52 | cc.ScaleTo.create(TROPHY.SCALE_TIME, 0) 53 | )); 54 | this.sprites[i].runAction(cc.FadeOut.create(TROPHY.FADEOUT_TIME)); 55 | this.remove(i); 56 | 57 | } 58 | 59 | } 60 | 61 | }, 62 | 63 | remove: function(index) { 64 | 65 | this.sprites.deleteElementByIndex(index); 66 | 67 | }, 68 | 69 | reset: function() { 70 | 71 | this.sprites = []; 72 | this.currentTrophies = null; 73 | this.velocity = TROPHY.ABSORB_VELOCITY; 74 | 75 | }, 76 | 77 | }; -------------------------------------------------------------------------------- /Classes/Controllers/TrophiesController.js: -------------------------------------------------------------------------------- 1 | 2 | var TrophiesController = { 3 | 4 | reset: function() { 5 | 6 | Coin.reset(); 7 | 8 | }, 9 | 10 | } -------------------------------------------------------------------------------- /Classes/Information/BackgroundInformation/BackgroundInformation.js: -------------------------------------------------------------------------------- 1 | /** 2 | * BackgroundInformation.js 3 | */ 4 | 5 | var BackgroundInformation = function(type) { 6 | 7 | var backgroundInformation = null; 8 | 9 | switch(type) { 10 | 11 | case 1: 12 | backgroundInformation = Background1; 13 | break; 14 | case 2: 15 | backgroundInformation = Background2; 16 | break; 17 | 18 | } 19 | 20 | return backgroundInformation; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Classes/Information/BackgroundInformation/Backgrounds.js: -------------------------------------------------------------------------------- 1 | 2 | var Background1 = { 3 | 4 | src: P_BACKGROUND_1, 5 | velocity: 200, 6 | 7 | } 8 | 9 | var Background2 = { 10 | 11 | src: P_BACKGROUND_2, 12 | velocity: 100, 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Classes/Information/Environments/Cloud.js: -------------------------------------------------------------------------------- 1 | 2 | var Cloud = cc.Sprite.extend({ 3 | 4 | cloudSrc: [P_CLOUD_1, P_CLOUD_2, P_CLOUD_3, P_CLOUD_4], 5 | 6 | ctor: function(index) { 7 | 8 | this.initWithFile(this.cloudSrc[index]); 9 | this.setAnchorPoint(cc.ccp(0.5, 0.5)); 10 | this.setIsVisible(false); 11 | 12 | this.randomMove(); 13 | 14 | }, 15 | 16 | setRandomPosition: function() { 17 | 18 | this.setPosition(cc.ccp( 19 | Utils.Random.range(0, 480), 20 | Utils.Random.range(0, 720) 21 | )); 22 | 23 | }, 24 | 25 | randomMove: function() { 26 | 27 | var rand = Math.random(); 28 | 29 | this.setIsVisible(true); 30 | this.setRandomPosition(); 31 | 32 | this.runAction(cc.Sequence.create( 33 | cc.FadeIn.create(1 + Utils.Random.range(0, 1)), 34 | cc.MoveBy.create(0.5 + Utils.Random.range(0, 1), cc.ccp(Utils.Random.range(-80, 80), 0)), 35 | cc.FadeOut.create(1 + Utils.Random.range(0, 1)), 36 | cc.CallFunc.create(this, function() { 37 | this.setIsVisible(false); 38 | this.randomMove(); 39 | }) 40 | )); 41 | 42 | }, 43 | 44 | }); 45 | 46 | var Sky = cc.Layer.extend({ 47 | 48 | cloud: [], 49 | 50 | duration: 0, 51 | 52 | ctor: function() { 53 | 54 | for (var i = 0; i < 5; ++i) { 55 | 56 | var index = Math.floor(Math.random() * 4); 57 | var cloudSprite = new Cloud(index); 58 | this.cloud.push(cloudSprite); 59 | this.addChild(cloudSprite, 100); 60 | 61 | } 62 | 63 | }, 64 | 65 | evolve: function() { 66 | } 67 | 68 | }); 69 | 70 | Sky.create = function() { 71 | 72 | var sg = new Sky(); 73 | if (sg) { 74 | return sg; 75 | } 76 | return null; 77 | 78 | }; 79 | -------------------------------------------------------------------------------- /Classes/Information/Environments/Footprints.js: -------------------------------------------------------------------------------- 1 | 2 | var Footprints = cc.Layer.extend({ 3 | 4 | FOOT_PRINTS_TAG_OFFSET: 100000, 5 | FOOT_PRINTS_DURATION: 0, 6 | footprints: [P_FOOTPRINT_1, P_FOOTPRINT_2, P_FOOTPRINT_3, P_FOOTPRINT_4, P_FOOTPRINT_5], 7 | innerPrint: null, 8 | innerPatternLight: null, 9 | outerPrint: null, 10 | currentTheme: THEMES.THEME_1, 11 | 12 | ctor: function() { 13 | 14 | this.setAnchorPoint(cc.ccp(0, 0)); 15 | this.setPosition(cc.ccp(0, 0)); 16 | 17 | this.createLandedPrint(this.initLandedSrc()); 18 | 19 | }, 20 | 21 | createLandedPrint: function(src) { 22 | 23 | this.innerPrint = cc.Sprite.create(src.INNER_PRINT); 24 | this.innerPrint.setAnchorPoint(cc.ccp(0.5, 0.5)); 25 | this.innerPrint.setIsVisible(false); 26 | this.addChild(this.innerPrint, 100); 27 | 28 | this.innerPatternLight = cc.Sprite.create(src.INNER_PATTERN_LIGHT); 29 | this.innerPatternLight.setAnchorPoint(cc.ccp(0.5, 0.5)); 30 | this.innerPatternLight.setIsVisible(false); 31 | this.addChild(this.innerPatternLight, 100); 32 | 33 | this.outerPrint = cc.Sprite.create(src.OUTER_PATTERN); 34 | this.outerPrint.setAnchorPoint(cc.ccp(0.5, 0.5)); 35 | this.outerPrint.setIsVisible(false); 36 | this.addChild(this.outerPrint, 100); 37 | 38 | }, 39 | 40 | initLandedSrc: function() { 41 | 42 | var src = { 43 | 44 | INNER_PRINT: P_INNER_RED, 45 | INNER_PATTERN_LIGHT: P_INNER_YELLOW, 46 | OUTER_PATTERN: P_OUTER_PURPLE, 47 | 48 | }; 49 | 50 | if (this.currentTheme.NAME == 'TRANQUIL FOREST') { 51 | 52 | src.INNER_PRINT = P_INNER_RED; 53 | src.INNER_PATTERN_LIGHT = P_INNER_YELLOW; 54 | src.OUTER_PATTERN = P_OUTER_PURPLE; 55 | 56 | } 57 | 58 | if (this.currentTheme.NAME == 'MISTERIOUS BUSH') { 59 | 60 | src.INNER_PRINT = P_INNER_WHITE; 61 | src.INNER_PATTERN_LIGHT = P_INNER_YELLOW; 62 | src.OUTER_PATTERN = P_OUTER_WHITE; 63 | 64 | } 65 | 66 | return src; 67 | 68 | }, 69 | 70 | createSprites: function() { 71 | 72 | var self = this; 73 | 74 | setTimeout(function() { 75 | 76 | self.removeChild(self.innerPrint); 77 | self.removeChild(self.innerPatternLight); 78 | self.removeChild(self.outerPrint); 79 | 80 | self.innerPrint = null; 81 | self.innerPatternLight = null; 82 | self.outerPrint = null; 83 | 84 | self.createLandedPrint(self.initLandedSrc()); 85 | 86 | }, 600); 87 | 88 | }, 89 | 90 | evolve: function(character, flag) { 91 | 92 | if (character.isRunning()) 93 | this.running(character); 94 | 95 | this.currentTheme = flag.theme; 96 | if (typeof flag.isLanded !== 'undefined' && flag.isLanded) 97 | this.landed(character); 98 | 99 | if (typeof flag.isAboutToJump !== 'undefined' && flag.isAboutToJump) 100 | this.aboutToJump(character); 101 | 102 | }, 103 | 104 | createFootprint: function(index, x, y, scale) { 105 | 106 | var newFootprint = cc.Sprite.create(this.footprints[index]); 107 | 108 | newFootprint.setScale(0.5); 109 | newFootprint.setAnchorPoint(cc.ccp(0.5, 0.5)); 110 | newFootprint.setPosition(cc.ccp(x, y)); 111 | this.addChild(newFootprint, 100); 112 | 113 | newFootprint.runAction(cc.ScaleTo.create(0.4, scale)); 114 | newFootprint.runAction(cc.FadeOut.create(1)); 115 | newFootprint.runAction(cc.MoveTo.create( 116 | (WIN_SIZE.height / 4 + 100) / LevelController.velocity, 117 | cc.ccp(x, -100)) 118 | ); 119 | 120 | var self = this; 121 | 122 | setTimeout((function(sprite) { 123 | return function() { 124 | self.removeChild(sprite); 125 | } 126 | })(newFootprint), 1000); 127 | 128 | }, 129 | 130 | running: function(character) { 131 | 132 | this.FOOT_PRINTS_DURATION++; 133 | 134 | if (this.FOOT_PRINTS_DURATION % 6 == 0) 135 | var x = character.getPosition().x - 20; 136 | else if (this.FOOT_PRINTS_DURATION % 11 == 0) 137 | var x = character.getPosition().x + 20; 138 | else 139 | return; 140 | 141 | var index = Math.floor(Math.random() * 5); 142 | this.createFootprint(index, x, WIN_SIZE.height / 4 - 50, 1.5); 143 | 144 | }, 145 | 146 | aboutToJump: function(character) { 147 | 148 | var x = character.getPosition().x; 149 | var y = character.getPosition().y; 150 | 151 | this.showJumpPrint(x, y - 30); 152 | 153 | }, 154 | 155 | showJumpPrint: function(x, y) { 156 | 157 | this.innerPrint.setScale(0.6); 158 | this.innerPrint.setIsVisible(true); 159 | this.innerPrint.setPosition(cc.ccp(x, y)); 160 | 161 | this.innerPatternLight.setScale(0.6); 162 | this.innerPatternLight.setIsVisible(true); 163 | this.innerPatternLight.setPosition(cc.ccp(x, y)); 164 | 165 | this.outerPrint.setScale(0.6); 166 | this.outerPrint.setIsVisible(true); 167 | this.outerPrint.setPosition(cc.ccp(x, y)); 168 | 169 | this.innerPatternLight.runAction(cc.RotateBy.create(0.6, -360)); 170 | this.innerPatternLight.runAction(cc.ScaleTo.create(0.6, 0.1)); 171 | this.innerPatternLight.runAction(cc.FadeOut.create(0.6)); 172 | 173 | this.outerPrint.runAction(cc.RotateBy.create(0.6, -360)); 174 | this.outerPrint.runAction(cc.ScaleTo.create(0.6, 0.1)); 175 | this.outerPrint.runAction(cc.FadeOut.create(0.6)); 176 | 177 | this.innerPrint.runAction(cc.RotateBy.create(0.6, 360)); 178 | this.innerPrint.runAction(cc.ScaleTo.create(0.6, 0.1)); 179 | this.innerPrint.runAction(cc.FadeOut.create(0.6)); 180 | 181 | this.createSprites(); 182 | 183 | }, 184 | 185 | landed: function(character) { 186 | 187 | var x = character.getPosition().x; 188 | var y = character.getPosition().y; 189 | 190 | this.showLandedPrint(x, y - 30); 191 | 192 | }, 193 | 194 | showLandedPrint: function(x, y) { 195 | 196 | this.innerPrint.setScale(0.5); 197 | this.innerPrint.setIsVisible(true); 198 | this.innerPrint.setPosition(cc.ccp(x, y)); 199 | 200 | this.innerPatternLight.setScale(0.5); 201 | this.innerPatternLight.setIsVisible(true); 202 | this.innerPatternLight.setPosition(cc.ccp(x, y)); 203 | 204 | this.outerPrint.setScale(0.5); 205 | this.outerPrint.setIsVisible(true); 206 | this.outerPrint.setPosition(cc.ccp(x, y)); 207 | 208 | this.innerPatternLight.runAction(cc.ScaleTo.create(0.2, 1.5)); 209 | this.innerPatternLight.runAction(cc.FadeOut.create(0.2)); 210 | 211 | this.outerPrint.runAction(cc.ScaleTo.create(0.2, 1)); 212 | this.outerPrint.runAction(cc.FadeOut.create(0.2)); 213 | 214 | this.innerPrint.runAction(cc.Sequence.create( 215 | cc.RotateBy.create(0.3, 360), 216 | cc.CallFunc.create(this.innerPrint, function() { 217 | 218 | this.runAction(cc.ScaleTo.create(0.2, 1)); 219 | this.runAction(cc.FadeOut.create(0.2)); 220 | this.runAction(cc.MoveTo.create( 221 | (WIN_SIZE.height / 4 + 100) / LevelController.velocity, 222 | cc.ccp(x, -100)) 223 | ); 224 | 225 | }) 226 | 227 | )); 228 | 229 | this.createSprites(); 230 | 231 | }, 232 | 233 | }); 234 | 235 | Footprints.create = function() { 236 | 237 | var sg = new Footprints(); 238 | if (sg) { 239 | return sg; 240 | } 241 | return null; 242 | 243 | }; 244 | -------------------------------------------------------------------------------- /Classes/Information/Environments/JumpShadow.js: -------------------------------------------------------------------------------- 1 | 2 | var JumpShadow = cc.Layer.extend({ 3 | 4 | shadow: null, 5 | 6 | ctor: function() { 7 | 8 | this.setAnchorPoint(cc.ccp(0, 0)); 9 | this.setPosition(cc.ccp(0, 0)); 10 | 11 | this.shadow = cc.Sprite.create(P_SHADOW); 12 | this.shadow.setAnchorPoint(cc.ccp(0.5, 0.5)); 13 | this.shadow.setPosition(cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height / 4)); 14 | this.shadow.setIsVisible(false); 15 | 16 | this.addChild(this.shadow, 100); 17 | 18 | }, 19 | 20 | evolve: function(character) { 21 | 22 | this.shadow.setPosition(cc.ccp(character.getPosition().x, WIN_SIZE.height / 4)); 23 | if (character.status != CHARACTER.STATUS.JUMPING) 24 | return; 25 | 26 | this.shadow.setIsVisible(true); 27 | this.shadow.runAction(cc.Sequence.create( 28 | cc.ScaleTo.create( ((character.jumpDistance) / TILE.VELOCITY) / 2 ,8), 29 | cc.ScaleTo.create( ((character.jumpDistance) / TILE.VELOCITY) / 2 ,0), 30 | cc.CallFunc.create(this, function() { 31 | this.shadow.setIsVisible(false); 32 | }) 33 | )); 34 | 35 | }, 36 | 37 | 38 | }); 39 | 40 | JumpShadow.create = function() { 41 | 42 | var sg = new JumpShadow(); 43 | if (sg) { 44 | return sg; 45 | } 46 | return null; 47 | 48 | }; -------------------------------------------------------------------------------- /Classes/Information/Environments/LightCircle.js: -------------------------------------------------------------------------------- 1 | 2 | var LightCircle = cc.Layer.extend({ 3 | 4 | lightPoints: [], 5 | lightPointsSrc: [ P_LIGHT_POINT_1, P_LIGHT_POINT_2, P_LIGHT_POINT_3, P_LIGHT_POINT_4 ], 6 | 7 | ctor: function() { 8 | 9 | this.setAnchorPoint(cc.ccp(0, 0)); 10 | this.setPosition(cc.ccp(0, 0)); 11 | 12 | for (var i = 0; i < 20; ++i) { 13 | 14 | var lightPoint = cc.Sprite.create(this.lightPointsSrc[Math.floor(Math.random()*4)]); 15 | lightPoint.setAnchorPoint(cc.ccp(0.5, 0.5)); 16 | lightPoint.setIsVisible(false); 17 | 18 | this.lightPoints.push(lightPoint); 19 | this.addChild(lightPoint, 100); 20 | 21 | } 22 | 23 | }, 24 | 25 | evolve: function(character, flag) { 26 | 27 | if (typeof flag.isGotProperty === 'undefined' || !flag.isGotProperty) 28 | return; 29 | 30 | var lightPoint, theta, rand; 31 | for (var i = 0; i < this.lightPoints.length ; ++i) { 32 | 33 | lightPoint = this.lightPoints[i]; 34 | 35 | lightPoint.setPosition(cc.ccp(character.getPosition().x, WIN_SIZE.height / 4)); 36 | lightPoint.setIsVisible(true); 37 | 38 | rand = Math.random() / 3; 39 | theta = 2 * Math.PI * i / 12; 40 | 41 | lightPoint.runAction(cc.MoveBy.create(rand, cc.ccp( 42 | (40 + rand * 260) * Math.sin(theta), 43 | (40 + rand * 260) * Math.cos(theta) 44 | ))); 45 | //lightPoint.runAction(cc.ScaleTo.create(0.5 + rand, 2)); 46 | lightPoint.runAction(cc.RotateBy.create(0.5 + rand, 360)); 47 | //this.lightPoint.runAction(cc.MoveBy.create(0.1, cc.ccp(0, -60))); 48 | //lightPoint.runAction(cc.MoveBy.create(0.2, cc.ccp(200*rand, 200*rand))); 49 | lightPoint.runAction(cc.FadeOut.create(0.5 + rand)); 50 | 51 | setTimeout((function(lightPoint) { 52 | return function() { 53 | lightPoint.setIsVisible(false); 54 | } 55 | })(lightPoint), 700); 56 | 57 | } 58 | 59 | }, 60 | 61 | }); 62 | 63 | LightCircle.create = function() { 64 | 65 | var sg = new LightCircle(); 66 | if (sg) { 67 | return sg; 68 | } 69 | return null; 70 | 71 | }; -------------------------------------------------------------------------------- /Classes/Information/PropertiesInformation/Double.js: -------------------------------------------------------------------------------- 1 | //Double var Double = { name: PROPERTY.TYPE.DOUBLE, src: P_DOUBLE, bgSrc: P_DOUBLE_BG, type: TYPE.TROPHY, life: 5, decorate: function(trophy) { trophy.value *= 2; trophy.src = P_DOUBLE_COIN; return trophy; }, uglify: function(trophy) { trophy.value = 1; trophy.src = P_COIN; return trophy; }, reset: function(trophy) { this.life = 5; }, }; -------------------------------------------------------------------------------- /Classes/Information/PropertiesInformation/Hp.js: -------------------------------------------------------------------------------- 1 | 2 | var Hp = { 3 | 4 | name: PROPERTY.TYPE.HP, 5 | src: P_HP, 6 | bgSrc: P_HP_UP, 7 | type: TYPE.CHARACTER, 8 | life: 1, 9 | 10 | energy: 1, 11 | 12 | 13 | decorate: function(character) { 14 | 15 | if (this.life > 0 && character.hp < CHARACTER.MAX_HP) { 16 | 17 | character.hp += this.energy; 18 | character.setSrc(character.hp); 19 | this.life--; 20 | 21 | } 22 | 23 | return character; 24 | 25 | }, 26 | 27 | uglify: function(character) { 28 | 29 | return character; 30 | 31 | }, 32 | 33 | reset: function() { 34 | 35 | this.life = 1; 36 | 37 | }, 38 | 39 | }; -------------------------------------------------------------------------------- /Classes/Information/PropertiesInformation/Magnet.js: -------------------------------------------------------------------------------- 1 | //Magne 2 | 3 | var Magnet = { 4 | 5 | name: PROPERTY.TYPE.MAGNET, 6 | src: P_MAGNET, 7 | bgSrc: P_MAGNET, 8 | type: TYPE.CHARACTER, 9 | life: 5, 10 | 11 | xForce: 2, 12 | yForce: 150, 13 | 14 | decorate: function(character) { 15 | 16 | var buffer = character.getTrophyBuffer(); 17 | var bufferX = buffer.trophyBufferX; 18 | var bufferY = buffer.trophyBufferY; 19 | 20 | character.TrophyBufferRect = new Utils.Rect(bufferX + this.xForce, bufferY + this.yForce); 21 | 22 | return character; 23 | 24 | }, 25 | 26 | uglify: function(character) { 27 | 28 | character.TrophyBufferRect = new Utils.Rect(TROPHY.GET_BUFFERX, TROPHY.GET_BUFFERY); 29 | 30 | return character; 31 | 32 | }, 33 | 34 | reset: function() { 35 | 36 | this.life = 5; 37 | 38 | }, 39 | 40 | }; -------------------------------------------------------------------------------- /Classes/Information/PropertiesInformation/PropertiesInformation.js: -------------------------------------------------------------------------------- 1 | /* 2 | * function return PropertyInformation accroding to type 3 | */ 4 | 5 | var PropertiesInformation = function(type) { 6 | 7 | var propertyInformation = null; 8 | var isUsed = false; 9 | 10 | switch(type) { 11 | case PROPERTY.TYPE.DOUBLE: 12 | propertyInformation = Double; 13 | break; 14 | case PROPERTY.TYPE.TRIPLE: 15 | propertyInformation = Triple; 16 | break; 17 | case PROPERTY.TYPE.MAGNET: 18 | propertyInformation = Magnet; 19 | break; 20 | case PROPERTY.TYPE.HP: 21 | propertyInformation = Hp; 22 | break; 23 | } 24 | 25 | return propertyInformation; 26 | 27 | } -------------------------------------------------------------------------------- /Classes/Information/PropertiesInformation/Triple.js: -------------------------------------------------------------------------------- 1 | //Double 2 | 3 | var Triple = { 4 | 5 | name: PROPERTY.TYPE.TRIPLE, 6 | src: P_TRIPLE, 7 | bgSrc: P_TRIPLE_BG, 8 | type: TYPE.TROPHY, 9 | life: 5, 10 | 11 | decorate: function(trophy) { 12 | 13 | trophy.value *= 3; 14 | trophy.src = P_TRIPLE_COIN; 15 | return trophy; 16 | 17 | }, 18 | 19 | uglify: function(trophy) { 20 | 21 | trophy.value = 1; 22 | trophy.src = P_COIN; 23 | 24 | return trophy; 25 | 26 | }, 27 | 28 | reset: function() { 29 | 30 | this.life = 5; 31 | 32 | }, 33 | 34 | }; -------------------------------------------------------------------------------- /Classes/Information/TilesInformation/BasicTile.js: -------------------------------------------------------------------------------- 1 | /* 2 | * return BasicTile accroding to configs 3 | */ 4 | 5 | var BasicTile = function(configs) { 6 | 7 | //return isBounded function 8 | var isBounded = IsBounded(configs.ranges); 9 | 10 | //return isValid function 11 | var isValid = (function(ranges, turnable, directions) { 12 | 13 | if (turnable) 14 | return IsValid.ToTurn(directions); 15 | else 16 | return IsValid.ToGoStraight(ranges); 17 | 18 | })(configs.ranges, configs.turnable, configs.directions); 19 | 20 | //return isTurnable function 21 | var isTurnable = function() { 22 | 23 | return configs.turnable; 24 | 25 | }; 26 | 27 | //return generateTrophies function 28 | var generateTrophies = (function(turnable, routes) { 29 | 30 | if (turnable) 31 | return GenerateTrophies.InTurnable(routes); 32 | else 33 | return GenerateTrophies.InStraight(routes); 34 | 35 | })(configs.turnable, configs.trophieRoutes); 36 | 37 | return { 38 | 39 | src : configs.src, 40 | isBounded : isBounded, 41 | isValid : isValid, 42 | isTurnable : isTurnable, 43 | generateTrophies : generateTrophies 44 | 45 | }; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Classes/Information/TilesInformation/GenerateTrophies.js: -------------------------------------------------------------------------------- 1 | /* 2 | * GenerateTrophies 3 | */ 4 | 5 | var GenerateTrophies = { 6 | 7 | //return generate trophies function in straight 8 | InStraight: function(routes) { 9 | 10 | return function() { 11 | 12 | var positions = []; 13 | var offset = TILE.SIZE / (MAX_TROPHY_NUM + 1); 14 | var index = Math.floor(Math.random() * (routes.length + 1)); 15 | var route = 0; 16 | 17 | if (index != routes.length) { 18 | 19 | route = routes[index]; 20 | for (var i = 0; i < MAX_TROPHY_NUM; ++i) { 21 | positions.push(cc.ccp(route * ROUTE.WIDTH + TRACK.LEFT_COORDINATE, offset * (i + 1))); 22 | } 23 | 24 | } 25 | 26 | return { 27 | route : route, 28 | pos : positions, 29 | }; 30 | 31 | }; 32 | 33 | }, 34 | 35 | //return generate trophies function in turn 36 | 37 | InTurnable: function(routes) { 38 | 39 | return function() { 40 | 41 | var positions = []; 42 | var offset = TILE.SIZE / (MAX_TROPHY_NUM + 1); 43 | var trophyNum = (TILE.SIZE - TRACK.WIDTH) / (2 * offset); 44 | var index = Math.floor(Math.random() * (routes.length + 1)); 45 | var route = 0; 46 | 47 | if (index != routes.length) { 48 | 49 | var route = routes[index]; 50 | for (var i = 0; i < trophyNum; ++i) { 51 | positions.push(cc.ccp(route * ROUTE.WIDTH + TRACK.LEFT_COORDINATE, offset * (i + 1))); 52 | } 53 | 54 | } 55 | 56 | return { 57 | route : route, 58 | pos : positions, 59 | }; 60 | 61 | }; 62 | 63 | }, 64 | 65 | }; 66 | -------------------------------------------------------------------------------- /Classes/Information/TilesInformation/IsBounded.js: -------------------------------------------------------------------------------- 1 | /* 2 | * return IsBounded function 3 | * ranges: {route, range, bound} 4 | * route: valid routes 5 | * range: valid ranges 6 | * bound: the sizes' bound 7 | */ 8 | var IsBounded = function(ranges) { 9 | 10 | //return is can move or not 11 | var movePermission = function(routes, jumpRoutes, bound) { 12 | return function(route) { 13 | 14 | var isValidToMoveLeft = true; 15 | var isValidToMoveRight = true; 16 | var isValidToJumpLeft = true; 17 | var isValidToJumpRight = true; 18 | 19 | if (!routes.isContain(route - 1) && 20 | bound.left == BOUND.SOLID) 21 | isValidToMoveLeft = false; 22 | if (!routes.isContain(route + 1) && 23 | bound.right == BOUND.SOLID) 24 | isValidToMoveRight = false; 25 | 26 | if (!jumpRoutes.isContain(route - 1) && 27 | bound.left == BOUND.SOLID) 28 | isValidToJumpLeft = false; 29 | if (!jumpRoutes.isContain(route + 1) && 30 | bound.right == BOUND.SOLID) 31 | isValidToJumpRight = false; 32 | 33 | 34 | return { 35 | 36 | ACTION_MOVE_LEFT : isValidToMoveLeft, 37 | ACTION_MOVE_RIGHT : isValidToMoveRight, 38 | ACTION_JUMP_LEFT : isValidToJumpLeft, 39 | ACTION_JUMP_RIGHT : isValidToJumpRight, 40 | 41 | }; 42 | }; 43 | }; 44 | 45 | //return is in range or not 46 | var isInRange = function(range) { 47 | return function(pos) { 48 | return range.isContain(pos); 49 | } 50 | }; 51 | 52 | var tests = []; 53 | for (var i = 0; i < ranges.length; ++i) { 54 | 55 | var routes = ranges[i].routes; 56 | var range = ranges[i].range; 57 | var bound = ranges[i].bound; 58 | var jumproutes = ranges[i].jumpRoutes; 59 | 60 | tests.push((function() { 61 | return { 62 | movePermission : movePermission(routes, jumproutes, bound), 63 | isInRange : isInRange(range), 64 | } 65 | })(routes, jumproutes, range, bound)); 66 | 67 | } 68 | 69 | //rentur isBounded function 70 | return function(tile, character) { 71 | 72 | var tile_pos = tile.getPosition().y; 73 | var character_pos = character.getPosition().y; 74 | var pos = character_pos - tile_pos + TILE.SIZE / 2; 75 | 76 | var route = character.getCurrentRoute(); 77 | 78 | for (var i = 0; i < tests.length; ++i) { 79 | 80 | if (tests[i].isInRange(pos)) { 81 | return tests[i].movePermission(route); 82 | } 83 | 84 | } 85 | 86 | return { 87 | ACTION_MOVE_LEFT : false, 88 | ACTION_MOVE_RIGHT : false, 89 | ACTION_JUMP_LEFT : false, 90 | ACTION_JUMP_RIGHT : false, 91 | }; 92 | 93 | }; 94 | 95 | }; 96 | -------------------------------------------------------------------------------- /Classes/Information/TilesInformation/IsValid.js: -------------------------------------------------------------------------------- 1 | var IsValid = { 2 | 3 | /** 4 | * return isValid function in tile to turn 5 | * directions: the character turn direction 6 | */ 7 | ToTurn: function(directions) { 8 | 9 | var turnDirections = directions; 10 | 11 | return function(tile, character) { 12 | 13 | var pos = tile.getPosition().y; 14 | var distance = pos + TRACK.WIDTH / 2 - character.getPosition().y; 15 | 16 | if (!turnDirections.isContain(tile.turnDirection) && distance < 0) 17 | return false; 18 | 19 | return true; 20 | 21 | }; 22 | 23 | }, 24 | 25 | /** 26 | * return isValid function in tile to go straight 27 | * ranges: {route, range, bound} 28 | * route: valid routes 29 | * range: valid ranges 30 | * bound: the sizes' bound 31 | */ 32 | ToGoStraight: function(ranges) { 33 | 34 | //return character is in route or not 35 | var isInRoute = function(routes) { 36 | return function(route) { 37 | return routes.isContain(route); 38 | } 39 | }; 40 | 41 | var isInJumpRoute = function(jumpRoutes) { 42 | return function(route) { 43 | return jumpRoutes.isContain(route); 44 | } 45 | } 46 | 47 | //return character is in range or not 48 | var isInRange = function(range) { 49 | return function(pos) { 50 | return range.isContain(pos); 51 | } 52 | }; 53 | 54 | var tests = []; 55 | for (var i = 0; i < ranges.length; ++i) { 56 | 57 | var routes = ranges[i].routes; 58 | var range = ranges[i].range; 59 | var jumpRoutes = ranges[i].jumpRoutes; 60 | 61 | tests.push((function() { 62 | return { 63 | isInRoute : isInRoute(routes), 64 | isInJumpRoute : isInJumpRoute(jumpRoutes), 65 | isInRange : isInRange(range), 66 | } 67 | })(routes, jumpRoutes, range)); 68 | 69 | } 70 | 71 | //rentur isvalid function 72 | return function(tile, character) { 73 | 74 | var tile_pos = tile.getPosition().y; 75 | var character_pos = character.getPosition().y; 76 | var pos = character_pos - tile_pos + TILE.SIZE / 2; 77 | 78 | var route = character.getCurrentRoute(); 79 | 80 | for (var i = 0; i < tests.length; ++i) { 81 | 82 | if (tests[i].isInRange(pos)) { 83 | 84 | if (character.isRunning() || character.isAboutToJump()) 85 | return tests[i].isInRoute(route); 86 | 87 | if (character.isJumping()) 88 | return tests[i].isInJumpRoute(route); 89 | 90 | } 91 | 92 | } 93 | 94 | return false; 95 | 96 | }; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /Classes/Information/TilesInformation/TileInformation.js: -------------------------------------------------------------------------------- 1 | /* 2 | * function return tileinformation accroding to type 3 | */ 4 | 5 | var TileInformation = function(type) { 6 | 7 | var tileInformation = null; 8 | 9 | switch(type) { 10 | 11 | case 1: 12 | tileInformation = Tile1; 13 | break; 14 | case 2: 15 | tileInformation = Tile2; 16 | break; 17 | case 3: 18 | tileInformation = Tile3; 19 | break; 20 | case 4: 21 | tileInformation = Tile4; 22 | break; 23 | case 5: 24 | tileInformation = Tile5; 25 | break; 26 | case 6: 27 | tileInformation = Tile6; 28 | break; 29 | case 7: 30 | tileInformation = Tile7; 31 | break; 32 | case 8: 33 | tileInformation = Tile8; 34 | break; 35 | case 9: 36 | tileInformation = Tile9; 37 | break; 38 | case 10: 39 | tileInformation = Tile10; 40 | break; 41 | case 11: 42 | tileInformation = Tile11; 43 | break; 44 | case 12: 45 | tileInformation = Tile12; 46 | break; 47 | 48 | } 49 | 50 | return tileInformation; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Classes/Information/TilesInformation/Tiles.js: -------------------------------------------------------------------------------- 1 | 2 | //tile 1: straight 3 | var Tile1 = BasicTile({ 4 | 5 | src: P_TILE_1, 6 | ranges: [{ 7 | routes : [1, 2, 3], 8 | jumpRoutes : [1, 2, 3], 9 | range : new Utils.Range(0, TILE.SIZE), 10 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 11 | }], 12 | turnable: false, 13 | directions: [ ACTION.GO_STRAIGHT ], 14 | trophieRoutes: [1, 2, 3], 15 | 16 | }); 17 | 18 | //tile 2: turn left 19 | var Tile2 = BasicTile({ 20 | 21 | src: P_TILE_2, 22 | ranges: [{ 23 | routes : [1, 2, 3], 24 | jumpRoutes : [1, 2, 3], 25 | range : new Utils.Range(0, TILE.SIZE), 26 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 27 | }], 28 | turnable: true, 29 | directions: [ ACTION.TURN_LEFT ], 30 | trophieRoutes: [1, 2, 3], 31 | 32 | }); 33 | 34 | //tile 3: turn right 35 | var Tile3 = BasicTile({ 36 | 37 | src: P_TILE_3, 38 | ranges: [{ 39 | routes : [1, 2, 3], 40 | jumpRoutes : [1, 2, 3], 41 | range : new Utils.Range(0, TILE.SIZE), 42 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 43 | }], 44 | turnable: true, 45 | directions: [ ACTION.TURN_RIGHT ], 46 | trophieRoutes: [1, 2, 3], 47 | 48 | }); 49 | 50 | //tile 4: turn left and turn right 51 | var Tile4 = BasicTile({ 52 | 53 | src: P_TILE_4, 54 | ranges: [{ 55 | routes : [1, 2, 3], 56 | jumpRoutes : [1, 2, 3], 57 | range : new Utils.Range(0, TILE.SIZE), 58 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 59 | }], 60 | turnable: true, 61 | directions: [ ACTION.TURN_LEFT, ACTION.TURN_RIGHT ], 62 | trophieRoutes: [1, 2, 3], 63 | 64 | }); 65 | 66 | //tile 5: short narrow 67 | var Tile5 = BasicTile({ 68 | 69 | src: P_TILE_5, 70 | ranges: [{ 71 | routes : [1, 2, 3], 72 | jumpRoutes : [1, 2, 3], 73 | range : new Utils.Range(0, TILE.SIZE / 3), 74 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 75 | },{ 76 | routes : [1], 77 | jumpRoutes : [0, 1, 2, 3, 4], 78 | range : new Utils.Range(TILE.SIZE / 3, 2 * TILE.SIZE / 3), 79 | bound : { left: BOUND.FRAGILE, right: BOUND.FRAGILE }, 80 | },{ 81 | routes : [1, 2, 3], 82 | jumpRoutes : [1, 2, 3], 83 | range : new Utils.Range(2 * TILE.SIZE / 3, TILE.SIZE), 84 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 85 | }], 86 | turnable: false, 87 | directions: [ ACTION.GO_STRAIGHT ], 88 | trophieRoutes: [1], 89 | 90 | }); 91 | 92 | //tile 6: long narrow 93 | var Tile6 = BasicTile({ 94 | 95 | src: P_TILE_6, 96 | ranges: [{ 97 | routes : [1, 2, 3], 98 | jumpRoutes : [1, 2, 3], 99 | range : new Utils.Range(0, TILE.SIZE / 3), 100 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 101 | },{ 102 | routes : [3], 103 | jumpRoutes : [0, 1, 2, 3, 4], 104 | range : new Utils.Range(TILE.SIZE / 3, 2 * TILE.SIZE / 3), 105 | bound : { left: BOUND.FRAGILE, right: BOUND.FRAGILE }, 106 | },{ 107 | routes : [1, 2, 3], 108 | jumpRoutes : [1, 2, 3], 109 | range : new Utils.Range(2 * TILE.SIZE / 3, TILE.SIZE), 110 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 111 | }], 112 | turnable: false, 113 | directions: [ ACTION.GO_STRAIGHT ], 114 | trophieRoutes: [3], 115 | 116 | }); 117 | 118 | //tile 7: straight 119 | var Tile7 = BasicTile({ 120 | 121 | src: P_TILE_7, 122 | ranges: [{ 123 | routes : [1, 2, 3], 124 | jumpRoutes : [1, 2, 3], 125 | range : new Utils.Range(0, TILE.SIZE), 126 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 127 | }], 128 | turnable: false, 129 | directions: [ ACTION.GO_STRAIGHT ], 130 | trophieRoutes: [1, 2, 3], 131 | 132 | }); 133 | 134 | 135 | //tile 8: turn left 136 | var Tile8 = BasicTile({ 137 | 138 | src: P_TILE_8, 139 | ranges: [{ 140 | routes : [1, 2, 3], 141 | jumpRoutes : [1, 2, 3], 142 | range : new Utils.Range(0, TILE.SIZE), 143 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 144 | }], 145 | turnable: true, 146 | directions: [ ACTION.TURN_LEFT ], 147 | trophieRoutes: [1, 2, 3], 148 | 149 | }); 150 | 151 | //tile 9: turn right 152 | var Tile9 = BasicTile({ 153 | 154 | src: P_TILE_9, 155 | ranges: [{ 156 | routes : [1, 2, 3], 157 | jumpRoutes : [1, 2, 3], 158 | range : new Utils.Range(0, TILE.SIZE), 159 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 160 | }], 161 | turnable: true, 162 | directions: [ ACTION.TURN_RIGHT ], 163 | trophieRoutes: [1, 2, 3], 164 | 165 | }); 166 | 167 | //tile 10: straight 168 | var Tile10 = BasicTile({ 169 | 170 | src: P_TILE_10, 171 | ranges: [{ 172 | routes : [1, 2, 3], 173 | jumpRoutes : [1, 2, 3], 174 | range : new Utils.Range(0, TILE.SIZE), 175 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 176 | }], 177 | turnable: false, 178 | directions: [ ACTION.GO_STRAIGHT ], 179 | trophieRoutes: [1, 2, 3], 180 | 181 | }); 182 | 183 | 184 | //tile 11: short narrow 185 | var Tile11 = BasicTile({ 186 | 187 | src: P_TILE_11, 188 | ranges: [{ 189 | routes : [1, 2, 3], 190 | jumpRoutes : [1, 2, 3], 191 | range : new Utils.Range(0, TILE.SIZE / 3), 192 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 193 | },{ 194 | routes : [], 195 | jumpRoutes : [0, 1, 2, 3, 4], 196 | range : new Utils.Range(TILE.SIZE / 3, 2 * TILE.SIZE / 3), 197 | bound : { left: BOUND.FRAGILE, right: BOUND.FRAGILE }, 198 | },{ 199 | routes : [1, 2, 3], 200 | jumpRoutes : [1, 2, 3], 201 | range : new Utils.Range(2 * TILE.SIZE / 3, TILE.SIZE), 202 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 203 | }], 204 | turnable: false, 205 | directions: [ ACTION.GO_STRAIGHT ], 206 | trophieRoutes: [], 207 | 208 | }); 209 | 210 | //tile 2: straight 211 | var Tile12 = BasicTile({ 212 | 213 | src: P_TILE_12, 214 | ranges: [{ 215 | routes : [1, 2, 3], 216 | jumpRoutes : [1, 2, 3], 217 | range : new Utils.Range(0, TILE.SIZE), 218 | bound : { left: BOUND.SOLID, right: BOUND.SOLID }, 219 | }], 220 | turnable: false, 221 | directions: [ ACTION.GO_STRAIGHT ], 222 | trophieRoutes: [1, 2, 3], 223 | 224 | }); 225 | -------------------------------------------------------------------------------- /Classes/Information/TrackInformation.js: -------------------------------------------------------------------------------- 1 | 2 | var TrackInformation = { 3 | 4 | basicTrophyType: Coin, 5 | 6 | }; -------------------------------------------------------------------------------- /Classes/Information/TrophiesInformation/Coin.js: -------------------------------------------------------------------------------- 1 | // Coin trophy 2 | var Coin = { 3 | 4 | value: 1, 5 | src: P_COIN, 6 | 7 | reset: function() { 8 | 9 | this.value = 1; 10 | this.src = P_COIN; 11 | 12 | }, 13 | 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /Classes/Information/TrophiesInformation/TrophiesInformation.js: -------------------------------------------------------------------------------- 1 | /* 2 | * function return TrophyInformation accroding to type 3 | */ 4 | 5 | var TrophyInformation = function(type) { 6 | 7 | var trophyInformation = null; 8 | 9 | switch(type) { 10 | case TROPHY.TYPE.COIN: 11 | trophyInformation = Coin; 12 | break; 13 | } 14 | 15 | return trophyInformation; 16 | 17 | } -------------------------------------------------------------------------------- /Classes/Models/Background.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Background is like the track, which manipulates the background tiles 4 | * as the track manipulates the tiles. The main difference between them 5 | * is that the background is not turnable. 6 | */ 7 | var Background = cc.Layer.extend({ 8 | 9 | backgroundTiles: null, 10 | 11 | currentBackgroundTile: null, 12 | nextBackgroundTile: null, 13 | 14 | // The index now is only used to generate the tag for the background, 15 | // which is less useful than the one in track. 16 | currentBackgroundTileIndex: null, 17 | 18 | scoreLayer: null, 19 | pauseLayer: null, 20 | 21 | ctor: function(backgrounds) { 22 | 23 | this._super(); 24 | 25 | this.backgroundTiles = backgrounds.copy(); 26 | 27 | // RESET(); 28 | this.loadFirstBackgroundTile(); 29 | this.scheduleUpdate(); 30 | 31 | return true; 32 | 33 | }, 34 | 35 | loadFirstBackgroundTile: function() { 36 | 37 | this.currentBackgroundTileIndex = 1; 38 | this.currentBackgroundTile = BackgroundTile.create( 39 | this.backgroundTiles[Utils.Random.rangeInteger(0, this.backgroundTiles.length)], 40 | this.currentBackgroundTileIndex, 41 | TILE.VELOCITY 42 | ); 43 | 44 | this.addChild( 45 | this.currentBackgroundTile, 46 | Z_ORDER.BACKGROUND, 47 | BACKGROUND.TAG + this.currentBackgroundTileIndex 48 | ); 49 | this.currentBackgroundTile.goStraight(); 50 | 51 | }, 52 | 53 | loadNextBackgroundTile: function() { 54 | 55 | this.currentBackgroundTileIndex++; 56 | 57 | /** 58 | * When loading the next tile, the current still moves. The triky thing that makes the problem 59 | * difficult is that in that little period of time, the distance that the current tile travels 60 | * is unpredictable, which leads a gap between the current tile and the next tile. The way to 61 | * solve the problem is that pause the movement of the current tile while the next tile is 62 | * loading. Then after the next tile is successfully registered to the trackLayer, the current 63 | * tile resumes to straight. 64 | */ 65 | this.currentBackgroundTile.pause(); 66 | 67 | /** 68 | * Calculates the offset between the current tile and the window height. After the current tile 69 | * travels under the buffer, the next tile is loaded. But it would be perfect to load the next 70 | * tile right above the current tile. So the offset is calculated. 71 | */ 72 | var offset = this.currentBackgroundTile.getPosition().y + TILE.SIZE / 2 - WIN_SIZE.height; 73 | this.nextBackgroundTile = BackgroundTile.create( 74 | this.backgroundTiles[Utils.Random.rangeInteger(0, this.backgroundTiles.length)], 75 | this.currentBackgroundTileIndex, 76 | offset 77 | ); 78 | 79 | this.addChild( 80 | this.nextBackgroundTile, 81 | Z_ORDER.BACKGROUND, 82 | BACKGROUND.TAG + this.currentBackgroundTileIndex 83 | ); 84 | 85 | /** 86 | * Since the next tile begins to go straight after the registration, the current tile can resume 87 | * to move now. 88 | */ 89 | this.nextBackgroundTile.goStraight(); 90 | this.currentBackgroundTile.resume(); 91 | 92 | this.currentBackgroundTile = this.nextBackgroundTile; 93 | 94 | }, 95 | 96 | removePreviousBackgroundTile: function() { 97 | 98 | if (this.currentBackgroundTileIndex >= 2) 99 | this.removeChildByTag(BACKGROUND.TAG + this.currentBackgroundTileIndex - 2); 100 | 101 | }, 102 | 103 | update: function() { 104 | 105 | if (this.currentBackgroundTile.isLoadNextBackgroundTile()) { 106 | 107 | this.loadNextBackgroundTile(); 108 | this.removePreviousBackgroundTile(); 109 | 110 | } 111 | 112 | }, 113 | 114 | }); 115 | 116 | Background.create = function(backgrounds) { 117 | 118 | var sg = new Background(backgrounds); 119 | if (sg) return sg; 120 | return null; 121 | 122 | }; 123 | 124 | -------------------------------------------------------------------------------- /Classes/Models/BackgroundTile.js: -------------------------------------------------------------------------------- 1 | /** 2 | * BackgroundTile is much like tile, which has less behaviors than tile. 3 | */ 4 | 5 | var BackgroundTile = cc.Layer.extend({ 6 | 7 | distance: null, 8 | isLoadedNext: false, 9 | backgroundInformation: null, 10 | backgroundPicture: null, 11 | 12 | goStraightAction: null, 13 | 14 | ctor: function(type, index, offset) { 15 | 16 | this.backgroundInformation = BackgroundInformation(type); 17 | 18 | this._super(); 19 | 20 | this.setContentSize(TILE.SIZE, TILE.SIZE); 21 | this.setAnchorPoint(cc.ccp(0.5, 0.5)); 22 | 23 | if (index == 1) { 24 | 25 | this.setPosition(cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height)); 26 | this.distance = TILE.SIZE / 2 + WIN_SIZE.height; 27 | 28 | } else { 29 | 30 | this.setPosition(cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height + TILE.SIZE / 2 + offset)); 31 | this.distance = WIN_SIZE.height + TILE.SIZE + offset; 32 | 33 | } 34 | 35 | this.backgroundPicture = cc.Sprite.create(this.backgroundInformation.src); 36 | this.backgroundPicture.setAnchorPoint(cc.ccp(0.5, 0.5)); 37 | this.backgroundPicture.setPosition(cc.ccp(0, 0)); 38 | this.addChild(this.backgroundPicture, Z_ORDER.BACKGROUND, index); 39 | 40 | return true; 41 | 42 | }, 43 | 44 | goStraight: function() { 45 | 46 | this.goStraightAction = cc.MoveTo.create( 47 | this.distance / this.backgroundInformation.velocity, 48 | cc.ccp(WIN_SIZE.width / 2, -TILE.SIZE / 2) 49 | ); 50 | this.runAction(this.goStraightAction); 51 | 52 | }, 53 | 54 | pause: function() { 55 | 56 | this.stopAction(this.goStraightAction); 57 | 58 | }, 59 | 60 | resume: function() { 61 | 62 | this.distance = this.getPosition().y + TILE.SIZE / 2; 63 | this.goStraightAction = cc.MoveTo.create( 64 | this.distance / this.backgroundInformation.velocity, 65 | cc.ccp(WIN_SIZE.width / 2, -TILE.SIZE / 2) 66 | ); 67 | this.runAction(this.goStraightAction); 68 | 69 | }, 70 | 71 | isLoadNextBackgroundTile: function() { 72 | 73 | if (WIN_SIZE.height >= this.getPosition().y + TILE.SIZE / 2 && 74 | !this.isLoadedNext) { 75 | this.isLoadedNext = true; 76 | return true; 77 | 78 | } 79 | 80 | return false; 81 | 82 | }, 83 | 84 | scale: function() { 85 | }, 86 | 87 | show: function() { 88 | }, 89 | 90 | hide: function() { 91 | }, 92 | 93 | }); 94 | 95 | BackgroundTile.create = function(type, index, offset, track) { 96 | 97 | var sg = new BackgroundTile(type, index, offset, track); 98 | if (sg) { 99 | return sg; 100 | } 101 | return null; 102 | 103 | }; 104 | -------------------------------------------------------------------------------- /Classes/Models/Character.js: -------------------------------------------------------------------------------- 1 | /* 2 | * the character sprite 3 | */ 4 | 5 | var Character = cc.Layer.extend({ 6 | 7 | currentRoute: ROUTE.MIDDLE, 8 | sources: [P_CHARACTER1, P_CHARACTER2, P_CHARACTER3], 9 | hp: null, 10 | 11 | status: CHARACTER.STATUS.RUNNING, 12 | 13 | jumpDistance: CHARACTER.JUMP_DISTANCE, 14 | landingPosition: null, 15 | 16 | moveLeftAction: null, 17 | moveRightAction: null, 18 | 19 | trophyBufferRect: null, 20 | trophyBufferX: TROPHY.GET_BUFFERX, 21 | trophyBufferY: TROPHY.GET_BUFFERY, 22 | 23 | animateId: null, 24 | 25 | characterSprite: null, 26 | hpDecreaseBg: null, 27 | hpIncreaseBg: null, 28 | 29 | ctor: function() { 30 | 31 | this._super(); 32 | this.hp = CHARACTER.MAX_HP; 33 | 34 | this.hpDecreaseBg = cc.Sprite.create(P_HP_DOWN); 35 | this.hpDecreaseBg.setIsVisible(false); 36 | this.addChild(this.hpDecreaseBg); 37 | 38 | this.characterSprite = cc.Sprite.create(this.sources[2], 39 | cc.RectMake(0, 0, CHARACTER.SPRITE_WIDTH, CHARACTER.SPRITE_HEIGHT)); 40 | this.addChild(this.characterSprite); 41 | 42 | this.setAnchorPoint(cc.ccp(0.5, 0.5)); 43 | this.setPosition(cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height / 4)); 44 | 45 | this.setTrophyBufferRect(this.trophyBufferX, this.trophyBufferY); 46 | 47 | this.runAnimate(); 48 | 49 | return true; 50 | 51 | }, 52 | 53 | runAnimate: function() { 54 | 55 | var w = CHARACTER.SPRITE_WIDTH; 56 | var h = CHARACTER.SPRITE_HEIGHT; 57 | var i = 0; 58 | 59 | var self = this; 60 | this.animateId = setInterval(function() { 61 | 62 | if (i == 8) 63 | i = 0; 64 | 65 | self.characterSprite.setTextureRect(cc.RectMake(w * i++, 0, w, h)); 66 | 67 | }, CHARACTER.SPEED); 68 | 69 | }, 70 | 71 | clearAnimate: function() { 72 | 73 | clearInterval(this.animateId); 74 | 75 | }, 76 | 77 | setTrophyBufferRect: function(bufferX, bufferY) { 78 | 79 | this.TrophyBufferRect = new Utils.Rect( 80 | bufferX, 81 | bufferY 82 | ); 83 | 84 | }, 85 | 86 | getTrophyBufferRect: function() { 87 | 88 | return this.TrophyBufferRect; 89 | 90 | }, 91 | 92 | getTrophyBuffer: function() { 93 | 94 | return { 95 | 96 | trophyBufferX: this.trophyBufferX, 97 | trophyBufferY: this.trophyBufferY, 98 | 99 | }; 100 | 101 | }, 102 | 103 | setSrc: function(index) { 104 | 105 | var characterTexture = cc.TextureCache.sharedTextureCache().addImage(this.sources[index]); 106 | this.characterSprite.setTexture(characterTexture); 107 | 108 | }, 109 | 110 | hpDecrease: function() { 111 | 112 | this.hpDecreaseBg.setPosition(cc.ccp(0, CHARACTER.SPRITE_HEIGHT / 2)); 113 | this.hpDecreaseBg.setIsVisible(true); 114 | this.hpDecreaseBg.runAction(cc.ScaleTo.create(0.5, 2)); 115 | this.hpDecreaseBg.runAction(cc.FadeOut.create(1)); 116 | 117 | this.hp--; 118 | if (this.hp >= 0) 119 | this.setSrc(this.hp); 120 | 121 | }, 122 | 123 | isDied: function() { 124 | 125 | return this.hp == -1; 126 | 127 | }, 128 | 129 | isValidToMove: function() { 130 | 131 | return true; 132 | 133 | }, 134 | 135 | moveLeft: function() { 136 | 137 | this.removeMoveAction(); 138 | this.currentRoute--; 139 | this.moveLeftAction = cc.MoveTo.create( 140 | ROUTE.WIDTH / CHARACTER.MOVE_VELOCITY, 141 | cc.ccp(this.currentRoute * ROUTE.WIDTH + TRACK.LEFT_COORDINATE, WIN_SIZE.height / 4) 142 | ); 143 | this.runAction(this.moveLeftAction); 144 | 145 | }, 146 | 147 | moveRight: function() { 148 | 149 | this.removeMoveAction(); 150 | this.currentRoute++; 151 | this.moveRightAction = cc.MoveTo.create( 152 | ROUTE.WIDTH / CHARACTER.MOVE_VELOCITY, 153 | cc.ccp(this.currentRoute * ROUTE.WIDTH + TRACK.LEFT_COORDINATE, WIN_SIZE.height / 4) 154 | ); 155 | 156 | this.runAction(this.moveRightAction); 157 | 158 | }, 159 | 160 | moveLeftMost: function() { 161 | 162 | this.currentRoute = ROUTE.LEFT; 163 | this.removeMoveAction(); 164 | this.moveLeftAction = cc.MoveTo.create( 165 | ROUTE.WIDTH * 3 / CHARACTER.MOVE_VELOCITY, 166 | cc.ccp(ROUTE.LEFT * ROUTE.WIDTH + TRACK.LEFT_COORDINATE, WIN_SIZE.height / 4) 167 | ); 168 | 169 | this.runAction(this.moveLeftAction); 170 | 171 | }, 172 | 173 | moveRightMost: function() { 174 | 175 | this.currentRoute = ROUTE.RIGHT; 176 | this.removeMoveAction(); 177 | this.moveRightAction = cc.MoveTo.create( 178 | ROUTE.WIDTH * 3 / CHARACTER.MOVE_VELOCITY, 179 | cc.ccp(ROUTE.RIGHT * ROUTE.WIDTH + TRACK.LEFT_COORDINATE, WIN_SIZE.height / 4) 180 | ); 181 | this.runAction(this.moveRightAction); 182 | 183 | }, 184 | 185 | removeMoveAction: function() { 186 | 187 | if (this.moveRightAction != null) { 188 | 189 | this.stopAction(this.moveRightAction); 190 | 191 | } 192 | 193 | if(this.moveLeftAction != null) { 194 | 195 | this.stopAction(this.moveLeftAction); 196 | 197 | } 198 | 199 | }, 200 | 201 | getCurrentRoute: function() { 202 | 203 | return this.currentRoute; 204 | 205 | }, 206 | 207 | changeStatus: function(status) { 208 | 209 | this.status = status; 210 | 211 | }, 212 | 213 | isJumping: function() { 214 | 215 | return this.status == CHARACTER.STATUS.JUMPING; 216 | 217 | }, 218 | 219 | isRunning: function() { 220 | 221 | return this.status == CHARACTER.STATUS.RUNNING; 222 | 223 | }, 224 | 225 | isAboutToJump: function() { 226 | 227 | return this.status == CHARACTER.STATUS.ABOUT_TO_JUMP; 228 | 229 | }, 230 | 231 | //character's position relative to the position of tile(tile's center) 232 | jump: function(currentTile) { 233 | 234 | if (this.isAboutToJump()) { 235 | 236 | this.changeStatus(CHARACTER.STATUS.JUMPING); 237 | var distance = this.getPosition().y - (currentTile.getPosition().y - TILE.SIZE / 2); 238 | this.landingPosition = distance + this.jumpDistance; 239 | 240 | if (this.landingPosition > TILE.SIZE) 241 | this.landingPosition -= TILE.SIZE; 242 | 243 | //Enlarge 244 | this.characterSprite.runAction(cc.Sequence.create( 245 | cc.ScaleTo.create( (this.jumpDistance / TILE.VELOCITY) / 2 ,2), 246 | cc.ScaleTo.create( (this.jumpDistance / TILE.VELOCITY) / 2 ,1) 247 | )); 248 | 249 | return true; 250 | 251 | } 252 | 253 | return false; 254 | 255 | }, 256 | 257 | landDetection: function(currentTile) { 258 | 259 | if (this.isJumping()) { 260 | 261 | var jumpingPosition = this.getPosition().y - (currentTile.getPosition().y - TILE.SIZE / 2); 262 | var landingRange = new Utils.Range( 263 | this.landingPosition - CHARACTER.LAND_BUFFER, 264 | this.landingPosition + CHARACTER.LAND_BUFFER 265 | ); 266 | 267 | if (landingRange.isContain(jumpingPosition)) { 268 | this.changeStatus(CHARACTER.STATUS.RUNNING); 269 | return true; 270 | } 271 | 272 | } 273 | 274 | return false; 275 | 276 | }, 277 | 278 | }); 279 | 280 | Character.create = function() { 281 | 282 | var sg = new Character(); 283 | if (sg) { 284 | return sg; 285 | } 286 | return null; 287 | 288 | }; 289 | -------------------------------------------------------------------------------- /Classes/Models/Property.js: -------------------------------------------------------------------------------- 1 | /* 2 | * the Property sprite 3 | */ 4 | 5 | var Property = cc.Layer.extend({ 6 | 7 | position: null, 8 | propertyInformation: null, 9 | distance: null, 10 | route: 0, 11 | goStraightAction: null, 12 | 13 | propertySprite: null, 14 | propertyBgSprite: null, 15 | 16 | ctor: function(route, type) { 17 | 18 | this.route = route; 19 | this.propertyInformation = PropertiesInformation(type); 20 | this._super(); 21 | 22 | this.propertySprite = cc.Sprite.create(this.propertyInformation.src); 23 | this.addChild(this.propertySprite); 24 | 25 | this.propertyBgSprite = cc.Sprite.create(this.propertyInformation.bgSrc); 26 | this.propertyBgSprite.setIsVisible(false); 27 | this.addChild(this.propertyBgSprite); 28 | 29 | this.setAnchorPoint(cc.ccp(0, 0)); 30 | this.setPosition(this.generatePosition()); 31 | 32 | this.distance = WIN_SIZE.height + TILE.SIZE; 33 | 34 | }, 35 | 36 | generatePosition: function() { 37 | 38 | return cc.ccp( 39 | -WIN_SIZE.width / 2 + TRACK.LEFT_COORDINATE + this.route * ROUTE.WIDTH, 40 | -TILE.SIZE / 2 + TILE.SIZE / 4 41 | ); 42 | 43 | }, 44 | 45 | isGot: function(character, tile) { 46 | 47 | var characterX = character.getCurrentRoute(); 48 | var characterY = character.getPosition().y; 49 | 50 | if (characterX != this.route) 51 | return false; 52 | 53 | var distance = tile.getPosition().y + this.getPosition().y - characterY; 54 | if (new Utils.Range(-TROPHY.GET_BUFFERY, TROPHY.GET_BUFFERY).isContain(distance) && 55 | character.isRunning()) 56 | return true; 57 | 58 | }, 59 | 60 | activate: function() { 61 | 62 | this.propertySprite.setIsVisible(false); 63 | this.propertyBgSprite.setPosition(cc.ccp(0, 2 * CHARACTER.SPRITE_HEIGHT)); 64 | this.propertyBgSprite.setIsVisible(true); 65 | this.propertyBgSprite.runAction(cc.ScaleTo.create(0.5, 3)); 66 | this.propertyBgSprite.runAction(cc.FadeOut.create(1)); 67 | 68 | }, 69 | 70 | decorate: function(type) { 71 | 72 | return this.propertyInformation.decorate(type); 73 | 74 | }, 75 | 76 | updateLife: function() { 77 | 78 | this.propertyInformation.life--; 79 | 80 | }, 81 | 82 | }); 83 | 84 | Property.create = function(route, type) { 85 | 86 | var sg = new Property(route, type); 87 | 88 | if (sg) return sg; 89 | return null; 90 | 91 | }; 92 | -------------------------------------------------------------------------------- /Classes/Models/Tile.js: -------------------------------------------------------------------------------- 1 | /* 2 | * the Tile sprite 3 | */ 4 | 5 | var Tile = cc.Layer.extend({ 6 | 7 | distance: null, 8 | turnDirection: ACTION.GO_STRAIGHT, 9 | tileInformation: null, 10 | isAboutToTurn: false, 11 | isLoadedNext: false, 12 | 13 | goStraightAction: null, 14 | 15 | tileBackground: null, 16 | trophies: null, 17 | property: null, 18 | 19 | ctor: function(type, index, offset, track) { 20 | 21 | this.tileInformation = TileInformation(type); 22 | this._super(); 23 | 24 | this.setContentSize(TILE.SIZE, TILE.SIZE); 25 | this.setAnchorPoint(cc.ccp(0.5, 0.5)); 26 | 27 | if (index == 1) { 28 | 29 | this.setPosition(cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height)); 30 | this.distance = TILE.SIZE / 2 + WIN_SIZE.height; 31 | 32 | } else { 33 | 34 | this.setPosition(cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height + TILE.SIZE / 2 + offset)); 35 | this.distance = WIN_SIZE.height + TILE.SIZE + offset; 36 | 37 | this.trophies = Trophies.create(this.generateTrophies(), TrackInformation.basicTrophyType); 38 | this.addChild(this.trophies, Z_ORDER.TROPHIES, TROPHY.TAG_OFFSET + index); 39 | 40 | this.property = PropertiesController.generate(this.trophies); 41 | if (this.property) 42 | this.addChild(this.property, Z_ORDER.PROPERTY, PROPERTY.TAG_OFFSET + index); 43 | 44 | 45 | } 46 | 47 | this.tileBackground = cc.Sprite.create(this.tileInformation.src); 48 | this.tileBackground.setAnchorPoint(cc.ccp(0.5, 0.5)); 49 | this.tileBackground.setPosition(cc.ccp(0, 0)); 50 | this.addChild(this.tileBackground, Z_ORDER.TILE, index); 51 | 52 | track.addChild(this, Z_ORDER.TILE, index); 53 | 54 | return true; 55 | 56 | }, 57 | 58 | goStraight: function() { 59 | 60 | this.goStraightAction = cc.MoveTo.create( 61 | this.distance / LevelController.velocity, 62 | cc.ccp(WIN_SIZE.width / 2, -TILE.SIZE / 2) 63 | ); 64 | this.runAction(this.goStraightAction); 65 | 66 | }, 67 | 68 | pause: function() { 69 | 70 | this.stopAction(this.goStraightAction); 71 | 72 | }, 73 | 74 | resume: function() { 75 | 76 | this.distance = this.getPosition().y + TILE.SIZE / 2; 77 | this.goStraightAction = cc.MoveTo.create( 78 | this.distance / LevelController.velocity, 79 | cc.ccp(WIN_SIZE.width / 2, -TILE.SIZE / 2) 80 | ); 81 | this.runAction(this.goStraightAction); 82 | 83 | }, 84 | 85 | isLoadNextTile: function() { 86 | 87 | if (WIN_SIZE.height >= this.getPosition().y + TILE.SIZE / 2 && 88 | !this.isLoadedNext) { 89 | this.isLoadedNext = true; 90 | return true; 91 | 92 | } 93 | 94 | return false; 95 | 96 | }, 97 | 98 | isGameOver: function(character) { 99 | 100 | return !this.tileInformation.isValid(this, character); 101 | 102 | }, 103 | 104 | isBounded: function(character) { 105 | 106 | return this.tileInformation.isBounded(this, character); 107 | 108 | }, 109 | 110 | /* 111 | * return the tile is valid to turn or not 112 | * the requirement are 113 | * 114 | * 1.is turnable 115 | * 2.turnDirection == ACTION.GO_STRAIGHT 116 | * 3.character is in trun buffer 4.is about to turn 117 | */ 118 | isValidToRotate: function(turnDirection, character) { 119 | 120 | var distance = character.getPosition().y - this.getPosition().y; 121 | 122 | if (this.tileInformation.isTurnable() && 123 | this.turnDirection == ACTION.GO_STRAIGHT && 124 | TILE.TURN_BUFFER.isContain(distance) && 125 | this.isAboutToTurn) { 126 | 127 | this.turnDirection = turnDirection; 128 | this.isAboutToTurn = false; 129 | return true; 130 | 131 | } 132 | 133 | return false; 134 | 135 | }, 136 | 137 | aboutToTurn: function() { 138 | 139 | this.isAboutToTurn = true; 140 | 141 | }, 142 | 143 | turnLeft: function() { 144 | 145 | // this.distance = this.getPosition().y + TILE.SIZE; 146 | this.runAction(cc.RotateTo.create(0.1, 90)); 147 | 148 | }, 149 | 150 | turnRight: function() { 151 | 152 | // this.distance = this.getPosition().y + TILE.SIZE; 153 | this.runAction(cc.RotateTo.create(0.1, -90)); 154 | 155 | }, 156 | 157 | scale: function() { 158 | }, 159 | 160 | show: function() { 161 | }, 162 | 163 | hide: function() { 164 | }, 165 | 166 | generateTrophies: function() { 167 | 168 | return this.tileInformation.generateTrophies(); 169 | 170 | }, 171 | 172 | getTrophy: function(character) { 173 | 174 | if (this.trophies != null) 175 | return this.trophies.getTrophy(character, this); 176 | 177 | }, 178 | 179 | getProperty: function(character) { 180 | 181 | if (this.property != null && this.property.isGot(character, this)) { 182 | 183 | PropertiesController.add(this.property); 184 | 185 | this.property.activate(); 186 | 187 | var self = this; 188 | setTimeout((function(property) { 189 | return function() { 190 | self.removeChild(property); 191 | }; 192 | })(this.property), 1000); 193 | 194 | return true; 195 | 196 | } 197 | 198 | return false; 199 | 200 | }, 201 | 202 | 203 | }); 204 | 205 | Tile.create = function(type, index, offset, track) { 206 | 207 | var sg = new Tile(type, index, offset, track); 208 | if (sg) { 209 | return sg; 210 | } 211 | return null; 212 | 213 | }; 214 | -------------------------------------------------------------------------------- /Classes/Models/Track.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The main game layer including: Tile, character, trophies. 3 | */ 4 | 5 | var Track = cc.Layer.extend({ 6 | 7 | tiles: null, 8 | 9 | character: null, 10 | turnDirection: null, 11 | 12 | currentTile: null, 13 | nextTile: null, 14 | currentTileIndex: null, 15 | currentTheme: THEMES.THEME_1.NAME, 16 | 17 | trophyType: TrackInformation.basicTrophyType, 18 | 19 | scoreLayer: null, 20 | pauseLayer: null, 21 | 22 | ctor: function() { 23 | 24 | this._super(); 25 | 26 | RESET(); 27 | 28 | this.initTiles(); 29 | this.loadFirstTile(); 30 | this.loadCharacter(); 31 | this.loadScoreLayer(); 32 | this.loadPauseLayer(); 33 | this.loadEnvironment(); 34 | 35 | this.setIsTouchEnabled(true); 36 | this.setIsKeypadEnabled(true); 37 | this.scheduleUpdate(); 38 | 39 | return true; 40 | 41 | }, 42 | 43 | initTiles: function() { 44 | 45 | this.tiles = [1, 1]; 46 | this.currentTileIndex = 1; 47 | LevelController.generateTiles(18, this.currentTileIndex, this.tiles); 48 | 49 | }, 50 | 51 | loadFirstTile: function() { 52 | 53 | this.currentTile = Tile.create(this.tiles[0], this.currentTileIndex, TILE.VELOCITY, this); 54 | this.currentTile.goStraight(); 55 | 56 | }, 57 | 58 | loadNextTile: function() { 59 | 60 | this.currentTileIndex++; 61 | 62 | /** 63 | * When loading the next tile, the current still moves. The triky thing that makes the problem 64 | * difficult is that in that little period of time, the distance that the current tile travels 65 | * is unpredictable, which leads a gap between the current tile and the next tile. The way to 66 | * solve the problem is that pause the movement of the current tile while the next tile is 67 | * loading. Then after the next tile is successfully registered to the trackLayer, the current 68 | * tile resumes to straight. 69 | */ 70 | this.currentTile.pause(); 71 | 72 | /** 73 | * Calculates the offset between the current tile and the window height. After the current tile 74 | * travels under the buffer, the next tile is loaded. But it would be perfect to load the next 75 | * tile right above the current tile. So the offset is calculated. 76 | */ 77 | var offset = this.currentTile.getPosition().y + TILE.SIZE / 2 - WIN_SIZE.height; 78 | this.nextTile = Tile.create(this.tiles[this.currentTileIndex], this.currentTileIndex, offset, this); 79 | 80 | /** 81 | * Since the next tile begins to go straight after the registration, the current tile can resume 82 | * to move now. 83 | */ 84 | this.nextTile.goStraight(); 85 | this.currentTile.resume(); 86 | 87 | this.currentTheme = THEMES.getThemeByTileIndex(this.tiles[this.currentTileIndex]); 88 | 89 | LevelController.updateVelocity(); 90 | LevelController.generateTiles(TILE.LOAD_DURATION, this.currentTileIndex, this.tiles); 91 | 92 | PropertiesController.updatePropertiesLife(this.trophyType, this.character); 93 | // BackgroundController.changeBackgrounds(this.currentTheme, this); 94 | 95 | }, 96 | 97 | removePreviousTile: function() { 98 | 99 | if (this.currentTileIndex >= 3) 100 | this.removeChildByTag(this.currentTileIndex - 2); 101 | 102 | }, 103 | 104 | loadCharacter: function() { 105 | 106 | this.character = Character.create(); 107 | this.addChild(this.character, Z_ORDER.CHARACTER, CHARACTER.TAG); 108 | this.character.setPosition(cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height / 4)); 109 | 110 | }, 111 | 112 | loadScoreLayer: function() { 113 | 114 | this.scoreLayer = ScoreLayer.create(); 115 | this.addChild(this.scoreLayer, Z_ORDER.SCORE_LAYER); 116 | 117 | this.scoreLayer.generatePanel([{ 118 | type: 'trophies', 119 | position: cc.ccp(LOCATION.GAME_LAYER.TROPHIES.X, LOCATION.GAME_LAYER.TROPHIES.Y), 120 | }, { 121 | type: 'distance', 122 | position: cc.ccp(LOCATION.GAME_LAYER.DISTANCE.X, LOCATION.GAME_LAYER.DISTANCE.Y), 123 | }]); 124 | 125 | }, 126 | 127 | loadPauseLayer: function() { 128 | 129 | this.pauseLayer = PauseLayer.create(this.character); 130 | this.pauseLayer.setPosition(cc.ccp(0, 0)); 131 | this.addChild(this.pauseLayer, Z_ORDER.PAUSE_BUTTON); 132 | 133 | }, 134 | 135 | loadEnvironment: function() { 136 | 137 | var footprint = Footprints.create(); 138 | var shadow = JumpShadow.create(); 139 | var lightCircle = LightCircle.create(); 140 | var sky = Sky.create(); 141 | 142 | EnvironmentsController.addTo(footprint, this); 143 | EnvironmentsController.addTo(shadow, this); 144 | EnvironmentsController.addTo(lightCircle, this); 145 | EnvironmentsController.addTo(sky, this); 146 | 147 | }, 148 | 149 | update: function() { 150 | 151 | if (this.isTimeToChangeCurrentTile()) 152 | this.changeCurrentTile(); 153 | 154 | if (this.currentTile.isValidToRotate(this.turnDirection, this.character)) 155 | this.turnAction(); 156 | 157 | if (this.isGameOver() != null) 158 | this.gameOver(this.isGameOver()); 159 | 160 | if (this.currentTile.isLoadNextTile()) { 161 | 162 | this.loadNextTile(); 163 | this.removePreviousTile(); 164 | 165 | } 166 | 167 | var isAboutToJump = this.character.jump(this.currentTile); 168 | var isLanded = this.character.landDetection(this.currentTile); 169 | 170 | this.scoreLayer.updateScores(this.currentTile.getTrophy(this.character)); 171 | 172 | var isGotProperty = this.currentTile.getProperty(this.character); 173 | PropertiesController.updateActiveProperties(this.trophyType, this.character); 174 | 175 | TrophiesActionsController.moveToCharacter(this.character, this.currentTile); 176 | EnvironmentsController.evolve(this.character, { 177 | 178 | theme : this.currentTheme, 179 | isGotProperty : isGotProperty, 180 | isLanded : isLanded, 181 | isAboutToJump : isAboutToJump, 182 | 183 | }); 184 | 185 | }, 186 | 187 | isTimeToChangeCurrentTile: function() { 188 | 189 | if (this.nextTile != null && 190 | this.nextTile.getPosition().y - TILE.SIZE / 2 < this.character.getPosition().y) 191 | return true; 192 | return false; 193 | 194 | }, 195 | 196 | changeCurrentTile: function() { 197 | 198 | this.currentTile = this.nextTile; 199 | this.nextTile = null; 200 | 201 | TrophiesActionsController.changeCurrentTrophies(this.currentTile.trophies); 202 | 203 | }, 204 | 205 | turnAction: function() { 206 | 207 | if (this.turnDirection == ACTION.TURN_LEFT) 208 | this.currentTile.turnLeft(); 209 | if (this.turnDirection == ACTION.TURN_RIGHT) 210 | this.currentTile.turnRight(); 211 | 212 | }, 213 | 214 | isGameOver: function() { 215 | 216 | var gameOverType = null; 217 | 218 | if (this.currentTile.isGameOver(this.character)) 219 | gameOverType = GAMEOVER.TYPE.CROSS_BORDER; 220 | else if (this.character.isDied()) 221 | gameOverType = GAMEOVER.TYPE.NO_HP; 222 | 223 | return gameOverType; 224 | 225 | }, 226 | 227 | gameOver: function(type) { 228 | 229 | this.removeChild(this.scoreLayer); 230 | 231 | var scene = cc.Scene.create(); 232 | scene.addChild(GameOver.create(this.scoreLayer, type)); 233 | cc.Director.sharedDirector().replaceScene(scene); 234 | 235 | }, 236 | 237 | /*ccTouchesEnded: function(touches, event) { 238 | 239 | var distance = this.character.getPosition().y - this.currentTile.getPosition().y; 240 | var actionPermissions = this.currentTile.isBounded(this.character); 241 | 242 | if (WIN_SIZE.height * 5 / 6 < touches[0].locationInView().y && 243 | touches[0].locationInView().y < WIN_SIZE.height) 244 | this.character.jump(this.currentTile); 245 | else if (0 < touches[0].locationInView().x && 246 | touches[0].locationInView().x < WIN_SIZE.width / 2) 247 | this.keyLeftHandler(distance, actionPermissions); 248 | else if (WIN_SIZE.width / 2 < touches[0].locationInView().x && 249 | touches[0].locationInView().x < WIN_SIZE.width) 250 | this.keyRightHandler(distance, actionPermissions); 251 | 252 | 253 | },*/ 254 | 255 | keyDown: function(key) { 256 | 257 | KEYS = []; 258 | KEYS[key] = true; 259 | 260 | }, 261 | 262 | keyUp: function() { 263 | 264 | var distance = this.character.getPosition().y - this.currentTile.getPosition().y; 265 | var actionPermissions = this.currentTile.isBounded(this.character); 266 | 267 | //with the Correct operation, set the turnDirection ACTION_TURN_LEFT or ACTION_TURN_RIGHT 268 | //with the Wrong operation, hp decrease 269 | if (KEYS[cc.KEY.left]) 270 | this.keyLeftHandler(distance, actionPermissions); 271 | if (KEYS[cc.KEY.right]) 272 | this.keyRightHandler(distance, actionPermissions); 273 | if (KEYS[cc.KEY.up]) 274 | this.keyUpHandler(); 275 | 276 | //if press 'a', move left, 277 | //if press 'd', move right 278 | if (KEYS[cc.KEY.a]) { 279 | if ((actionPermissions.ACTION_MOVE_LEFT && this.character.isRunning()) || 280 | (actionPermissions.ACTION_JUMP_LEFT && this.character.isJumping())) 281 | this.character.moveLeft(); 282 | } 283 | 284 | if (KEYS[cc.KEY.d]) { 285 | if ((actionPermissions.ACTION_MOVE_RIGHT && this.character.isRunning()) || 286 | (actionPermissions.ACTION_JUMP_RIGHT && this.character.isJumping())) 287 | this.character.moveRight(); 288 | } 289 | 290 | }, 291 | 292 | keyLeftHandler: function(distance, actionPermissions) { 293 | 294 | // If the tile is straight, then there is no need for it to have a 295 | // turn buffer. The same as the keyRightHandler. 296 | if (this.currentTile.tileInformation.isTurnable() && 297 | CHARACTER.TURN_BUFFER.isContain(distance)) { 298 | 299 | this.currentTile.aboutToTurn(); 300 | this.turnDirection = ACTION.TURN_LEFT; 301 | 302 | } else { 303 | 304 | this.character.hpDecrease(); 305 | if (actionPermissions.ACTION_MOVE_LEFT) 306 | this.character.moveLeftMost(); 307 | 308 | } 309 | 310 | }, 311 | 312 | keyRightHandler: function(distance, actionPermissions) { 313 | 314 | if (this.currentTile.tileInformation.isTurnable() && 315 | CHARACTER.TURN_BUFFER.isContain(distance)) { 316 | 317 | this.currentTile.aboutToTurn(); 318 | this.turnDirection = ACTION.TURN_RIGHT; 319 | 320 | } else { 321 | 322 | this.character.hpDecrease(); 323 | if (actionPermissions.ACTION_MOVE_RIGHT) 324 | this.character.moveRightMost(); 325 | 326 | } 327 | 328 | }, 329 | 330 | keyUpHandler: function() { 331 | 332 | if (this.character.isRunning()) 333 | this.character.changeStatus(CHARACTER.STATUS.ABOUT_TO_JUMP); 334 | 335 | }, 336 | 337 | }); 338 | 339 | Track.create = function() { 340 | 341 | var sg = new Track(); 342 | if (sg && sg.init()) { 343 | return sg; 344 | } 345 | return null; 346 | 347 | }; 348 | 349 | Track.scene = function() { 350 | 351 | var scene = cc.Scene.create(); 352 | var layer = Track.create(); 353 | scene.addChild(layer, 1, 1); 354 | return scene; 355 | 356 | }; 357 | -------------------------------------------------------------------------------- /Classes/Models/Trophies.js: -------------------------------------------------------------------------------- 1 | /** 2 | * the Trophies layer 3 | */ 4 | 5 | var Trophies = cc.Layer.extend({ 6 | 7 | route: null, 8 | trophies: null, 9 | goStraightAction: null, 10 | 11 | ctor: function(trophies, trophyType) { 12 | 13 | this._super(); 14 | this.route = trophies.route; 15 | this.trophies = trophies.pos; 16 | 17 | this.trophieSprites = []; 18 | 19 | this.setContentSize(WIN_SIZE.width, TILE.SIZE); 20 | this.setAnchorPoint(cc.ccp(0, 0)); 21 | this.setPosition(cc.ccp(-WIN_SIZE.width / 2, -TILE.SIZE / 2)); 22 | 23 | for (var i = 0; i < this.trophies.length - 1; ++i) { 24 | 25 | var trophySprite = Trophy.create(trophyType, this.trophies[i]); 26 | this.addChild(trophySprite, Z_ORDER.TROPHY, i); 27 | 28 | } 29 | 30 | return true; 31 | 32 | }, 33 | 34 | getCurrentRoute: function() { 35 | 36 | return this.route; 37 | 38 | }, 39 | 40 | getTrophy: function(character, tile) { 41 | 42 | var characterY = character.getPosition().y + CHARACTER.SPRITE_HEIGHT / 2; 43 | var characterX = character.getCurrentRoute(); 44 | 45 | var offset = TILE.SIZE / ( MAX_TROPHY_NUM + 1 ); 46 | 47 | var sprites = this.getChildren(); 48 | 49 | if (null != sprites) { 50 | 51 | for (var i = 0; i < sprites.length; ++i) { 52 | 53 | var trophyY = tile.getPosition().y - TILE.SIZE / 2 + sprites[i].getPosition().y; 54 | 55 | var distanceY = characterY - trophyY; 56 | var distanceX = characterX - this.route; 57 | 58 | if (character.getTrophyBufferRect().isContain(distanceX, distanceY) && 59 | character.isRunning() && 60 | !sprites[i].isGot) { 61 | 62 | TrophiesActionsController.add(sprites[i]); 63 | sprites[i].isGot = true; 64 | 65 | return sprites[i]; 66 | 67 | } 68 | 69 | } 70 | 71 | } 72 | 73 | return 0; 74 | 75 | }, 76 | 77 | }); 78 | 79 | Trophies.create = function(trophies, trophyType) { 80 | 81 | var sg = new Trophies(trophies, trophyType); 82 | 83 | if (sg) return sg; 84 | return null; 85 | 86 | }; 87 | -------------------------------------------------------------------------------- /Classes/Models/Trophy.js: -------------------------------------------------------------------------------- 1 | /* 2 | * the trophy sprite 3 | */ 4 | 5 | var Trophy = cc.Sprite.extend({ 6 | 7 | position: null, 8 | trophyInformation: null, 9 | 10 | ctor: function(type, pos) { 11 | 12 | //this.trophyInformation = TrophyInformation(type); //get trophy information according to type 13 | this.trophyInformation = type; 14 | this._super(); 15 | 16 | this['isGot'] = false; 17 | this.initWithFile(this.trophyInformation.src); 18 | this.setAnchorPoint(cc.ccp(0.5, 0.5)); 19 | this.setPosition(pos); 20 | //this.setScale(SCALE_RATE); 21 | 22 | this.showTwink(); 23 | 24 | }, 25 | 26 | getValue: function() { 27 | 28 | return this.trophyInformation.value; 29 | 30 | }, 31 | 32 | showTwink: function() { 33 | 34 | var characterTexture = cc.TextureCache.sharedTextureCache().addImage(this.trophyInformation.src); 35 | var w = TROPHY.SPRITE_WIDTH; 36 | var h = TROPHY.SPRITE_HEIGHT; 37 | 38 | var animation = cc.Animation.create(); 39 | animation.addFrameWithTexture(characterTexture, cc.RectMake(0, 0, w, h)); 40 | animation.addFrameWithTexture(characterTexture, cc.RectMake(w, 0, w, h)); 41 | animation.addFrameWithTexture(characterTexture, cc.RectMake(w * 2, 0, w, h)); 42 | animation.addFrameWithTexture(characterTexture, cc.RectMake(w * 3, 0, w, h)); 43 | animation.addFrameWithTexture(characterTexture, cc.RectMake(w * 4, 0, w, h)); 44 | animation.addFrameWithTexture(characterTexture, cc.RectMake(w * 5, 0, w, h)); 45 | animation.addFrameWithTexture(characterTexture, cc.RectMake(w * 6, 0, w, h)); 46 | 47 | this.action = cc.Animate.create(0.5, animation, true); 48 | this.runAction(cc.RepeatForever.create(this.action)); 49 | 50 | } 51 | 52 | }); 53 | 54 | Trophy.create = function(type, pos) { 55 | 56 | var sg = new Trophy(type, pos); 57 | 58 | if (sg) return sg; 59 | return null; 60 | 61 | }; 62 | -------------------------------------------------------------------------------- /Classes/Panels/PauseLayer.js: -------------------------------------------------------------------------------- 1 | 2 | var PauseLayer = cc.Layer.extend({ 3 | 4 | pauseLayer: null, 5 | character: null, 6 | 7 | ctor: function(character) { 8 | 9 | this._super(); 10 | 11 | this.character = character; 12 | this.loadButton(); 13 | this.loadMenu(); 14 | 15 | }, 16 | 17 | onPause: function() { 18 | 19 | this.character.clearAnimate(); 20 | cc.Director.sharedDirector().pause(); 21 | this.menu.setIsVisible(true); 22 | 23 | }, 24 | 25 | loadButton: function() { 26 | 27 | var pauseNormal = cc.Sprite.create(P_PAUSE); 28 | var pauseSelected = cc.Sprite.create(P_PAUSE); 29 | var pauseDisabled = cc.Sprite.create(P_PAUSE); 30 | 31 | 32 | var goToPause = cc.MenuItemSprite.create( 33 | pauseNormal, 34 | pauseSelected, 35 | pauseDisabled, 36 | this, 37 | this.onPause 38 | ); 39 | 40 | this.menu = cc.Menu.create(goToPause); 41 | this.menu.setPosition(cc.ccp(LOCATION.PAUSE.BUTTON.X, LOCATION.PAUSE.BUTTON.Y)); 42 | this.addChild(this.menu, 500, 2); 43 | 44 | }, 45 | 46 | onResumeGame: function() { 47 | 48 | this.character.runAnimate(); 49 | cc.Director.sharedDirector().resume(); 50 | this.menu.setIsVisible(false); 51 | 52 | }, 53 | 54 | onNewGame: function() { 55 | 56 | var scene = cc.Scene.create(); 57 | scene.addChild(Track.create()); 58 | cc.Director.sharedDirector().replaceScene(scene); 59 | cc.Director.sharedDirector().resume(); 60 | 61 | }, 62 | 63 | onMainMenu: function(trophyType, character) { 64 | 65 | LevelController.reset(); 66 | EnvironmentsController.reset(); 67 | PropertiesController.updatePropertiesLife(this.trophyType, this.character, true); 68 | TrophiesActionsController.reset(); 69 | 70 | var scene = cc.Scene.create(); 71 | scene.addChild(MainMenu.create()); 72 | cc.Director.sharedDirector().replaceScene(scene); 73 | cc.Director.sharedDirector().resume(); 74 | 75 | }, 76 | 77 | loadMenu: function() { 78 | 79 | var resumeGameNormal = cc.Sprite.create(P_MENU, cc.RectMake(600, 0, 200, 50)); 80 | var resumeGameSelected = cc.Sprite.create(P_MENU, cc.RectMake(600, 50, 200, 50)); 81 | var resumeGameDisabled = cc.Sprite.create(P_MENU, cc.RectMake(600, 50 * 2, 200, 50)); 82 | 83 | var gameSettingsNormal = cc.Sprite.create(P_MENU, cc.RectMake(200, 0, 200, 50)); 84 | var gameSettingsSelected = cc.Sprite.create(P_MENU, cc.RectMake(200, 50, 200, 50)); 85 | var gameSettingsDisabled = cc.Sprite.create(P_MENU, cc.RectMake(200, 50 * 2, 200, 50)); 86 | 87 | var goToMainMenuNormal = cc.Sprite.create(P_MENU, cc.RectMake(800, 0, 200, 50)); 88 | var goToMainMenuSelected = cc.Sprite.create(P_MENU, cc.RectMake(800, 50, 200, 50)); 89 | var goToMainMenuDisabled = cc.Sprite.create(P_MENU, cc.RectMake(800, 50 * 2, 200, 50)); 90 | 91 | var resumeGame = cc.MenuItemSprite.create( 92 | resumeGameNormal, 93 | resumeGameSelected, 94 | resumeGameDisabled, 95 | this, 96 | this.onResumeGame 97 | ); 98 | var gameSettings = cc.MenuItemSprite.create( 99 | gameSettingsNormal, 100 | gameSettingsSelected, 101 | gameSettingsDisabled, 102 | this, 103 | this.onSettings 104 | ); 105 | var goToMainMenu = cc.MenuItemSprite.create( 106 | goToMainMenuNormal, 107 | goToMainMenuSelected, 108 | goToMainMenuDisabled, 109 | this, 110 | this.onMainMenu 111 | ); 112 | 113 | this.menu = cc.Menu.create(resumeGame, gameSettings, goToMainMenu); 114 | this.menu.alignItemsVerticallyWithPadding(10); 115 | this.menu.setPosition(cc.ccp(LOCATION.PAUSE.LAYER.X, LOCATION.PAUSE.LAYER.Y)); 116 | this.menu.setIsVisible(false); 117 | this.addChild(this.menu, 500, 2); 118 | 119 | }, 120 | 121 | }); 122 | 123 | PauseLayer.create = function(character) { 124 | 125 | var sg = new PauseLayer(character); 126 | 127 | if (sg) return sg; 128 | return null; 129 | 130 | }; 131 | -------------------------------------------------------------------------------- /Classes/Panels/ScoreItem.js: -------------------------------------------------------------------------------- 1 | /* 2 | * the score layer 3 | */ 4 | 5 | var ScoreItem = cc.Layer.extend({ 6 | 7 | scoreType: null, 8 | value: 0, 9 | 10 | digits: null, 11 | 12 | ctor: function(type, value) { 13 | 14 | this.scoreType = cc.Sprite.create(type); 15 | this.scoreType.setAnchorPoint(cc.ccp(0, 0)); 16 | this.scoreType.setPosition(cc.ccp(0, 0)); 17 | //this.scoreType.setScale(SCALE_RATE); 18 | this.addChild(this.scoreType, 900); 19 | 20 | this.digits = new Array(MAX_SCORE_DIGITS_NUM); 21 | this.initNumberSprites(); 22 | 23 | }, 24 | 25 | initNumberSprites: function() { 26 | 27 | for (var n = 0; n < MAX_SCORE_DIGITS_NUM; ++n) { 28 | 29 | var numberSprites = []; 30 | 31 | for (var i = 0; i < 10; ++i) { 32 | 33 | var sprite = cc.Sprite.create( 34 | P_NUMBERS, 35 | cc.RectMake(NUMBER_SPRITE_WIDTH * i, 0, NUMBER_SPRITE_WIDTH, NUMBER_SPRITE_HEIGHT) 36 | ); 37 | 38 | sprite.setAnchorPoint(cc.ccp(0, 0)); 39 | //sprite.setScale(SCALE_RATE); 40 | numberSprites.push(sprite); 41 | this.addChild(sprite, 100000000); 42 | 43 | } 44 | 45 | this.digits[n] = numberSprites; 46 | 47 | } 48 | 49 | this.arrangeNumberSprites(); 50 | 51 | }, 52 | 53 | setNumerSpritesInvisible: function() { 54 | 55 | this.digits.map(function(digit) { 56 | digit.map(function(num) { 57 | num.setIsVisible(false); 58 | }); 59 | }); 60 | 61 | }, 62 | 63 | arrangeNumberSprites: function() { 64 | 65 | var typeWidth = this.scoreType.getContentSize().width; 66 | var numString = this.value + ''; 67 | this.setNumerSpritesInvisible(); 68 | 69 | 70 | for(var i = 0; i < numString.length; ++i) { 71 | 72 | var numSprite = this.digits[i][numString[i]]; 73 | numSprite.setIsVisible(true); 74 | numSprite.setPosition(cc.ccp(typeWidth + i * (NUMBER_SPRITE_WIDTH - 7), 5)); 75 | 76 | } 77 | 78 | }, 79 | 80 | updateValue: function(updateValue) { 81 | 82 | this.value = updateValue(this.value); 83 | this.arrangeNumberSprites(); 84 | 85 | }, 86 | 87 | getValue: function() { 88 | 89 | return this.value; 90 | 91 | }, 92 | 93 | }); 94 | 95 | ScoreItem.create = function(type, value) { 96 | 97 | var sg = new ScoreItem(type, value); 98 | 99 | if (sg) return sg; 100 | return null; 101 | 102 | }; 103 | -------------------------------------------------------------------------------- /Classes/Panels/ScoreLayer.js: -------------------------------------------------------------------------------- 1 | 2 | var ScoreLayer = cc.Layer.extend({ 3 | 4 | trophies: null, 5 | distance: null, 6 | score: null, 7 | 8 | ctor: function() { 9 | 10 | this.initPanelItems(); 11 | 12 | return this; 13 | 14 | }, 15 | 16 | initPanelItems: function() { 17 | 18 | this.trophies = ScoreItem.create(P_TROPHIES, 0); 19 | this.addChild(this.trophies, 100000000); 20 | 21 | this.distance = ScoreItem.create(P_DISTANCE, 0); 22 | this.addChild(this.distance, 100000000); 23 | 24 | this.score = ScoreItem.create(P_SCORE, 0); 25 | this.addChild(this.score, 100000000); 26 | 27 | this.setItemsInvisiable(); 28 | 29 | }, 30 | 31 | setItemsInvisiable: function(){ 32 | 33 | this.trophies.setIsVisible(false); 34 | this.distance.setIsVisible(false); 35 | this.score.setIsVisible(false); 36 | 37 | }, 38 | 39 | generatePanel: function(items) { 40 | 41 | this.setItemsInvisiable(); 42 | for (var i = 0; i < items.length; ++i) { 43 | 44 | switch (items[i].type) { 45 | 46 | case 'trophies': 47 | this.trophies.setIsVisible(true); 48 | this.trophies.setPosition(items[i].position); 49 | break; 50 | case 'distance': 51 | this.distance.setIsVisible(true); 52 | this.distance.setPosition(items[i].position); 53 | break; 54 | case 'score': 55 | this.score.setIsVisible(true); 56 | this.score.setPosition(items[i].position); 57 | break; 58 | 59 | } 60 | 61 | } 62 | 63 | }, 64 | 65 | updateScores: function(trophy) { 66 | 67 | this.updateTrophyScore(trophy); 68 | this.updateDistance(); 69 | 70 | this.updateTotalScore(); 71 | 72 | }, 73 | 74 | updateTrophyScore: function(trophy) { 75 | 76 | if (!trophy) 77 | return ; 78 | 79 | this.trophies.updateValue(function(trophyScore) { 80 | 81 | if (trophyScore + trophy.getValue() > 9999) 82 | return 9999; 83 | 84 | return trophyScore + trophy.getValue(); 85 | 86 | }); 87 | 88 | }, 89 | 90 | updateDistance: function() { 91 | 92 | this.distance.updateValue(function(distance) { 93 | 94 | if (distance + 1 > 9999) 95 | return 9999; 96 | return distance + 1; 97 | 98 | }); 99 | 100 | }, 101 | 102 | updateTotalScore: function() { 103 | 104 | var self = this; 105 | this.score.updateValue(function() { 106 | 107 | return self.trophies.getValue() + self.distance.getValue(); 108 | 109 | }); 110 | 111 | 112 | }, 113 | 114 | }); 115 | 116 | ScoreLayer.create = function() { 117 | 118 | var sg = new ScoreLayer(); 119 | 120 | if (sg) return sg; 121 | return null; 122 | 123 | }; 124 | -------------------------------------------------------------------------------- /Classes/Scenes/About.js: -------------------------------------------------------------------------------- 1 | var About = cc.Layer.extend({ 2 | 3 | content: null, 4 | menu: null, 5 | 6 | init: function() { 7 | 8 | if (this._super) { 9 | this.loadBg(); 10 | this.loadLabel(); 11 | } 12 | 13 | return true; 14 | 15 | }, 16 | 17 | loadBg: function() { 18 | 19 | this.addPic(P_MENUBG, cc.ccp(0.5, 0.5), cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height / 2), 1, -1); 20 | this.addPic(P_ABOUT_PAGE, cc.ccp(0.5, 0.5), cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height / 2), 1, 10); 21 | 22 | }, 23 | 24 | //add picture 25 | addPic: function(src, anchorPoint, position, scale, zOrder) { 26 | 27 | var sprite = cc.Sprite.create(src); 28 | sprite.setAnchorPoint(anchorPoint); 29 | sprite.setPosition(position); 30 | sprite.setScale(scale) 31 | this.addChild(sprite, zOrder, this.intemTag); 32 | this.intemTag++; 33 | 34 | }, 35 | 36 | goBack: function() { 37 | 38 | var scene = cc.Scene.create(); 39 | scene.addChild(MainMenu.create()); 40 | cc.Director.sharedDirector().replaceScene(scene); 41 | 42 | }, 43 | 44 | //load label 45 | loadLabel: function() { 46 | 47 | var goToMainMenuNormal = cc.Sprite.create(P_MENU, cc.RectMake(800, 0, 200, 50)); 48 | var goToMainMenuSelected = cc.Sprite.create(P_MENU, cc.RectMake(800, 50, 200, 50)); 49 | var goToMainMenuDisabled = cc.Sprite.create(P_MENU, cc.RectMake(800, 50 * 2, 200, 50)); 50 | 51 | var goToMainMenu = cc.MenuItemSprite.create( 52 | goToMainMenuNormal, 53 | goToMainMenuSelected, 54 | goToMainMenuDisabled, 55 | this, 56 | this.goBack 57 | ); 58 | 59 | this.menu = cc.Menu.create(goToMainMenu); 60 | this.menu.alignItemsVerticallyWithPadding(10); 61 | this.menu.setPosition(cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height / 7)); 62 | this.addChild(this.menu, 500, 2); 63 | 64 | }, 65 | 66 | }); 67 | 68 | About.create = function() { 69 | 70 | var sg = new About(); 71 | if (sg && sg.init()) { 72 | return sg; 73 | } 74 | return null; 75 | 76 | }; 77 | 78 | About.scene = function() { 79 | 80 | var scene = cc.Scene.create(); 81 | var layer = About.create(); 82 | scene.addChild(layer); 83 | return scene; 84 | 85 | }; 86 | -------------------------------------------------------------------------------- /Classes/Scenes/GameOver.js: -------------------------------------------------------------------------------- 1 | 2 | var GameOver = cc.Layer.extend({ 3 | 4 | init: function (scoreLayer, type) { 5 | 6 | if (this._super) { 7 | 8 | var sp = cc.Sprite.create(P_GAMEOVERBG); 9 | sp.setAnchorPoint(cc.ccp(0.5, 0.5)); 10 | sp.setPosition(cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height / 2)), 11 | this.addChild(sp, 0, 1); 12 | 13 | var gameoverLogo = cc.Sprite.create(P_GAMEOVER); 14 | gameoverLogo.setAnchorPoint(cc.ccp(0.5, 0.5)); 15 | gameoverLogo.setPosition(cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height * 5 / 7 )); 16 | this.addChild(gameoverLogo, 10, 1); 17 | 18 | this.addChild(scoreLayer, 100); 19 | scoreLayer.generatePanel([{ 20 | type: 'trophies', 21 | position: cc.ccp(LOCATION.GAMEOVER_LAYER.TROPHIES.X, LOCATION.GAMEOVER_LAYER.TROPHIES.Y), 22 | }, { 23 | type: 'distance', 24 | position: cc.ccp(LOCATION.GAMEOVER_LAYER.DISTANCE.X, LOCATION.GAMEOVER_LAYER.DISTANCE.Y), 25 | }, { 26 | type: 'score', 27 | position: cc.ccp(LOCATION.GAMEOVER_LAYER.SCORE.X, LOCATION.GAMEOVER_LAYER.SCORE.Y), 28 | }]); 29 | 30 | 31 | var playAgainNormal = cc.Sprite.create(P_MENU, cc.RectMake(0, 0, 200, 50)); 32 | var playAgainSelected = cc.Sprite.create(P_MENU, cc.RectMake(0, 50, 200, 50)); 33 | var playAgainDisabled = cc.Sprite.create(P_MENU, cc.RectMake(0, 50 * 2, 200, 50)); 34 | var playAgain = cc.MenuItemSprite.create( 35 | playAgainNormal, 36 | playAgainSelected, 37 | playAgainDisabled, 38 | this, 39 | this.onPlayAgain 40 | ); 41 | var menu = cc.Menu.create(playAgain); 42 | this.addChild(menu, 10, 2); 43 | menu.setPosition(cc.ccp(WIN_SIZE.width / 2, 220)); 44 | 45 | 46 | /*var typeSrc = null; 47 | 48 | switch (type) { 49 | 50 | case GAMEOVER.TYPE.CROSS_BORDER: 51 | typeSrc = P_INVALID; 52 | break; 53 | case GAMEOVER.TYPE.NO_HP: 54 | typeSrc = P_NOHP; 55 | break; 56 | 57 | }; 58 | 59 | var gameOverTypeSprite = cc.Sprite.create(typeSrc); 60 | gameOverTypeSprite.setAnchorPoint(cc.ccp(0.5, 0.5)); 61 | gameOverTypeSprite.setPosition(cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height / 10)); 62 | this.addChild(gameOverTypeSprite, 10);*/ 63 | 64 | this.schedule(this.update,0.1); 65 | 66 | } 67 | 68 | return true; 69 | 70 | }, 71 | 72 | onPlayAgain: function (pSender) { 73 | 74 | var scene = cc.Scene.create(); 75 | scene.addChild(Track.create()); 76 | cc.Director.sharedDirector().replaceScene(cc.TransitionFade.create(1.2, scene)); 77 | 78 | } 79 | 80 | }); 81 | 82 | GameOver.create = function (scoreLayer, type) { 83 | 84 | var sg = new GameOver(); 85 | if (sg && sg.init(scoreLayer, type)) { 86 | return sg; 87 | } 88 | return null; 89 | 90 | }; 91 | -------------------------------------------------------------------------------- /Classes/Scenes/MainMenu.js: -------------------------------------------------------------------------------- 1 | var MainMenu = cc.Layer.extend({ 2 | 3 | intemTag: 0, 4 | menubg: null, 5 | 6 | init: function() { 7 | 8 | if (this._super) { 9 | this.Rendering(); 10 | this.addMenu(); 11 | } 12 | 13 | return true; 14 | 15 | }, 16 | 17 | Rendering: function() { 18 | 19 | this.addPic(P_MENUBG, cc.ccp(0.5, 0.5), cc.ccp(WIN_SIZE.width / 2 , WIN_SIZE.height / 2), SCALE_RATE, -1); 20 | 21 | this.addPic(P_LOGO, cc.ccp(0, 0), cc.ccp(WIN_SIZE.width / 10, 3 * WIN_SIZE.height / 5), SCALE_RATE, 20); 22 | 23 | }, 24 | 25 | 26 | 27 | addPic: function(src, anchorPoint, position, scale, zOrder) { 28 | 29 | var sprite = cc.Sprite.create(src); 30 | sprite.setAnchorPoint(anchorPoint); 31 | sprite.setPosition(position); 32 | sprite.setScale(scale) 33 | this.addChild(sprite, zOrder, this.intemTag); 34 | this.intemTag++; 35 | 36 | }, 37 | 38 | //let the tile to go straight 39 | goStraight: function() { 40 | 41 | this.runAction(cc.MoveTo.create(this.distance / this.velocity, cc.PointMake(WIN_SIZE.width / 2, -this.height / 2))); 42 | 43 | }, 44 | 45 | addMenu: function() { 46 | 47 | var newGameNormal = cc.Sprite.create(P_MENU, cc.RectMake(0, 0, 200, 50)); 48 | var newGameSelected = cc.Sprite.create(P_MENU, cc.RectMake(0, 50, 200, 50)); 49 | var newGameDisabled = cc.Sprite.create(P_MENU, cc.RectMake(0, 50 * 2, 200, 50)); 50 | 51 | var gameSettingsNormal = cc.Sprite.create(P_MENU, cc.RectMake(200, 0, 200, 50)); 52 | var gameSettingsSelected = cc.Sprite.create(P_MENU, cc.RectMake(200, 50, 200, 50)); 53 | var gameSettingsDisabled = cc.Sprite.create(P_MENU, cc.RectMake(200, 50 * 2, 200, 50)); 54 | 55 | var aboutNormal = cc.Sprite.create(P_MENU, cc.RectMake(400, 0, 200, 50)); 56 | var aboutSelected = cc.Sprite.create(P_MENU, cc.RectMake(400, 50, 200, 50)); 57 | var aboutDisabled = cc.Sprite.create(P_MENU, cc.RectMake(400, 50 * 2, 200, 50)); 58 | 59 | var newGame = cc.MenuItemSprite.create(newGameNormal, newGameSelected, newGameDisabled, this, this.onNewGame); 60 | var gameSettings = cc.MenuItemSprite.create(gameSettingsNormal, gameSettingsSelected, gameSettingsDisabled, this, this.onSettings); 61 | var about = cc.MenuItemSprite.create(aboutNormal, aboutSelected, aboutDisabled, this, this.onAbout); 62 | 63 | var menu = cc.Menu.create(newGame, gameSettings, about); 64 | menu.alignItemsVerticallyWithPadding(10); 65 | menu.setPosition(cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height / 2 - 80)); 66 | this.addChild(menu, 600, 2); 67 | 68 | }, 69 | 70 | onNewGame: function(pSender) { 71 | 72 | var scene = cc.Scene.create(); 73 | scene.addChild(Track.create()); 74 | cc.Director.sharedDirector().replaceScene(scene); 75 | 76 | }, 77 | 78 | onSettings: function(pSender) { 79 | 80 | 81 | // var scene = cc.Scene.create(); 82 | // scene.addChild(SettingsLayer.create()); 83 | // cc.Director.sharedDirector().replaceScene(cc.TransitionFade.create(1.2, scene)); 84 | 85 | }, 86 | 87 | onAbout: function(pSender) { 88 | 89 | var scene = cc.Scene.create(); 90 | scene.addChild(About.create()); 91 | cc.Director.sharedDirector().replaceScene(scene); 92 | 93 | }, 94 | 95 | onButtonEffect: function() { 96 | 97 | // if (global.sound) { 98 | // var s = cc.AudioManager.sharedEngine().playEffect(s_buttonEffect); 99 | // } 100 | 101 | } 102 | 103 | }); 104 | 105 | MainMenu.create = function() { 106 | 107 | var sg = new MainMenu(); 108 | if (sg && sg.init()) { 109 | return sg; 110 | } 111 | return null; 112 | 113 | }; 114 | 115 | MainMenu.scene = function() { 116 | 117 | var scene = cc.Scene.create(); 118 | var layer = MainMenu.create(); 119 | scene.addChild(layer); 120 | return scene; 121 | 122 | }; 123 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Naughty Squirrel 2 | 3 | Using chrome to get the best performance. 4 | [Here to PLAY!](http://bufferspace.github.com/NaughtySquirrel/) 5 | 6 | We have to clear that the name means nothing...and it's kind of stupid... 7 | 8 | This game is inspired by TEMPLE RUN. More specifically, this game is a 2D version of temple run. The game is developped for pure fun. But one of the serious reason is to see the performance of HTML5 and Cocos2D HTML. Obviously, the performance is not that good and you may feel dazzling not because of the speed of the game but the bad performance. 9 | 10 | ## Rules 11 | 12 | + You have 3 HP at the very beginning. 13 | + Invalid turning decreases your HP by 1. 14 | + If you failed to jump in some specific landscape, game over. 15 | + If you failed to turn in turnings, game over. 16 | + If you don't have any HP, game over. 17 | 18 | ## Score 19 | 20 | + Each golden bean worths 1 point. 21 | + The running distance keeps increasing. 22 | + The total score is the combination of the above points. 23 | 24 | ## Operations 25 | 26 | + a:Slide left. 27 | + d:Slide right. 28 | + ←:Turn left. 29 | + →:Turn right. 30 | + ↑:Jump. 31 | 32 | ## Properties 33 | 34 | + Ruby: In the following 500 meters, score is doubled. 35 | + Saphire: In the following 500 meters, score is tripled. 36 | + magnet: Absorbe golden beans for you. 37 | + medicine: Heal 1 HP. 38 | 39 | ## LICENCE 40 | 41 | (The MIT License) 42 | 43 | Copyright (c) 2012 by [Zero](https://github.com/Aquietzero) and [fsiaonma](https://github.com/fsiaonma) 44 | 45 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 46 | 47 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 48 | 49 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 50 | -------------------------------------------------------------------------------- /Resource.js: -------------------------------------------------------------------------------- 1 | var P_LOGO = 'Resources/title.png'; 2 | var P_MENU = 'Resources/menu.png'; 3 | 4 | var P_TILE_1 = 'Resources/tile_1.jpg'; 5 | var P_TILE_2 = 'Resources/tile_2.jpg'; 6 | var P_TILE_3 = 'Resources/tile_3.jpg'; 7 | var P_TILE_4 = 'Resources/tile_4.jpg'; 8 | var P_TILE_5 = 'Resources/tile_5.jpg'; 9 | var P_TILE_6 = 'Resources/tile_6.jpg'; 10 | var P_TILE_7 = 'Resources/tile_7.jpg'; 11 | var P_TILE_8 = 'Resources/tile_8.jpg'; 12 | var P_TILE_9 = 'Resources/tile_9.jpg'; 13 | var P_TILE_10 = 'Resources/tile_10.jpg'; 14 | var P_TILE_11 = 'Resources/tile_11.jpg'; 15 | var P_TILE_12 = 'Resources/tile_12.png'; 16 | 17 | var P_BACKGROUND_1 = 'Resources/background_1.png'; 18 | var P_BACKGROUND_2 = 'Resources/background_2.png'; 19 | 20 | var P_CHARACTER1 = 'Resources/runner1.png'; 21 | var P_CHARACTER2 = 'Resources/runner2.png'; 22 | var P_CHARACTER3 = 'Resources/runner3.png'; 23 | 24 | var P_LIGHT_POINT_1 = 'Resources/light_point1.png'; 25 | var P_LIGHT_POINT_2 = 'Resources/light_point2.png'; 26 | var P_LIGHT_POINT_3 = 'Resources/light_point3.png'; 27 | var P_LIGHT_POINT_4 = 'Resources/light_point4.png'; 28 | 29 | var P_SHADOW = 'Resources/shadow.png'; 30 | 31 | var P_CLOUD_1 = 'Resources/cloud_1.png'; 32 | var P_CLOUD_2 = 'Resources/cloud_2.png'; 33 | var P_CLOUD_3 = 'Resources/cloud_3.png'; 34 | var P_CLOUD_4 = 'Resources/cloud_4.png'; 35 | 36 | var P_INNER_RED = 'Resources/JumpPrints/inner_red.png'; 37 | var P_INNER_YELLOW = 'Resources/JumpPrints/inner_yellow.png'; 38 | var P_INNER_WHITE = 'Resources/JumpPrints/inner_white.png'; 39 | var P_OUTER_WHITE = 'Resources/JumpPrints/outer_white.png'; 40 | var P_OUTER_PURPLE = 'Resources/JumpPrints/outer_purple.png'; 41 | 42 | var P_FOOTPRINT_1 = 'Resources/footprint_1.png'; 43 | var P_FOOTPRINT_2 = 'Resources/footprint_2.png'; 44 | var P_FOOTPRINT_3 = 'Resources/footprint_3.png'; 45 | var P_FOOTPRINT_4 = 'Resources/footprint_4.png'; 46 | var P_FOOTPRINT_5 = 'Resources/footprint_5.png'; 47 | 48 | var P_COIN = 'Resources/beans.png'; 49 | var P_DOUBLE_COIN = 'Resources/beans_red.png'; 50 | var P_TRIPLE_COIN = 'Resources/beans_blue.png'; 51 | 52 | var P_DOUBLE = 'Resources/double.png'; 53 | var P_DOUBLE_BG = 'Resources/double_bg.png'; 54 | var P_TRIPLE = 'Resources/triple.png'; 55 | var P_TRIPLE_BG = 'Resources/triple_bg.png'; 56 | var P_MAGNET = 'Resources/magnet.png'; 57 | var P_HP = 'Resources/hp.png'; 58 | 59 | var P_HP_UP = 'Resources/hp_up.png'; 60 | var P_HP_DOWN = 'Resources/hp_down.png'; 61 | 62 | var P_MENUBG = 'Resources/menubg.jpg'; 63 | 64 | var P_GAMEOVER = 'Resources/game-over.png'; 65 | var P_GAMEOVERBG = 'Resources/gameover-bg.jpg'; 66 | 67 | var P_INVALID = 'Resources/invalid.png'; 68 | var P_NOHP = 'Resources/no_hp.png'; 69 | 70 | var P_PAUSE = 'Resources/pause.png'; 71 | 72 | var P_SCORE = 'Resources/score.png'; 73 | var P_TROPHIES = 'Resources/trophies.png'; 74 | var P_DISTANCE = 'Resources/distance.png'; 75 | 76 | var P_NUMBERS = 'Resources/numbers.png'; 77 | var P_ABOUT_PAGE = 'Resources/about_page.png'; 78 | 79 | var G_RESOURCES = [ 80 | 81 | { type: 'image', src: P_LOGO }, 82 | { type: 'image', src: P_MENU }, 83 | 84 | { type: 'image', src: P_TILE_1 }, 85 | { type: 'image', src: P_TILE_2 }, 86 | { type: 'image', src: P_TILE_3 }, 87 | { type: 'image', src: P_TILE_4 }, 88 | { type: 'image', src: P_TILE_5 }, 89 | { type: 'image', src: P_TILE_6 }, 90 | { type: 'image', src: P_TILE_7 }, 91 | { type: 'image', src: P_TILE_8 }, 92 | { type: 'image', src: P_TILE_9 }, 93 | { type: 'image', src: P_TILE_10 }, 94 | { type: 'image', src: P_TILE_11 }, 95 | { type: 'image', src: P_TILE_12 }, 96 | 97 | { type: 'image', src: P_BACKGROUND_1 }, 98 | { type: 'image', src: P_BACKGROUND_2 }, 99 | 100 | { type: 'image', src: P_CHARACTER1 }, 101 | { type: 'image', src: P_CHARACTER2 }, 102 | { type: 'image', src: P_CHARACTER3 }, 103 | 104 | { type: 'image', src: P_LIGHT_POINT_1 }, 105 | { type: 'image', src: P_LIGHT_POINT_2 }, 106 | { type: 'image', src: P_LIGHT_POINT_3 }, 107 | { type: 'image', src: P_LIGHT_POINT_4 }, 108 | 109 | { type: 'image', src: P_HP_UP }, 110 | { type: 'image', src: P_HP_DOWN }, 111 | 112 | { type: 'image', src: P_SHADOW }, 113 | 114 | { type: 'image', src: P_CLOUD_1 }, 115 | { type: 'image', src: P_CLOUD_2 }, 116 | { type: 'image', src: P_CLOUD_3 }, 117 | { type: 'image', src: P_CLOUD_4 }, 118 | 119 | { type: 'image', src: P_INNER_RED }, 120 | { type: 'image', src: P_INNER_YELLOW }, 121 | { type: 'image', src: P_INNER_WHITE }, 122 | { type: 'image', src: P_OUTER_WHITE }, 123 | { type: 'image', src: P_OUTER_PURPLE }, 124 | 125 | { type: 'image', src: P_FOOTPRINT_1 }, 126 | { type: 'image', src: P_FOOTPRINT_2 }, 127 | { type: 'image', src: P_FOOTPRINT_3 }, 128 | { type: 'image', src: P_FOOTPRINT_4 }, 129 | { type: 'image', src: P_FOOTPRINT_5 }, 130 | 131 | { type: 'image', src: P_COIN }, 132 | { type: 'image', src: P_DOUBLE_COIN }, 133 | { type: 'image', src: P_TRIPLE_COIN }, 134 | 135 | { type: 'image', src: P_MENUBG }, 136 | 137 | { type: 'image', src: P_GAMEOVER }, 138 | { type: 'image', src: P_GAMEOVERBG }, 139 | 140 | { type: 'image', src: P_INVALID }, 141 | { type: 'image', src: P_NOHP }, 142 | 143 | { type: 'image', src: P_DOUBLE }, 144 | { type: 'image', src: P_DOUBLE_BG }, 145 | { type: 'image', src: P_MAGNET }, 146 | { type: 'image', src: P_HP }, 147 | 148 | { type: 'image', src: P_PAUSE }, 149 | 150 | { type: 'image', src: P_SCORE }, 151 | { type: 'image', src: P_TROPHIES }, 152 | { type: 'image', src: P_DISTANCE }, 153 | 154 | { type: 'image', src: P_NUMBERS }, 155 | { type: 'image', src: P_ABOUT_PAGE }, 156 | 157 | ]; 158 | -------------------------------------------------------------------------------- /Resources/JumpPrints/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/JumpPrints/Thumbs.db -------------------------------------------------------------------------------- /Resources/JumpPrints/inner_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/JumpPrints/inner_red.png -------------------------------------------------------------------------------- /Resources/JumpPrints/inner_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/JumpPrints/inner_white.png -------------------------------------------------------------------------------- /Resources/JumpPrints/inner_yellow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/JumpPrints/inner_yellow.png -------------------------------------------------------------------------------- /Resources/JumpPrints/outer_purple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/JumpPrints/outer_purple.png -------------------------------------------------------------------------------- /Resources/JumpPrints/outer_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/JumpPrints/outer_white.png -------------------------------------------------------------------------------- /Resources/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/Thumbs.db -------------------------------------------------------------------------------- /Resources/about_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/about_page.png -------------------------------------------------------------------------------- /Resources/background_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/background_1.png -------------------------------------------------------------------------------- /Resources/background_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/background_2.png -------------------------------------------------------------------------------- /Resources/bean.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/bean.png -------------------------------------------------------------------------------- /Resources/beans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/beans.png -------------------------------------------------------------------------------- /Resources/beans_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/beans_blue.png -------------------------------------------------------------------------------- /Resources/beans_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/beans_red.png -------------------------------------------------------------------------------- /Resources/cloud_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/cloud_1.png -------------------------------------------------------------------------------- /Resources/cloud_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/cloud_2.png -------------------------------------------------------------------------------- /Resources/cloud_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/cloud_3.png -------------------------------------------------------------------------------- /Resources/cloud_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/cloud_4.png -------------------------------------------------------------------------------- /Resources/distance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/distance.png -------------------------------------------------------------------------------- /Resources/double.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/double.png -------------------------------------------------------------------------------- /Resources/double_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/double_bg.png -------------------------------------------------------------------------------- /Resources/footprint_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/footprint_1.png -------------------------------------------------------------------------------- /Resources/footprint_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/footprint_2.png -------------------------------------------------------------------------------- /Resources/footprint_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/footprint_3.png -------------------------------------------------------------------------------- /Resources/footprint_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/footprint_4.png -------------------------------------------------------------------------------- /Resources/footprint_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/footprint_5.png -------------------------------------------------------------------------------- /Resources/game-over.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/game-over.png -------------------------------------------------------------------------------- /Resources/gameover-bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/gameover-bg.jpg -------------------------------------------------------------------------------- /Resources/hp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/hp.png -------------------------------------------------------------------------------- /Resources/hp_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/hp_down.png -------------------------------------------------------------------------------- /Resources/hp_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/hp_up.png -------------------------------------------------------------------------------- /Resources/invalid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/invalid.png -------------------------------------------------------------------------------- /Resources/light_point1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/light_point1.png -------------------------------------------------------------------------------- /Resources/light_point2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/light_point2.png -------------------------------------------------------------------------------- /Resources/light_point3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/light_point3.png -------------------------------------------------------------------------------- /Resources/light_point4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/light_point4.png -------------------------------------------------------------------------------- /Resources/magnet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/magnet.png -------------------------------------------------------------------------------- /Resources/menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/menu.png -------------------------------------------------------------------------------- /Resources/menubg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/menubg.jpg -------------------------------------------------------------------------------- /Resources/no_hp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/no_hp.png -------------------------------------------------------------------------------- /Resources/numbers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/numbers.png -------------------------------------------------------------------------------- /Resources/pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/pause.png -------------------------------------------------------------------------------- /Resources/runner1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/runner1.png -------------------------------------------------------------------------------- /Resources/runner2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/runner2.png -------------------------------------------------------------------------------- /Resources/runner3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/runner3.png -------------------------------------------------------------------------------- /Resources/score.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/score.png -------------------------------------------------------------------------------- /Resources/shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/shadow.png -------------------------------------------------------------------------------- /Resources/tile_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/tile_1.jpg -------------------------------------------------------------------------------- /Resources/tile_10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/tile_10.jpg -------------------------------------------------------------------------------- /Resources/tile_11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/tile_11.jpg -------------------------------------------------------------------------------- /Resources/tile_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/tile_12.png -------------------------------------------------------------------------------- /Resources/tile_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/tile_2.jpg -------------------------------------------------------------------------------- /Resources/tile_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/tile_3.jpg -------------------------------------------------------------------------------- /Resources/tile_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/tile_4.jpg -------------------------------------------------------------------------------- /Resources/tile_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/tile_5.jpg -------------------------------------------------------------------------------- /Resources/tile_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/tile_6.jpg -------------------------------------------------------------------------------- /Resources/tile_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/tile_7.jpg -------------------------------------------------------------------------------- /Resources/tile_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/tile_8.jpg -------------------------------------------------------------------------------- /Resources/tile_9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/tile_9.jpg -------------------------------------------------------------------------------- /Resources/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/title.png -------------------------------------------------------------------------------- /Resources/triple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/triple.png -------------------------------------------------------------------------------- /Resources/triple_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/triple_bg.png -------------------------------------------------------------------------------- /Resources/trophies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BufferSpace/NaughtySquirrel/7a374262a6046f7c094a79d48cc5f556a092d871/Resources/trophies.png -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | + Add a layer controller to achieve multiple backgrounds. 4 | + Partial environment. 5 | + Re-design the tile information. 6 | + Add more themes. -------------------------------------------------------------------------------- /cocos2d.js: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | Copyright (c) 2010-2012 cocos2d-x.org 3 | Copyright (c) 2008-2010 Ricardo Quesada 4 | Copyright (c) 2011 Zynga Inc. 5 | 6 | http://www.cocos2d-x.org 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | ****************************************************************************/ 26 | 27 | var cc = cc = cc || {}; 28 | //Cocos2d directory 29 | cc.Dir = '';//in relate to the html file or use absolute 30 | cc.loadQue = [];//the load que which js files are loaded 31 | cc.COCOS2D_DEBUG = 2; 32 | cc._DEBUG = 1; 33 | cc._IS_RETINA_DISPLAY_SUPPORTED = 0; 34 | //html5 selector method 35 | cc.$ = function (x) { 36 | return document.querySelector(x); 37 | }; 38 | cc.$new = function (x) { 39 | return document.createElement(x); 40 | }; 41 | 42 | cc.loadjs = function (filename) { 43 | //add the file to the que 44 | var script = cc.$new('script'); 45 | script.src = cc.Dir + filename; 46 | script.order = cc.loadQue.length; 47 | cc.loadQue.push(script); 48 | 49 | script.onload = function () { 50 | //file have finished loading, 51 | //if there is more file to load, we should put the next file on the head 52 | if (this.order + 1 < cc.loadQue.length) { 53 | cc.$('head').appendChild(cc.loadQue[this.order + 1]); 54 | //console.log(this.order); 55 | } 56 | else { 57 | cc.setup("gameCanvas"); 58 | cc.Loader.shareLoader().onload = function () { 59 | cc.AppController.shareAppController().didFinishLaunchingWithOptions(); 60 | }; 61 | //preload ressources 62 | cc.Loader.shareLoader().preload(G_RESOURCES); 63 | } 64 | }; 65 | if (script.order === 0)//if the first file to load, then we put it on the head 66 | { 67 | cc.$('head').appendChild(script); 68 | } 69 | }; 70 | 71 | cc.loadjs('cocos2d-html5-canvasmenu-min.js'); 72 | cc.loadjs('Resource.js'); 73 | 74 | cc.loadjs('Classes/AppDelegate.js'); 75 | 76 | cc.loadjs('Classes/Auxiliary/Array.js'); 77 | cc.loadjs('Classes/Auxiliary/Utils.js'); 78 | 79 | cc.loadjs('Classes/Config/Global.js'); 80 | cc.loadjs('Classes/Config/Location.js'); 81 | cc.loadjs('Classes/Config/Themes.js'); 82 | 83 | cc.loadjs('Classes/Controllers/LevelController.js'); 84 | 85 | cc.loadjs('Classes/Information/TilesInformation/IsBounded.js'); 86 | cc.loadjs('Classes/Information/TilesInformation/IsValid.js'); 87 | cc.loadjs('Classes/Information/TilesInformation/GenerateTrophies.js'); 88 | cc.loadjs('Classes/Information/TilesInformation/BasicTile.js'); 89 | cc.loadjs('Classes/Information/TilesInformation/Tiles.js'); 90 | cc.loadjs('Classes/Information/TilesInformation/TileInformation.js'); 91 | 92 | cc.loadjs('Classes/Information/BackgroundInformation/Backgrounds.js'); 93 | cc.loadjs('Classes/Information/BackgroundInformation/BackgroundInformation.js'); 94 | cc.loadjs('Classes/Controllers/BackgroundController.js'); 95 | 96 | cc.loadjs('Classes/Information/TrophiesInformation/Coin.js'); 97 | cc.loadjs('Classes/Information/TrophiesInformation/TrophiesInformation.js'); 98 | cc.loadjs('Classes/Controllers/TrophiesController.js'); 99 | cc.loadjs('Classes/Controllers/TrophiesActionsController.js'); 100 | 101 | cc.loadjs('Classes/Information/Environments/Footprints.js'); 102 | cc.loadjs('Classes/Information/Environments/JumpShadow.js'); 103 | cc.loadjs('Classes/Information/Environments/LightCircle.js'); 104 | cc.loadjs('Classes/Information/Environments/Cloud.js'); 105 | cc.loadjs('Classes/Controllers/EnvironmentsController.js'); 106 | 107 | cc.loadjs('Classes/Information/PropertiesInformation/Double.js'); 108 | cc.loadjs('Classes/Information/PropertiesInformation/Triple.js'); 109 | cc.loadjs('Classes/Information/PropertiesInformation/Magnet.js'); 110 | cc.loadjs('Classes/Information/PropertiesInformation/Hp.js'); 111 | cc.loadjs('Classes/Information/PropertiesInformation/PropertiesInformation.js'); 112 | cc.loadjs('Classes/Controllers/PropertiesController.js'); 113 | 114 | cc.loadjs('Classes/Scenes/MainMenu.js'); 115 | cc.loadjs('Classes/Scenes/GameOver.js'); 116 | cc.loadjs('Classes/Scenes/About.js'); 117 | 118 | cc.loadjs('Classes/Models/Tile.js'); 119 | cc.loadjs('Classes/Models/Trophy.js'); 120 | cc.loadjs('Classes/Models/Trophies.js'); 121 | cc.loadjs('Classes/Models/Property.js'); 122 | cc.loadjs('Classes/Models/Character.js'); 123 | cc.loadjs('Classes/Models/BackgroundTile.js'); 124 | cc.loadjs('Classes/Models/Background.js'); 125 | 126 | cc.loadjs('Classes/Panels/ScoreItem.js'); 127 | cc.loadjs('Classes/Panels/ScoreLayer.js'); 128 | cc.loadjs('Classes/Panels/PauseLayer.js'); 129 | 130 | cc.loadjs('Classes/Information/TrackInformation.js'); 131 | cc.loadjs('Classes/Models/Track.js'); 132 | 133 | 134 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Naughty Squirrel 6 | 7 | 8 | 32 | 33 | 34 | 35 |
36 | Fork me on GitHub 37 | 38 |
39 |

Attention

40 | 44 | 45 |

Other Stuff

46 | 49 | 50 |
51 | 52 | 53 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /test/testPic.js: -------------------------------------------------------------------------------- 1 | var testPic = cc.Layer.extend({ 2 | 3 | intemTag: 0, 4 | menubg: null, 5 | 6 | init: function() { 7 | 8 | if (this._super) { 9 | 10 | var sprite = cc.Sprite.create(P_TILE_1); 11 | sprite.setAnchorPoint(cc.ccp(0.5, 0.5)); 12 | sprite.setPosition(cc.ccp(WIN_SIZE.width / 2, WIN_SIZE.height * 2)); 13 | this.addChild(sprite, 1, 1); 14 | 15 | sprite.runAction( 16 | cc.MoveBy.create(7, cc.ccp(0, -WIN_SIZE.height * 4)) 17 | ); 18 | 19 | } 20 | 21 | return true; 22 | 23 | }, 24 | 25 | }); 26 | 27 | testPic.create = function() { 28 | 29 | var sg = new testPic(); 30 | if (sg && sg.init()) { 31 | return sg; 32 | } 33 | return null; 34 | 35 | }; 36 | 37 | testPic.scene = function() { 38 | 39 | var scene = cc.Scene.create(); 40 | var layer = testPic.create(); 41 | scene.addChild(layer); 42 | return scene; 43 | 44 | }; 45 | --------------------------------------------------------------------------------