[Add]: Implemented 4 levels logic

This commit is contained in:
Mohammad_Hasan 2025-10-29 13:27:41 +04:00
parent 3576a2e2a0
commit 956c4152ae
6 changed files with 233 additions and 58 deletions

View File

@ -65,23 +65,23 @@
"__id__": 5 "__id__": 5
}, },
{ {
"__id__": 13 "__id__": 14
}, },
{ {
"__id__": 20 "__id__": 23
}, },
{ {
"__id__": 27 "__id__": 32
} }
], ],
"_active": true, "_active": true,
"_level": 0, "_level": 0,
"_components": [ "_components": [
{ {
"__id__": 34 "__id__": 41
}, },
{ {
"__id__": 35 "__id__": 42
} }
], ],
"_prefab": null, "_prefab": null,
@ -239,7 +239,7 @@
"__id__": 11 "__id__": 11
}, },
{ {
"__id__": 12 "__id__": 13
} }
], ],
"_prefab": null, "_prefab": null,
@ -509,7 +509,11 @@
"_enabled": true, "_enabled": true,
"duration": 0.1, "duration": 0.1,
"zoomScale": 1.2, "zoomScale": 1.2,
"clickEvents": [], "clickEvents": [
{
"__id__": 12
}
],
"_N$interactable": true, "_N$interactable": true,
"_N$enableAutoGrayEffect": false, "_N$enableAutoGrayEffect": false,
"_N$transition": 2, "_N$transition": 2,
@ -579,6 +583,16 @@
}, },
"_id": "f0IHoTsa9JbaCKLuhzu4sQ" "_id": "f0IHoTsa9JbaCKLuhzu4sQ"
}, },
{
"__type__": "cc.ClickEvent",
"target": {
"__id__": 5
},
"component": "",
"_componentId": "3a2abJhRaJFyrM9SBg5rWtB",
"handler": "loadGameScene",
"customEventData": "1"
},
{ {
"__type__": "3a2abJhRaJFyrM9SBg5rWtB", "__type__": "3a2abJhRaJFyrM9SBg5rWtB",
"_name": "", "_name": "",
@ -598,14 +612,17 @@
}, },
"_children": [ "_children": [
{ {
"__id__": 14 "__id__": 15
} }
], ],
"_active": true, "_active": true,
"_level": 1, "_level": 1,
"_components": [ "_components": [
{ {
"__id__": 19 "__id__": 20
},
{
"__id__": 22
} }
], ],
"_prefab": null, "_prefab": null,
@ -656,21 +673,21 @@
"_name": "Background", "_name": "Background",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 13 "__id__": 14
}, },
"_children": [ "_children": [
{ {
"__id__": 15 "__id__": 16
} }
], ],
"_active": true, "_active": true,
"_level": 2, "_level": 2,
"_components": [ "_components": [
{ {
"__id__": 17 "__id__": 18
}, },
{ {
"__id__": 18 "__id__": 19
} }
], ],
"_prefab": null, "_prefab": null,
@ -721,14 +738,14 @@
"_name": "Label", "_name": "Label",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 14 "__id__": 15
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_level": 3, "_level": 3,
"_components": [ "_components": [
{ {
"__id__": 16 "__id__": 17
} }
], ],
"_prefab": null, "_prefab": null,
@ -779,7 +796,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 15 "__id__": 16
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -811,7 +828,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 14 "__id__": 15
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -843,7 +860,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 14 "__id__": 15
}, },
"_enabled": true, "_enabled": true,
"alignMode": 0, "alignMode": 0,
@ -870,12 +887,16 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 13 "__id__": 14
}, },
"_enabled": true, "_enabled": true,
"duration": 0.1, "duration": 0.1,
"zoomScale": 1.2, "zoomScale": 1.2,
"clickEvents": [], "clickEvents": [
{
"__id__": 21
}
],
"_N$interactable": true, "_N$interactable": true,
"_N$enableAutoGrayEffect": false, "_N$enableAutoGrayEffect": false,
"_N$transition": 2, "_N$transition": 2,
@ -941,10 +962,30 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e" "__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
}, },
"_N$target": { "_N$target": {
"__id__": 14 "__id__": 15
}, },
"_id": "26wq34PNZHVIy0AG+mYHqX" "_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", "__type__": "cc.Node",
"_name": "button", "_name": "button",
@ -954,14 +995,17 @@
}, },
"_children": [ "_children": [
{ {
"__id__": 21 "__id__": 24
} }
], ],
"_active": true, "_active": true,
"_level": 1, "_level": 1,
"_components": [ "_components": [
{ {
"__id__": 26 "__id__": 29
},
{
"__id__": 31
} }
], ],
"_prefab": null, "_prefab": null,
@ -1012,21 +1056,21 @@
"_name": "Background", "_name": "Background",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 20 "__id__": 23
}, },
"_children": [ "_children": [
{ {
"__id__": 22 "__id__": 25
} }
], ],
"_active": true, "_active": true,
"_level": 2, "_level": 2,
"_components": [ "_components": [
{ {
"__id__": 24 "__id__": 27
}, },
{ {
"__id__": 25 "__id__": 28
} }
], ],
"_prefab": null, "_prefab": null,
@ -1077,14 +1121,14 @@
"_name": "Label", "_name": "Label",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 21 "__id__": 24
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_level": 3, "_level": 3,
"_components": [ "_components": [
{ {
"__id__": 23 "__id__": 26
} }
], ],
"_prefab": null, "_prefab": null,
@ -1135,7 +1179,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 22 "__id__": 25
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -1167,7 +1211,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 21 "__id__": 24
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -1199,7 +1243,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 21 "__id__": 24
}, },
"_enabled": true, "_enabled": true,
"alignMode": 0, "alignMode": 0,
@ -1226,12 +1270,16 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 20 "__id__": 23
}, },
"_enabled": true, "_enabled": true,
"duration": 0.1, "duration": 0.1,
"zoomScale": 1.2, "zoomScale": 1.2,
"clickEvents": [], "clickEvents": [
{
"__id__": 30
}
],
"_N$interactable": true, "_N$interactable": true,
"_N$enableAutoGrayEffect": false, "_N$enableAutoGrayEffect": false,
"_N$transition": 2, "_N$transition": 2,
@ -1297,10 +1345,30 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e" "__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
}, },
"_N$target": { "_N$target": {
"__id__": 21 "__id__": 24
}, },
"_id": "f8is4J+KZG66QUsc4/ge0G" "_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", "__type__": "cc.Node",
"_name": "button", "_name": "button",
@ -1310,14 +1378,17 @@
}, },
"_children": [ "_children": [
{ {
"__id__": 28 "__id__": 33
} }
], ],
"_active": true, "_active": true,
"_level": 1, "_level": 1,
"_components": [ "_components": [
{ {
"__id__": 33 "__id__": 38
},
{
"__id__": 40
} }
], ],
"_prefab": null, "_prefab": null,
@ -1368,21 +1439,21 @@
"_name": "Background", "_name": "Background",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 27 "__id__": 32
}, },
"_children": [ "_children": [
{ {
"__id__": 29 "__id__": 34
} }
], ],
"_active": true, "_active": true,
"_level": 2, "_level": 2,
"_components": [ "_components": [
{ {
"__id__": 31 "__id__": 36
}, },
{ {
"__id__": 32 "__id__": 37
} }
], ],
"_prefab": null, "_prefab": null,
@ -1433,14 +1504,14 @@
"_name": "Label", "_name": "Label",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 28 "__id__": 33
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_level": 3, "_level": 3,
"_components": [ "_components": [
{ {
"__id__": 30 "__id__": 35
} }
], ],
"_prefab": null, "_prefab": null,
@ -1491,7 +1562,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 29 "__id__": 34
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -1523,7 +1594,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 28 "__id__": 33
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -1555,7 +1626,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 28 "__id__": 33
}, },
"_enabled": true, "_enabled": true,
"alignMode": 0, "alignMode": 0,
@ -1582,12 +1653,16 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 27 "__id__": 32
}, },
"_enabled": true, "_enabled": true,
"duration": 0.1, "duration": 0.1,
"zoomScale": 1.2, "zoomScale": 1.2,
"clickEvents": [], "clickEvents": [
{
"__id__": 39
}
],
"_N$interactable": true, "_N$interactable": true,
"_N$enableAutoGrayEffect": false, "_N$enableAutoGrayEffect": false,
"_N$transition": 2, "_N$transition": 2,
@ -1653,10 +1728,30 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e" "__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
}, },
"_N$target": { "_N$target": {
"__id__": 28 "__id__": 33
}, },
"_id": "07Xool7WZN8ovK0H1mRfer" "_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", "__type__": "cc.Canvas",
"_name": "", "_name": "",

View File

@ -8,12 +8,13 @@
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [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 // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
import GameData from "./GameData";
const {ccclass, property} = cc._decorator; const {ccclass, property} = cc._decorator;
@ccclass @ccclass
export default class NewClass extends cc.Component { export default class NewClass extends cc.Component {
duratrion : number = 2.5;
moveAmountX : number = 0; moveAmountX : number = 0;
RTL: boolean = false; RTL: boolean = false;
@ -22,13 +23,13 @@ export default class NewClass extends cc.Component {
@property(cc.Prefab) @property(cc.Prefab)
yellowBullet: cc.Prefab = null; yellowBullet: cc.Prefab = null;
enemyLife: number = 1 enemyLife: number = GameData.instance.enemyHealth;
playAnimation : Boolean = true; playAnimation : Boolean = true;
setMovements() { setMovements() {
var moveLeft = 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(this.duratrion, 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))); 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 () { onLoad () {
this.scheduleOnce(this.setMovements, 0.1); 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) { onCollisionEnter(otherCollider, selfCollider) {
if(otherCollider.name === 'greenbullet<PolygonCollider>') { if(otherCollider.name === 'greenbullet<PolygonCollider>') {

View File

@ -8,6 +8,8 @@
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [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 // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
import GameData from "./GameData";
const {ccclass, property} = cc._decorator; const {ccclass, property} = cc._decorator;
@ccclass @ccclass
@ -39,7 +41,7 @@ export default class NewClass extends cc.Component {
const shipXMax = screenHalfWidth - shipMaxMove - margin; const shipXMax = screenHalfWidth - shipMaxMove - margin;
const shipX = Math.random() * (shipXMax - shipXMin) + shipXMin; 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(() => { this.scheduleOnce(() => {
const ship = cc.instantiate(shipPrefab); const ship = cc.instantiate(shipPrefab);
ship.setPosition(shipX, shipY); ship.setPosition(shipX, shipY);
@ -48,7 +50,7 @@ export default class NewClass extends cc.Component {
const shipScript = ship.getComponent('EnemyShip'); const shipScript = ship.getComponent('EnemyShip');
shipScript.moveAmountX = batchMoveAmountX; shipScript.moveAmountX = batchMoveAmountX;
shipScript.RTL = RTL; shipScript.RTL = RTL;
}, i * 0.5); }, i * GameData.instance.enemyMoveTime * 0.25);
} }
} }

View File

@ -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;
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "58f17fa0-2478-408d-8bcd-790f44f2386e",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@ -8,6 +8,8 @@
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [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 // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
import GameData from "./GameData";
const {ccclass, property} = cc._decorator; const {ccclass, property} = cc._decorator;
@ccclass @ccclass
@ -20,8 +22,10 @@ export default class NewClass extends cc.Component {
} }
loadGameScene(event, customData) { loadGameScene(event, customData) {
cc.director.preloadScene('Level', () => { const selectedLevel = Number(customData);
cc.director.loadScene('Level'); GameData.instance.selectedLevel = selectedLevel;
cc.director.preloadScene('Game', () => {
cc.director.loadScene('Game');
}); });
} }
} }