diff --git a/assets/Game.fire b/assets/Game.fire index 6f0d291..1b11ccd 100644 --- a/assets/Game.fire +++ b/assets/Game.fire @@ -90,10 +90,10 @@ "_level": 1, "_components": [ { - "__id__": 23 + "__id__": 25 }, { - "__id__": 24 + "__id__": 26 } ], "_prefab": null, @@ -558,7 +558,7 @@ "_skewX": 0, "_skewY": 0, "_is3DNode": false, - "groupIndex": 0, + "groupIndex": 3, "_id": "f7jh+kBxhCWakG/dJc/bGy" }, { @@ -658,7 +658,7 @@ "_skewX": 0, "_skewY": 0, "_is3DNode": false, - "groupIndex": 0, + "groupIndex": 2, "_id": "a2v8qIaKpJ9KfekoQURhld" }, { @@ -748,7 +748,7 @@ "_skewX": 0, "_skewY": 0, "_is3DNode": false, - "groupIndex": 0, + "groupIndex": 2, "_id": "abaWHTg1VBt7IU8cLHOhFV" }, { @@ -838,7 +838,7 @@ "_skewX": 0, "_skewY": 0, "_is3DNode": false, - "groupIndex": 0, + "groupIndex": 2, "_id": "42Y7rKoIZAuawCU18pO6kh" }, { @@ -915,7 +915,7 @@ }, "_scale": { "__type__": "cc.Vec3", - "x": 0.2, + "x": 0.15, "y": 0.2, "z": 1 }, @@ -976,6 +976,12 @@ "_components": [ { "__id__": 22 + }, + { + "__id__": 23 + }, + { + "__id__": 24 } ], "_prefab": null, @@ -1005,7 +1011,7 @@ }, "_scale": { "__type__": "cc.Vec3", - "x": 1, + "x": 0.4, "y": 1, "z": 1 }, @@ -1018,7 +1024,7 @@ "_skewX": 0, "_skewY": 0, "_is3DNode": false, - "groupIndex": 0, + "groupIndex": 1, "_id": "7ecCcOtJ1F1L0KGm/DlBkM" }, { @@ -1053,6 +1059,72 @@ "_atlas": null, "_id": "8f5/Nu625BkpbGoxZj/LEO" }, + { + "__type__": "703c7fWWSFIqLoVKP56Pw8g", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 21 + }, + "_enabled": true, + "label": null, + "text": "hello", + "BulletSpeed": -500, + "_id": "01vS3EADhFDa1/Pux7n4sn" + }, + { + "__type__": "cc.PolygonCollider", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 21 + }, + "_enabled": true, + "tag": 0, + "_offset": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "points": [ + { + "__type__": "cc.Vec2", + "x": -12, + "y": 2.5 + }, + { + "__type__": "cc.Vec2", + "x": -15, + "y": 1.5 + }, + { + "__type__": "cc.Vec2", + "x": -15, + "y": -1.5 + }, + { + "__type__": "cc.Vec2", + "x": -13, + "y": -2.5 + }, + { + "__type__": "cc.Vec2", + "x": 15, + "y": -1.5 + }, + { + "__type__": "cc.Vec2", + "x": 14, + "y": 1.5 + }, + { + "__type__": "cc.Vec2", + "x": 10, + "y": 2.5 + } + ], + "_id": "71V6W6+DpALrLKIrb3VnkD" + }, { "__type__": "cc.Canvas", "_name": "", diff --git a/assets/Scripts/MoveBullet.ts b/assets/Scripts/MoveBullet.ts new file mode 100644 index 0000000..604f606 --- /dev/null +++ b/assets/Scripts/MoveBullet.ts @@ -0,0 +1,39 @@ +// Learn TypeScript: +// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html +// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html +// Learn Attribute: +// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html +// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html +// Learn life-cycle callbacks: +// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html +// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html + +const {ccclass, property} = cc._decorator; + +@ccclass +export default class NewClass extends cc.Component { + + @property(cc.Label) + label: cc.Label = null; + + @property + text: string = 'hello'; + + @property + BulletSpeed: number = -500; + + // LIFE-CYCLE CALLBACKS: + + // onLoad () {} + + start () { + + } + + update (dt) { + this.node.setPosition(this.node.position.x, this.node.position.y -= this.BulletSpeed * dt); + if(this.node.position.y <= -(this.node.parent.getContentSize().height)) { + this.node.destroy(); + } + } +} diff --git a/assets/Scripts/MoveBullet.ts.meta b/assets/Scripts/MoveBullet.ts.meta new file mode 100644 index 0000000..4894cc5 --- /dev/null +++ b/assets/Scripts/MoveBullet.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.5", + "uuid": "703c77d6-5921-48a8-ba15-28fe7a3f0f20", + "isPlugin": false, + "loadPluginInWeb": true, + "loadPluginInNative": true, + "loadPluginInEditor": false, + "subMetas": {} +} \ No newline at end of file diff --git a/assets/Scripts/MoveJet.ts b/assets/Scripts/MoveJet.ts index 782ecdc..2702423 100644 --- a/assets/Scripts/MoveJet.ts +++ b/assets/Scripts/MoveJet.ts @@ -16,12 +16,23 @@ export default class NewClass extends cc.Component { private isDragging: boolean = false; private touchOffset: cc.Vec2 = cc.v2(0, 0); + @property(cc.Prefab) + greenBullet: cc.Prefab = null; + + shootBullets() { + var bullet = cc.instantiate(this.greenBullet); + bullet.setPosition(this.node.position.x, this.node.position.y + 40); + this.node.parent.addChild(bullet); + } + onLoad() { // Enable touch on this node directly this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this); this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this); this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this); this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this); + + this.schedule(this.shootBullets, 0.1, cc.macro.REPEAT_FOREVER, 0); } onTouchStart(event: cc.Event.EventTouch) { @@ -33,7 +44,6 @@ export default class NewClass extends cc.Component { // Calculate offset between jet center and touch point this.touchOffset = this.node.position.sub(cc.v2(touchPos.x, touchPos.y)); } - onTouchMove(event: cc.Event.EventTouch) { if (!this.isDragging) return; @@ -43,7 +53,6 @@ export default class NewClass extends cc.Component { // Keep the offset so dragging feels natural (finger stays on the same point) this.node.setPosition(cc.v2(touchPos.x, touchPos.y).add(this.touchOffset)); } - onTouchEnd(event: cc.Event.EventTouch) { this.isDragging = false; } diff --git a/assets/greenbullet.prefab b/assets/greenbullet.prefab new file mode 100644 index 0000000..8662280 --- /dev/null +++ b/assets/greenbullet.prefab @@ -0,0 +1,187 @@ +[ + { + "__type__": "cc.Prefab", + "_name": "", + "_objFlags": 0, + "_native": "", + "data": { + "__id__": 1 + }, + "optimizationPolicy": 0, + "asyncLoadAssets": false, + "readonly": false + }, + { + "__type__": "cc.Node", + "_name": "greenbullet", + "_objFlags": 0, + "_parent": null, + "_children": [], + "_active": true, + "_level": 2, + "_components": [ + { + "__id__": 2 + }, + { + "__id__": 3 + }, + { + "__id__": 4 + } + ], + "_prefab": { + "__id__": 5 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 30, + "height": 5 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_position": { + "__type__": "cc.Vec3", + "x": 23.334, + "y": -180.667, + "z": 0 + }, + "_scale": { + "__type__": "cc.Vec3", + "x": 0.4, + "y": 1, + "z": 1 + }, + "_eulerAngles": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 90 + }, + "_skewX": 0, + "_skewY": 0, + "_is3DNode": false, + "groupIndex": 1, + "_id": "" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "_materials": [ + { + "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" + } + ], + "_srcBlendFactor": 770, + "_dstBlendFactor": 771, + "_spriteFrame": { + "__uuid__": "4b8db938-46ea-4d13-baae-2576f0d38610" + }, + "_type": 0, + "_sizeMode": 1, + "_fillType": 0, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_atlas": null, + "_id": "" + }, + { + "__type__": "703c7fWWSFIqLoVKP56Pw8g", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "label": null, + "text": "hello", + "BulletSpeed": -500, + "_id": "" + }, + { + "__type__": "cc.PolygonCollider", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "tag": 0, + "_offset": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "points": [ + { + "__type__": "cc.Vec2", + "x": -12, + "y": 2.5 + }, + { + "__type__": "cc.Vec2", + "x": -15, + "y": 1.5 + }, + { + "__type__": "cc.Vec2", + "x": -15, + "y": -1.5 + }, + { + "__type__": "cc.Vec2", + "x": -13, + "y": -2.5 + }, + { + "__type__": "cc.Vec2", + "x": 15, + "y": -1.5 + }, + { + "__type__": "cc.Vec2", + "x": 14, + "y": 1.5 + }, + { + "__type__": "cc.Vec2", + "x": 10, + "y": 2.5 + } + ], + "_id": "" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "7ecCcOtJ1F1L0KGm/DlBkM", + "sync": false + } +] \ No newline at end of file diff --git a/assets/greenbullet.prefab.meta b/assets/greenbullet.prefab.meta new file mode 100644 index 0000000..7c1fdb7 --- /dev/null +++ b/assets/greenbullet.prefab.meta @@ -0,0 +1,8 @@ +{ + "ver": "1.2.1", + "uuid": "80ebb5d6-8175-4c2a-918e-375e3bb9fcaf", + "optimizationPolicy": "AUTO", + "asyncLoadAssets": false, + "readonly": false, + "subMetas": {} +} \ No newline at end of file