123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676 |
- // 对手削球,从右侧到右侧
- cc.Class({
- extends: cc.Component,
- properties: {
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.initValues();
- this.initNodes();
- },
- // start () {
- // this.rivalPeelLtoR_01();
- // this.ballAction();
- // },
- // update() {
- // var beginPos = cc.v2(-95, 264);
- // var centerPos = cc.v2(30, 5);
- // var endPos = cc.v2(163, -140);
- // this.g.lineWidth = 4;
- // this.g.moveTo(beginPos.x, beginPos.y);
- // this.g.bezierCurveTo(beginPos.x, beginPos.y, -270, 440, centerPos.x, centerPos.y);
- // this.g.bezierCurveTo(centerPos.x, centerPos.y, 110, 20, endPos.x, endPos.y);
- // this.g.stroke();
- // },
- // 初始化
- initValues:function () {
- // 配置绘制的数据
- // 从配置中心获取数据
- this.gameconfig = require ("gameconfig")
- // 配置绘制组件
- this.g = this.getComponent(cc.Graphics);
- // 球的状态
- this.ballconfig = require("ballconfig");
- // 记录下节点
- this.poses = new Array();
- // 记录是否需要撞击的效果
- this.showBump = false;
- // 速度
- this.speed = 100.0;
- },
- // 初始化子节点
- initNodes:function() {
- this.head = new cc.Node("");
- this.head.setPosition(cc.v2(0, 0));
- this.head.parent = this.node;
- },
- // 外部调用
- // 球的运动停止
- ballStop:function() {
- // 首先停止所有动作
- this.head.stopAllActions();
- // 清空节点数组
- this.poses = [];
- this.g.clear();
- },
- // 全部停止
- ballEnd:function() {
- this.unschedule(this.ballUpdate);
- // 首先停止所有动作
- this.head.stopAllActions();
- // 清空节点数组
- this.poses = [];
- this.g.clear();
- },
- // 球开始运动,开始刷新帧
- ballAction:function() {
- this.schedule(this.ballUpdate, 1 / 60);
- },
- // 我方接球,从左到左
- minePatLToL_01:function() {
- if(this.stateCallback != null) {
- this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
- }
- var beginPos = cc.v2(-103, -110);
- var dropPos = cc.v2(-64, 144);
- var endPos = cc.v2(-53, 313);
- // 将节点移动到指定位置
- this.head.setPosition(beginPos);
- var bezier_01 = [beginPos, cc.v2(-82, 20), dropPos];
- var bezier_02 = [dropPos, cc.v2(-68, 220), endPos];
- var move_01 = cc.bezierTo(this.speed / 300, bezier_01);
- var self = this;
- var move_01_end = cc.callFunc(function() {
- self.bump(dropPos);
- });
- var move_02_time = this.speed / 300;
- var move_02 = cc.bezierTo(move_02_time, bezier_02);
- // 在第二条路线后开始的一段时间,需要通知控制器改变状态
- var delay = cc.delayTime(move_02_time / 4);
- var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_RIVAL_LEFT_PAT);
- var spawn = cc.spawn(move_02, cc.sequence(delay, change));
- var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_RIVAL);
- var jump = cc.jumpBy(1, cc.v2(50, 40), 30, 2);
- this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
- },
- // 我方接球,从右到右
- minePatRToR_01:function() {
- if(this.stateCallback != null) {
- this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
- }
- var beginPos = cc.v2(52, -109);
- var dropPos = cc.v2(71, 141);
- var endPos = cc.v2(131, 309);
- // 将节点移动到指定位置
- this.head.setPosition(beginPos);
- var bezier_01 = [beginPos, cc.v2(61, 16), dropPos];
- var bezier_02 = [dropPos, cc.v2(40, 289), endPos];
- var move_01 = cc.bezierTo(this.speed / 350, bezier_01);
- var self = this;
- var move_01_end = cc.callFunc(function() {
- self.bump(dropPos);
- });
- var move_02_time = this.speed / 150;
- var move_02 = cc.bezierTo(move_02_time, bezier_02);
- // 在第二条路线后开始的一段时间,需要通知控制器改变状态
- var delay = cc.delayTime(move_02_time / 4);
- var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_RIVAL_RIGHT_PAT);
- var spawn = cc.spawn(move_02, cc.sequence(delay, change));
- var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_RIVAL);
- var jump = cc.jumpBy(1, cc.v2(50, 40), 30, 2);
- this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
- },
- // 我方接球,从左到右
- minePatLToR_01:function() {
- if(this.stateCallback != null) {
- this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
- }
- var beginPos = cc.v2(-103, -76);
- var dropPos = cc.v2(47, 140);
- var endPos = cc.v2(221, 346);
- // 将节点移动到指定位置
- this.head.setPosition(beginPos);
- var bezier_01 = [beginPos, cc.v2(-52, 20), dropPos];
- var bezier_02 = [dropPos, cc.v2(22, 340), endPos];
- var move_01 = cc.bezierTo(this.speed / 400, bezier_01);
- var self = this;
- var move_01_end = cc.callFunc(function() {
- self.bump(dropPos);
- });
- var move_02_time = this.speed / 150;
- var move_02 = cc.bezierTo(move_02_time, bezier_02);
- // 在第二条路线后开始的一段时间,需要通知控制器改变状态
- var delay = cc.delayTime(move_02_time / 4);
- var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_RIVAL_RIGHT_PAT);
- var spawn = cc.spawn(move_02, cc.sequence(delay, change));
- var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_RIVAL);
- var jump = cc.jumpBy(1, cc.v2(50, 40), 30, 2);
- this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
- },
- // 我方削球,从右到左
- minePeelRToL_01:function() {
- if(this.stateCallback != null) {
- this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
- }
- var beginPos = cc.v2(128, -117);
- var dropPos = cc.v2(-66, 143);
- var endPos = cc.v2(-134, 308);
- // 将节点移动到指定位置
- this.head.setPosition(beginPos);
- var bezier_01 = [beginPos, cc.v2(31, 15), dropPos];
- var bezier_02 = [dropPos, cc.v2(-75, 300), endPos];
- var move_01 = cc.bezierTo(this.speed / 150, bezier_01);
- var self = this;
- var move_01_end = cc.callFunc(function() {
- self.bump(dropPos);
- });
- var move_02_time = this.speed / 150;
- var move_02 = cc.bezierTo(move_02_time, bezier_02);
- // 在第二条路线后开始的一段时间,需要通知控制器改变状态
- var delay = cc.delayTime(move_02_time / 4);
- var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_RIVAL_LEFT_PEEL);
- var spawn = cc.spawn(move_02, cc.sequence(delay, change));
- var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_RIVAL);
- var jump = cc.jumpBy(1, cc.v2(-50, 40), 30, 2);
- this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
- },
- // 我方削球,从右到右
- minePeelRToR_01:function() {
- if(this.stateCallback != null) {
- this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
- }
- var beginPos = cc.v2(148, -176);
- var dropPos = cc.v2(79, 99);
- var endPos = cc.v2(104, 319);
- // 将节点移动到指定位置
- this.head.setPosition(beginPos);
- var bezier_01 = [beginPos, cc.v2(180, -20), dropPos];
- var bezier_02 = [dropPos, cc.v2(92, 210), endPos];
- var move_01 = cc.bezierTo(this.speed / 250, bezier_01);
- var self = this;
- var move_01_end = cc.callFunc(function() {
- self.bump(dropPos);
- });
- var move_02_time = this.speed / 200;
- var move_02 = cc.bezierTo(move_02_time, bezier_02);
- // 在第二条路线后开始的一段时间,需要通知控制器改变状态
- var delay = cc.delayTime(move_02_time / 2);
- var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_RIVAL_RIGHT_PAT);
- var spawn = cc.spawn(move_02, cc.sequence(delay, change));
- var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_RIVAL);
- var jump = cc.jumpBy(1, cc.v2(50, 40), 30, 2);
- this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
- },
- // 对手发球
- rivalServer:function() {
- if(this.stateCallback != null) {
- this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
- }
- var serverBegin = cc.v2(166, 290);
- var beatPos = cc.v2(96, 274);
- var dropPos = cc.v2(28, 144);
- var jumpPos = cc.v2(-14, 21);
- var endPos = cc.v2(-147, -161);
- // 将节点移动到指定位置
- this.head.setPosition(serverBegin);
- // 4条贝塞尔曲线
- var bezier_01 = [serverBegin, cc.v2(125, 400), beatPos];
- var bezier_02 = [beatPos, cc.v2(45, 250), dropPos];
- var bezier_03 = [dropPos, cc.v2(0, 56), jumpPos];
- var bezier_04 = [jumpPos, cc.v2(-80, 10), endPos];
-
- // 四条路线
- var move_01 = cc.bezierTo(1.2, bezier_01);
- var move_02 = cc.bezierTo(this.speed / 750, bezier_02);
- var move_03 = cc.bezierTo(this.speed / 1000, bezier_03);
- var self = this;
- var move_03_end = cc.callFunc(function() {
- self.bump(jumpPos);
- });
- var move_04_time = this.speed / 350;
- var move_04 = cc.bezierTo(move_04_time, bezier_04);
- // 在第四条路线后开始的一段时间,需要通知控制器改变状态
- var delay = cc.delayTime(move_04_time / 3);
- var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_LEFT_PAT);
- var spawn = cc.spawn(move_04, cc.sequence(delay, change));
- var move_04_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
- var jump = cc.jumpBy(1, cc.v2(-100, -40), 30, 4);
- this.head.runAction(cc.sequence(move_01, move_02, move_03, move_03_end, spawn, move_04_end, jump));
- },
- // 对手接球,从右到左
- rivalPatRToL_01:function() {
- if(this.stateCallback != null) {
- this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
- }
- var beginPos = cc.v2(112, 328);
- var dropPos = cc.v2(-22, 16);
- var endPos = cc.v2(-122, -182);
- // 将节点移动到指定位置
- this.head.setPosition(beginPos);
- // 贝塞尔曲线的关键点
- var bezier_01 = [beginPos, cc.v2(45, 172), dropPos];
- var bezier_02 = [dropPos, cc.v2(-120, -10), endPos];
- // 第一条路线
- var move_01 = cc.bezierTo(this.speed / 300, bezier_01);
- var self = this;
- // 中间碰到了桌面
- var move_01_end = cc.callFunc(function() {
- self.bump(dropPos);
- });
- var move_02_time = this.speed / 200;
- var move_02 = cc.bezierTo(move_02_time, bezier_02);
- // 在第二条路线后开始的一段时间,需要通知控制器改变状态
- var delay = cc.delayTime(move_02_time / 4);
- var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_LEFT_PAT);
- var spawn = cc.spawn(move_02, cc.sequence(delay, change));
- var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
- var jump = cc.jumpBy(1, cc.v2(-100, -40), 30, 3);
- this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
- },
- // 对手接球,第二种从右到左
- rivalPatRToL_02:function() {
- if(this.stateCallback != null) {
- this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
- }
- var beginPos = cc.v2(103, 272);
- var dropPos = cc.v2(-15, 23);
- var endPos = cc.v2(-135, -123);
- // 将节点移动到指定位置
- this.head.setPosition(beginPos);
- // 贝塞尔曲线的关键点
- var bezier_01 = [beginPos, cc.v2(-15, 350), dropPos];
- var bezier_02 = [dropPos, cc.v2(-85, 65), endPos];
- // 第一条路线
- var move_01 = cc.bezierTo(this.speed / 250, bezier_01);
- var self = this;
- // 中间碰到了桌面
- var move_01_end = cc.callFunc(function() {
- self.bump(dropPos);
- });
- var move_02_time = this.speed / 150;
- var move_02 = cc.bezierTo(move_02_time, bezier_02);
- // 在第二条路线后开始的一段时间,需要通知控制器改变状态
- var delay = cc.delayTime(move_02_time / 4);
- var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_LEFT_PAT);
- var spawn = cc.spawn(move_02, cc.sequence(delay, change));
- var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
- var jump = cc.jumpBy(1, cc.v2(-100, -40), 30, 3);
- this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
- },
- // 对手接球,从左到左
- rivalPatLToL_01:function() {
- if(this.stateCallback != null) {
- this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
- }
-
- var beginPos = cc.v2(-53, 272);
- var dropPos = cc.v2(-73, 10);
- var endPos = cc.v2(-127, -171);
- // 将节点移动到指定位置
- this.head.setPosition(beginPos);
- // 贝塞尔曲线的关键点
- var bezier_01 = [beginPos, cc.v2(-63, 149), dropPos];
- var bezier_02 = [dropPos, cc.v2(-95, -40), endPos];
- // 第一条路线
- var move_01 = cc.bezierTo(this.speed / 400, bezier_01);
- var self = this;
- // 中间碰到了桌面
- var move_01_end = cc.callFunc(function() {
- self.bump(dropPos);
- });
- var move_02_time = this.speed / 250;
- var move_02 = cc.bezierTo(move_02_time, bezier_02);
- // 在第二条路线后开始的一段时间,需要通知控制器改变状态
- var delay = cc.delayTime(move_02_time / 4);
- var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_LEFT_PAT);
- var spawn = cc.spawn(move_02, cc.sequence(delay, change));
- var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
- var jump = cc.jumpBy(1, cc.v2(-40, -40), 30, 2);
- this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
- },
- // 对手接球,从左到右
- rivalPatLToR_01:function() {
- if(this.stateCallback != null) {
- this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
- }
-
- var beginPos = cc.v2(-56, 298);
- var dropPos = cc.v2(25, 13);
- var endPos = cc.v2(95, -115);
- // 将节点移动到指定位置
- this.head.setPosition(beginPos);
- // 贝塞尔曲线的关键点
- var bezier_01 = [beginPos, cc.v2(4, 145), dropPos];
- var bezier_02 = [dropPos, cc.v2(95, -35), endPos];
- // 第一条路线
- var move_01 = cc.bezierTo(this.speed / 400, bezier_01);
- var self = this;
- // 中间碰到了桌面
- var move_01_end = cc.callFunc(function() {
- self.bump(dropPos);
- });
- var move_02_time = this.speed / 200;
- var move_02 = cc.bezierTo(move_02_time, bezier_02);
- // 在第二条路线后开始的一段时间,需要通知控制器改变状态
- var delay = cc.delayTime(move_02_time / 4);
- var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_RIGHT_PEEL);
- var spawn = cc.spawn(move_02, cc.sequence(delay, change));
- var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
- var jump = cc.jumpBy(1, cc.v2(40, -40), 30, 2);
- this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
- },
- // 对手接球,从右到右
- rivalPatRToR_01:function() {
- if(this.stateCallback != null) {
- this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
- }
-
- var beginPos = cc.v2(101, 271);
- var dropPos = cc.v2(49, 29);
- var endPos = cc.v2(24, -171);
- // 将节点移动到指定位置
- this.head.setPosition(beginPos);
- // 贝塞尔曲线的关键点
- var bezier_01 = [beginPos, cc.v2(50, 450), dropPos];
- var bezier_02 = [dropPos, cc.v2(15, 95), endPos];
- // 第一条路线
- var move_01 = cc.bezierTo(this.speed / 200, bezier_01);
- var self = this;
- // 中间碰到了桌面
- var move_01_end = cc.callFunc(function() {
- self.bump(dropPos);
- });
- var move_02_time = this.speed / 250;
- var move_02 = cc.bezierTo(move_02_time, bezier_02);
- // 在第二条路线后开始的一段时间,需要通知控制器改变状态
- var delay = cc.delayTime(move_02_time / 4);
- var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_RIGHT_PAT);
- var spawn = cc.spawn(move_02, cc.sequence(delay, change));
- var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
- var jump = cc.jumpBy(1, cc.v2(-40, -40), 30, 2);
- this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
- },
- // 对手接球,第二种从右到右
- rivalPatRToR_02:function() {
- if(this.stateCallback != null) {
- this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
- }
-
- var beginPos = cc.v2(98, 273);
- var dropPos = cc.v2(49, 21);
- var endPos = cc.v2(28, -130);
- // 将节点移动到指定位置
- this.head.setPosition(beginPos);
- // 贝塞尔曲线的关键点
- var bezier_01 = [beginPos, cc.v2(68, 147), dropPos];
- var bezier_02 = [dropPos, cc.v2(15, -20), endPos];
- // 第一条路线
- var move_01 = cc.bezierTo(this.speed / 200, bezier_01);
- var self = this;
- // 中间碰到了桌面
- var move_01_end = cc.callFunc(function() {
- self.bump(dropPos);
- });
-
- var move_02_time = this.speed / 150;
- var move_02 = cc.bezierTo(move_02_time, bezier_02);
- // 在第二条路线后开始的一段时间,需要通知控制器改变状态
- var delay = cc.delayTime(move_02_time / 4);
- var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_RIGHT_PAT);
- var spawn = cc.spawn(move_02, cc.sequence(delay, change));
- var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
- var jump = cc.jumpBy(1, cc.v2(-40, -40), 30, 2);
- this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
- },
- // 对手削球,从左到左
- rivalPeelLtoL_01:function() {
- if(this.stateCallback != null) {
- this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
- }
- var beginPos = cc.v2(-95, 263);
- var centerPos = cc.v2(-75, 58);
- var endPos = cc.v2(-66, -163);
- // 将节点移动到指定位置
- this.head.setPosition(beginPos);
- var bezier_01 = [beginPos, cc.v2(-230, 410), centerPos];
- var move_01 = cc.bezierTo(this.speed / 180, bezier_01);
- var move_01_end = cc.callFunc(function() {
- this.bump(centerPos);
- }, this);
- var bezier_02 = [centerPos, cc.v2(-125, 40), endPos];
- var move_02_time = this.speed / 180;
- var move_02 = cc.bezierTo(move_02_time, bezier_02);
- // 在第二条路线后开始的一段时间,需要通知控制器改变状态
- var delay = cc.delayTime(move_02_time / 4);
- var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_LEFT_PAT);
- var spawn = cc.spawn(move_02, cc.sequence(delay, change));
- var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
- var jump = cc.jumpBy(1, cc.v2(-40, -40), 30, 2);
- this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
- },
- // 对手削球,从左到右
- rivalPeelLtoR_01:function() {
- if(this.stateCallback != null) {
- this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
- }
- var beginPos = cc.v2(-95, 264);
- var centerPos = cc.v2(30, 5);
- var endPos = cc.v2(163, -140);
- // 将节点移动到指定位置
- this.head.setPosition(beginPos);
- var bezier_01 = [beginPos, cc.v2(-270, 440), centerPos];
- var move_01 = cc.bezierTo(this.speed / 180, bezier_01);
- var move_01_end = cc.callFunc(function() {
- this.bump(centerPos);
- }, this);
- var bezier_02 = [centerPos, cc.v2(110, 20), endPos];
- var move_02_time = this.speed / 150;
- var move_02 = cc.bezierTo(move_02_time, bezier_02);
- // 在第二条路线后开始的一段时间,需要通知控制器改变状态
- var delay = cc.delayTime(move_02_time / 4);
- var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_RIGHT_PEEL);
- var spawn = cc.spawn(move_02, cc.sequence(delay, change));
- var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
- var jump = cc.jumpBy(1, cc.v2(40, -40), 30, 2);
- this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
- },
- // 球磕碰
- bump:function(loc) {
- this.bumpLoc = loc;
- this.bumpTime = 0;
- this.showBump = true;
- },
- // 更改状态
- changeState:function(node, state) {
- // cc.log ("改变状态 ... " + state);
- if(this.stateCallback != null) {
- this.stateCallback(state);
- }
- },
- // 绘图
- draw:function(delay) {
- this.g.clear();
- // 画脑袋和身体
- this.g.lineWidth = this.gameconfig.CIRCLE_WIDTH
- // 画个头部
- this.g.fillColor.fromHEX('#ff00000');
- this.g.circle(this.head.x, this.head.y, this.gameconfig.HEAD_SIZE);
- this.g.close();
- this.g.stroke();
- this.g.fill();
-
- var pos = this.poses[0];
- this.g.lineWidth = 3;
- this.g.moveTo(pos.x, pos.y)
- for (var i = 0; i < this.poses.length; i++) {
- var getPos = this.poses[i];
- this.g.lineTo(getPos.x, getPos.y);
- }
- this.g.stroke();
- // 当需要绘制撞击点时
- if (this.showBump) {
- this.bumpTime += delay;
- var timeScale = 15;
- var space = 1;
- var low = 2.5;
- var high = 10;
- // 右上
- this.g.lineWidth = 3;
- this.g.moveTo(this.bumpLoc.x + space + this.bumpTime * timeScale * low, this.bumpLoc.y + space + this.bumpTime * timeScale * low);
- this.g.lineTo(this.bumpLoc.x + space + this.bumpTime * timeScale * high, this.bumpLoc.y + space + this.bumpTime * timeScale * high)
- this.g.stroke();
- // 右下
- this.g.lineWidth = 3;
- this.g.moveTo(this.bumpLoc.x + space + this.bumpTime * timeScale * low, this.bumpLoc.y - space - this.bumpTime * timeScale * low);
- this.g.lineTo(this.bumpLoc.x + space + this.bumpTime * timeScale * high, this.bumpLoc.y - space - this.bumpTime * timeScale * high)
- this.g.stroke();
- // 左上
- this.g.lineWidth = 3;
- this.g.moveTo(this.bumpLoc.x - space - this.bumpTime * timeScale * low, this.bumpLoc.y + space + this.bumpTime * timeScale * low);
- this.g.lineTo(this.bumpLoc.x - space - this.bumpTime * timeScale * high, this.bumpLoc.y + space + this.bumpTime * timeScale * high)
- this.g.stroke();
- // 右下
- this.g.lineWidth = 3;
- this.g.moveTo(this.bumpLoc.x - space - this.bumpTime * timeScale * low, this.bumpLoc.y - space - this.bumpTime * timeScale * low);
- this.g.lineTo(this.bumpLoc.x - space - this.bumpTime * timeScale * high, this.bumpLoc.y - space - this.bumpTime * timeScale * high)
- this.g.stroke();
- if (this.bumpTime > 0.1) {
- this.showBump = false;
- }
- }
- },
- // 帧更新
- ballUpdate:function (dt) {
- // 记录当前的位置
- var news = [this.head.position];
- // 在结合当前的数组
- this.poses = news.concat(this.poses);
- // 如果数组长度大于20,则将最后一个删除
- if (this.poses.length > 10) {
- this.poses.pop();
- }
- this.draw(dt);
- },
- });
|