+
+
diff --git a/games/RunSnailRun/js/classes/Application.js b/games/RunSnailRun/js/classes/Application.js
new file mode 100644
index 00000000..dd61fd5c
--- /dev/null
+++ b/games/RunSnailRun/js/classes/Application.js
@@ -0,0 +1,37 @@
+"use strict";
+classes.Application = cc.Application.extend({
+ config : document.ccConfig,
+ ctor : function(scene) {
+ this._super();
+ this.startScene = scene;
+ cc.COCOS2D_DEBUG = this.config['COCOS2D_DEBUG'];
+ cc.setup(this.config['tag']);
+ cc.AppController.shareAppController().didFinishLaunchingWithOptions();
+ },
+ applicationDidFinishLaunching : function() {
+ var that = this;
+ // initialize director
+ var director = cc.Director.getInstance();
+
+ // enable High Resource Mode(2x, such as iphone4) and maintains low
+ // resource on other devices.
+ // director->enableRetinaDisplay(true);
+
+ // turn on display FPS
+ director.setDisplayStats(this.config['showFPS']);
+
+ // set FPS. the default value is 1.0/60 if you don't call this
+ director.setAnimationInterval(1.0 / this.config['frameRate']);
+
+ // create a scene. it's an autorelease object
+
+ // load resources and run
+ cc.Loader.preload(game.config.resources, function() {
+ var startSceneInstance = new that.startScene();
+ director.runWithScene(startSceneInstance);
+ //game.setScene('intro', startSceneInstance);
+ });
+
+ return true;
+ }
+});
diff --git a/games/RunSnailRun/js/classes/Application.js~ b/games/RunSnailRun/js/classes/Application.js~
new file mode 100644
index 00000000..a541707a
--- /dev/null
+++ b/games/RunSnailRun/js/classes/Application.js~
@@ -0,0 +1,37 @@
+"use strict";
+classes.Application = cc.Application.extend({
+ config : document.ccConfig,
+ ctor : function(scene) {
+ this._super();
+ this.startScene = scene;
+ cc.COCOS2D_DEBUG = this.config['COCOS2D_DEBUG'];
+ cc.setup(this.config['tag']);
+ cc.AppController.shareAppController().didFinishLaunchingWithOptions();
+ },
+ applicationDidFinishLaunching : function() {
+ var that = this;
+ // initialize director
+ var director = cc.Director.getInstance();
+
+ // enable High Resource Mode(2x, such as iphone4) and maintains low
+ // resource on other devices.
+ // director->enableRetinaDisplay(true);
+
+ // turn on display FPS
+ director.setDisplayStats(this.config['showFPS']);
+
+ // set FPS. the default value is 1.0/60 if you don't call this
+ director.setAnimationInterval(1.0 / this.config['frameRate']);
+
+ // create a scene. it's an autorelease object
+
+ // load resources and run
+ cc.Loader.preload(game.config.resources, function() {
+ var startSceneInstance = new that.startScene();
+ director.replaceScene(startSceneInstance);
+ game.setScene('intro', startSceneInstance);
+ });
+
+ return true;
+ }
+});
\ No newline at end of file
diff --git a/games/RunSnailRun/js/classes/classes.js b/games/RunSnailRun/js/classes/classes.js
new file mode 100644
index 00000000..482246e4
--- /dev/null
+++ b/games/RunSnailRun/js/classes/classes.js
@@ -0,0 +1,5 @@
+/**
+ * @namespace
+ */
+"use strict";
+var classes = {};
\ No newline at end of file
diff --git a/games/RunSnailRun/js/classes/layers/Intro.js b/games/RunSnailRun/js/classes/layers/Intro.js
new file mode 100644
index 00000000..e9207ffd
--- /dev/null
+++ b/games/RunSnailRun/js/classes/layers/Intro.js
@@ -0,0 +1,101 @@
+"use strict";
+classes.layers.Intro = cc.Layer
+ .extend({
+ isMouseDown : false,
+ onEnter : function() {
+ this._super();
+ this.logo.setScale(0.1);
+ this.logo.runAction(cc.Sequence.create(cc.EaseElasticOut
+ .create(cc.ScaleTo.create(2, 1, 1), 0.5)));
+ setTimeout(function() {
+ var level = new classes.scenes.Level();
+ game.setScene('level', level);
+ game.changeScene(level);
+ }, 3000);
+ },
+ ctor : function() {
+ this._super();
+ tizen.logger.info("classes.layers.Intro.ctor()");
+ var selfPointer = this;
+ this.addExitAppButton();
+
+ // Background layer
+ // var background = cc.LayerColor.create(new cc.Color4B(0, 0, 0,
+ // 255), 1280, 670);
+ // ask director the window size
+ var size = cc.Director.getInstance().getWinSize();
+
+ var about = cc.MenuItemImage.create("images/forward.png",
+ "images/forward.png", this, function() {
+ var level = new classes.scenes.Level();
+ game.setScene('level', level);
+ game.changeScene(level);
+ });
+ var menuNext = cc.Menu.create(about);
+ menuNext.setPosition(cc.p(size.width - 100, 350));
+
+ var background = cc.Sprite.create("images/splash/bg.png");
+ background.setPosition(new cc.Point(
+ game.getWindowSize().width / 2,
+ game.getWindowSize().height / 2));
+
+ var hedgehog = cc.Sprite.create("images/splash/hedgehog.png");
+ hedgehog.setPosition(new cc.Point(
+ 200 + game.getWindowSize().width / 2, (game
+ .getWindowSize().height / 2) - 150));
+
+ var snail = cc.Sprite.create("images/splash/snail.png");
+ snail.setPosition(new cc.Point(
+ (game.getWindowSize().width / 2) - 200, (game
+ .getWindowSize().height / 2) - 150));
+
+ this.logo = cc.Sprite.create("images/splash/logo.png");
+ this.logo.setPosition(new cc.Point(
+ (game.getWindowSize().width / 2) - 100, (game
+ .getWindowSize().height / 2) + 70));
+
+ this.setTouchEnabled(true);
+
+ // adds layers/sprites to this layer in given order
+ this.addChild(background, 0);
+ // this.addChild(menuNext, 1);
+ this.addChild(hedgehog, 3);
+ this.addChild(snail, 4);
+ this.addChild(this.logo, 2);
+
+ return true;
+ },
+
+ adjustSizeForWindow : function() {
+ var margin = document.documentElement.clientWidth
+ - document.body.clientWidth;
+ if (document.documentElement.clientWidth < cc.originalCanvasSize.width) {
+ cc.canvas.width = cc.originalCanvasSize.width;
+ } else {
+ cc.canvas.width = document.documentElement.clientWidth
+ - margin;
+ }
+ if (document.documentElement.clientHeight < cc.originalCanvasSize.height) {
+ cc.canvas.height = cc.originalCanvasSize.height;
+ } else {
+ cc.canvas.height = document.documentElement.clientHeight
+ - margin;
+ }
+
+ var xScale = cc.canvas.width / cc.originalCanvasSize.width;
+ var yScale = cc.canvas.height / cc.originalCanvasSize.height;
+ if (xScale > yScale) {
+ xScale = yScale;
+ }
+ cc.canvas.width = cc.originalCanvasSize.width * xScale;
+ cc.canvas.height = cc.originalCanvasSize.height * xScale;
+ var parentDiv = document.getElementById("Cocos2dGameContainer");
+ if (parentDiv) {
+ parentDiv.style.width = cc.canvas.width + "px";
+ parentDiv.style.height = cc.canvas.height + "px";
+ }
+ cc.renderContext.translate(0, cc.canvas.height);
+ cc.renderContext.scale(xScale, xScale);
+ cc.Director.getInstance().setContentScaleFactor(xScale);
+ }
+ });
\ No newline at end of file
diff --git a/games/RunSnailRun/js/classes/layers/Level.js b/games/RunSnailRun/js/classes/layers/Level.js
new file mode 100644
index 00000000..ea5c4e94
--- /dev/null
+++ b/games/RunSnailRun/js/classes/layers/Level.js
@@ -0,0 +1,173 @@
+"use strict";
+classes.layers.Level = cc.Layer.extend({
+
+ timer : function(sec) {
+ return '
' + sec + '
'
+ + '
sec remaining
';
+ },
+
+ ctor : function() {
+ tizen.logger.info("classes.layers.Level.ctor()");
+ this._super();
+ this.addExitAppButton();
+ var that = this;
+ this.snails = [];
+ this.numberOfSnails = 0;
+ // keyboard enabled
+ this.setKeyboardEnabled(true);
+ this.keyboardArrows = {
+ left : false,
+ right : false,
+ up : false,
+ down : false
+ };
+
+ this.initTiledMap();
+ this.initSnails();
+ var size = cc.Director.getInstance().getWinSize();
+
+ // Timeout
+ var timeDisplayer = document.getElementById("timeLeft");
+ timeDisplayer.innerHTML = this.timer(game.config.timeout);
+
+ game.startCountdown(function(time) {
+ timeDisplayer.innerHTML = that.timer(game.config.timeout);
+ });
+
+ this.scheduleUpdate();
+ },
+
+ update : function(dt) {
+ var that = this;
+ this.moveAndCheckForObstacles(this.hedgehog, dt);
+ this.snails.forEach(function(snail) {
+ that.moveAndCheckForObstacles(snail, dt);
+ });
+ this.collisionDetection();
+ },
+
+ /**
+ * Initializes static sprite as a background
+ */
+ initBackground : function() {
+ this.background = new classes.sprites.Background();
+ this.addChild(this.background, -9);
+ },
+
+ initTiledMap : function() {
+ this.tiledMap = new classes.maps.TiledMeadow();
+ this.addChild(this.tiledMap, -8);
+
+ var objectGroup = this.tiledMap.getObjectGroup("hedgehog");
+ var startPoint = objectGroup.objectNamed("StartPosition");
+
+ this.hedgehog = new classes.sprites.Hedgehog();
+ this.hedgehog.setPosition(new cc.Point(startPoint.x, startPoint.y));
+ this.addChild(this.hedgehog, 2);
+ },
+
+ initSnails : function() {
+ if (this.tiledMap) {
+ var objectGroupSnails = this.tiledMap.getObjectGroup("snails");
+ var objectSnails = objectGroupSnails.getObjects();
+ this.numberOfSnails = objectSnails.length;
+ var that = this;
+ objectSnails.forEach(function(objectSnail) {
+ var snail = new classes.sprites.Snail();
+ snail.setPosition(new cc.Point(objectSnail.x, objectSnail.y));
+ that.snails.push(snail);
+ that.addChild(snail, 1);
+ });
+ }
+ },
+
+ isCollisionInArray : function(item, array) {
+ var i;
+ for (i = 0; i < array.length; i++) {
+ if (cc.rectIntersectsRect(item, array[i])) {
+ return true;
+ }
+ }
+ return false;
+ },
+
+ moveAndCheckForObstacles : function(object, dt) {
+ var newPosition = object.move(dt, this.keyboardArrows);
+ var newReactangle = cc.rect(newPosition.x + 2 - object.width / 2,
+ newPosition.y + 2 - object.height / 2, object.width - 4,
+ object.height - 4);
+ if (!this.isCollisionInArray(newReactangle, this.tiledMap.obstacles)) {
+ object.setPosition(newPosition);
+ }
+ },
+
+ onKeyDown : function(key) {
+ switch (key) {
+ case 37:
+ this.keyboardArrows.left = true;
+ break;
+ case 38:
+ this.keyboardArrows.up = true;
+ break;
+ case 39:
+ this.keyboardArrows.right = true;
+ break;
+ case 40:
+ this.keyboardArrows.down = true;
+ break;
+ default:
+ break;
+ }
+ },
+
+ onKeyUp : function(key) {
+ switch (key) {
+ case 37:
+ this.keyboardArrows.left = false;
+ break;
+ case 38:
+ this.keyboardArrows.up = false;
+ break;
+ case 39:
+ this.keyboardArrows.right = false;
+ break;
+ case 40:
+ this.keyboardArrows.down = false;
+ break;
+ default:
+ break;
+ }
+ },
+
+ removeCounter : function() {
+ var timeDisplayer = document.getElementById("timeLeft");
+ timeDisplayer.innerHTML = '';
+ },
+
+ collisionDetection : function() {
+ var i;
+ for (i = 0; i < this.snails.length; i++) {
+ if (cc.rectIntersectsRect(this.hedgehog.collideRect(),
+ this.snails[i].collideRect())) {
+ /**
+ * TODO: Sound effects temporary turned off
+ */
+ // game.getAudio().playEffect("sounds/splat");
+ this.removeChild(this.snails[i]);
+ this.numberOfSnails--;
+ this.snails.splice(i, 1);
+ if (this.numberOfSnails === 0) {
+ alert("You win!");
+ game.changeScene(game.getScene('intro'));
+ game.stopCountdown();
+ this.removeCounter();
+ }
+ }
+ }
+ },
+ removeAllSnails : function() {
+ for ( var i = 0; i < this.snails.length; i++) {
+ this.removeChild(this.snails[i]);
+ }
+ }
+});
\ No newline at end of file
diff --git a/games/RunSnailRun/js/classes/layers/layers.js b/games/RunSnailRun/js/classes/layers/layers.js
new file mode 100644
index 00000000..ca32f1e2
--- /dev/null
+++ b/games/RunSnailRun/js/classes/layers/layers.js
@@ -0,0 +1,5 @@
+/**
+ * @namespace
+ */
+"use strict";
+classes.layers = {};
\ No newline at end of file
diff --git a/games/RunSnailRun/js/classes/maps/TiledMeadow.js b/games/RunSnailRun/js/classes/maps/TiledMeadow.js
new file mode 100644
index 00000000..9c1587c2
--- /dev/null
+++ b/games/RunSnailRun/js/classes/maps/TiledMeadow.js
@@ -0,0 +1,54 @@
+"use strict";
+classes.maps.TiledMeadow = cc.TMXTiledMap
+ .extend({
+ ctor : function() {
+ this._super();
+ tizen.logger.info("classes.maps.TiledMeadow.ctor()");
+ this.initWithTMXFile("images/tiledMeadow.tmx");
+ this.initObstacles();
+ },
+
+ getTileCoordForPosition : function(position) {
+ var x = Math.floor(position.x / this.getTileSize().width);
+ var y = Math.floor(((this.getTileSize().height * this
+ .getMapSize().height) - position.y)
+ / this.getTileSize().height);
+ return new cc.Point(x, y);
+ },
+
+ isCollidable : function(tileCoord) {
+ var collidableLayer = this.getLayer("collidable");
+ var gid = collidableLayer.getTileGIDAt(tileCoord);
+ if (gid) {
+ var tileProperties = this.propertiesForGID(gid);
+ return true;
+ }
+ return false;
+ },
+
+ initObstacles : function() {
+ this.obstacles = [];
+ var mapWidth = this.getMapSize().width;
+ var mapHeight = this.getMapSize().height;
+ var tileWidth = this.getTileSize().width;
+ var tileHeight = this.getTileSize().height;
+ var collidableLayer = this.getLayer("collidable");
+ var i, j;
+ for (i = 0; i < mapWidth; i++) {
+ for (j = 0; j < mapHeight; j++) {
+ var tileCoord = new cc.Point(i, j);
+ var gid = collidableLayer.getTileGIDAt(tileCoord);
+ if (gid) {
+ var tileXPositon = i * tileWidth;
+ var tileYPosition = (mapHeight * tileHeight)
+ - ((j + 1) * tileHeight);
+ var react = cc.rect(tileXPositon, tileYPosition,
+ tileWidth, tileHeight);
+ this.obstacles.push(react);
+ }
+ }
+ }
+ tizen.logger.info("TiledMeadow: There are "
+ + this.obstacles.length + " tiled obstacles");
+ }
+ });
diff --git a/games/RunSnailRun/js/classes/maps/maps.js b/games/RunSnailRun/js/classes/maps/maps.js
new file mode 100644
index 00000000..0ed9e604
--- /dev/null
+++ b/games/RunSnailRun/js/classes/maps/maps.js
@@ -0,0 +1,5 @@
+/**
+ * @namespace
+ */
+"use strict";
+classes.maps = {};
\ No newline at end of file
diff --git a/games/RunSnailRun/js/classes/scenes/Intro.js b/games/RunSnailRun/js/classes/scenes/Intro.js
new file mode 100644
index 00000000..5492f1f5
--- /dev/null
+++ b/games/RunSnailRun/js/classes/scenes/Intro.js
@@ -0,0 +1,8 @@
+"use strict";
+classes.scenes.Intro = cc.Scene.extend({
+ ctor : function() {
+ this._super();
+ this.introLayer = new classes.layers.Intro();
+ this.addChild(this.introLayer);
+ }
+});
\ No newline at end of file
diff --git a/games/RunSnailRun/js/classes/scenes/Level.js b/games/RunSnailRun/js/classes/scenes/Level.js
new file mode 100644
index 00000000..ff810b72
--- /dev/null
+++ b/games/RunSnailRun/js/classes/scenes/Level.js
@@ -0,0 +1,8 @@
+"use strict";
+classes.scenes.Level = cc.Scene.extend({
+ ctor : function() {
+ this._super();
+ this.levelLayer = new classes.layers.Level();
+ this.addChild(this.levelLayer);
+ }
+});
\ No newline at end of file
diff --git a/games/RunSnailRun/js/classes/scenes/scenes.js b/games/RunSnailRun/js/classes/scenes/scenes.js
new file mode 100644
index 00000000..f23ea492
--- /dev/null
+++ b/games/RunSnailRun/js/classes/scenes/scenes.js
@@ -0,0 +1,5 @@
+/**
+ * @namespace
+ */
+"use strict";
+classes.scenes = {};
\ No newline at end of file
diff --git a/games/RunSnailRun/js/classes/sprites/Background.js b/games/RunSnailRun/js/classes/sprites/Background.js
new file mode 100644
index 00000000..800d9b58
--- /dev/null
+++ b/games/RunSnailRun/js/classes/sprites/Background.js
@@ -0,0 +1,12 @@
+"use strict";
+classes.sprites.Background = cc.Sprite.extend({
+ width : 1280,
+ height : 670,
+ ctor : function() {
+ this._super();
+ tizen.logger.info("classes.sprites.Background.ctor()");
+ this.initWithFile("images/meadow.jpeg");
+ this.setPosition(new cc.Point(game.getWindowSize().width / 2, game
+ .getWindowSize().height / 2));
+ }
+});
diff --git a/games/RunSnailRun/js/classes/sprites/Circle.js b/games/RunSnailRun/js/classes/sprites/Circle.js
new file mode 100644
index 00000000..6a2bf8a9
--- /dev/null
+++ b/games/RunSnailRun/js/classes/sprites/Circle.js
@@ -0,0 +1,21 @@
+"use strict";
+classes.sprites.Circle = cc.Sprite.extend({
+ _radians : 0,
+ ctor : function() {
+ this._super();
+ },
+ draw : function() {
+ cc.renderContext.fillStyle = "rgba(255,255,255,1)";
+ cc.renderContext.strokeStyle = "rgba(255,255,255,1)";
+
+ if (this._radians < 0) {
+ this._radians = 360;
+ }
+ ;
+ cc.drawingUtil.drawCircle(cc.PointZero(), 30, cc
+ .DEGREES_TO_RADIANS(this._radians), 60, true);
+ },
+ myUpdate : function(dt) {
+ this._radians -= 6;
+ }
+});
\ No newline at end of file
diff --git a/games/RunSnailRun/js/classes/sprites/Hedgehog.js b/games/RunSnailRun/js/classes/sprites/Hedgehog.js
new file mode 100644
index 00000000..c83fd133
--- /dev/null
+++ b/games/RunSnailRun/js/classes/sprites/Hedgehog.js
@@ -0,0 +1,55 @@
+"use strict";
+classes.sprites.Hedgehog = cc.Sprite
+ .extend({
+ width : 30,
+ height : 30,
+ speed : 300,
+ ctor : function() {
+ this._super();
+ tizen.logger.info("classes.sprites.Hedgehog.ctor()");
+ this.initWithFile("images/hedgehog.png");
+ this.setPosition(new cc.Point(game.getWindowSize().width / 2,
+ game.getWindowSize().height / 2));
+
+ },
+ move : function(dt, keyboardArrows) {
+ var pos = this.getPosition();
+ /**
+ * TODO: Axis are inverted for different types of devices.
+ *
+ */
+ if (keyboardArrows.left) {
+ pos.x = pos.x - this.speed * dt;
+ }
+ if (keyboardArrows.right) {
+ pos.x = pos.x + this.speed * dt;
+ }
+ if (keyboardArrows.up) {
+ pos.y = pos.y + this.speed * dt;
+ }
+ if (keyboardArrows.down) {
+ pos.y = pos.y - this.speed * dt;
+ }
+
+ pos.x = pos.x - (sensors.getBeta() / 4);
+ pos.y = pos.y - (sensors.getGamma() / 5);
+
+ if (pos.x < this.width / 2) {
+ pos.x = this.width / 2;
+ } else if (pos.x > (game.getWindowSize().width - this.width / 2)) {
+ pos.x = (game.getWindowSize().width - this.width / 2);
+ }
+ if (pos.y < this.height / 2) {
+ pos.y = this.height / 2;
+ } else if (pos.y > (game.getWindowSize().height - this.height / 2)) {
+ pos.y = (game.getWindowSize().height - this.height / 2);
+ }
+ return new cc.Point(pos.x, pos.y);
+ },
+ collideRect : function() {
+ var a = this.getContentSize();
+ var p = this.getPosition();
+ return cc.rect(p.x - a.width / 2, p.y - a.height / 2, a.width,
+ a.height);
+ }
+ });
\ No newline at end of file
diff --git a/games/RunSnailRun/js/classes/sprites/Snail.js b/games/RunSnailRun/js/classes/sprites/Snail.js
new file mode 100644
index 00000000..79089a06
--- /dev/null
+++ b/games/RunSnailRun/js/classes/sprites/Snail.js
@@ -0,0 +1,50 @@
+"use strict";
+classes.sprites.Snail = cc.Sprite
+ .extend({
+ width : 30,
+ height : 30,
+ x : 0,
+ y : 0,
+ vx : Math.random() - 0.5,
+ vy : Math.random() - 0.5,
+ ctor : function() {
+ this._super();
+ this.initWithFile("images/snail.png");
+ },
+ move : function() {
+ var DAMP = 0.99;
+
+ this.x = this.getPosition().x;
+ this.y = this.getPosition().y;
+
+ this.vx += Math.random() * 0.5 - 0.25;
+ this.vy += Math.random() * 0.5 - 0.25;
+
+ var newx = this.x + this.vx;
+ var newy = this.y + this.vy;
+
+ this.x += this.vx;
+ this.y += this.vy;
+
+ this.vx *= DAMP;
+ this.vy *= DAMP;
+
+ this.vx = this.x < 50 ? this.vx * -1 : this.x > 1200 ? this.vx
+ * -1 : this.vx;
+ this.vy = this.y < 50 ? this.vy * -1 : this.y > 600 ? this.vy
+ * -1 : this.vy;
+ this.x = this.x < 0 ? game.getWindowSize().width
+ : this.x > game.getWindowSize().width ? 0 : this.x;
+ this.y = this.y < 0 ? game.getWindowSize().height
+ : this.y > game.getWindowSize().height ? 0 : this.y;
+
+ return new cc.Point(this.x, this.y);
+
+ },
+ collideRect : function() {
+ var a = this.getContentSize();
+ var p = this.getPosition();
+ return cc.rect(p.x - a.width / 2, p.y - a.height / 2, a.width,
+ a.height);
+ }
+ });
\ No newline at end of file
diff --git a/games/RunSnailRun/js/classes/sprites/sprites.js b/games/RunSnailRun/js/classes/sprites/sprites.js
new file mode 100644
index 00000000..5935329c
--- /dev/null
+++ b/games/RunSnailRun/js/classes/sprites/sprites.js
@@ -0,0 +1,5 @@
+/**
+ * @namespace
+ */
+"use strict";
+classes.sprites = {};
\ No newline at end of file
diff --git a/games/RunSnailRun/js/cocos2d.js b/games/RunSnailRun/js/cocos2d.js
new file mode 100644
index 00000000..1db294a7
--- /dev/null
+++ b/games/RunSnailRun/js/cocos2d.js
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2008-2010 Ricardo Quesada
+ * Copyright (c) 2011 Zynga Inc.
+ *
+ * http://www.cocos2d-x.org
+ *
+ *
+ * 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:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * 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.
+ ******************************************************************************/
+(function() {
+ var d = document;
+ /**
+ * The following c variable is the global cocos2d configuration. You can set
+ * all the cocos2d related values, like frame rate or box2d.
+ */
+ var c = {
+ // 0 to turn debug off, 1 for basic debug, and 2 for full debug
+ COCOS2D_DEBUG : 2,
+
+ box2d : false,
+ chipmunk : false,
+ showFPS : true,
+ frameRate : 60,
+ loadExtension : false,
+
+ // the dom element to run cocos2d on
+ tag : 'gameCanvas',
+
+ engineDir : '../../../cocos2d/',
+ // SingleEngineFile:'',
+ /**
+ * In this array you should put your custom application files.
+ */
+ appFiles : [ "js/game.js", "js/sensors.js", "js/power.js", "js/extentions.js",
+ "js/classes/classes.js", "js/classes/Application.js",
+ "js/classes/sprites/sprites.js", "js/classes/sprites/Circle.js",
+ "js/classes/sprites/Hedgehog.js", "js/classes/sprites/Snail.js",
+ "js/classes/sprites/Background.js", "js/classes/layers/layers.js",
+ "js/classes/layers/Intro.js", "js/classes/layers/Level.js",
+ "js/classes/scenes/scenes.js", "js/classes/scenes/Intro.js",
+ "js/classes/scenes/Level.js", "js/classes/maps/maps.js",
+ "js/classes/maps/TiledMeadow.js" ]
+ };
+
+ if (!d.createElement('canvas').getContext) {
+ var s = d.createElement('div');
+ s.innerHTML = '
Your browser does not support HTML5 canvas!
'
+ + '
Google Chrome is a browser that combines a minimal design with sophisticated technology to make the web faster, safer, and easier.Click the logo to download.
'
+ + '';
+ var p = d.getElementById(c.tag).parentNode;
+ p.style.background = 'none';
+ p.style.border = 'none';
+ p.insertBefore(s);
+
+ d.body.style.background = '#ffffff';
+ return;
+ }
+
+ window
+ .addEventListener(
+ 'DOMContentLoaded',
+ function() {
+ // first load engine file if specified
+ var s = d.createElement('script');
+ /**
+ * *******Delete this section if you have packed all
+ * files into one******
+ */
+ if (c.SingleEngineFile && !c.engineDir) {
+ s.src = c.SingleEngineFile;
+ } else if (c.engineDir && !c.SingleEngineFile) {
+ s.src = c.engineDir + 'platform/jsloader.js';
+ } else {
+ alert('You must specify either the single engine file OR the engine directory in "cocos2d.js"');
+ }
+ /**
+ * *******Delete this section if you have packed all
+ * files into one******
+ */
+
+ // s.src = 'Packed_Release_File.js'; //IMPORTANT:
+ // Un-comment this line if you have packed all files
+ // into one
+ document.ccConfig = c;
+ s.id = 'cocos2d-html5';
+ d.body.appendChild(s);
+ // else if single file specified, load singlefile
+ });
+})();
diff --git a/games/RunSnailRun/js/extentions.js b/games/RunSnailRun/js/extentions.js
new file mode 100644
index 00000000..6ced8549
--- /dev/null
+++ b/games/RunSnailRun/js/extentions.js
@@ -0,0 +1,15 @@
+"use strict";
+cc.Layer.prototype.addExitAppButton = function() {
+ var size = cc.Director.getInstance().getWinSize();
+ var closeItem = cc.MenuItemImage.create("images/CloseNormal.png",
+ "images/CloseSelected.png", function() {
+ if (confirm("Exit?") && tizen && tizen.application) {
+ tizen.application.getCurrentApplication().exit();
+ }
+ });
+ closeItem.setAnchorPoint(cc.p(0.5, 0.5));
+ var menu = cc.Menu.create(closeItem);
+ menu.setPosition(cc.PointZero());
+ closeItem.setPosition(cc.p(size.width - 20, 20));
+ this.addChild(menu, 10);
+};
\ No newline at end of file
diff --git a/games/RunSnailRun/js/game.js b/games/RunSnailRun/js/game.js
new file mode 100644
index 00000000..9ccf64a2
--- /dev/null
+++ b/games/RunSnailRun/js/game.js
@@ -0,0 +1,129 @@
+"use strict";
+var game = (function() {
+ var application;
+ var initialTimeout;
+ var intPtr;
+ var audio = cc.AudioEngine.getInstance();
+ /**
+ * All scenes for the application
+ */
+ var scenes = {};
+
+ return {
+
+ /**
+ * The following config variable is the global game configuration. You
+ * can set all the game related values, like sensors or game timeout.
+ */
+ config : {
+ width : 1260,
+ height : 660,
+ useSensor : true,
+ debug : false,
+ timeout : 30,
+ /**
+ * All game multimedia resources
+ */
+ resources : [ {
+ type : "image",
+ src : "images/HelloWorld.png"
+ }, {
+ type : "image",
+ src : "images/CloseNormal.png"
+ }, {
+ type : "image",
+ src : "images/CloseSelected.png"
+ }, {
+ type : "image",
+ src : "images/forward.png"
+ }, {
+ type : "image",
+ src : "images/hedgehog.png"
+ }, {
+ type : "image",
+ src : "images/snail.png"
+ }, {
+ type : "image",
+ src : "images/lettuce.png"
+ }, {
+ type : "image",
+ src : "images/ground.png"
+ }, {
+ type : "effect",
+ src : "sounds/splat.mp3"
+ }, {
+ type : "tmx",
+ src : "images/tiledMeadow.tmx"
+ }, {
+ type : "image",
+ src : "images/splash/bg.png"
+ }, {
+ type : "image",
+ src : "images/splash/hedgehog.png"
+ }, {
+ type : "image",
+ src : "images/splash/logo.png"
+ }, {
+ type : "image",
+ src : "images/splash/snail.png"
+ } ]
+ },
+
+ getScene : function(scene) {
+ return scenes[scene];
+ },
+
+ setScene : function(name, scene) {
+ scenes[name] = scene;
+ },
+
+ initialize : function() {
+ tizen.logger = tizen.logger({
+ logLevel : 3
+ });
+ tizen.logger.info("game.initialize()");
+ tizen.view.getScreenWidth();
+ tizen.view.getScreenHeight();
+ audio.init("mp3,ogg");
+ power.setScreen(power.getPowerState().SCREEN_BRIGHT);
+ },
+ getRandomXPosition : function() {
+ return Math.floor((Math.random() * this.config.width));
+ },
+ getRandomYPosition : function() {
+ return Math.floor((Math.random() * this.config.height));
+ },
+ changeScene : function(scene) {
+ cc.Director.getInstance().replaceScene(
+ cc.TransitionFade.create(1.2, scene));
+ },
+ getWindowSize : function() {
+ return cc.Director.getInstance().getWinSize();
+ },
+ getAudio : function() {
+ return audio;
+ },
+ start : function() {
+ tizen.logger.info("game.start()");
+ application = new classes.Application(classes.scenes.Intro);
+ },
+ stopCountdown : function() {
+ clearInterval(intPtr);
+ this.getScene('level').levelLayer.removeAllSnails();
+ this.config.timeout = initialTimeout;
+ },
+ startCountdown : function(callback) {
+ var that = this;
+ initialTimeout = that.config.timeout;
+ intPtr = setInterval(function() {
+ callback(--that.config.timeout);
+ if (that.config.timeout === 0) {
+ that.stopCountdown();
+ alert("Game over... Please try again...");
+ that.getScene('level').levelLayer.removeCounter();
+ that.changeScene(that.getScene('intro'));
+ }
+ }, 1000);
+ }
+ };
+}());
diff --git a/games/RunSnailRun/js/lib/external/jquery-1.8.2.js b/games/RunSnailRun/js/lib/external/jquery-1.8.2.js
new file mode 100644
index 00000000..63174a0d
--- /dev/null
+++ b/games/RunSnailRun/js/lib/external/jquery-1.8.2.js
@@ -0,0 +1,2 @@
+/*! jQuery v1.8.2 jquery.com | jquery.org/license */
+(function(a,b){function G(a){var b=F[a]={};return p.each(a.split(s),function(a,c){b[c]=!0}),b}function J(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(I,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:+d+""===d?+d:H.test(d)?p.parseJSON(d):d}catch(f){}p.data(a,c,d)}else d=b}return d}function K(a){var b;for(b in a){if(b==="data"&&p.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function ba(){return!1}function bb(){return!0}function bh(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function bi(a,b){do a=a[b];while(a&&a.nodeType!==1);return a}function bj(a,b,c){b=b||0;if(p.isFunction(b))return p.grep(a,function(a,d){var e=!!b.call(a,d,a);return e===c});if(b.nodeType)return p.grep(a,function(a,d){return a===b===c});if(typeof b=="string"){var d=p.grep(a,function(a){return a.nodeType===1});if(be.test(b))return p.filter(b,d,!c);b=p.filter(b,d)}return p.grep(a,function(a,d){return p.inArray(a,b)>=0===c})}function bk(a){var b=bl.split("|"),c=a.createDocumentFragment();if(c.createElement)while(b.length)c.createElement(b.pop());return c}function bC(a,b){return a.getElementsByTagName(b)[0]||a.appendChild(a.ownerDocument.createElement(b))}function bD(a,b){if(b.nodeType!==1||!p.hasData(a))return;var c,d,e,f=p._data(a),g=p._data(b,f),h=f.events;if(h){delete g.handle,g.events={};for(c in h)for(d=0,e=h[c].length;d").appendTo(e.body),c=b.css("display");b.remove();if(c==="none"||c===""){bI=e.body.appendChild(bI||p.extend(e.createElement("iframe"),{frameBorder:0,width:0,height:0}));if(!bJ||!bI.createElement)bJ=(bI.contentWindow||bI.contentDocument).document,bJ.write(""),bJ.close();b=bJ.body.appendChild(bJ.createElement(a)),c=bH(b,"display"),e.body.removeChild(bI)}return bS[a]=c,c}function ci(a,b,c,d){var e;if(p.isArray(b))p.each(b,function(b,e){c||ce.test(a)?d(a,e):ci(a+"["+(typeof e=="object"?b:"")+"]",e,c,d)});else if(!c&&p.type(b)==="object")for(e in b)ci(a+"["+e+"]",b[e],c,d);else d(a,b)}function cz(a){return function(b,c){typeof b!="string"&&(c=b,b="*");var d,e,f,g=b.toLowerCase().split(s),h=0,i=g.length;if(p.isFunction(c))for(;h)[^>]*$|#([\w\-]*)$)/,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,w=/^[\],:{}\s]*$/,x=/(?:^|:|,)(?:\s*\[)+/g,y=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,z=/"[^"\\\r\n]*"|true|false|null|-?(?:\d\d*\.|)\d+(?:[eE][\-+]?\d+|)/g,A=/^-ms-/,B=/-([\da-z])/gi,C=function(a,b){return(b+"").toUpperCase()},D=function(){e.addEventListener?(e.removeEventListener("DOMContentLoaded",D,!1),p.ready()):e.readyState==="complete"&&(e.detachEvent("onreadystatechange",D),p.ready())},E={};p.fn=p.prototype={constructor:p,init:function(a,c,d){var f,g,h,i;if(!a)return this;if(a.nodeType)return this.context=this[0]=a,this.length=1,this;if(typeof a=="string"){a.charAt(0)==="<"&&a.charAt(a.length-1)===">"&&a.length>=3?f=[null,a,null]:f=u.exec(a);if(f&&(f[1]||!c)){if(f[1])return c=c instanceof p?c[0]:c,i=c&&c.nodeType?c.ownerDocument||c:e,a=p.parseHTML(f[1],i,!0),v.test(f[1])&&p.isPlainObject(c)&&this.attr.call(a,c,!0),p.merge(this,a);g=e.getElementById(f[2]);if(g&&g.parentNode){if(g.id!==f[2])return d.find(a);this.length=1,this[0]=g}return this.context=e,this.selector=a,this}return!c||c.jquery?(c||d).find(a):this.constructor(c).find(a)}return p.isFunction(a)?d.ready(a):(a.selector!==b&&(this.selector=a.selector,this.context=a.context),p.makeArray(a,this))},selector:"",jquery:"1.8.2",length:0,size:function(){return this.length},toArray:function(){return k.call(this)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=p.merge(this.constructor(),a);return d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")"),d},each:function(a,b){return p.each(this,a,b)},ready:function(a){return p.ready.promise().done(a),this},eq:function(a){return a=+a,a===-1?this.slice(a):this.slice(a,a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(k.apply(this,arguments),"slice",k.call(arguments).join(","))},map:function(a){return this.pushStack(p.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:j,sort:[].sort,splice:[].splice},p.fn.init.prototype=p.fn,p.extend=p.fn.extend=function(){var a,c,d,e,f,g,h=arguments[0]||{},i=1,j=arguments.length,k=!1;typeof h=="boolean"&&(k=h,h=arguments[1]||{},i=2),typeof h!="object"&&!p.isFunction(h)&&(h={}),j===i&&(h=this,--i);for(;i0)return;d.resolveWith(e,[p]),p.fn.trigger&&p(e).trigger("ready").off("ready")},isFunction:function(a){return p.type(a)==="function"},isArray:Array.isArray||function(a){return p.type(a)==="array"},isWindow:function(a){return a!=null&&a==a.window},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},type:function(a){return a==null?String(a):E[m.call(a)]||"object"},isPlainObject:function(a){if(!a||p.type(a)!=="object"||a.nodeType||p.isWindow(a))return!1;try{if(a.constructor&&!n.call(a,"constructor")&&!n.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||n.call(a,d)},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},error:function(a){throw new Error(a)},parseHTML:function(a,b,c){var d;return!a||typeof a!="string"?null:(typeof b=="boolean"&&(c=b,b=0),b=b||e,(d=v.exec(a))?[b.createElement(d[1])]:(d=p.buildFragment([a],b,c?null:[]),p.merge([],(d.cacheable?p.clone(d.fragment):d.fragment).childNodes)))},parseJSON:function(b){if(!b||typeof b!="string")return null;b=p.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(w.test(b.replace(y,"@").replace(z,"]").replace(x,"")))return(new Function("return "+b))();p.error("Invalid JSON: "+b)},parseXML:function(c){var d,e;if(!c||typeof c!="string")return null;try{a.DOMParser?(e=new DOMParser,d=e.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(f){d=b}return(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&p.error("Invalid XML: "+c),d},noop:function(){},globalEval:function(b){b&&r.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(A,"ms-").replace(B,C)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,c,d){var e,f=0,g=a.length,h=g===b||p.isFunction(a);if(d){if(h){for(e in a)if(c.apply(a[e],d)===!1)break}else for(;f0&&a[0]&&a[i-1]||i===0||p.isArray(a));if(j)for(;h-1)i.splice(c,1),e&&(c<=g&&g--,c<=h&&h--)}),this},has:function(a){return p.inArray(a,i)>-1},empty:function(){return i=[],this},disable:function(){return i=j=c=b,this},disabled:function(){return!i},lock:function(){return j=b,c||l.disable(),this},locked:function(){return!j},fireWith:function(a,b){return b=b||[],b=[a,b.slice?b.slice():b],i&&(!d||j)&&(e?j.push(b):k(b)),this},fire:function(){return l.fireWith(this,arguments),this},fired:function(){return!!d}};return l},p.extend({Deferred:function(a){var b=[["resolve","done",p.Callbacks("once memory"),"resolved"],["reject","fail",p.Callbacks("once memory"),"rejected"],["notify","progress",p.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return p.Deferred(function(c){p.each(b,function(b,d){var f=d[0],g=a[b];e[d[1]](p.isFunction(g)?function(){var a=g.apply(this,arguments);a&&p.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f+"With"](this===e?c:this,[a])}:c[f])}),a=null}).promise()},promise:function(a){return a!=null?p.extend(a,d):d}},e={};return d.pipe=d.then,p.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[a^1][2].disable,b[2][2].lock),e[f[0]]=g.fire,e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=k.call(arguments),d=c.length,e=d!==1||a&&p.isFunction(a.promise)?d:0,f=e===1?a:p.Deferred(),g=function(a,b,c){return function(d){b[a]=this,c[a]=arguments.length>1?k.call(arguments):d,c===h?f.notifyWith(b,c):--e||f.resolveWith(b,c)}},h,i,j;if(d>1){h=new Array(d),i=new Array(d),j=new Array(d);for(;b
a",c=n.getElementsByTagName("*"),d=n.getElementsByTagName("a")[0],d.style.cssText="top:1px;float:left;opacity:.5";if(!c||!c.length)return{};f=e.createElement("select"),g=f.appendChild(e.createElement("option")),h=n.getElementsByTagName("input")[0],b={leadingWhitespace:n.firstChild.nodeType===3,tbody:!n.getElementsByTagName("tbody").length,htmlSerialize:!!n.getElementsByTagName("link").length,style:/top/.test(d.getAttribute("style")),hrefNormalized:d.getAttribute("href")==="/a",opacity:/^0.5/.test(d.style.opacity),cssFloat:!!d.style.cssFloat,checkOn:h.value==="on",optSelected:g.selected,getSetAttribute:n.className!=="t",enctype:!!e.createElement("form").enctype,html5Clone:e.createElement("nav").cloneNode(!0).outerHTML!=="<:nav>",boxModel:e.compatMode==="CSS1Compat",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0,boxSizingReliable:!0,pixelPosition:!1},h.checked=!0,b.noCloneChecked=h.cloneNode(!0).checked,f.disabled=!0,b.optDisabled=!g.disabled;try{delete n.test}catch(o){b.deleteExpando=!1}!n.addEventListener&&n.attachEvent&&n.fireEvent&&(n.attachEvent("onclick",m=function(){b.noCloneEvent=!1}),n.cloneNode(!0).fireEvent("onclick"),n.detachEvent("onclick",m)),h=e.createElement("input"),h.value="t",h.setAttribute("type","radio"),b.radioValue=h.value==="t",h.setAttribute("checked","checked"),h.setAttribute("name","t"),n.appendChild(h),i=e.createDocumentFragment(),i.appendChild(n.lastChild),b.checkClone=i.cloneNode(!0).cloneNode(!0).lastChild.checked,b.appendChecked=h.checked,i.removeChild(h),i.appendChild(n);if(n.attachEvent)for(k in{submit:!0,change:!0,focusin:!0})j="on"+k,l=j in n,l||(n.setAttribute(j,"return;"),l=typeof n[j]=="function"),b[k+"Bubbles"]=l;return p(function(){var c,d,f,g,h="padding:0;margin:0;border:0;display:block;overflow:hidden;",i=e.getElementsByTagName("body")[0];if(!i)return;c=e.createElement("div"),c.style.cssText="visibility:hidden;border:0;width:0;height:0;position:static;top:0;margin-top:1px",i.insertBefore(c,i.firstChild),d=e.createElement("div"),c.appendChild(d),d.innerHTML="