[Add]: Score and lifes

This commit is contained in:
Mohammad_Hasan 2025-10-31 16:20:20 +04:00
parent 87e03ac837
commit f17cad716a
17 changed files with 1268 additions and 38 deletions

File diff suppressed because it is too large Load Diff

View File

@ -156,7 +156,7 @@
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": 0, "y": 0,
"z": 780.2888888097792 "z": 539.5338265577053
}, },
"_scale": { "_scale": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",

View File

@ -118,6 +118,7 @@
"__id__": 1 "__id__": 1
}, },
"_enabled": true, "_enabled": true,
"scoreLabel": null,
"yellowBullet": { "yellowBullet": {
"__uuid__": "1e6b2ed9-fc9b-4d1a-8f2a-7773b0428ecb" "__uuid__": "1e6b2ed9-fc9b-4d1a-8f2a-7773b0428ecb"
}, },
@ -739,7 +740,7 @@
"asset": { "asset": {
"__id__": 0 "__id__": 0
}, },
"fileId": "c9zFlVfU9Pr7HzSY8BJeaQ", "fileId": "79n62fy2FB0phxl7o8lzGi",
"sync": false "sync": false
} }
] ]

View File

@ -1,6 +1,6 @@
{ {
"ver": "1.2.1", "ver": "1.2.1",
"uuid": "cc9c71b8-6dce-463b-a0a8-99baebb6aa72", "uuid": "4fd20ca9-dc4a-45b4-8c83-4fcc89828fe6",
"optimizationPolicy": "AUTO", "optimizationPolicy": "AUTO",
"asyncLoadAssets": false, "asyncLoadAssets": false,
"readonly": false, "readonly": false,

View File

@ -118,6 +118,7 @@
"__id__": 1 "__id__": 1
}, },
"_enabled": true, "_enabled": true,
"scoreLabel": null,
"yellowBullet": { "yellowBullet": {
"__uuid__": "1e6b2ed9-fc9b-4d1a-8f2a-7773b0428ecb" "__uuid__": "1e6b2ed9-fc9b-4d1a-8f2a-7773b0428ecb"
}, },
@ -1104,7 +1105,7 @@
"asset": { "asset": {
"__id__": 0 "__id__": 0
}, },
"fileId": "f9f/isXgZHr78pxJAgRYe9", "fileId": "a0FzMZOHFP1a3ZrrwMZQvt",
"sync": false "sync": false
} }
] ]

View File

@ -1,6 +1,6 @@
{ {
"ver": "1.2.1", "ver": "1.2.1",
"uuid": "2a44b465-8729-484a-b0d5-8028192c3600", "uuid": "f819b8da-8f4c-4c09-babc-dac7ec7d20a3",
"optimizationPolicy": "AUTO", "optimizationPolicy": "AUTO",
"asyncLoadAssets": false, "asyncLoadAssets": false,
"readonly": false, "readonly": false,

View File

@ -56,15 +56,15 @@
}, },
"_position": { "_position": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 314.563, "x": -165.437,
"y": 292.913, "y": -18.058,
"z": 0 "z": 0
}, },
"_scale": { "_scale": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0.5, "x": 0.5,
"y": 0.5, "y": 0.33333,
"z": 1 "z": 0.5
}, },
"_eulerAngles": { "_eulerAngles": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -118,6 +118,7 @@
"__id__": 1 "__id__": 1
}, },
"_enabled": true, "_enabled": true,
"scoreLabel": null,
"yellowBullet": { "yellowBullet": {
"__uuid__": "1e6b2ed9-fc9b-4d1a-8f2a-7773b0428ecb" "__uuid__": "1e6b2ed9-fc9b-4d1a-8f2a-7773b0428ecb"
}, },
@ -1139,7 +1140,7 @@
"asset": { "asset": {
"__id__": 0 "__id__": 0
}, },
"fileId": "53aBGR+eRGY7mE48Fc6Wgn", "fileId": "70RrlGOxlLe4BuVM1d8Jqr",
"sync": false "sync": false
} }
] ]

View File

@ -1,6 +1,6 @@
{ {
"ver": "1.2.1", "ver": "1.2.1",
"uuid": "022c2978-0c9b-442a-89ef-f4df3dd70646", "uuid": "6c6bd86b-1419-437a-b3db-9e653f754b61",
"optimizationPolicy": "AUTO", "optimizationPolicy": "AUTO",
"asyncLoadAssets": false, "asyncLoadAssets": false,
"readonly": false, "readonly": false,

View File

@ -18,7 +18,7 @@
"_parent": null, "_parent": null,
"_children": [], "_children": [],
"_active": true, "_active": true,
"_level": 2, "_level": 1,
"_components": [ "_components": [
{ {
"__id__": 2 "__id__": 2
@ -115,8 +115,7 @@
"__id__": 1 "__id__": 1
}, },
"_enabled": true, "_enabled": true,
"label": null, "scoreLabel": null,
"text": "hello",
"BulletSpeed": -500, "BulletSpeed": -500,
"_id": "" "_id": ""
}, },
@ -181,7 +180,7 @@
"asset": { "asset": {
"__id__": 0 "__id__": 0
}, },
"fileId": "7ecCcOtJ1F1L0KGm/DlBkM", "fileId": "c01ayalttID5NDkK1bsCpd",
"sync": false "sync": false
} }
] ]

View File

@ -1,6 +1,6 @@
{ {
"ver": "1.2.1", "ver": "1.2.1",
"uuid": "b7521c67-e13a-4a83-affe-f86364304313", "uuid": "9c1eea54-1438-4486-9ff4-c2ba640da280",
"optimizationPolicy": "AUTO", "optimizationPolicy": "AUTO",
"asyncLoadAssets": false, "asyncLoadAssets": false,
"readonly": false, "readonly": false,

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 KiB

View File

@ -0,0 +1,34 @@
{
"ver": "2.3.3",
"uuid": "eba7d3b8-1d34-4939-a6f4-87831b8ea9d0",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"platformSettings": {},
"subMetas": {
"glossy-red-heart-symbol-3d-render-shiny-heart 2": {
"ver": "1.0.4",
"uuid": "746cf043-7cf7-4d62-86fd-fbe6ff6d470d",
"rawTextureUuid": "eba7d3b8-1d34-4939-a6f4-87831b8ea9d0",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 5.5,
"offsetY": -32,
"trimX": 333,
"trimY": 422,
"width": 1345,
"height": 1220,
"rawWidth": 2000,
"rawHeight": 2000,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 KiB

View File

@ -0,0 +1,34 @@
{
"ver": "2.3.3",
"uuid": "8ebaee0c-e662-449f-ab9d-a101bf9a9e50",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"platformSettings": {},
"subMetas": {
"—Pngtree—violet gradient creative abstract gaming_8152127 2": {
"ver": "1.0.4",
"uuid": "fba0bf13-b989-443d-8fdf-a5f7f8bb391c",
"rawTextureUuid": "8ebaee0c-e662-449f-ab9d-a101bf9a9e50",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": -0.5,
"trimX": 144,
"trimY": 1971,
"width": 4712,
"height": 1059,
"rawWidth": 5000,
"rawHeight": 5000,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

View File

@ -15,6 +15,9 @@ const {ccclass, property} = cc._decorator;
@ccclass @ccclass
export default class NewClass extends cc.Component { export default class NewClass extends cc.Component {
@property(cc.Label)
scoreLabel: cc.Label = null;
moveAmountX : number = 0; moveAmountX : number = 0;
RTL: boolean = false; RTL: boolean = false;
@ -52,6 +55,10 @@ export default class NewClass extends cc.Component {
this.scheduleOnce(this.setMovements, 0.1); this.scheduleOnce(this.setMovements, 0.1);
this.schedule(this.shootBullets, GameData.instance.playerShootingInterval * Math.max(0.25, Math.random()), cc.macro.REPEAT_FOREVER, 0); this.schedule(this.shootBullets, GameData.instance.playerShootingInterval * Math.max(0.25, Math.random()), cc.macro.REPEAT_FOREVER, 0);
if (!this.scoreLabel) {
this.scoreLabel = cc.find("Canvas/ScoreBox/ScoreLabel").getComponent(cc.Label);
}
} }
onCollisionEnter(otherCollider, selfCollider) { onCollisionEnter(otherCollider, selfCollider) {
if(otherCollider.name === 'greenbullet<PolygonCollider>') { if(otherCollider.name === 'greenbullet<PolygonCollider>') {
@ -61,6 +68,7 @@ export default class NewClass extends cc.Component {
this.node.stopAllActions(); this.node.stopAllActions();
this.playAnimation = false; this.playAnimation = false;
this.node.getComponent(cc.Animation).play(); this.node.getComponent(cc.Animation).play();
this.scoreLabel.string = (parseInt(this.scoreLabel.string) + GameData.instance.selectedLevel * 5).toString();
} }
} }
if(otherCollider.name === 'player<PolygonCollider>') { if(otherCollider.name === 'player<PolygonCollider>') {

View File

@ -13,12 +13,6 @@ const {ccclass, property} = cc._decorator;
@ccclass @ccclass
export default class NewClass extends cc.Component { export default class NewClass extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property
text: string = 'hello';
@property @property
BulletSpeed: number = -500; BulletSpeed: number = -500;

View File

@ -20,11 +20,16 @@ export default class NewClass extends cc.Component {
@property(cc.Prefab) @property(cc.Prefab)
greenBullet: cc.Prefab = null; greenBullet: cc.Prefab = null;
playerLifes: number = 5; @property(cc.Node)
heartContainer: cc.Node = null;
private hearts: cc.Node[] = [];
playerLifes: number = 8;
onCollisionEnter(otherCollider, selfCollider) { onCollisionEnter(otherCollider, selfCollider) {
if(otherCollider.name === 'Bullet<PolygonCollider>') { if(otherCollider.name === 'Bullet<PolygonCollider>') {
this.playerLifes--; this.playerLifes--;
this.setLifes(this.playerLifes);
otherCollider.node.destroy(); otherCollider.node.destroy();
if(this.playerLifes <= 0) { if(this.playerLifes <= 0) {
this.node.destroy(); this.node.destroy();
@ -32,11 +37,12 @@ export default class NewClass extends cc.Component {
} }
} }
else if(otherCollider.name === 'health<PolygonCollider>') { else if(otherCollider.name === 'health<PolygonCollider>') {
this.playerLifes = 5; this.playerLifes = 8;
this.setLifes(this.playerLifes);
otherCollider.node.destroy(); otherCollider.node.destroy();
} }
else if(otherCollider.name === 'rocket<PolygonCollider>') { else if(otherCollider.name === 'rocket<PolygonCollider>') {
this.shootingInterval = Math.min(this.shootingInterval + 1, 3); this.shootingInterval = Math.min(this.shootingInterval + 1, 5);
otherCollider.node.destroy(); otherCollider.node.destroy();
} }
} }
@ -53,17 +59,45 @@ export default class NewClass extends cc.Component {
this.spawnBullet(0, 40); this.spawnBullet(0, 40);
break; break;
case 2: case 2:
this.spawnBullet(-30, 20); this.spawnBullet(-35, 20);
this.spawnBullet(30, 20); this.spawnBullet(35, 20);
break; break;
case 3: case 3:
this.spawnBullet(0, 40); this.spawnBullet(0, 40);
this.spawnBullet(-30, 20); this.spawnBullet(-35, 20);
this.spawnBullet(30, 20); this.spawnBullet(35, 20);
break;
case 4:
this.spawnBullet(-35, 20);
this.spawnBullet(17.5, 30);
this.spawnBullet(35, 20);
this.spawnBullet(-17.5, 30);
break;
case 5:
this.spawnBullet(0, 40);
this.spawnBullet(-35, 20);
this.spawnBullet(17.5, 30);
this.spawnBullet(35, 20);
this.spawnBullet(-17.5, 30);
break; break;
} }
} }
updateHearts() {
for (let i = 0; i < this.hearts.length; i++) {
if (i < this.playerLifes) {
this.hearts[i].opacity = 255;
} else {
this.hearts[i].opacity = 60;
}
}
}
setLifes(newLife: number) {
this.playerLifes = newLife;
this.updateHearts();
}
onLoad() { onLoad() {
// Enable touch on this node directly // Enable touch on this node directly
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this); this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
@ -71,7 +105,10 @@ export default class NewClass extends cc.Component {
this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this); this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this); this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
this.schedule(this.shootBullets, 0.25, cc.macro.REPEAT_FOREVER, 0); this.schedule(this.shootBullets, 0.35, cc.macro.REPEAT_FOREVER, 0);
this.hearts = this.heartContainer.children;
this.updateHearts();
} }
onTouchStart(event: cc.Event.EventTouch) { onTouchStart(event: cc.Event.EventTouch) {