123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- // 我方接球,从我方左侧至敌方左侧
- var Bump = require("bump")
- cc.Class({
- extends: cc.Component,
- properties: {
- g: {
- default: null,
- type: cc.Graphics,
- },
- bump: {
- default: null,
- type: Bump,
- },
- },
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {},
- start () {
- this.initValues();
- },
- // 初始化
- initValues:function() {
- // 球的状态信息
- this.ballconfig = require("ballconfig");
-
- // 球的运动区间
- this.flyLeft = -101;
- this.flyRight = -65;
- this.flipRight = -30;
- // 配置方程式的各项数据
- // 飞翔时候的数据
- this.flyX = 0;
- this.flyY = 530;
- this.flyDown = 6.2;
- // 弹起来时候的数据
- this.flipX = 0;
- this.flipY = 759;
- this.flipDown = 9.8;
- },
- // update (dt) {},
- // 发球时的方程式
- equation:function(x) {
- // return (x * x - this.flipX * 2 * x + this.flipX * this.flipX) / this.flipDown + this.flipY;
-
- if (x >= this.flyLeft - 10 && x <= this.flyRight) {
- return x * this.flyDown + this.flyY;
- } else if (x > this.flyRight && x <= this.flipRight) {
- return (x * this.flipDown) + this.flipY;
- }
- return x * this.flyDown + this.flyY;
- },
- ballPat:function() {
- this.unschedule(this.patUpdate);
- this.x = this.flyLeft;
- this.schedule(this.patUpdate, 1.0 / 60);
- },
- ballStop:function() {
- this.unschedule(this.patUpdate);
- },
-
- patUpdate:function (dt) {
- this.g.clear();
- var speed = 0;
- var state;
- if (this.x >= this.flyLeft - 10 && this.x < this.flyRight) {
- speed = 2;
- state = s.ballconfig.BALL_STATE_MINE_LEFT_TO_LEFT_FLY;
- } else if (this.x >= this.flyRight && this.x < this.flipRight) {
- speed = 2;
- state = this.ballconfig.BALL_STATE_MINE_LEFT_TO_LEFT_FLIP;
- } else if (this.x >= this.flipRight) {
- speed = 2;
- state = this.ballconfig.BALL_STATE_DROP_IN_RIVAL;
- }
- if (this.stateCallback != null) {
- // 给控制器传递发球左侧的状态
- this.stateCallback(state);
- }
- // 判断是否需要磕碰
- var next = this.x + speed;
- if (this.x < this.flyRight && next >= this.flyRight) {
- cc.log ("到了中间 ... ");
- this.bump.bump(cc.v2(this.x, this.equation(this.x)));
- }
- // cc.log ("x = " + this.x + " mid = " + this.flyRight + " x = " + next);
- this.x = next;
- this.g.lineWidth = 3;
- this.g.moveTo(this.x, this.equation(this.x));
- this.g.bezierCurveTo(this.x, this.equation(this.x), this.x - 5, this.equation(this.x - 5), this.x - 10, this.equation(this.x - 10));
- this.g.stroke();
- },
- });
|