Blinking end of lifetime

This commit is contained in:
Martin 2022-12-19 16:24:52 +01:00
parent 5650165d3c
commit 4400311a11
4 changed files with 350 additions and 67 deletions

View File

@ -17,24 +17,25 @@
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"_parent": null, "_parent": null,
"_children": [], "_children": [
{
"__id__": 2
}
],
"_active": true, "_active": true,
"_components": [ "_components": [
{
"__id__": 2
},
{
"__id__": 4
},
{
"__id__": 6
},
{ {
"__id__": 8 "__id__": 8
},
{
"__id__": 10
},
{
"__id__": 12
} }
], ],
"_prefab": { "_prefab": {
"__id__": 10 "__id__": 14
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -64,16 +65,64 @@
}, },
"_id": "" "_id": ""
}, },
{
"__type__": "cc.Node",
"_name": "Graphics",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 3
},
{
"__id__": 5
}
],
"_prefab": {
"__id__": 7
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{ {
"__type__": "cc.UITransform", "__type__": "cc.UITransform",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 1 "__id__": 2
}, },
"_enabled": false, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 3 "__id__": 4
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
@ -89,18 +138,18 @@
}, },
{ {
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "bbsWYc2MNCLLweNFP7pjHF" "fileId": "c4cbC3G4lJcovI9zoCe/21"
}, },
{ {
"__type__": "cc.Sprite", "__type__": "cc.Sprite",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 1 "__id__": 2
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 5 "__id__": 6
}, },
"_customMaterial": null, "_customMaterial": null,
"_srcBlendFactor": 2, "_srcBlendFactor": 2,
@ -133,7 +182,44 @@
}, },
{ {
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "bfkBAEWOZDbILym05Q5wrx" "fileId": "78W7mwOx9Kc4cDvfMFcZjX"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "f0Ff0jfgNKTqjoStNmJGP/"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": false,
"__prefab": {
"__id__": 9
},
"_contentSize": {
"__type__": "cc.Size",
"width": 25,
"height": 26
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "bbsWYc2MNCLLweNFP7pjHF"
}, },
{ {
"__type__": "cc.BoxCollider2D", "__type__": "cc.BoxCollider2D",
@ -144,7 +230,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 7 "__id__": 11
}, },
"tag": 0, "tag": 0,
"_group": 4, "_group": 4,
@ -177,13 +263,13 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 9 "__id__": 13
}, },
"collider": { "collider": {
"__id__": 6 "__id__": 10
}, },
"sprite": { "sprite": {
"__id__": 4 "__id__": 5
}, },
"whiteMaterial": { "whiteMaterial": {
"__uuid__": "9cb17675-370b-48ed-bfa2-bb613a88af44", "__uuid__": "9cb17675-370b-48ed-bfa2-bb613a88af44",

View File

@ -17,24 +17,25 @@
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"_parent": null, "_parent": null,
"_children": [], "_children": [
{
"__id__": 2
}
],
"_active": true, "_active": true,
"_components": [ "_components": [
{
"__id__": 2
},
{
"__id__": 4
},
{
"__id__": 6
},
{ {
"__id__": 8 "__id__": 8
},
{
"__id__": 10
},
{
"__id__": 12
} }
], ],
"_prefab": { "_prefab": {
"__id__": 10 "__id__": 14
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -64,16 +65,64 @@
}, },
"_id": "" "_id": ""
}, },
{
"__type__": "cc.Node",
"_name": "Graphics",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 3
},
{
"__id__": 5
}
],
"_prefab": {
"__id__": 7
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{ {
"__type__": "cc.UITransform", "__type__": "cc.UITransform",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 1 "__id__": 2
}, },
"_enabled": false, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 3 "__id__": 4
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
@ -89,18 +138,18 @@
}, },
{ {
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "bbsWYc2MNCLLweNFP7pjHF" "fileId": "464/MPdiZA5qZYQRCq97Ha"
}, },
{ {
"__type__": "cc.Sprite", "__type__": "cc.Sprite",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 1 "__id__": 2
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 5 "__id__": 6
}, },
"_customMaterial": null, "_customMaterial": null,
"_srcBlendFactor": 2, "_srcBlendFactor": 2,
@ -133,7 +182,44 @@
}, },
{ {
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "bfkBAEWOZDbILym05Q5wrx" "fileId": "d0xqMqB4RM45zTqWTxtmE+"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "eeHhbzhLlHZ6xMMi0bNFTG"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": false,
"__prefab": {
"__id__": 9
},
"_contentSize": {
"__type__": "cc.Size",
"width": 25,
"height": 28
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "bbsWYc2MNCLLweNFP7pjHF"
}, },
{ {
"__type__": "cc.BoxCollider2D", "__type__": "cc.BoxCollider2D",
@ -144,7 +230,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 7 "__id__": 11
}, },
"tag": 0, "tag": 0,
"_group": 4, "_group": 4,
@ -177,13 +263,13 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 9 "__id__": 13
}, },
"collider": { "collider": {
"__id__": 6 "__id__": 10
}, },
"sprite": { "sprite": {
"__id__": 4 "__id__": 5
}, },
"whiteMaterial": { "whiteMaterial": {
"__uuid__": "9cb17675-370b-48ed-bfa2-bb613a88af44", "__uuid__": "9cb17675-370b-48ed-bfa2-bb613a88af44",

View File

@ -17,24 +17,25 @@
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"_parent": null, "_parent": null,
"_children": [], "_children": [
{
"__id__": 2
}
],
"_active": true, "_active": true,
"_components": [ "_components": [
{
"__id__": 2
},
{
"__id__": 4
},
{
"__id__": 6
},
{ {
"__id__": 8 "__id__": 8
},
{
"__id__": 10
},
{
"__id__": 12
} }
], ],
"_prefab": { "_prefab": {
"__id__": 10 "__id__": 14
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -64,16 +65,64 @@
}, },
"_id": "" "_id": ""
}, },
{
"__type__": "cc.Node",
"_name": "Graphics",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 3
},
{
"__id__": 5
}
],
"_prefab": {
"__id__": 7
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{ {
"__type__": "cc.UITransform", "__type__": "cc.UITransform",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 1 "__id__": 2
}, },
"_enabled": false, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 3 "__id__": 4
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
@ -89,18 +138,18 @@
}, },
{ {
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "bbsWYc2MNCLLweNFP7pjHF" "fileId": "a3+ZZgs3ROZYsgwk/9mKPx"
}, },
{ {
"__type__": "cc.Sprite", "__type__": "cc.Sprite",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 1 "__id__": 2
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 5 "__id__": 6
}, },
"_customMaterial": null, "_customMaterial": null,
"_srcBlendFactor": 2, "_srcBlendFactor": 2,
@ -133,7 +182,44 @@
}, },
{ {
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "bfkBAEWOZDbILym05Q5wrx" "fileId": "2a9qQUmpNPhLo3/pi7NiW+"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "1amYNnXbNLeKZa6imz7kGg"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": false,
"__prefab": {
"__id__": 9
},
"_contentSize": {
"__type__": "cc.Size",
"width": 34,
"height": 33
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "bbsWYc2MNCLLweNFP7pjHF"
}, },
{ {
"__type__": "cc.BoxCollider2D", "__type__": "cc.BoxCollider2D",
@ -144,7 +230,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 7 "__id__": 11
}, },
"tag": 0, "tag": 0,
"_group": 4, "_group": 4,
@ -177,13 +263,13 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 9 "__id__": 13
}, },
"collider": { "collider": {
"__id__": 6 "__id__": 10
}, },
"sprite": { "sprite": {
"__id__": 4 "__id__": 5
}, },
"whiteMaterial": { "whiteMaterial": {
"__uuid__": "9cb17675-370b-48ed-bfa2-bb613a88af44", "__uuid__": "9cb17675-370b-48ed-bfa2-bb613a88af44",

View File

@ -1,4 +1,4 @@
import { BoxCollider2D, Component, Material, randomRange, Sprite, Vec3, _decorator } from "cc"; import { BoxCollider2D, Color, Component, Material, randomRange, Sprite, Vec3, _decorator } from "cc";
import { ISignal } from "../../../Services/EventSystem/ISignal"; import { ISignal } from "../../../Services/EventSystem/ISignal";
import { Signal } from "../../../Services/EventSystem/Signal"; import { Signal } from "../../../Services/EventSystem/Signal";
import { delay } from "../../../Services/Utils/AsyncUtils"; import { delay } from "../../../Services/Utils/AsyncUtils";
@ -29,6 +29,8 @@ export class Enemy extends Component {
private xpReward: number; private xpReward: number;
private goldReward: number; private goldReward: number;
private endOfLifetimeTriggered = false;
public setup(position: Vec3, settings: EnemySettings): void { public setup(position: Vec3, settings: EnemySettings): void {
this.defaultMaterial = this.sprite.material; this.defaultMaterial = this.sprite.material;
@ -46,6 +48,7 @@ export class Enemy extends Component {
this.node.active = true; this.node.active = true;
this.health.HealthPointsChangeEvent.on(this.animateHurt, this); this.health.HealthPointsChangeEvent.on(this.animateHurt, this);
this.endOfLifetimeTriggered = false;
} }
public get MovementType(): EnemyMovementType { public get MovementType(): EnemyMovementType {
@ -92,16 +95,38 @@ export class Enemy extends Component {
newPosition.x += move.x * this.speedX * deltaTime; newPosition.x += move.x * this.speedX * deltaTime;
newPosition.y += move.y * this.speedY * deltaTime; newPosition.y += move.y * this.speedY * deltaTime;
if (move.x < 0) {
this.sprite.node.setScale(-1, 1, 1);
} else {
this.sprite.node.setScale(1, 1, 1);
}
this.node.setWorldPosition(newPosition); this.node.setWorldPosition(newPosition);
if (0 < this.lifetimeLeft) { if (0 < this.lifetimeLeft) {
this.lifetimeLeft -= deltaTime; this.lifetimeLeft -= deltaTime;
if (this.lifetimeLeft <= 0) { if (this.lifetimeLeft <= 0) {
this.lifetimeEndedEvent.trigger(this); this.lifetimeEndedEvent.trigger(this);
} else if (this.lifetimeLeft <= 2) {
this.animateEndOfLifetime();
} }
} }
} }
private async animateEndOfLifetime(): Promise<void> {
if (this.endOfLifetimeTriggered) return;
this.endOfLifetimeTriggered = true;
while (this.node.active) {
this.sprite.node.active = false;
await delay(200);
this.sprite.node.active = true;
await delay(200);
}
}
private async animateHurt(): Promise<void> { private async animateHurt(): Promise<void> {
this.sprite.material = this.whiteMaterial; this.sprite.material = this.whiteMaterial;
await delay(100); await delay(100);