From c72f35006522a2858d55407201302ca3e33682c1 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 20 Dec 2022 11:27:51 +0100 Subject: [PATCH 1/2] Item manager --- .../Prefabs/Game/Effects/PickBonus.prefab | 25 +- assets/Media/Prefabs/Game/Player.prefab | 3 + assets/Scenes/Game.scene | 409 ++++++++++++------ .../Game/Collision/PlayerCollisionSystem.ts | 35 +- assets/Scripts/Game/Game.ts | 13 +- assets/Scripts/Game/{ => Items}/Gold.meta | 0 assets/Scripts/Game/{ => Items}/Gold/Gold.ts | 5 +- .../Game/{ => Items}/Gold/Gold.ts.meta | 0 .../Game/{ => Items}/Gold/GoldSpawner.ts | 2 +- .../Game/{ => Items}/Gold/GoldSpawner.ts.meta | 0 assets/Scripts/Game/Items/ItemManager.ts | 88 ++++ assets/Scripts/Game/Items/ItemManager.ts.meta | 9 + assets/Scripts/Game/Items/PickupEffect.meta | 12 + .../Game/Items/PickupEffect/PickupEffect.ts | 10 + .../Items/PickupEffect/PickupEffect.ts.meta | 9 + .../Items/PickupEffect/PickupEffectManager.ts | 26 ++ .../PickupEffect/PickupEffectManager.ts.meta | 9 + assets/Scripts/Game/{ => Items}/XP.meta | 0 assets/Scripts/Game/{ => Items}/XP/XP.ts | 5 +- assets/Scripts/Game/{ => Items}/XP/XP.ts.meta | 0 .../Scripts/Game/{ => Items}/XP/XPSpawner.ts | 3 +- .../Game/{ => Items}/XP/XPSpawner.ts.meta | 0 assets/Scripts/Game/Pickups.meta | 12 + .../Scripts/Game/Unit/Enemy/EnemyManager.ts | 35 +- assets/Scripts/Game/Unit/Player/Player.ts | 12 +- 25 files changed, 514 insertions(+), 208 deletions(-) rename assets/Scripts/Game/{ => Items}/Gold.meta (100%) rename assets/Scripts/Game/{ => Items}/Gold/Gold.ts (80%) rename assets/Scripts/Game/{ => Items}/Gold/Gold.ts.meta (100%) rename assets/Scripts/Game/{ => Items}/Gold/GoldSpawner.ts (92%) rename assets/Scripts/Game/{ => Items}/Gold/GoldSpawner.ts.meta (100%) create mode 100644 assets/Scripts/Game/Items/ItemManager.ts create mode 100644 assets/Scripts/Game/Items/ItemManager.ts.meta create mode 100644 assets/Scripts/Game/Items/PickupEffect.meta create mode 100644 assets/Scripts/Game/Items/PickupEffect/PickupEffect.ts create mode 100644 assets/Scripts/Game/Items/PickupEffect/PickupEffect.ts.meta create mode 100644 assets/Scripts/Game/Items/PickupEffect/PickupEffectManager.ts create mode 100644 assets/Scripts/Game/Items/PickupEffect/PickupEffectManager.ts.meta rename assets/Scripts/Game/{ => Items}/XP.meta (100%) rename assets/Scripts/Game/{ => Items}/XP/XP.ts (85%) rename assets/Scripts/Game/{ => Items}/XP/XP.ts.meta (100%) rename assets/Scripts/Game/{ => Items}/XP/XPSpawner.ts (92%) rename assets/Scripts/Game/{ => Items}/XP/XPSpawner.ts.meta (100%) create mode 100644 assets/Scripts/Game/Pickups.meta diff --git a/assets/Media/Prefabs/Game/Effects/PickBonus.prefab b/assets/Media/Prefabs/Game/Effects/PickBonus.prefab index 679ba70..4b4d849 100644 --- a/assets/Media/Prefabs/Game/Effects/PickBonus.prefab +++ b/assets/Media/Prefabs/Game/Effects/PickBonus.prefab @@ -28,10 +28,13 @@ }, { "__id__": 6 + }, + { + "__id__": 8 } ], "_prefab": { - "__id__": 8 + "__id__": 10 }, "_lpos": { "__type__": "cc.Vec3", @@ -160,6 +163,26 @@ "__type__": "cc.CompPrefabInfo", "fileId": "3ag4rexLNJW6A/sp6OpwZ8" }, + { + "__type__": "0f2b2zQHR5IYoIfX8uDxOwj", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 9 + }, + "animation": { + "__id__": 6 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "a1aUx8U+FGmqrGQlPCmH17" + }, { "__type__": "cc.PrefabInfo", "root": { diff --git a/assets/Media/Prefabs/Game/Player.prefab b/assets/Media/Prefabs/Game/Player.prefab index 9dfd113..5af50b2 100644 --- a/assets/Media/Prefabs/Game/Player.prefab +++ b/assets/Media/Prefabs/Game/Player.prefab @@ -2258,6 +2258,9 @@ "animation": { "__id__": 7 }, + "sprite": { + "__id__": 5 + }, "_id": "" }, { diff --git a/assets/Scenes/Game.scene b/assets/Scenes/Game.scene index f4dc874..0680b68 100644 --- a/assets/Scenes/Game.scene +++ b/assets/Scenes/Game.scene @@ -27,11 +27,11 @@ "_active": true, "_components": [], "_prefab": { - "__id__": 98 + "__id__": 102 }, "autoReleaseAssets": false, "_globals": { - "__id__": 101 + "__id__": 105 }, "_id": "cffa5b19-2043-4cef-8221-1a10ab7a2c1f" }, @@ -236,21 +236,24 @@ }, { "__id__": 40 + }, + { + "__id__": 44 } ], "_active": true, "_components": [ { - "__id__": 94 + "__id__": 98 }, { - "__id__": 95 + "__id__": 99 }, { - "__id__": 96 + "__id__": 100 }, { - "__id__": 97 + "__id__": 101 } ], "_prefab": null, @@ -724,7 +727,7 @@ }, { "__type__": "cc.Node", - "_name": "EnemyManager", + "_name": "ItemManager", "_objFlags": 0, "_parent": { "__id__": 12 @@ -773,7 +776,7 @@ "y": 0, "z": 0 }, - "_id": "c5hUW3WnRPzJB48SFIf+Ud" + "_id": "d8k6jk9pFJNL2Fqe9mVpWa" }, { "__type__": "cc.Node", @@ -893,7 +896,7 @@ }, { "__type__": "cc.Node", - "_name": "EnemySpawner", + "_name": "PickupEffectManager", "_objFlags": 0, "_parent": { "__id__": 32 @@ -932,6 +935,131 @@ "y": 0, "z": 0 }, + "_id": "98e6SJrnJIlYvBUzvAiGSQ" + }, + { + "__type__": "65b41IfpM9H4ZfUHg0/xy7s", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 37 + }, + "_enabled": true, + "__prefab": null, + "pickupEffect": { + "__uuid__": "37b789e2-6452-48fe-a2fe-efec6ea89d5c", + "__expectedType__": "cc.Prefab" + }, + "_id": "54wwD4xgxJD6Ay14uROQJ8" + }, + { + "__type__": "7f3f88Cth5KB41SHDJviJ/K", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 32 + }, + "_enabled": true, + "__prefab": null, + "xpSpawner": { + "__id__": 34 + }, + "goldSpawner": { + "__id__": 36 + }, + "pickupEffectManager": { + "__id__": 38 + }, + "_id": "98EDpSoeBKp7eDmPXKNFJ0" + }, + { + "__type__": "cc.Node", + "_name": "EnemyManager", + "_objFlags": 0, + "_parent": { + "__id__": 12 + }, + "_children": [ + { + "__id__": 41 + } + ], + "_active": true, + "_components": [ + { + "__id__": 43 + } + ], + "_prefab": null, + "_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": "c5hUW3WnRPzJB48SFIf+Ud" + }, + { + "__type__": "cc.Node", + "_name": "EnemySpawner", + "_objFlags": 0, + "_parent": { + "__id__": 40 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 42 + } + ], + "_prefab": null, + "_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": "936Vpv3ydL8JZMvakVgAP5" }, { @@ -939,7 +1067,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 37 + "__id__": 41 }, "_enabled": true, "__prefab": null, @@ -964,18 +1092,12 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 32 + "__id__": 40 }, "_enabled": true, "__prefab": null, "enemySpawner": { - "__id__": 38 - }, - "xpSpawner": { - "__id__": 34 - }, - "goldSpawner": { - "__id__": 36 + "__id__": 42 }, "_id": "1ffjazmm5IkZwKInsSIULY" }, @@ -988,28 +1110,28 @@ }, "_children": [ { - "__id__": 41 + "__id__": 45 }, { - "__id__": 67 + "__id__": 71 }, { - "__id__": 81 + "__id__": 85 }, { - "__id__": 84 + "__id__": 88 }, { - "__id__": 87 + "__id__": 91 }, { - "__id__": 90 + "__id__": 94 } ], "_active": true, "_components": [ { - "__id__": 93 + "__id__": 97 } ], "_prefab": null, @@ -1046,20 +1168,20 @@ "_name": "GameUI", "_objFlags": 0, "_parent": { - "__id__": 40 + "__id__": 44 }, "_children": [ { - "__id__": 42 + "__id__": 46 }, { - "__id__": 57 + "__id__": 61 } ], "_active": true, "_components": [ { - "__id__": 66 + "__id__": 70 } ], "_prefab": null, @@ -1096,23 +1218,23 @@ "_name": "TopUI", "_objFlags": 0, "_parent": { - "__id__": 41 + "__id__": 45 }, "_children": [ { - "__id__": 43 + "__id__": 47 }, { - "__id__": 52 + "__id__": 56 } ], "_active": true, "_components": [ { - "__id__": 55 + "__id__": 59 }, { - "__id__": 56 + "__id__": 60 } ], "_prefab": null, @@ -1149,23 +1271,23 @@ "_name": "XpBar", "_objFlags": 0, "_parent": { - "__id__": 42 + "__id__": 46 }, "_children": [ { - "__id__": 44 + "__id__": 48 }, { - "__id__": 47 + "__id__": 51 } ], "_active": true, "_components": [ { - "__id__": 50 + "__id__": 54 }, { - "__id__": 51 + "__id__": 55 } ], "_prefab": null, @@ -1202,16 +1324,16 @@ "_name": "Background", "_objFlags": 0, "_parent": { - "__id__": 43 + "__id__": 47 }, "_children": [], "_active": true, "_components": [ { - "__id__": 45 + "__id__": 49 }, { - "__id__": 46 + "__id__": 50 } ], "_prefab": null, @@ -1248,7 +1370,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 44 + "__id__": 48 }, "_enabled": true, "__prefab": null, @@ -1269,7 +1391,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 44 + "__id__": 48 }, "_enabled": true, "__prefab": null, @@ -1307,16 +1429,16 @@ "_name": "MovableBar", "_objFlags": 0, "_parent": { - "__id__": 43 + "__id__": 47 }, "_children": [], "_active": true, "_components": [ { - "__id__": 48 + "__id__": 52 }, { - "__id__": 49 + "__id__": 53 } ], "_prefab": null, @@ -1353,7 +1475,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 47 + "__id__": 51 }, "_enabled": true, "__prefab": null, @@ -1374,7 +1496,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 47 + "__id__": 51 }, "_enabled": true, "__prefab": null, @@ -1412,7 +1534,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 43 + "__id__": 47 }, "_enabled": true, "__prefab": null, @@ -1433,12 +1555,12 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 43 + "__id__": 47 }, "_enabled": true, "__prefab": null, "_barSprite": { - "__id__": 49 + "__id__": 53 }, "_mode": 0, "_totalLength": 600, @@ -1451,16 +1573,16 @@ "_name": "TimeAliveText", "_objFlags": 0, "_parent": { - "__id__": 42 + "__id__": 46 }, "_children": [], "_active": true, "_components": [ { - "__id__": 53 + "__id__": 57 }, { - "__id__": 54 + "__id__": 58 } ], "_prefab": null, @@ -1497,7 +1619,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 52 + "__id__": 56 }, "_enabled": true, "__prefab": null, @@ -1518,7 +1640,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 52 + "__id__": 56 }, "_enabled": true, "__prefab": null, @@ -1559,7 +1681,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 42 + "__id__": 46 }, "_enabled": true, "__prefab": null, @@ -1580,7 +1702,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 42 + "__id__": 46 }, "_enabled": true, "__prefab": null, @@ -1609,17 +1731,17 @@ "_name": "UI", "_objFlags": 0, "_parent": { - "__id__": 41 + "__id__": 45 }, "_children": [ { - "__id__": 58 + "__id__": 62 } ], "_active": true, "_components": [ { - "__id__": 65 + "__id__": 69 } ], "_prefab": null, @@ -1656,23 +1778,23 @@ "_name": "VirtualJoystic", "_objFlags": 0, "_parent": { - "__id__": 57 + "__id__": 61 }, "_children": [ { - "__id__": 59 + "__id__": 63 } ], "_active": true, "_components": [ { - "__id__": 62 + "__id__": 66 }, { - "__id__": 63 + "__id__": 67 }, { - "__id__": 64 + "__id__": 68 } ], "_prefab": null, @@ -1709,16 +1831,16 @@ "_name": "Knob", "_objFlags": 0, "_parent": { - "__id__": 58 + "__id__": 62 }, "_children": [], "_active": true, "_components": [ { - "__id__": 60 + "__id__": 64 }, { - "__id__": 61 + "__id__": 65 } ], "_prefab": null, @@ -1755,7 +1877,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 59 + "__id__": 63 }, "_enabled": true, "__prefab": null, @@ -1776,7 +1898,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 59 + "__id__": 63 }, "_enabled": true, "__prefab": null, @@ -1814,7 +1936,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 58 + "__id__": 62 }, "_enabled": true, "__prefab": null, @@ -1835,7 +1957,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 58 + "__id__": 62 }, "_enabled": true, "__prefab": null, @@ -1873,13 +1995,13 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 58 + "__id__": 62 }, "_enabled": true, "__prefab": null, "maxDistance": 50, "knob": { - "__id__": 59 + "__id__": 63 }, "_id": "50ceZG62tGlYXvZWEvSDKl" }, @@ -1888,7 +2010,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 57 + "__id__": 61 }, "_enabled": true, "__prefab": null, @@ -1909,15 +2031,15 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 41 + "__id__": 45 }, "_enabled": true, "__prefab": null, "xpBar": { - "__id__": 51 + "__id__": 55 }, "timeAliveText": { - "__id__": 54 + "__id__": 58 }, "_id": "bau/7eItRFrKKoAZZb/uYL" }, @@ -1926,20 +2048,20 @@ "_name": "ModalWindowManager", "_objFlags": 0, "_parent": { - "__id__": 40 + "__id__": 44 }, "_children": [ { - "__id__": 68 + "__id__": 72 } ], "_active": true, "_components": [ { - "__id__": 79 + "__id__": 83 }, { - "__id__": 80 + "__id__": 84 } ], "_prefab": null, @@ -1975,17 +2097,17 @@ "__type__": "cc.Node", "_objFlags": 0, "_parent": { - "__id__": 67 + "__id__": 71 }, "_prefab": { - "__id__": 69 + "__id__": 73 }, "__editorExtras__": {} }, { "__type__": "cc.PrefabInfo", "root": { - "__id__": 68 + "__id__": 72 }, "asset": { "__uuid__": "663674aa-da1c-44b0-8049-49db9b020973", @@ -1993,11 +2115,11 @@ }, "fileId": "32U/bJCUBDlaQxxGFNXZTu", "instance": { - "__id__": 70 + "__id__": 74 }, "targetOverrides": [ { - "__id__": 77 + "__id__": 81 } ] }, @@ -2007,20 +2129,20 @@ "mountedChildren": [], "mountedComponents": [], "propertyOverrides": [ - { - "__id__": 71 - }, - { - "__id__": 73 - }, - { - "__id__": 74 - }, { "__id__": 75 }, { - "__id__": 76 + "__id__": 77 + }, + { + "__id__": 78 + }, + { + "__id__": 79 + }, + { + "__id__": 80 } ], "removedComponents": [] @@ -2028,7 +2150,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 72 + "__id__": 76 }, "propertyPath": [ "_name" @@ -2044,7 +2166,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 72 + "__id__": 76 }, "propertyPath": [ "_lpos" @@ -2059,7 +2181,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 72 + "__id__": 76 }, "propertyPath": [ "_lrot" @@ -2075,7 +2197,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 72 + "__id__": 76 }, "propertyPath": [ "_euler" @@ -2090,7 +2212,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 72 + "__id__": 76 }, "propertyPath": [ "_active" @@ -2107,7 +2229,7 @@ ], "target": null, "targetInfo": { - "__id__": 78 + "__id__": 82 } }, { @@ -2121,7 +2243,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 67 + "__id__": 71 }, "_enabled": true, "__prefab": null, @@ -2142,7 +2264,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 67 + "__id__": 71 }, "_enabled": true, "__prefab": null, @@ -2159,16 +2281,16 @@ "_name": "Sprite", "_objFlags": 0, "_parent": { - "__id__": 40 + "__id__": 44 }, "_children": [], "_active": true, "_components": [ { - "__id__": 82 + "__id__": 86 }, { - "__id__": 83 + "__id__": 87 } ], "_prefab": null, @@ -2205,7 +2327,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 81 + "__id__": 85 }, "_enabled": true, "__prefab": null, @@ -2226,7 +2348,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 81 + "__id__": 85 }, "_enabled": true, "__prefab": null, @@ -2264,16 +2386,16 @@ "_name": "Sprite-001", "_objFlags": 0, "_parent": { - "__id__": 40 + "__id__": 44 }, "_children": [], "_active": true, "_components": [ { - "__id__": 85 + "__id__": 89 }, { - "__id__": 86 + "__id__": 90 } ], "_prefab": null, @@ -2310,7 +2432,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 84 + "__id__": 88 }, "_enabled": true, "__prefab": null, @@ -2331,7 +2453,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 84 + "__id__": 88 }, "_enabled": true, "__prefab": null, @@ -2369,16 +2491,16 @@ "_name": "Sprite-002", "_objFlags": 0, "_parent": { - "__id__": 40 + "__id__": 44 }, "_children": [], "_active": true, "_components": [ { - "__id__": 88 + "__id__": 92 }, { - "__id__": 89 + "__id__": 93 } ], "_prefab": null, @@ -2415,7 +2537,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 87 + "__id__": 91 }, "_enabled": true, "__prefab": null, @@ -2436,7 +2558,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 87 + "__id__": 91 }, "_enabled": true, "__prefab": null, @@ -2474,16 +2596,16 @@ "_name": "Sprite-003", "_objFlags": 0, "_parent": { - "__id__": 40 + "__id__": 44 }, "_children": [], "_active": true, "_components": [ { - "__id__": 91 + "__id__": 95 }, { - "__id__": 92 + "__id__": 96 } ], "_prefab": null, @@ -2520,7 +2642,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 90 + "__id__": 94 }, "_enabled": true, "__prefab": null, @@ -2541,7 +2663,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 90 + "__id__": 94 }, "_enabled": true, "__prefab": null, @@ -2579,7 +2701,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 40 + "__id__": 44 }, "_enabled": true, "__prefab": null, @@ -2648,7 +2770,7 @@ "_enabled": true, "__prefab": null, "_cameraComponent": { - "__id__": 93 + "__id__": 97 }, "_alignCanvasWithScreen": true, "_id": "12O/ljcVlEqLmVm3U2gEOQ" @@ -2692,7 +2814,7 @@ "_enabled": true, "__prefab": null, "virtualJoystic": { - "__id__": 64 + "__id__": 68 }, "player": null, "haloProjectileLauncherComponent": { @@ -2705,19 +2827,22 @@ "__id__": 23 }, "enemyManager": { + "__id__": 43 + }, + "itemManager": { "__id__": 39 }, "camera": { - "__id__": 93 + "__id__": 97 }, "gameUI": { - "__id__": 66 + "__id__": 70 }, "background": { "__id__": 17 }, "modalWindowManager": { - "__id__": 80 + "__id__": 84 }, "gameAudioAdapter": { "__id__": 14 @@ -2729,7 +2854,7 @@ "fileId": "cffa5b19-2043-4cef-8221-1a10ab7a2c1f", "targetOverrides": [ { - "__id__": 99 + "__id__": 103 } ], "nestedPrefabInstanceRoots": [ @@ -2740,14 +2865,14 @@ "__id__": 24 }, { - "__id__": 68 + "__id__": 72 } ] }, { "__type__": "cc.TargetOverrideInfo", "source": { - "__id__": 97 + "__id__": 101 }, "sourceInfo": null, "propertyPath": [ @@ -2757,7 +2882,7 @@ "__id__": 24 }, "targetInfo": { - "__id__": 100 + "__id__": 104 } }, { @@ -2769,19 +2894,19 @@ { "__type__": "cc.SceneGlobals", "ambient": { - "__id__": 102 + "__id__": 106 }, "shadows": { - "__id__": 103 + "__id__": 107 }, "_skybox": { - "__id__": 104 + "__id__": 108 }, "fog": { - "__id__": 105 + "__id__": 109 }, "octree": { - "__id__": 106 + "__id__": 110 } }, { diff --git a/assets/Scripts/Game/Collision/PlayerCollisionSystem.ts b/assets/Scripts/Game/Collision/PlayerCollisionSystem.ts index 61d27cf..6ccef01 100644 --- a/assets/Scripts/Game/Collision/PlayerCollisionSystem.ts +++ b/assets/Scripts/Game/Collision/PlayerCollisionSystem.ts @@ -1,11 +1,13 @@ -import { Collider2D, Contact2DType } from "cc"; -import { GroupType } from "../GroupType"; -import { Player } from "../Unit/Player/Player"; +import { Collider2D, Contact2DType, Node } from "cc"; +import { ISignal } from "../../Services/EventSystem/ISignal"; +import { Signal } from "../../Services/EventSystem/Signal"; import { GameTimer } from "../../Services/GameTimer"; -import { XP } from "../XP/XP"; +import { GroupType } from "../GroupType"; +import { Gold } from "../Items/Gold/Gold"; +import { ItemManager } from "../Items/ItemManager"; +import { XP } from "../Items/XP/XP"; import { Enemy } from "../Unit/Enemy/Enemy"; -import { Gold } from "../Gold/Gold"; -import { GameResult } from "../Game"; +import { Player } from "../Unit/Player/Player"; export class PlayerCollisionSystem { private playerContacts: Collider2D[] = []; @@ -13,7 +15,9 @@ export class PlayerCollisionSystem { private groupToResolver: Map void> = new Map void>(); - public constructor(private player: Player, collisionDelay: number, private gameResult: GameResult) { + private itemPickedUpEvent = new Signal(); + + public constructor(private player: Player, collisionDelay: number, private itemManager: ItemManager) { this.player = player; player.Collider.on(Contact2DType.BEGIN_CONTACT, this.onPlayerContactBegin, this); @@ -33,6 +37,10 @@ export class PlayerCollisionSystem { } } + public get ItemPickedUpEvent(): ISignal { + return this.itemPickedUpEvent; + } + private onPlayerContactBegin(_selfCollider: Collider2D, otherCollider: Collider2D): void { this.playerContacts.push(otherCollider); this.resolveContact(otherCollider); @@ -66,18 +74,11 @@ export class PlayerCollisionSystem { } private resolveXpContact(xpCollider: Collider2D): void { - const xp: XP = xpCollider.node.getComponent(XP); - this.player.Level.addXp(xp.Value); - xp.pickup(); - - console.log("Collided with xp: " + xp); + console.log("Collided with XP"); + this.itemManager.pickupXP(xpCollider.node.getComponent(XP)); } private resolveGoldContact(goldCollider: Collider2D): void { - const gold: Gold = goldCollider.node.getComponent(Gold); - gold.pickup(); - this.gameResult.goldCoins++; - - console.log("Collided with gold " + gold); + this.itemManager.pickupGold(goldCollider.node.getComponent(Gold)); } } diff --git a/assets/Scripts/Game/Game.ts b/assets/Scripts/Game/Game.ts index 85857e0..ce1ec99 100644 --- a/assets/Scripts/Game/Game.ts +++ b/assets/Scripts/Game/Game.ts @@ -1,5 +1,4 @@ -import { Camera, Component, JsonAsset, KeyCode, Vec2, _decorator } from "cc"; -import { runInThisContext } from "vm"; +import { Camera, Component, KeyCode, Vec2, _decorator } from "cc"; import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager"; import { delay } from "../Services/Utils/AsyncUtils"; import { GameAudioAdapter } from "./Audio/GameAudioAdapter"; @@ -13,6 +12,7 @@ import { UserData } from "./Data/UserData"; import { KeyboardInput } from "./Input/KeyboardInput"; import { MultiInput } from "./Input/MultiInput"; import { VirtualJoystic } from "./Input/VirtualJoystic"; +import { ItemManager } from "./Items/ItemManager"; import { GameModalLauncher } from "./ModalWIndows/GameModalLauncher"; import { Pauser } from "./Pauser"; import { TestValues } from "./TestGameRunner"; @@ -36,6 +36,7 @@ export class Game extends Component { @property(ProjectileLauncher) private horizontalProjectileLauncherComponent: ProjectileLauncher; @property(ProjectileLauncher) private diagonalProjectileLauncherComponent: ProjectileLauncher; @property(EnemyManager) private enemyManager: EnemyManager; + @property(ItemManager) private itemManager: ItemManager; @property(Camera) private camera: Camera; @property(GameUI) private gameUI: GameUI; @property(Background) private background: Background; @@ -77,11 +78,11 @@ export class Game extends Component { const multiInput: MultiInput = new MultiInput([this.virtualJoystic, wasd, arrowKeys]); this.player.init(multiInput, this.createPlayerData(settings.player, metaUpgrades)); - - this.playerCollisionSystem = new PlayerCollisionSystem(this.player, settings.player.collisionDelay, gameResult); - new WeaponCollisionSystem(this.player.Weapon); - this.enemyManager.init(this.player.node, settings.enemyManager); + this.itemManager.init(this.enemyManager, this.player, gameResult); + + this.playerCollisionSystem = new PlayerCollisionSystem(this.player, settings.player.collisionDelay, this.itemManager); + new WeaponCollisionSystem(this.player.Weapon); const projectileData = new ProjectileData(); projectileData.damage = 1 + metaUpgrades.getUpgradeValue(MetaUpgradeType.OverallDamage); diff --git a/assets/Scripts/Game/Gold.meta b/assets/Scripts/Game/Items/Gold.meta similarity index 100% rename from assets/Scripts/Game/Gold.meta rename to assets/Scripts/Game/Items/Gold.meta diff --git a/assets/Scripts/Game/Gold/Gold.ts b/assets/Scripts/Game/Items/Gold/Gold.ts similarity index 80% rename from assets/Scripts/Game/Gold/Gold.ts rename to assets/Scripts/Game/Items/Gold/Gold.ts index d851e01..e7a88f1 100644 --- a/assets/Scripts/Game/Gold/Gold.ts +++ b/assets/Scripts/Game/Items/Gold/Gold.ts @@ -1,6 +1,7 @@ import { Component, Vec3, _decorator } from "cc"; -import { ISignal } from "../../Services/EventSystem/ISignal"; -import { Signal } from "../../Services/EventSystem/Signal"; +import { ISignal } from "../../../Services/EventSystem/ISignal"; +import { Signal } from "../../../Services/EventSystem/Signal"; + const { ccclass, property } = _decorator; @ccclass("Gold") diff --git a/assets/Scripts/Game/Gold/Gold.ts.meta b/assets/Scripts/Game/Items/Gold/Gold.ts.meta similarity index 100% rename from assets/Scripts/Game/Gold/Gold.ts.meta rename to assets/Scripts/Game/Items/Gold/Gold.ts.meta diff --git a/assets/Scripts/Game/Gold/GoldSpawner.ts b/assets/Scripts/Game/Items/Gold/GoldSpawner.ts similarity index 92% rename from assets/Scripts/Game/Gold/GoldSpawner.ts rename to assets/Scripts/Game/Items/Gold/GoldSpawner.ts index c19348c..4032362 100644 --- a/assets/Scripts/Game/Gold/GoldSpawner.ts +++ b/assets/Scripts/Game/Items/Gold/GoldSpawner.ts @@ -1,5 +1,5 @@ import { Component, Prefab, Vec3, _decorator } from "cc"; -import { ObjectPool } from "../../Services/ObjectPool"; +import { ObjectPool } from "../../../Services/ObjectPool"; import { Gold } from "./Gold"; const { ccclass, property } = _decorator; diff --git a/assets/Scripts/Game/Gold/GoldSpawner.ts.meta b/assets/Scripts/Game/Items/Gold/GoldSpawner.ts.meta similarity index 100% rename from assets/Scripts/Game/Gold/GoldSpawner.ts.meta rename to assets/Scripts/Game/Items/Gold/GoldSpawner.ts.meta diff --git a/assets/Scripts/Game/Items/ItemManager.ts b/assets/Scripts/Game/Items/ItemManager.ts new file mode 100644 index 0000000..3d77858 --- /dev/null +++ b/assets/Scripts/Game/Items/ItemManager.ts @@ -0,0 +1,88 @@ +import { Component, random, randomRange, Vec3, _decorator } from "cc"; +import { GameResult } from "../Game"; +import { Enemy } from "../Unit/Enemy/Enemy"; +import { EnemyManager } from "../Unit/Enemy/EnemyManager"; +import { Player } from "../Unit/Player/Player"; +import { Gold } from "./Gold/Gold"; +import { GoldSpawner } from "./Gold/GoldSpawner"; +import { PickupEffectManager } from "./PickupEffect/PickupEffectManager"; +import { XP } from "./XP/XP"; +import { XPSpawner } from "./XP/XPSpawner"; +const { ccclass, property } = _decorator; + +@ccclass("ItemManager") +export class ItemManager extends Component { + @property(XPSpawner) private xpSpawner: XPSpawner; + @property(GoldSpawner) private goldSpawner: GoldSpawner; + @property(PickupEffectManager) private pickupEffectManager: PickupEffectManager; + + private player: Player; + private gameResult: GameResult; + + public init(enemyManager: EnemyManager, player: Player, gameResult: GameResult): void { + this.player = player; + this.gameResult = gameResult; + + enemyManager.EnemyAddedEvent.on(this.addEnemyListeners, this); + enemyManager.EnemyRemovedEvent.on(this.removeEnemyListeners, this); + + this.xpSpawner.init(); + this.goldSpawner.init(); + this.pickupEffectManager.init(); + } + + public pickupXP(xp: XP): void { + this.pickupEffectManager.showEffect(xp.node.worldPosition); + + this.player.Level.addXp(xp.Value); + xp.pickup(); + } + + public pickupGold(gold: Gold): void { + this.pickupEffectManager.showEffect(gold.node.worldPosition); + + gold.pickup(); + this.gameResult.goldCoins++; + } + + private addEnemyListeners(enemy: Enemy): void { + enemy.DeathEvent.on(this.trySpawnItems, this); + } + + private removeEnemyListeners(enemy: Enemy): void { + enemy.DeathEvent.off(this.trySpawnItems); + } + + private trySpawnItems(enemy: Enemy): void { + this.trySpawnXP(enemy); + this.trySpawnGold(enemy); + } + + private trySpawnXP(enemy: Enemy): void { + for (let index = 0; index < enemy.XPReward; index++) { + this.xpSpawner.spawnXp(this.getRandomPosition(enemy), 1); + } + } + + private trySpawnGold(enemy: Enemy): void { + if (enemy.GoldReward <= 0) return; + + if (enemy.GoldReward < 1) { + if (random() < enemy.GoldReward) { + this.goldSpawner.spawn(enemy.node.worldPosition); + } + } else { + for (let i = 0; i < enemy.GoldReward; i++) { + this.goldSpawner.spawn(this.getRandomPosition(enemy)); + } + } + } + + private getRandomPosition(enemy: Enemy): Vec3 { + const position: Vec3 = enemy.node.worldPosition; + position.x += randomRange(-10, 10); + position.y += randomRange(-10, 10); + + return position; + } +} diff --git a/assets/Scripts/Game/Items/ItemManager.ts.meta b/assets/Scripts/Game/Items/ItemManager.ts.meta new file mode 100644 index 0000000..2ca7fc1 --- /dev/null +++ b/assets/Scripts/Game/Items/ItemManager.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "7f3f8f02-b61e-4a07-8d52-1c326f889fca", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/Game/Items/PickupEffect.meta b/assets/Scripts/Game/Items/PickupEffect.meta new file mode 100644 index 0000000..3b000dd --- /dev/null +++ b/assets/Scripts/Game/Items/PickupEffect.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "264a4734-6753-4278-b3b7-b6b100e059a4", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/assets/Scripts/Game/Items/PickupEffect/PickupEffect.ts b/assets/Scripts/Game/Items/PickupEffect/PickupEffect.ts new file mode 100644 index 0000000..3f80c06 --- /dev/null +++ b/assets/Scripts/Game/Items/PickupEffect/PickupEffect.ts @@ -0,0 +1,10 @@ +import { Animation, Component, _decorator } from "cc"; +const { ccclass, property } = _decorator; + +@ccclass("PickupEffect") +export class PickupEffect extends Component { + @property(Animation) private animation: Animation; + public init(): void { + this.animation.play("PickBonus"); + } +} diff --git a/assets/Scripts/Game/Items/PickupEffect/PickupEffect.ts.meta b/assets/Scripts/Game/Items/PickupEffect/PickupEffect.ts.meta new file mode 100644 index 0000000..548c302 --- /dev/null +++ b/assets/Scripts/Game/Items/PickupEffect/PickupEffect.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "0f2b2cd0-1d1e-4862-821f-5fcb83c4ec23", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/Game/Items/PickupEffect/PickupEffectManager.ts b/assets/Scripts/Game/Items/PickupEffect/PickupEffectManager.ts new file mode 100644 index 0000000..96e61b1 --- /dev/null +++ b/assets/Scripts/Game/Items/PickupEffect/PickupEffectManager.ts @@ -0,0 +1,26 @@ +import { _decorator, Component, Node, Prefab, Vec3 } from "cc"; +import { ObjectPool } from "../../../Services/ObjectPool"; +import { delay } from "../../../Services/Utils/AsyncUtils"; +import { PickupEffect } from "./PickupEffect"; +const { ccclass, property } = _decorator; + +@ccclass("PickupEffectManager") +export class PickupEffectManager extends Component { + @property(Prefab) private pickupEffect: Prefab; + + private effectPool: ObjectPool; + + public init(): void { + this.effectPool = new ObjectPool(this.pickupEffect, this.node, 5, "PickupEffect"); + } + + public async showEffect(position: Vec3): Promise { + const effect = this.effectPool.borrow(); + effect.node.setWorldPosition(position); + effect.node.active = true; + + await delay(450); + + this.effectPool.return(effect); + } +} diff --git a/assets/Scripts/Game/Items/PickupEffect/PickupEffectManager.ts.meta b/assets/Scripts/Game/Items/PickupEffect/PickupEffectManager.ts.meta new file mode 100644 index 0000000..f942e6c --- /dev/null +++ b/assets/Scripts/Game/Items/PickupEffect/PickupEffectManager.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "65b4121f-a4cf-47e1-97d4-1e0d3fc72eec", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/Game/XP.meta b/assets/Scripts/Game/Items/XP.meta similarity index 100% rename from assets/Scripts/Game/XP.meta rename to assets/Scripts/Game/Items/XP.meta diff --git a/assets/Scripts/Game/XP/XP.ts b/assets/Scripts/Game/Items/XP/XP.ts similarity index 85% rename from assets/Scripts/Game/XP/XP.ts rename to assets/Scripts/Game/Items/XP/XP.ts index 91e5d7b..8dce070 100644 --- a/assets/Scripts/Game/XP/XP.ts +++ b/assets/Scripts/Game/Items/XP/XP.ts @@ -1,6 +1,7 @@ import { Animation, Component, Vec3, _decorator } from "cc"; -import { ISignal } from "../../Services/EventSystem/ISignal"; -import { Signal } from "../../Services/EventSystem/Signal"; +import { ISignal } from "../../../Services/EventSystem/ISignal"; +import { Signal } from "../../../Services/EventSystem/Signal"; + const { ccclass, property } = _decorator; @ccclass("XP") diff --git a/assets/Scripts/Game/XP/XP.ts.meta b/assets/Scripts/Game/Items/XP/XP.ts.meta similarity index 100% rename from assets/Scripts/Game/XP/XP.ts.meta rename to assets/Scripts/Game/Items/XP/XP.ts.meta diff --git a/assets/Scripts/Game/XP/XPSpawner.ts b/assets/Scripts/Game/Items/XP/XPSpawner.ts similarity index 92% rename from assets/Scripts/Game/XP/XPSpawner.ts rename to assets/Scripts/Game/Items/XP/XPSpawner.ts index 37e3223..cc0f426 100644 --- a/assets/Scripts/Game/XP/XPSpawner.ts +++ b/assets/Scripts/Game/Items/XP/XPSpawner.ts @@ -1,5 +1,6 @@ import { Component, Prefab, Vec3, _decorator } from "cc"; -import { ObjectPool } from "../../Services/ObjectPool"; +import { ObjectPool } from "../../../Services/ObjectPool"; + import { XP } from "./XP"; const { ccclass, property } = _decorator; diff --git a/assets/Scripts/Game/XP/XPSpawner.ts.meta b/assets/Scripts/Game/Items/XP/XPSpawner.ts.meta similarity index 100% rename from assets/Scripts/Game/XP/XPSpawner.ts.meta rename to assets/Scripts/Game/Items/XP/XPSpawner.ts.meta diff --git a/assets/Scripts/Game/Pickups.meta b/assets/Scripts/Game/Pickups.meta new file mode 100644 index 0000000..ef20c68 --- /dev/null +++ b/assets/Scripts/Game/Pickups.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "363c5a59-0b4d-48d4-8b20-7163f1a82ad6", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts b/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts index 8079bd4..42417b6 100644 --- a/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts @@ -1,8 +1,6 @@ -import { Component, Node, random, randomRange, Vec3, _decorator } from "cc"; +import { Component, Node, _decorator } from "cc"; import { ISignal } from "../../../Services/EventSystem/ISignal"; import { EnemyManagerSettings } from "../../Data/GameSettings"; -import { GoldSpawner } from "../../Gold/GoldSpawner"; -import { XPSpawner } from "../../XP/XPSpawner"; import { Enemy } from "./Enemy"; import { EnemyMovementType } from "./EnemyMovementType"; import { EnemyMover } from "./EnemyMover/EnemyMover"; @@ -20,8 +18,6 @@ const { ccclass, property } = _decorator; @ccclass("EnemyManager") export class EnemyManager extends Component { @property(EnemySpawner) private enemySpawner: EnemySpawner; - @property(XPSpawner) private xpSpawner: XPSpawner; - @property(GoldSpawner) private goldSpawner: GoldSpawner; private movementTypeToMover: Map = new Map(); @@ -50,9 +46,6 @@ export class EnemyManager extends Component { this.movementTypeToMover.set(EnemyMovementType.Follow, new FollowTargetEnemyMover(targetNode)); this.movementTypeToMover.set(EnemyMovementType.Launch, new WaveEnemyMover(targetNode)); this.movementTypeToMover.set(EnemyMovementType.PeriodicFollow, new PeriodicFollowTargetEnemyMover(targetNode, 5, 5)); - - this.xpSpawner.init(); - this.goldSpawner.init(); } public gameTick(deltaTime: number): void { @@ -74,39 +67,13 @@ export class EnemyManager extends Component { } private onEnemyAdded(enemy: Enemy): void { - enemy.DeathEvent.on(this.onEnemyDied, this); this.getEnemyMover(enemy).addEnemy(enemy); } private onEnemyRemoved(enemy: Enemy): void { - enemy.DeathEvent.off(this.onEnemyDied); this.getEnemyMover(enemy).removeEnemy(enemy); } - private onEnemyDied(enemy: Enemy): void { - for (let index = 0; index < enemy.XPReward; index++) { - const position: Vec3 = enemy.node.worldPosition; - position.x += randomRange(-10, 10); - position.y += randomRange(-10, 10); - this.xpSpawner.spawnXp(position, 1); - } - - if (0 < enemy.GoldReward) { - if (enemy.GoldReward < 1) { - if (random() < enemy.GoldReward) { - this.goldSpawner.spawn(enemy.node.worldPosition); - } - } else { - for (let i = 0; i < enemy.GoldReward; i++) { - const position: Vec3 = enemy.node.worldPosition; - position.x += randomRange(-10, 10); - position.y += randomRange(-10, 10); - this.goldSpawner.spawn(position); - } - } - } - } - private getEnemyMover(enemy: Enemy): EnemyMover { if (this.movementTypeToMover.has(enemy.MovementType)) { return this.movementTypeToMover.get(enemy.MovementType); diff --git a/assets/Scripts/Game/Unit/Player/Player.ts b/assets/Scripts/Game/Unit/Player/Player.ts index e858f4d..df2b03f 100644 --- a/assets/Scripts/Game/Unit/Player/Player.ts +++ b/assets/Scripts/Game/Unit/Player/Player.ts @@ -1,4 +1,5 @@ -import { Animation, Node, BoxCollider2D, Collider2D, Component, Vec2, Vec3, _decorator, Details } from "cc"; +import { Animation, Node, BoxCollider2D, Collider2D, Component, Vec2, Vec3, _decorator, Details, Sprite, Color } from "cc"; +import { delay } from "../../../Services/Utils/AsyncUtils"; import { IInput } from "../../Input/IInput"; import { UnitHealth } from "../UnitHealth"; import { UnitLevel } from "../UnitLevel"; @@ -15,6 +16,7 @@ export class Player extends Component { @property(Weapon) private weapon: Weapon; @property(Node) private playerGraphics: Node; @property(Animation) private animation: Animation; + @property(Sprite) private sprite: Sprite; private input: IInput; private health: UnitHealth; @@ -32,7 +34,7 @@ export class Player extends Component { this.speed = data.speed; this.weapon.init(data.strikeDelay, data.damage); - + this.health.HealthPointsChangeEvent.on(this.animateHurt, this); this.playerUI.init(this.health); } @@ -91,6 +93,12 @@ export class Player extends Component { } } } + + private async animateHurt(): Promise { + this.sprite.color = Color.RED; + await delay(100); + this.sprite.color = Color.WHITE; + } } export class PlayerData { From e17fe5527a8380619941e92166d33388ffbae74a Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 20 Dec 2022 11:28:42 +0100 Subject: [PATCH 2/2] Meta --- assets/Scripts/Game/Items.meta | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 assets/Scripts/Game/Items.meta diff --git a/assets/Scripts/Game/Items.meta b/assets/Scripts/Game/Items.meta new file mode 100644 index 0000000..ef20c68 --- /dev/null +++ b/assets/Scripts/Game/Items.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "363c5a59-0b4d-48d4-8b20-7163f1a82ad6", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +}