|
| 1 | +// Learn cc.Class: |
| 2 | +// - https://docs.cocos.com/creator/manual/en/scripting/class.html |
| 3 | +// Learn Attribute: |
| 4 | +// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html |
| 5 | +// Learn life-cycle callbacks: |
| 6 | +// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html |
| 7 | + |
| 8 | +cc.Class({ |
| 9 | + extends: cc.Component, |
| 10 | + |
| 11 | + properties: { |
| 12 | + change5: cc.Node, |
| 13 | + up: cc.Node, |
| 14 | + ret: cc.Node, |
| 15 | + borer: cc.Node, |
| 16 | + soil: cc.Node, |
| 17 | + flag: cc.Node, |
| 18 | + output: cc.RichText, |
| 19 | + ending: cc.Node, |
| 20 | + |
| 21 | + G: -0.01, |
| 22 | + F: 0, |
| 23 | + R: 0, |
| 24 | + phase: 1, |
| 25 | + ticks: 0, |
| 26 | + |
| 27 | + // foo: { |
| 28 | + // // ATTRIBUTES: |
| 29 | + // default: null, // The default value will be used only when the component attaching |
| 30 | + // // to a node for the first time |
| 31 | + // type: cc.SpriteFrame, // optional, default is typeof default |
| 32 | + // serializable: true, // optional, default is true |
| 33 | + // }, |
| 34 | + // bar: { |
| 35 | + // get () { |
| 36 | + // return this._bar; |
| 37 | + // }, |
| 38 | + // set (value) { |
| 39 | + // this._bar = value; |
| 40 | + // } |
| 41 | + // }, |
| 42 | + }, |
| 43 | + |
| 44 | + // LIFE-CYCLE CALLBACKS: |
| 45 | + |
| 46 | + onLoad () { |
| 47 | + cc.debug.setDisplayStats(false); |
| 48 | + |
| 49 | + this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this); |
| 50 | + this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this); |
| 51 | + |
| 52 | + this.output.string = "1. 月面着陆\n<color=#88ffff>点击屏幕中部:点火减速\n点击屏幕两侧:调整姿态\n注意控制着落时的速度和角度</c>\n"; |
| 53 | + }, |
| 54 | + |
| 55 | + start () { |
| 56 | + |
| 57 | + }, |
| 58 | + |
| 59 | + onTouchStart (event) { |
| 60 | + var pos = event.getLocation(); |
| 61 | + if (pos.x < cc.winSize.width / 2 - 100) { |
| 62 | + this.R = 0.25; |
| 63 | + } else if (pos.x > cc.winSize.width / 2 + 100) { |
| 64 | + this.R = -0.25; |
| 65 | + } else { |
| 66 | + this.F = 10 * 0.005; |
| 67 | + } |
| 68 | + }, |
| 69 | + onTouchEnd (event) { |
| 70 | + this.F = 0; |
| 71 | + this.R = 0; |
| 72 | + |
| 73 | + if (this.phase == 4 && this.ticks > 1) { |
| 74 | + cc.game.restart(); |
| 75 | + } |
| 76 | + }, |
| 77 | + |
| 78 | + update (dt) { |
| 79 | + if (this.phase == 1) { |
| 80 | + if (Math.abs(this.change5.x) > 300 || Math.abs(this.change5.y) > 500) { |
| 81 | + this.phase = 4; |
| 82 | + this.output.string += "<color=#ff8888>偏离目标区域太远,着陆失败!</c>\n点击屏幕再次尝试"; |
| 83 | + } |
| 84 | + if (this.change5.y < -300) { |
| 85 | + var c5 = this.change5.getComponent('change5'); |
| 86 | + if (Math.abs(c5.speed_x) > 1 || Math.abs(c5.speed_y) > 1) { |
| 87 | + this.phase = 4; |
| 88 | + this.output.string += "<color=#ff8888>速度太快,着陆失败!</c>\n点击屏幕再次尝试"; |
| 89 | + } else if (Math.abs(this.change5.rotation) > 30) { |
| 90 | + this.phase = 4; |
| 91 | + this.output.string += "<color=#ff8888>角度太大,着陆失败!</c>\n点击屏幕再次尝试"; |
| 92 | + } else { |
| 93 | + this.phase = 2; |
| 94 | + this.output.string += "<color=#88ff88>着陆成功!</c>\n\n2. 月壤采集工作中\n"; |
| 95 | + this.land(); |
| 96 | + } |
| 97 | + } |
| 98 | + } else if (this.phase == 3) { |
| 99 | + if (Math.abs(this.up.x) > 300 || Math.abs(this.up.y) > 500) { |
| 100 | + this.phase = 4; |
| 101 | + this.output.string += "<color=#ff8888>偏离轨道器太远,对接失败!</c>\n点击屏幕再次尝试"; |
| 102 | + } |
| 103 | + if (Math.abs(this.up.y-this.ret.y)<10 && Math.abs(this.up.x-this.ret.x)<10) { |
| 104 | + var up = this.up.getComponent('up'); |
| 105 | + var ret = this.ret.getComponent('return'); |
| 106 | + if (Math.abs(up.speed_x-0.5) > 1 || Math.abs(up.speed_y) > 1) { |
| 107 | + this.output.string += "<color=#ff8888>速度太快,对接失败!</c>\n点击屏幕再次尝试"; |
| 108 | + } else if (Math.abs(this.change5.rotation) > 30) { |
| 109 | + this.output.string += "<color=#ff8888>角度太大,对接失败!</c>\n点击屏幕再次尝试"; |
| 110 | + } else { |
| 111 | + this.output.string += "<color=#88ff88>对接成功!</c>\n任务完成"; |
| 112 | + this.ending.runAction(cc.fadeIn(1)); |
| 113 | + } |
| 114 | + this.phase = 4; |
| 115 | + } |
| 116 | + } else if (this.phase == 4) { |
| 117 | + this.ticks += dt; |
| 118 | + } |
| 119 | + }, |
| 120 | + |
| 121 | + land () { |
| 122 | + var c5 = this.change5; |
| 123 | + if (c5.angle == 0) { |
| 124 | + this.bore1(); |
| 125 | + } else { |
| 126 | + // 此段为落地后的调整动画,可略过 |
| 127 | + var dx = c5.width * 0.23 * Math.cos(Math.PI / 180 * c5.angle); |
| 128 | + var dy = c5.width * 0.23 * Math.sin(Math.PI / 180 * c5.angle); |
| 129 | + if (c5.angle < 0) { |
| 130 | + c5.anchorX = 0.73; |
| 131 | + c5.x += dx; |
| 132 | + c5.y += dy; |
| 133 | + } else { |
| 134 | + c5.anchorX = 0.27; |
| 135 | + c5.x -= dx; |
| 136 | + c5.y -= dy; |
| 137 | + } |
| 138 | + for (var i = c5.children.length - 1; i >= 0; i--) { |
| 139 | + var item = c5.children[i]; |
| 140 | + var sign = c5.anchorX > 0.5 ? -1 : 1; |
| 141 | + item.x += sign * c5.width * 0.23; |
| 142 | + } |
| 143 | + var a1 = cc.rotateTo(Math.abs(c5.angle/45), 0); |
| 144 | + var a2 = cc.callFunc(this.bore1, this); |
| 145 | + c5.runAction(cc.sequence(a1, a2)); |
| 146 | + } |
| 147 | + }, |
| 148 | + |
| 149 | + bore1 () { |
| 150 | + this.borer.opacity = 255; |
| 151 | + var a1 = cc.scaleTo(2, 1, 20); |
| 152 | + var a2 = cc.callFunc(this.bore2, this); |
| 153 | + this.borer.runAction(cc.sequence(cc.delayTime(1), a1, cc.delayTime(1), a2)); |
| 154 | + }, |
| 155 | + |
| 156 | + bore2 () { |
| 157 | + var a1 = cc.scaleTo(2, 1, 20); |
| 158 | + this.soil.y = this.borer.y - this.borer.height * this.borer.scaleY; |
| 159 | + this.soil.opacity = 255; |
| 160 | + var a2 = cc.callFunc(this.bore3, this); |
| 161 | + this.soil.runAction(cc.sequence(a1, cc.delayTime(2), a2)); |
| 162 | + }, |
| 163 | + |
| 164 | + bore3 () { |
| 165 | + var a1 = cc.scaleTo(2, 1, 0.1); |
| 166 | + this.soil.anchorY = 1; |
| 167 | + this.soil.y = this.borer.y; |
| 168 | + var a2 = cc.callFunc(this.flag1, this); |
| 169 | + this.soil.runAction(cc.sequence(a1, cc.delayTime(1), a2)); |
| 170 | + }, |
| 171 | + |
| 172 | + flag1 () { |
| 173 | + this.flag.opacity = 255; |
| 174 | + var a1 = cc.rotateTo(1, 360); |
| 175 | + var a2 = cc.callFunc(this.flag2, this); |
| 176 | + this.flag.runAction(cc.sequence(a1, a2)); |
| 177 | + }, |
| 178 | + |
| 179 | + flag2 () { |
| 180 | + this.phase = 3; |
| 181 | + this.output.string += "<color=#88ff88>采集完毕!</c>\n\n3. 月面上升\n<color=#88ffff>点击屏幕中部:点火上升\n点击屏幕两侧:调整姿态\n注意控制对接时的速度和角度</c>\n"; |
| 182 | + }, |
| 183 | + |
| 184 | + restart () { |
| 185 | + |
| 186 | + } |
| 187 | +}); |
0 commit comments