diff --git a/assets/Level.fire b/assets/Level.fire index 0d7bdc0..cecf121 100644 --- a/assets/Level.fire +++ b/assets/Level.fire @@ -65,23 +65,23 @@ "__id__": 5 }, { - "__id__": 13 + "__id__": 14 }, { - "__id__": 20 + "__id__": 23 }, { - "__id__": 27 + "__id__": 32 } ], "_active": true, "_level": 0, "_components": [ { - "__id__": 34 + "__id__": 41 }, { - "__id__": 35 + "__id__": 42 } ], "_prefab": null, @@ -239,7 +239,7 @@ "__id__": 11 }, { - "__id__": 12 + "__id__": 13 } ], "_prefab": null, @@ -509,7 +509,11 @@ "_enabled": true, "duration": 0.1, "zoomScale": 1.2, - "clickEvents": [], + "clickEvents": [ + { + "__id__": 12 + } + ], "_N$interactable": true, "_N$enableAutoGrayEffect": false, "_N$transition": 2, @@ -579,6 +583,16 @@ }, "_id": "f0IHoTsa9JbaCKLuhzu4sQ" }, + { + "__type__": "cc.ClickEvent", + "target": { + "__id__": 5 + }, + "component": "", + "_componentId": "3a2abJhRaJFyrM9SBg5rWtB", + "handler": "loadGameScene", + "customEventData": "1" + }, { "__type__": "3a2abJhRaJFyrM9SBg5rWtB", "_name": "", @@ -598,14 +612,17 @@ }, "_children": [ { - "__id__": 14 + "__id__": 15 } ], "_active": true, "_level": 1, "_components": [ { - "__id__": 19 + "__id__": 20 + }, + { + "__id__": 22 } ], "_prefab": null, @@ -656,21 +673,21 @@ "_name": "Background", "_objFlags": 0, "_parent": { - "__id__": 13 + "__id__": 14 }, "_children": [ { - "__id__": 15 + "__id__": 16 } ], "_active": true, "_level": 2, "_components": [ { - "__id__": 17 + "__id__": 18 }, { - "__id__": 18 + "__id__": 19 } ], "_prefab": null, @@ -721,14 +738,14 @@ "_name": "Label", "_objFlags": 0, "_parent": { - "__id__": 14 + "__id__": 15 }, "_children": [], "_active": true, "_level": 3, "_components": [ { - "__id__": 16 + "__id__": 17 } ], "_prefab": null, @@ -779,7 +796,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 15 + "__id__": 16 }, "_enabled": true, "_materials": [ @@ -811,7 +828,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 14 + "__id__": 15 }, "_enabled": true, "_materials": [ @@ -843,7 +860,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 14 + "__id__": 15 }, "_enabled": true, "alignMode": 0, @@ -870,12 +887,16 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 13 + "__id__": 14 }, "_enabled": true, "duration": 0.1, "zoomScale": 1.2, - "clickEvents": [], + "clickEvents": [ + { + "__id__": 21 + } + ], "_N$interactable": true, "_N$enableAutoGrayEffect": false, "_N$transition": 2, @@ -941,10 +962,30 @@ "__uuid__": "29158224-f8dd-4661-a796-1ffab537140e" }, "_N$target": { - "__id__": 14 + "__id__": 15 }, "_id": "26wq34PNZHVIy0AG+mYHqX" }, + { + "__type__": "cc.ClickEvent", + "target": { + "__id__": 14 + }, + "component": "", + "_componentId": "3a2abJhRaJFyrM9SBg5rWtB", + "handler": "loadGameScene", + "customEventData": "2" + }, + { + "__type__": "3a2abJhRaJFyrM9SBg5rWtB", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 14 + }, + "_enabled": true, + "_id": "5eRUNEzqdBwJboXqlf9GLZ" + }, { "__type__": "cc.Node", "_name": "button", @@ -954,14 +995,17 @@ }, "_children": [ { - "__id__": 21 + "__id__": 24 } ], "_active": true, "_level": 1, "_components": [ { - "__id__": 26 + "__id__": 29 + }, + { + "__id__": 31 } ], "_prefab": null, @@ -1012,21 +1056,21 @@ "_name": "Background", "_objFlags": 0, "_parent": { - "__id__": 20 + "__id__": 23 }, "_children": [ { - "__id__": 22 + "__id__": 25 } ], "_active": true, "_level": 2, "_components": [ { - "__id__": 24 + "__id__": 27 }, { - "__id__": 25 + "__id__": 28 } ], "_prefab": null, @@ -1077,14 +1121,14 @@ "_name": "Label", "_objFlags": 0, "_parent": { - "__id__": 21 + "__id__": 24 }, "_children": [], "_active": true, "_level": 3, "_components": [ { - "__id__": 23 + "__id__": 26 } ], "_prefab": null, @@ -1135,7 +1179,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 22 + "__id__": 25 }, "_enabled": true, "_materials": [ @@ -1167,7 +1211,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 21 + "__id__": 24 }, "_enabled": true, "_materials": [ @@ -1199,7 +1243,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 21 + "__id__": 24 }, "_enabled": true, "alignMode": 0, @@ -1226,12 +1270,16 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 20 + "__id__": 23 }, "_enabled": true, "duration": 0.1, "zoomScale": 1.2, - "clickEvents": [], + "clickEvents": [ + { + "__id__": 30 + } + ], "_N$interactable": true, "_N$enableAutoGrayEffect": false, "_N$transition": 2, @@ -1297,10 +1345,30 @@ "__uuid__": "29158224-f8dd-4661-a796-1ffab537140e" }, "_N$target": { - "__id__": 21 + "__id__": 24 }, "_id": "f8is4J+KZG66QUsc4/ge0G" }, + { + "__type__": "cc.ClickEvent", + "target": { + "__id__": 23 + }, + "component": "", + "_componentId": "3a2abJhRaJFyrM9SBg5rWtB", + "handler": "loadGameScene", + "customEventData": "3" + }, + { + "__type__": "3a2abJhRaJFyrM9SBg5rWtB", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 23 + }, + "_enabled": true, + "_id": "49GmEY8MBCIap9tfJG7/2U" + }, { "__type__": "cc.Node", "_name": "button", @@ -1310,14 +1378,17 @@ }, "_children": [ { - "__id__": 28 + "__id__": 33 } ], "_active": true, "_level": 1, "_components": [ { - "__id__": 33 + "__id__": 38 + }, + { + "__id__": 40 } ], "_prefab": null, @@ -1368,21 +1439,21 @@ "_name": "Background", "_objFlags": 0, "_parent": { - "__id__": 27 + "__id__": 32 }, "_children": [ { - "__id__": 29 + "__id__": 34 } ], "_active": true, "_level": 2, "_components": [ { - "__id__": 31 + "__id__": 36 }, { - "__id__": 32 + "__id__": 37 } ], "_prefab": null, @@ -1433,14 +1504,14 @@ "_name": "Label", "_objFlags": 0, "_parent": { - "__id__": 28 + "__id__": 33 }, "_children": [], "_active": true, "_level": 3, "_components": [ { - "__id__": 30 + "__id__": 35 } ], "_prefab": null, @@ -1491,7 +1562,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 29 + "__id__": 34 }, "_enabled": true, "_materials": [ @@ -1523,7 +1594,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 28 + "__id__": 33 }, "_enabled": true, "_materials": [ @@ -1555,7 +1626,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 28 + "__id__": 33 }, "_enabled": true, "alignMode": 0, @@ -1582,12 +1653,16 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 27 + "__id__": 32 }, "_enabled": true, "duration": 0.1, "zoomScale": 1.2, - "clickEvents": [], + "clickEvents": [ + { + "__id__": 39 + } + ], "_N$interactable": true, "_N$enableAutoGrayEffect": false, "_N$transition": 2, @@ -1653,10 +1728,30 @@ "__uuid__": "29158224-f8dd-4661-a796-1ffab537140e" }, "_N$target": { - "__id__": 28 + "__id__": 33 }, "_id": "07Xool7WZN8ovK0H1mRfer" }, + { + "__type__": "cc.ClickEvent", + "target": { + "__id__": 32 + }, + "component": "", + "_componentId": "3a2abJhRaJFyrM9SBg5rWtB", + "handler": "loadGameScene", + "customEventData": "4" + }, + { + "__type__": "3a2abJhRaJFyrM9SBg5rWtB", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 32 + }, + "_enabled": true, + "_id": "66rwOafM5EjKiP+oFLy0Hv" + }, { "__type__": "cc.Canvas", "_name": "", diff --git a/assets/Scripts/EnemyShip.ts b/assets/Scripts/EnemyShip.ts index 31f997b..ea647df 100644 --- a/assets/Scripts/EnemyShip.ts +++ b/assets/Scripts/EnemyShip.ts @@ -8,12 +8,13 @@ // - [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 +import GameData from "./GameData"; + const {ccclass, property} = cc._decorator; @ccclass export default class NewClass extends cc.Component { - duratrion : number = 2.5; moveAmountX : number = 0; RTL: boolean = false; @@ -22,13 +23,13 @@ export default class NewClass extends cc.Component { @property(cc.Prefab) yellowBullet: cc.Prefab = null; - enemyLife: number = 1 + enemyLife: number = GameData.instance.enemyHealth; playAnimation : Boolean = true; setMovements() { - var moveLeft = cc.moveBy(this.duratrion, cc.v2(-this.moveAmountX, -this.node.parent.getContentSize().height * 0.32)); - var moveRight = cc.moveBy(this.duratrion, cc.v2(this.moveAmountX, -this.node.parent.getContentSize().height * 0.32)); + var moveLeft = cc.moveBy(GameData.instance.enemyMoveTime, cc.v2(-this.moveAmountX, -this.node.parent.getContentSize().height * 0.32)); + var moveRight = cc.moveBy(GameData.instance.enemyMoveTime, cc.v2(this.moveAmountX, -this.node.parent.getContentSize().height * 0.32)); this.node.runAction(cc.repeatForever(this.RTL ? cc.sequence(moveRight, moveLeft) : cc.sequence(moveLeft, moveRight))); } @@ -43,7 +44,7 @@ export default class NewClass extends cc.Component { onLoad () { this.scheduleOnce(this.setMovements, 0.1); - this.schedule(this.shootBullets, Math.random() * 1 + 1, cc.macro.REPEAT_FOREVER, 0); + this.schedule(this.shootBullets, GameData.instance.enemyShootingInterval, cc.macro.REPEAT_FOREVER, 0); } onCollisionEnter(otherCollider, selfCollider) { if(otherCollider.name === 'greenbullet') { diff --git a/assets/Scripts/Game.ts b/assets/Scripts/Game.ts index 8f57843..cc14b60 100644 --- a/assets/Scripts/Game.ts +++ b/assets/Scripts/Game.ts @@ -8,6 +8,8 @@ // - [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 +import GameData from "./GameData"; + const {ccclass, property} = cc._decorator; @ccclass @@ -39,7 +41,7 @@ export default class NewClass extends cc.Component { const shipXMax = screenHalfWidth - shipMaxMove - margin; const shipX = Math.random() * (shipXMax - shipXMin) + shipXMin; - for (let i = 0; i < 12; i++) { + for (let i = 0; i < GameData.instance.enemySpawnInterval; i++) { this.scheduleOnce(() => { const ship = cc.instantiate(shipPrefab); ship.setPosition(shipX, shipY); @@ -48,7 +50,7 @@ export default class NewClass extends cc.Component { const shipScript = ship.getComponent('EnemyShip'); shipScript.moveAmountX = batchMoveAmountX; shipScript.RTL = RTL; - }, i * 0.5); + }, i * GameData.instance.enemyMoveTime * 0.25); } } diff --git a/assets/Scripts/GameData.ts b/assets/Scripts/GameData.ts new file mode 100644 index 0000000..921f6c0 --- /dev/null +++ b/assets/Scripts/GameData.ts @@ -0,0 +1,64 @@ +// 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 GameData extends cc.Component { + + private static _instance: GameData = null; + + public selectedLevel: number = 1; + + public static get instance(): GameData { + if (!this._instance) { + this._instance = new GameData(); + } + return this._instance; + } + + // 🔹 Shooting speed (seconds per shot) + public get enemyShootingInterval(): number { + switch (this.selectedLevel) { + case 1: return 8; + case 2: return 6; + case 3: return 4; + case 4: return 2; + default: return 8; + } + } + + // 🔹 Enemy spawn interval (seconds) + public get enemySpawnInterval(): number { + switch (this.selectedLevel) { + case 1: return 6; + case 2: return 8; + case 3: return 10; + case 4: return 12; + default: return 6; + } + } + + // 🔹 Player speed + public get enemyMoveTime(): number { + switch (this.selectedLevel) { + case 1: return 3; + case 2: return 4; + case 3: return 5; + case 4: return 6; + default: return 3; + } + } + + // 🔹 Any other level-based settings... + public get enemyHealth(): number { + return this.selectedLevel; + } +} diff --git a/assets/Scripts/GameData.ts.meta b/assets/Scripts/GameData.ts.meta new file mode 100644 index 0000000..dbd46bb --- /dev/null +++ b/assets/Scripts/GameData.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.5", + "uuid": "58f17fa0-2478-408d-8bcd-790f44f2386e", + "isPlugin": false, + "loadPluginInWeb": true, + "loadPluginInNative": true, + "loadPluginInEditor": false, + "subMetas": {} +} \ No newline at end of file diff --git a/assets/Scripts/SwitchScreens.ts b/assets/Scripts/SwitchScreens.ts index ea45a72..5b5e87a 100644 --- a/assets/Scripts/SwitchScreens.ts +++ b/assets/Scripts/SwitchScreens.ts @@ -8,6 +8,8 @@ // - [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 +import GameData from "./GameData"; + const {ccclass, property} = cc._decorator; @ccclass @@ -20,8 +22,10 @@ export default class NewClass extends cc.Component { } loadGameScene(event, customData) { - cc.director.preloadScene('Level', () => { - cc.director.loadScene('Level'); + const selectedLevel = Number(customData); + GameData.instance.selectedLevel = selectedLevel; + cc.director.preloadScene('Game', () => { + cc.director.loadScene('Game'); }); } }