From 50c44b7d6458eaa7f9da9af3181069d76958a217 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 31 Dec 2022 12:53:49 +0100 Subject: [PATCH] barbarian anim --- assets/Data/GameSettings.json | 10 +- .../Barbarian/Animation Graph.animgraph | 174 ------------------ .../Barbarian/Animation Graph.animgraph.meta | 11 -- .../Barbarian/{Shoot.anim => Idle.anim} | 0 .../{Shoot.anim.meta => Idle.anim.meta} | 2 +- .../Game/Enemies/Barbarian/Move.anim.meta | 1 - .../Enemies/Barbarian/{Move.anim => Run.anim} | 0 .../Game/Enemies/Barbarian/Run.anim.meta | 13 ++ .../Prefabs/Game/Enemies/Barbarian.prefab | 67 +++---- .../Scripts/Game/Unit/Enemy/AnimatedEnemy.ts | 36 ++++ .../Game/Unit/Enemy/AnimatedEnemy.ts.meta | 9 + assets/Scripts/Game/Unit/Enemy/Enemy.ts | 2 +- .../PeriodicFollowTargetEnemyMover.ts | 13 +- 13 files changed, 107 insertions(+), 231 deletions(-) delete mode 100644 assets/Media/Animation/Game/Enemies/Barbarian/Animation Graph.animgraph delete mode 100644 assets/Media/Animation/Game/Enemies/Barbarian/Animation Graph.animgraph.meta rename assets/Media/Animation/Game/Enemies/Barbarian/{Shoot.anim => Idle.anim} (100%) rename assets/Media/Animation/Game/Enemies/Barbarian/{Shoot.anim.meta => Idle.anim.meta} (90%) delete mode 100644 assets/Media/Animation/Game/Enemies/Barbarian/Move.anim.meta rename assets/Media/Animation/Game/Enemies/Barbarian/{Move.anim => Run.anim} (100%) create mode 100644 assets/Media/Animation/Game/Enemies/Barbarian/Run.anim.meta create mode 100644 assets/Scripts/Game/Unit/Enemy/AnimatedEnemy.ts create mode 100644 assets/Scripts/Game/Unit/Enemy/AnimatedEnemy.ts.meta diff --git a/assets/Data/GameSettings.json b/assets/Data/GameSettings.json index b2c6228..6b58a60 100644 --- a/assets/Data/GameSettings.json +++ b/assets/Data/GameSettings.json @@ -151,7 +151,7 @@ "projectileLifetime": 8, "projectileSpeed": 140, "projectileDamage": 4, - "cooldown": 2.5 + "cooldown": 3.67 }, "magicOrbLauncher": { "enemyIds": [], @@ -464,16 +464,16 @@ }, { "enemyIdToAffect": "SiegeEnemyRanged", - "followTime": 4, - "waitTime": 4 + "followTime": 3, + "waitTime": 0.67 } ], "individualEnemySpawners": [ { "common": { - "enemyId": "BasicEnemy", + "enemyId": "SiegeEnemyRanged", "startDelay": 0, - "stopDelay": 59, + "stopDelay": 2, "cooldown": 1 } }, diff --git a/assets/Media/Animation/Game/Enemies/Barbarian/Animation Graph.animgraph b/assets/Media/Animation/Game/Enemies/Barbarian/Animation Graph.animgraph deleted file mode 100644 index 8cd7dbe..0000000 --- a/assets/Media/Animation/Game/Enemies/Barbarian/Animation Graph.animgraph +++ /dev/null @@ -1,174 +0,0 @@ -[ - { - "__type__": "cc.animation.AnimationGraph", - "_name": "", - "_objFlags": 0, - "_native": "", - "_layers": [ - { - "__id__": 1 - } - ], - "_variables": {} - }, - { - "__type__": "cc.animation.Layer", - "_stateMachine": { - "__id__": 2 - }, - "name": "", - "weight": 1, - "mask": null - }, - { - "__type__": "cc.animation.StateMachine", - "_states": [ - { - "__id__": 3 - }, - { - "__id__": 4 - }, - { - "__id__": 5 - }, - { - "__id__": 6 - }, - { - "__id__": 8 - } - ], - "_transitions": [ - { - "__id__": 10 - }, - { - "__id__": 11 - } - ], - "_entryState": { - "__id__": 3 - }, - "_exitState": { - "__id__": 4 - }, - "_anyState": { - "__id__": 5 - } - }, - { - "__type__": "cc.animation.State", - "__editorExtras__": { - "centerX": -143, - "centerY": -22, - "id": "16724216539930.48119152753701666" - }, - "name": "Entry" - }, - { - "__type__": "cc.animation.State", - "name": "Exit" - }, - { - "__type__": "cc.animation.State", - "__editorExtras__": { - "centerX": 126, - "centerY": 0, - "id": "16724216387450.1472316540497729" - }, - "name": "Any" - }, - { - "__type__": "cc.animation.Motion", - "__editorExtras__": { - "centerX": 14, - "centerY": -116.5, - "id": "16724216351510.5534679250082009" - }, - "name": "Shoot", - "_components": [], - "motion": { - "__id__": 7 - }, - "speed": 1, - "speedMultiplier": "", - "speedMultiplierEnabled": false - }, - { - "__type__": "cc.animation.ClipMotion", - "__editorExtras__": { - "id": "16724216351480.6384312560331595", - "centerX": 0, - "centerY": 0, - "name": "" - }, - "clip": { - "__uuid__": "02f5cb0a-b58e-418e-aa60-45f28f5a4e9f", - "__expectedType__": "cc.AnimationClip" - } - }, - { - "__type__": "cc.animation.Motion", - "__editorExtras__": { - "centerX": 14, - "centerY": -31.5, - "id": "16724216351510.4468726373332348" - }, - "name": "Move", - "_components": [], - "motion": { - "__id__": 9 - }, - "speed": 1, - "speedMultiplier": "", - "speedMultiplierEnabled": false - }, - { - "__type__": "cc.animation.ClipMotion", - "__editorExtras__": { - "id": "16724216351510.04360222304205896", - "centerX": 0, - "centerY": 0, - "name": "" - }, - "clip": { - "__uuid__": "01f039bc-a24c-45e7-a938-336d2111f3dc", - "__expectedType__": "cc.AnimationClip" - } - }, - { - "__type__": "cc.animation.AnimationTransition", - "from": { - "__id__": 8 - }, - "to": { - "__id__": 6 - }, - "conditions": [], - "duration": 0.3, - "relativeDuration": false, - "exitConditionEnabled": true, - "destinationStart": 0, - "relativeDestinationStart": false, - "interruptionSource": 0, - "_exitCondition": 1 - }, - { - "__type__": "cc.animation.AnimationTransition", - "from": { - "__id__": 6 - }, - "to": { - "__id__": 8 - }, - "conditions": [], - "duration": 0.3, - "relativeDuration": false, - "exitConditionEnabled": true, - "destinationStart": 0, - "relativeDestinationStart": false, - "interruptionSource": 0, - "_exitCondition": 1 - } -] \ No newline at end of file diff --git a/assets/Media/Animation/Game/Enemies/Barbarian/Animation Graph.animgraph.meta b/assets/Media/Animation/Game/Enemies/Barbarian/Animation Graph.animgraph.meta deleted file mode 100644 index d111c1e..0000000 --- a/assets/Media/Animation/Game/Enemies/Barbarian/Animation Graph.animgraph.meta +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ver": "1.1.0", - "importer": "animation-graph", - "imported": true, - "uuid": "10c1208e-fa86-4f5b-851b-7fb7c52ebcf1", - "files": [ - ".json" - ], - "subMetas": {}, - "userData": {} -} diff --git a/assets/Media/Animation/Game/Enemies/Barbarian/Shoot.anim b/assets/Media/Animation/Game/Enemies/Barbarian/Idle.anim similarity index 100% rename from assets/Media/Animation/Game/Enemies/Barbarian/Shoot.anim rename to assets/Media/Animation/Game/Enemies/Barbarian/Idle.anim diff --git a/assets/Media/Animation/Game/Enemies/Barbarian/Shoot.anim.meta b/assets/Media/Animation/Game/Enemies/Barbarian/Idle.anim.meta similarity index 90% rename from assets/Media/Animation/Game/Enemies/Barbarian/Shoot.anim.meta rename to assets/Media/Animation/Game/Enemies/Barbarian/Idle.anim.meta index 5ab8e19..aea231a 100644 --- a/assets/Media/Animation/Game/Enemies/Barbarian/Shoot.anim.meta +++ b/assets/Media/Animation/Game/Enemies/Barbarian/Idle.anim.meta @@ -8,6 +8,6 @@ ], "subMetas": {}, "userData": { - "name": "Shoot" + "name": "Idle" } } diff --git a/assets/Media/Animation/Game/Enemies/Barbarian/Move.anim.meta b/assets/Media/Animation/Game/Enemies/Barbarian/Move.anim.meta deleted file mode 100644 index d258750..0000000 --- a/assets/Media/Animation/Game/Enemies/Barbarian/Move.anim.meta +++ /dev/null @@ -1 +0,0 @@ -{"ver":"2.0.3","importer":"animation-clip","imported":true,"uuid":"01f039bc-a24c-45e7-a938-336d2111f3dc","files":[".cconb"],"subMetas":{},"userData":{"name":"Move"}} diff --git a/assets/Media/Animation/Game/Enemies/Barbarian/Move.anim b/assets/Media/Animation/Game/Enemies/Barbarian/Run.anim similarity index 100% rename from assets/Media/Animation/Game/Enemies/Barbarian/Move.anim rename to assets/Media/Animation/Game/Enemies/Barbarian/Run.anim diff --git a/assets/Media/Animation/Game/Enemies/Barbarian/Run.anim.meta b/assets/Media/Animation/Game/Enemies/Barbarian/Run.anim.meta new file mode 100644 index 0000000..d988bcf --- /dev/null +++ b/assets/Media/Animation/Game/Enemies/Barbarian/Run.anim.meta @@ -0,0 +1,13 @@ +{ + "ver": "2.0.3", + "importer": "animation-clip", + "imported": true, + "uuid": "01f039bc-a24c-45e7-a938-336d2111f3dc", + "files": [ + ".cconb" + ], + "subMetas": {}, + "userData": { + "name": "Run" + } +} diff --git a/assets/Media/Prefabs/Game/Enemies/Barbarian.prefab b/assets/Media/Prefabs/Game/Enemies/Barbarian.prefab index f96beb5..df6c0f8 100644 --- a/assets/Media/Prefabs/Game/Enemies/Barbarian.prefab +++ b/assets/Media/Prefabs/Game/Enemies/Barbarian.prefab @@ -257,37 +257,6 @@ "__type__": "cc.CompPrefabInfo", "fileId": "5dR8969SVAfLXx5AY1X9B5" }, - { - "__type__": "7f8b6NKHsNNW5nLY3fwejhw", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 1 - }, - "_enabled": true, - "__prefab": { - "__id__": 13 - }, - "collider": { - "__id__": 10 - }, - "sprite": { - "__id__": 5 - }, - "defaultMaterial": { - "__uuid__": "fda095cb-831d-4601-ad94-846013963de8", - "__expectedType__": "cc.Material" - }, - "whiteMaterial": { - "__uuid__": "9cb17675-370b-48ed-bfa2-bb613a88af44", - "__expectedType__": "cc.Material" - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "b5ONKVkchBpaoqReE981lo" - }, { "__type__": "cc.Animation", "_name": "", @@ -297,7 +266,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 15 + "__id__": 13 }, "playOnLoad": true, "_clips": [ @@ -320,6 +289,40 @@ "__type__": "cc.CompPrefabInfo", "fileId": "74x/uTmM5C8J/ZyOW71lz5" }, + { + "__type__": "2fbd7DLmiNFybvIJxxrW6Iu", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 15 + }, + "collider": { + "__id__": 10 + }, + "sprite": { + "__id__": 5 + }, + "defaultMaterial": { + "__uuid__": "fda095cb-831d-4601-ad94-846013963de8", + "__expectedType__": "cc.Material" + }, + "whiteMaterial": { + "__uuid__": "9cb17675-370b-48ed-bfa2-bb613a88af44", + "__expectedType__": "cc.Material" + }, + "animation": { + "__id__": 12 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "23A8mHvnBHz7LyWYrq9p/n" + }, { "__type__": "cc.PrefabInfo", "root": { diff --git a/assets/Scripts/Game/Unit/Enemy/AnimatedEnemy.ts b/assets/Scripts/Game/Unit/Enemy/AnimatedEnemy.ts new file mode 100644 index 0000000..be501bc --- /dev/null +++ b/assets/Scripts/Game/Unit/Enemy/AnimatedEnemy.ts @@ -0,0 +1,36 @@ +import { Animation, Vec3, _decorator } from "cc"; +import { Enemy } from "./Enemy"; +const { ccclass, property } = _decorator; + +@ccclass("AnimatedEnemy") +export class AnimatedEnemy extends Enemy { + @property(Animation) private animation: Animation; + + private isAnimatingIdle = false; + + public gameTick(move: Vec3, deltaTime: number): void { + super.gameTick(move, deltaTime); + + console.log("Move x: " + move.x + " Move y: " + move.y); + + if (move.x === 0 && move.y === 0) { + this.animateIdle(); + } else { + this.animateRun(); + } + } + + private animateIdle(): void { + if (this.isAnimatingIdle) return; + this.isAnimatingIdle = true; + + this.animation.play("Idle"); + } + + private animateRun(): void { + if (!this.isAnimatingIdle) return; + this.isAnimatingIdle = false; + + this.animation.play("Run"); + } +} diff --git a/assets/Scripts/Game/Unit/Enemy/AnimatedEnemy.ts.meta b/assets/Scripts/Game/Unit/Enemy/AnimatedEnemy.ts.meta new file mode 100644 index 0000000..14ff722 --- /dev/null +++ b/assets/Scripts/Game/Unit/Enemy/AnimatedEnemy.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "2fbd70cb-9a23-45c9-bbc8-271c6b5ba22e", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/Game/Unit/Enemy/Enemy.ts b/assets/Scripts/Game/Unit/Enemy/Enemy.ts index c69b38d..aea7b15 100644 --- a/assets/Scripts/Game/Unit/Enemy/Enemy.ts +++ b/assets/Scripts/Game/Unit/Enemy/Enemy.ts @@ -118,7 +118,7 @@ export class Enemy extends Component { if (move.x < 0) { this.sprite.node.setScale(-1, 1, 1); - } else { + } else if (0 < move.x) { this.sprite.node.setScale(1, 1, 1); } diff --git a/assets/Scripts/Game/Unit/Enemy/EnemyMover/PeriodicFollow/PeriodicFollowTargetEnemyMover.ts b/assets/Scripts/Game/Unit/Enemy/EnemyMover/PeriodicFollow/PeriodicFollowTargetEnemyMover.ts index 62be0ac..2127602 100644 --- a/assets/Scripts/Game/Unit/Enemy/EnemyMover/PeriodicFollow/PeriodicFollowTargetEnemyMover.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemyMover/PeriodicFollow/PeriodicFollowTargetEnemyMover.ts @@ -26,12 +26,13 @@ export class PeriodicFollowTargetEnemyMover extends EnemyMover { this.switchEnemyFollowState(enemy); } else { this.enemyToStateTimeLeft.set(enemy, stateTimeLeft); - - if (this.enemyToFollowState.get(enemy) === EnemyFollowState.Follow) { - let direction: Vec3 = new Vec3(); - direction = Vec3.subtract(direction, this.targetNode.worldPosition, enemy.node.worldPosition); - enemy.gameTick(direction.normalize(), deltaTime); - } + } + if (this.enemyToFollowState.get(enemy) === EnemyFollowState.Follow) { + let direction: Vec3 = new Vec3(); + direction = Vec3.subtract(direction, this.targetNode.worldPosition, enemy.node.worldPosition); + enemy.gameTick(direction.normalize(), deltaTime); + } else if (this.enemyToFollowState.get(enemy) === EnemyFollowState.Wait) { + enemy.gameTick(new Vec3(), deltaTime); } } }