var o0 = require('o0'); var o0CC = require('o0CC'); var o0Game = require('o0Game'); cc.Class({ extends: cc.CircleCollider, properties: { speed: 1,//per frame turningSpeed: 6,//degree per frame normalSpeedRate: 1,//加速时的速度比率 speedingSpeedRate: 3,//加速时的速度比率 targetSpeedRate: 1,//当前速度比率 isSpeeding: { get: function (){ return this.targetSpeedRate != this.normalSpeedRate; } }, targetVector:null, bodySpacingRate: 0.4,//rate of size bodySpacing: 0, pulledScore: 0, pullScoreThreshold: { get: function (){ return Math.pow(this.snake.body[0].scaleX * this.snake.body[0].scaleY,1) * 2; } }, pullScoreRate:0.7,//the rate means remove 1 score from snake, and 0.5 score will come out to be food. speedingScoreCost: 0.1,//score cost per frame speeding minScore: 5, snake:null, fixedTimer:null, }, updateSpeed:function(){ this.speed = 5 * Math.pow(this.snake.body[0].scaleX * this.snake.body[0].scaleY,1.0/3); }, updateBodySpacing:function(){ this.bodySpacing = this.radius*2 * this.bodySpacingRate * Math.sqrt(this.snake.body[0].scaleX * this.snake.body[0].scaleY); }, setTargetSpeeding:function(bool){ if(!bool) this.targetSpeedRate = this.normalSpeedRate; else this.targetSpeedRate = this.speedingSpeedRate; }, setTargetVector:function(vector){ this.targetVector = vector; }, removeTargetVector:function(){ this.setTargetVector(o0CC.vectorFromRotation(this.snake.head.rotation)); }, addScore: function (score) { if(this.snake == null){ return; } this.snake.setScore(this.snake.score + score); //this.snake.score += score; //this.snake.updateScale(); this.updateBodySpacing(); this.updateSpeed(); /*var targetBodyLength = Math.ceil(this.snake.bodyLength); while(targetBodyLength > this.snake.body.length){ this.snake.addBody(); }/** */ }, pullFood: function (score) { var newFood = o0CC.addScriptNode(this.snake.gameScene.foodNode,'Food',-100); var lastBody = this.snake.body[this.snake.body.length-1]; var foodPosition = o0.randomInCircle2(lastBody,(this.radius-newFood.radius)*2); newFood.node.x = foodPosition.x; newFood.node.y = foodPosition.y; newFood.score = score; newFood.node.name = ''+(this.snake.gameScene.foodIDcounter++); }, pullAllFood: function () { var pullScoreThreshold = this.pullScoreThreshold; while(this.snake.score >= 1){ this.pullScore(1,pullScoreThreshold); } }, pullScore:function(score){ this.snake.setScore(this.snake.score - score); //this.snake.score -= score; //this.snake.updateScale(); this.updateBodySpacing(); this.updateSpeed(); this.pulledScore += score * this.pullScoreRate; var pullScoreThreshold; if(arguments.length < 2){ pullScoreThreshold = this.pullScoreThreshold; }else{ pullScoreThreshold = arguments[1]; } if(this.pulledScore >= pullScoreThreshold){ this.pulledScore -= pullScoreThreshold; this.pullFood(pullScoreThreshold); }/* var targetBodyLength = Math.ceil(this.snake.bodyLength); while(targetBodyLength < this.snake.body.length && this.snake.body.length > 1){ this.snake.removeBody(); }/** */ }, updateSnakeBody:function(){ //cc.log(this.getComponent('Snake').body.length); for(var i = 0, j = 1;j= 1){ this.pullScore(1); } while(this.snake.body.length > 1){ this.removeBody(); } //cc.log(this.snake.score); //this.destroy(); },/** */ pulsatingFeedback:function(){ if(this.isSpeeding && this.snake.score > this.minScore){ for(var i =0;i 1) for(var i = 1; i