From 136a8989426483965f1b58bbec29073bc98c3451 Mon Sep 17 00:00:00 2001 From: tiendat3699 <96950844+tiendat3699@users.noreply.github.com> Date: Thu, 7 Mar 2024 01:08:30 +0700 Subject: [PATCH] feat: update game event manager --- assets/_Game/Prefabs/Ball.prefab | 8 +- assets/_Game/Scenes/EndLessScene.scene | 551 ++++++++---------- assets/_Game/Scripts/Enum/GameEvent.ts | 5 +- assets/_Game/Scripts/Enum/GameState.ts | 7 + assets/_Game/Scripts/Enum/GameState.ts.meta | 9 + assets/_Game/Scripts/Gameplay/Ball.ts | 53 +- assets/_Game/Scripts/Gameplay/Outer.ts | 17 + assets/_Game/Scripts/Gameplay/Outer.ts.meta | 9 + assets/_Game/Scripts/Interface.meta | 12 + .../_Game/Scripts/Interface/GameEventMap.ts | 12 + .../Scripts/Interface/GameEventMap.ts.meta | 9 + assets/_Game/Scripts/Manager/EventManger.ts | 27 +- assets/_Game/Scripts/Manager/GameManager.ts | 45 +- assets/_Game/Scripts/Manager/SoundManager.ts | 4 +- assets/_Game/Scripts/Pool/ObjectPool.ts | 1 - 15 files changed, 428 insertions(+), 341 deletions(-) create mode 100644 assets/_Game/Scripts/Enum/GameState.ts create mode 100644 assets/_Game/Scripts/Enum/GameState.ts.meta create mode 100644 assets/_Game/Scripts/Gameplay/Outer.ts create mode 100644 assets/_Game/Scripts/Gameplay/Outer.ts.meta create mode 100644 assets/_Game/Scripts/Interface.meta create mode 100644 assets/_Game/Scripts/Interface/GameEventMap.ts create mode 100644 assets/_Game/Scripts/Interface/GameEventMap.ts.meta diff --git a/assets/_Game/Prefabs/Ball.prefab b/assets/_Game/Prefabs/Ball.prefab index 7b75c2f..1ff495b 100644 --- a/assets/_Game/Prefabs/Ball.prefab +++ b/assets/_Game/Prefabs/Ball.prefab @@ -962,12 +962,16 @@ "__prefab": { "__id__": 70 }, - "rigidbody": { + "_rigidbody": { "__id__": 67 }, - "collider": { + "_collider": { "__id__": 65 }, + "_hitSound": { + "__uuid__": "6a432293-3852-4267-be19-c671f36fe9f0", + "__expectedType__": "cc.AudioClip" + }, "_id": "" }, { diff --git a/assets/_Game/Scenes/EndLessScene.scene b/assets/_Game/Scenes/EndLessScene.scene index 5bee36e..f9110a4 100644 --- a/assets/_Game/Scenes/EndLessScene.scene +++ b/assets/_Game/Scenes/EndLessScene.scene @@ -22,7 +22,7 @@ "_active": true, "_components": [], "_prefab": { - "__id__": 204 + "__id__": 202 }, "_lpos": { "__type__": "cc.Vec3", @@ -53,7 +53,7 @@ }, "autoReleaseAssets": false, "_globals": { - "__id__": 208 + "__id__": 206 }, "_id": "82e6ef2e-3f9c-4d4e-ab02-dc963e925b88" }, @@ -71,18 +71,21 @@ }, { "__id__": 5 + }, + { + "__id__": 138 } ], "_active": true, "_components": [ + { + "__id__": 199 + }, + { + "__id__": 200 + }, { "__id__": 201 - }, - { - "__id__": 202 - }, - { - "__id__": 203 } ], "_prefab": null, @@ -217,43 +220,40 @@ "__id__": 6 }, { - "__id__": 88 + "__id__": 86 }, { - "__id__": 92 + "__id__": 90 }, { - "__id__": 98 + "__id__": 96 }, { - "__id__": 107 + "__id__": 105 }, { - "__id__": 116 + "__id__": 114 }, { - "__id__": 121 + "__id__": 119 }, { - "__id__": 126 + "__id__": 124 }, { - "__id__": 130 + "__id__": 128 }, { - "__id__": 134 - }, - { - "__id__": 138 + "__id__": 132 } ], "_active": true, "_components": [ { - "__id__": 199 + "__id__": 136 }, { - "__id__": 200 + "__id__": 137 } ], "_prefab": null, @@ -319,10 +319,10 @@ "__id__": 61 }, { - "__id__": 66 + "__id__": 64 }, { - "__id__": 77 + "__id__": 75 } ], "_active": true, @@ -2553,12 +2553,6 @@ }, { "__id__": 63 - }, - { - "__id__": 64 - }, - { - "__id__": 65 } ], "_prefab": null, @@ -2650,60 +2644,6 @@ "_atlas": null, "_id": "2fzI5ushJK5rLwMZHfgR2t" }, - { - "__type__": "cc.BoxCollider2D", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 61 - }, - "_enabled": true, - "__prefab": null, - "tag": 0, - "_group": 1, - "_density": 1, - "_sensor": false, - "_friction": 2, - "_restitution": 0.5, - "_offset": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 - }, - "_size": { - "__type__": "cc.Size", - "width": 1500, - "height": 20 - }, - "_id": "f5+DT0evdJw43QRpVBZDqm" - }, - { - "__type__": "cc.RigidBody2D", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 61 - }, - "_enabled": true, - "__prefab": null, - "enabledContactListener": false, - "bullet": false, - "awakeOnLoad": true, - "_group": 1, - "_type": 0, - "_allowSleep": true, - "_gravityScale": 0, - "_linearDamping": 0, - "_angularDamping": 0, - "_linearVelocity": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 - }, - "_angularVelocity": 0, - "_fixedRotation": false, - "_id": "71vvI7PwxCooqIdxT2lVwz" - }, { "__type__": "cc.Node", "_name": "wall-008", @@ -2713,25 +2653,25 @@ }, "_children": [ { - "__id__": 67 + "__id__": 65 }, { - "__id__": 70 + "__id__": 68 } ], "_active": true, "_components": [ + { + "__id__": 71 + }, + { + "__id__": 72 + }, { "__id__": 73 }, { "__id__": 74 - }, - { - "__id__": 75 - }, - { - "__id__": 76 } ], "_prefab": null, @@ -2769,16 +2709,16 @@ "_name": "wall-009", "_objFlags": 0, "_parent": { - "__id__": 66 + "__id__": 64 }, "_children": [], "_active": true, "_components": [ { - "__id__": 68 + "__id__": 66 }, { - "__id__": 69 + "__id__": 67 } ], "_prefab": null, @@ -2816,7 +2756,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 67 + "__id__": 65 }, "_enabled": true, "__prefab": null, @@ -2837,7 +2777,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 67 + "__id__": 65 }, "_enabled": true, "__prefab": null, @@ -2875,16 +2815,16 @@ "_name": "wall-010", "_objFlags": 0, "_parent": { - "__id__": 66 + "__id__": 64 }, "_children": [], "_active": true, "_components": [ { - "__id__": 71 + "__id__": 69 }, { - "__id__": 72 + "__id__": 70 } ], "_prefab": null, @@ -2922,7 +2862,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 70 + "__id__": 68 }, "_enabled": true, "__prefab": null, @@ -2943,7 +2883,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 70 + "__id__": 68 }, "_enabled": true, "__prefab": null, @@ -2981,7 +2921,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 66 + "__id__": 64 }, "_enabled": true, "__prefab": null, @@ -3002,7 +2942,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 66 + "__id__": 64 }, "_enabled": true, "__prefab": null, @@ -3040,7 +2980,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 66 + "__id__": 64 }, "_enabled": true, "__prefab": null, @@ -3114,7 +3054,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 66 + "__id__": 64 }, "_enabled": true, "__prefab": null, @@ -3145,25 +3085,25 @@ }, "_children": [ { - "__id__": 78 + "__id__": 76 }, { - "__id__": 81 + "__id__": 79 } ], "_active": true, "_components": [ + { + "__id__": 82 + }, + { + "__id__": 83 + }, { "__id__": 84 }, { "__id__": 85 - }, - { - "__id__": 86 - }, - { - "__id__": 87 } ], "_prefab": null, @@ -3201,16 +3141,16 @@ "_name": "wall-009", "_objFlags": 0, "_parent": { - "__id__": 77 + "__id__": 75 }, "_children": [], "_active": true, "_components": [ { - "__id__": 79 + "__id__": 77 }, { - "__id__": 80 + "__id__": 78 } ], "_prefab": null, @@ -3248,7 +3188,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 78 + "__id__": 76 }, "_enabled": true, "__prefab": null, @@ -3269,7 +3209,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 78 + "__id__": 76 }, "_enabled": true, "__prefab": null, @@ -3307,16 +3247,16 @@ "_name": "wall-010", "_objFlags": 0, "_parent": { - "__id__": 77 + "__id__": 75 }, "_children": [], "_active": true, "_components": [ { - "__id__": 82 + "__id__": 80 }, { - "__id__": 83 + "__id__": 81 } ], "_prefab": null, @@ -3354,7 +3294,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 81 + "__id__": 79 }, "_enabled": true, "__prefab": null, @@ -3375,7 +3315,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 81 + "__id__": 79 }, "_enabled": true, "__prefab": null, @@ -3413,7 +3353,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 77 + "__id__": 75 }, "_enabled": true, "__prefab": null, @@ -3434,7 +3374,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 77 + "__id__": 75 }, "_enabled": true, "__prefab": null, @@ -3472,7 +3412,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 77 + "__id__": 75 }, "_enabled": true, "__prefab": null, @@ -3556,7 +3496,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 77 + "__id__": 75 }, "_enabled": true, "__prefab": null, @@ -3589,14 +3529,14 @@ "_children": [], "_active": true, "_components": [ + { + "__id__": 87 + }, + { + "__id__": 88 + }, { "__id__": 89 - }, - { - "__id__": 90 - }, - { - "__id__": 91 } ], "_prefab": null, @@ -3635,7 +3575,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 88 + "__id__": 86 }, "_enabled": true, "__prefab": null, @@ -3657,7 +3597,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 88 + "__id__": 86 }, "_enabled": true, "__prefab": null, @@ -3695,7 +3635,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 88 + "__id__": 86 }, "_enabled": true, "__prefab": null, @@ -3744,13 +3684,13 @@ }, "_children": [ { - "__id__": 93 + "__id__": 91 } ], "_active": true, "_components": [ { - "__id__": 97 + "__id__": 95 } ], "_prefab": null, @@ -3788,19 +3728,19 @@ "_name": "goal", "_objFlags": 0, "_parent": { - "__id__": 92 + "__id__": 90 }, "_children": [], "_active": true, "_components": [ + { + "__id__": 92 + }, + { + "__id__": 93 + }, { "__id__": 94 - }, - { - "__id__": 95 - }, - { - "__id__": 96 } ], "_prefab": null, @@ -3838,7 +3778,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 93 + "__id__": 91 }, "_enabled": true, "__prefab": null, @@ -3859,7 +3799,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 93 + "__id__": 91 }, "_enabled": true, "__prefab": null, @@ -3897,7 +3837,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 93 + "__id__": 91 }, "_enabled": true, "__prefab": null, @@ -3986,7 +3926,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 92 + "__id__": 90 }, "_enabled": true, "__prefab": null, @@ -4013,16 +3953,16 @@ }, "_children": [ { - "__id__": 99 + "__id__": 97 } ], "_active": true, "_components": [ { - "__id__": 102 + "__id__": 100 }, { - "__id__": 106 + "__id__": 104 } ], "_prefab": null, @@ -4061,25 +4001,25 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 98 + "__id__": 96 }, "_children": [], "_active": true, "_components": [ { - "__id__": 100 + "__id__": 98 + }, + { + "__id__": 99 }, { "__id__": 101 }, + { + "__id__": 102 + }, { "__id__": 103 - }, - { - "__id__": 104 - }, - { - "__id__": 105 } ], "_prefab": null, @@ -4118,7 +4058,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 99 + "__id__": 97 }, "_enabled": true, "__prefab": null, @@ -4146,7 +4086,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 99 + "__id__": 97 }, "_enabled": true, "__prefab": null, @@ -4162,7 +4102,7 @@ }, "collideConnected": false, "connectedBody": { - "__id__": 102 + "__id__": 100 }, "_enableLimit": true, "_lowerAngle": -25, @@ -4178,7 +4118,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 98 + "__id__": 96 }, "_enabled": true, "__prefab": null, @@ -4206,7 +4146,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 99 + "__id__": 97 }, "_enabled": true, "__prefab": null, @@ -4280,7 +4220,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 99 + "__id__": 97 }, "_enabled": true, "__prefab": null, @@ -4301,7 +4241,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 99 + "__id__": 97 }, "_enabled": true, "__prefab": null, @@ -4339,12 +4279,12 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 98 + "__id__": 96 }, "_enabled": true, "__prefab": null, "_hingeJoint": { - "__id__": 101 + "__id__": 99 }, "_motorSpeedActive": -10000, "_motorSpeedDeActive": 10000, @@ -4361,16 +4301,16 @@ }, "_children": [ { - "__id__": 108 + "__id__": 106 } ], "_active": true, "_components": [ { - "__id__": 111 + "__id__": 109 }, { - "__id__": 115 + "__id__": 113 } ], "_prefab": null, @@ -4409,25 +4349,25 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 107 + "__id__": 105 }, "_children": [], "_active": true, "_components": [ { - "__id__": 109 + "__id__": 107 + }, + { + "__id__": 108 }, { "__id__": 110 }, + { + "__id__": 111 + }, { "__id__": 112 - }, - { - "__id__": 113 - }, - { - "__id__": 114 } ], "_prefab": null, @@ -4466,7 +4406,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 108 + "__id__": 106 }, "_enabled": true, "__prefab": null, @@ -4494,7 +4434,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 108 + "__id__": 106 }, "_enabled": true, "__prefab": null, @@ -4510,7 +4450,7 @@ }, "collideConnected": false, "connectedBody": { - "__id__": 111 + "__id__": 109 }, "_enableLimit": true, "_lowerAngle": -30, @@ -4526,7 +4466,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 107 + "__id__": 105 }, "_enabled": true, "__prefab": null, @@ -4554,7 +4494,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 108 + "__id__": 106 }, "_enabled": true, "__prefab": null, @@ -4628,7 +4568,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 108 + "__id__": 106 }, "_enabled": true, "__prefab": null, @@ -4649,7 +4589,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 108 + "__id__": 106 }, "_enabled": true, "__prefab": null, @@ -4687,12 +4627,12 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 107 + "__id__": 105 }, "_enabled": true, "__prefab": null, "_hingeJoint": { - "__id__": 110 + "__id__": 108 }, "_motorSpeedActive": 10000, "_motorSpeedDeActive": -10000, @@ -4709,17 +4649,17 @@ "_children": [], "_active": true, "_components": [ + { + "__id__": 115 + }, + { + "__id__": 116 + }, { "__id__": 117 }, { "__id__": 118 - }, - { - "__id__": 119 - }, - { - "__id__": 120 } ], "_prefab": null, @@ -4757,7 +4697,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 116 + "__id__": 114 }, "_enabled": true, "__prefab": null, @@ -4778,7 +4718,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 116 + "__id__": 114 }, "_enabled": true, "__prefab": null, @@ -4816,7 +4756,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 116 + "__id__": 114 }, "_enabled": true, "__prefab": null, @@ -4890,7 +4830,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 116 + "__id__": 114 }, "_enabled": true, "__prefab": null, @@ -4922,17 +4862,17 @@ "_children": [], "_active": true, "_components": [ + { + "__id__": 120 + }, + { + "__id__": 121 + }, { "__id__": 122 }, { "__id__": 123 - }, - { - "__id__": 124 - }, - { - "__id__": 125 } ], "_prefab": null, @@ -4970,7 +4910,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 121 + "__id__": 119 }, "_enabled": true, "__prefab": null, @@ -4991,7 +4931,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 121 + "__id__": 119 }, "_enabled": true, "__prefab": null, @@ -5029,7 +4969,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 121 + "__id__": 119 }, "_enabled": true, "__prefab": null, @@ -5103,7 +5043,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 121 + "__id__": 119 }, "_enabled": true, "__prefab": null, @@ -5135,14 +5075,14 @@ "_children": [], "_active": true, "_components": [ + { + "__id__": 125 + }, + { + "__id__": 126 + }, { "__id__": 127 - }, - { - "__id__": 128 - }, - { - "__id__": 129 } ], "_prefab": null, @@ -5180,7 +5120,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 126 + "__id__": 124 }, "_enabled": true, "__prefab": null, @@ -5201,7 +5141,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 126 + "__id__": 124 }, "_enabled": true, "__prefab": null, @@ -5239,7 +5179,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 126 + "__id__": 124 }, "_enabled": true, "__prefab": null, @@ -5318,14 +5258,14 @@ "_children": [], "_active": true, "_components": [ + { + "__id__": 129 + }, + { + "__id__": 130 + }, { "__id__": 131 - }, - { - "__id__": 132 - }, - { - "__id__": 133 } ], "_prefab": null, @@ -5363,7 +5303,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 130 + "__id__": 128 }, "_enabled": true, "__prefab": null, @@ -5384,7 +5324,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 130 + "__id__": 128 }, "_enabled": true, "__prefab": null, @@ -5422,7 +5362,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 130 + "__id__": 128 }, "_enabled": true, "__prefab": null, @@ -5501,21 +5441,21 @@ "_children": [], "_active": true, "_components": [ + { + "__id__": 133 + }, + { + "__id__": 134 + }, { "__id__": 135 - }, - { - "__id__": 136 - }, - { - "__id__": 137 } ], "_prefab": null, "_lpos": { "__type__": "cc.Vec3", "x": 0, - "y": -1162.633, + "y": -1226.271, "z": 0 }, "_lrot": { @@ -5546,7 +5486,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 134 + "__id__": 132 }, "_enabled": true, "__prefab": null, @@ -5567,60 +5507,94 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 134 + "__id__": 132 }, "_enabled": true, "__prefab": null, "tag": 1, - "_group": 1, + "_group": 2, "_density": 1, - "_sensor": false, + "_sensor": true, "_friction": 0.2, "_restitution": 0, "_offset": { "__type__": "cc.Vec2", - "x": 4.2, - "y": -28.2 + "x": 0, + "y": 0 }, "_size": { "__type__": "cc.Size", "width": 289.2, - "height": 71.7 + "height": 131 }, "_id": "98zDTZnlhAOYrrE1sIfU+t" }, { - "__type__": "cc.RigidBody2D", + "__type__": "dabd5jcdwhJMa1jzXh1t7Xf", "_name": "", "_objFlags": 0, "node": { - "__id__": 134 + "__id__": 132 }, "_enabled": true, "__prefab": null, - "enabledContactListener": false, - "bullet": false, - "awakeOnLoad": true, - "_group": 1, - "_type": 0, - "_allowSleep": true, - "_gravityScale": 1, - "_linearDamping": 0, - "_angularDamping": 0, - "_linearVelocity": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 + "_collider": { + "__id__": 134 }, - "_angularVelocity": 0, - "_fixedRotation": false, - "_id": "03aGLMQZRCOIuAGwVC9srP" + "_id": "bbbZDnhUdOPK/ENRBm53G2" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 5 + }, + "_enabled": true, + "__prefab": null, + "_contentSize": { + "__type__": "cc.Size", + "width": 1920, + "height": 1440 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "79IdOCQ/dEzoI70UU/heUu" + }, + { + "__type__": "85b9aaRsZBAn5sUxS5RQ3EF", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 5 + }, + "_enabled": true, + "__prefab": null, + "_ballPrefab": { + "__uuid__": "9b471c78-2e1d-4db8-ab08-b3df7c938d64", + "__expectedType__": "cc.Prefab" + }, + "_ballSpawnPosition": { + "__type__": "cc.Vec3", + "x": 0, + "y": -1130, + "z": 0 + }, + "audio": { + "__uuid__": "6a432293-3852-4267-be19-c671f36fe9f0", + "__expectedType__": "cc.AudioClip" + }, + "_id": "94qg9r7nVDkbO1S3Aid8/t" }, { "__type__": "cc.Node", "_objFlags": 0, "_parent": { - "__id__": 5 + "__id__": 2 }, "_prefab": { "__id__": 139 @@ -6519,43 +6493,6 @@ ], "value": 0.25 }, - { - "__type__": "cc.UITransform", - "_name": "", - "_objFlags": 0, - "__editorExtras__": {}, - "node": { - "__id__": 5 - }, - "_enabled": true, - "__prefab": null, - "_contentSize": { - "__type__": "cc.Size", - "width": 1920, - "height": 1440 - }, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0.5, - "y": 0.5 - }, - "_id": "79IdOCQ/dEzoI70UU/heUu" - }, - { - "__type__": "85b9aaRsZBAn5sUxS5RQ3EF", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 5 - }, - "_enabled": true, - "__prefab": null, - "_ballPrefab": { - "__uuid__": "9b471c78-2e1d-4db8-ab08-b3df7c938d64", - "__expectedType__": "cc.Prefab" - }, - "_id": "94qg9r7nVDkbO1S3Aid8/t" - }, { "__type__": "cc.UITransform", "_name": "", @@ -6632,7 +6569,7 @@ "instance": null, "targetOverrides": [ { - "__id__": 205 + "__id__": 203 } ], "nestedPrefabInstanceRoots": [ @@ -6647,7 +6584,7 @@ "__id__": 138 }, "sourceInfo": { - "__id__": 206 + "__id__": 204 }, "propertyPath": [ "_trailModule", @@ -6657,7 +6594,7 @@ "__id__": 138 }, "targetInfo": { - "__id__": 207 + "__id__": 205 } }, { @@ -6675,22 +6612,22 @@ { "__type__": "cc.SceneGlobals", "ambient": { - "__id__": 209 + "__id__": 207 }, "shadows": { - "__id__": 210 + "__id__": 208 }, "_skybox": { - "__id__": 211 + "__id__": 209 }, "fog": { - "__id__": 212 + "__id__": 210 }, "octree": { - "__id__": 213 + "__id__": 211 }, "lightProbeInfo": { - "__id__": 214 + "__id__": 212 }, "bakedWithStationaryMainLight": false, "bakedWithHighpLightmap": false diff --git a/assets/_Game/Scripts/Enum/GameEvent.ts b/assets/_Game/Scripts/Enum/GameEvent.ts index aa17d3b..a54d062 100644 --- a/assets/_Game/Scripts/Enum/GameEvent.ts +++ b/assets/_Game/Scripts/Enum/GameEvent.ts @@ -1,3 +1,6 @@ -enum GameEvent {} +enum GameEvent { + GameStateChange, + BallHit, +} export default GameEvent; diff --git a/assets/_Game/Scripts/Enum/GameState.ts b/assets/_Game/Scripts/Enum/GameState.ts new file mode 100644 index 0000000..5fb6d05 --- /dev/null +++ b/assets/_Game/Scripts/Enum/GameState.ts @@ -0,0 +1,7 @@ +enum GameState { + Init, + Playing, + GameOver, +} + +export default GameState; diff --git a/assets/_Game/Scripts/Enum/GameState.ts.meta b/assets/_Game/Scripts/Enum/GameState.ts.meta new file mode 100644 index 0000000..d049216 --- /dev/null +++ b/assets/_Game/Scripts/Enum/GameState.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "cf53cc6f-2c88-4312-828e-6edf8bfc7583", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/_Game/Scripts/Gameplay/Ball.ts b/assets/_Game/Scripts/Gameplay/Ball.ts index 2df4d30..4aed3d0 100644 --- a/assets/_Game/Scripts/Gameplay/Ball.ts +++ b/assets/_Game/Scripts/Gameplay/Ball.ts @@ -1,5 +1,6 @@ import { _decorator, + AudioClip, CCFloat, Collider2D, Component, @@ -9,52 +10,64 @@ import { EventTarget, IPhysics2DContact, RigidBody2D, + Vec2, } from 'cc'; import IPoolable from '../Pool/IPoolable'; -import Utilities from '../Utilities/Utilities'; +import { SoundManager } from '../Manager/SoundManager'; const { ccclass, property } = _decorator; @ccclass('Ball') export class Ball extends Component implements IPoolable { - @property({ visible: true, type: CCFloat }) - public maxSpeed: number; - @property({ visible: true, type: RigidBody2D }) - public rigidbody: RigidBody2D; - @property(Collider2D) - public collider: Collider2D; - public isActive: boolean; - private hitted = false; + @property({ type: CCFloat, visible: true }) + private _maxSpeed: number; + @property({ type: RigidBody2D, visible: true }) + private _rigidbody: RigidBody2D; + @property({ type: Collider2D, visible: true }) + private _collider: Collider2D; + @property({ type: AudioClip, visible: true }) + private _hitSound: AudioClip; + + private _hitted = false; public eventHitObstacle = new EventTarget(); public eventGoal = new EventTarget(); protected onLoad(): void { - if (this.getComponent(Collider2D)) { - this.collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); - this.collider.on(Contact2DType.END_CONTACT, this.onEndContact, this); + if (this._collider) { + this._collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); + this._collider.on(Contact2DType.END_CONTACT, this.onEndContact, this); } - director.on(Director.EVENT_AFTER_PHYSICS, this.setMaxVelocity, this); } - private onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {} + private onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { + if (this._hitted) return; + this._hitted = true; + if (this._rigidbody.linearVelocity.length() >= 3) { + SoundManager.instance.playSfx(this._hitSound); + } + } private setMaxVelocity() { - if (this.rigidbody.linearVelocity.length() > this.maxSpeed) { - this.rigidbody.linearVelocity = this.rigidbody.linearVelocity.normalize().multiplyScalar(this.maxSpeed); + if (this._rigidbody.linearVelocity.length() > this._maxSpeed) { + this._rigidbody.linearVelocity = this._rigidbody.linearVelocity.normalize().multiplyScalar(this._maxSpeed); } } private onEndContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { // console.log(otherCollider.tag, otherCollider.node.name); - this.hitted = false; + this._hitted = false; } - reuse() { - console.log('use'); + public addFocre(force: Vec2) { + const point = this.node.getWorldPosition(); + this._rigidbody.applyLinearImpulse(force, new Vec2(point.x, point.y), true); } + reuse() {} + unuse() { - console.log('unuse'); + this._rigidbody.linearVelocity = Vec2.ZERO.clone(); + this._rigidbody.angularVelocity = 0; } } diff --git a/assets/_Game/Scripts/Gameplay/Outer.ts b/assets/_Game/Scripts/Gameplay/Outer.ts new file mode 100644 index 0000000..c7db602 --- /dev/null +++ b/assets/_Game/Scripts/Gameplay/Outer.ts @@ -0,0 +1,17 @@ +import { _decorator, Collider2D, Component, Contact2DType, Node } from 'cc'; +import { GameManager } from '../Manager/GameManager'; +const { ccclass, property } = _decorator; + +@ccclass('Outer') +export class Outer extends Component { + @property({ type: Collider2D, visible: true }) + private _collider: Collider2D; + + protected start(): void { + this._collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); + } + + private onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D) { + GameManager.instance.ballOut(otherCollider.node); + } +} diff --git a/assets/_Game/Scripts/Gameplay/Outer.ts.meta b/assets/_Game/Scripts/Gameplay/Outer.ts.meta new file mode 100644 index 0000000..a4a88d6 --- /dev/null +++ b/assets/_Game/Scripts/Gameplay/Outer.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "dabd58dc-7708-4931-ad63-cd7875b7b5df", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/_Game/Scripts/Interface.meta b/assets/_Game/Scripts/Interface.meta new file mode 100644 index 0000000..fe0d363 --- /dev/null +++ b/assets/_Game/Scripts/Interface.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "29983e40-308b-4f9e-9e19-104e958a083b", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/assets/_Game/Scripts/Interface/GameEventMap.ts b/assets/_Game/Scripts/Interface/GameEventMap.ts new file mode 100644 index 0000000..f9d9f82 --- /dev/null +++ b/assets/_Game/Scripts/Interface/GameEventMap.ts @@ -0,0 +1,12 @@ +import GameEvent from '../Enum/GameEvent'; +import GameState from '../Enum/GameState'; + +export interface GameEventCallbackMap { + [GameEvent.GameStateChange]: (state: GameState) => void; + [GameEvent.BallHit]: () => void; +} + +export interface GameEventArgMap { + [GameEvent.GameStateChange]: GameState; + [GameEvent.BallHit]: null; +} diff --git a/assets/_Game/Scripts/Interface/GameEventMap.ts.meta b/assets/_Game/Scripts/Interface/GameEventMap.ts.meta new file mode 100644 index 0000000..157a024 --- /dev/null +++ b/assets/_Game/Scripts/Interface/GameEventMap.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "b1eecaf3-413b-4baa-b963-ac905620d203", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/_Game/Scripts/Manager/EventManger.ts b/assets/_Game/Scripts/Manager/EventManger.ts index 8b5f6dc..714a13c 100644 --- a/assets/_Game/Scripts/Manager/EventManger.ts +++ b/assets/_Game/Scripts/Manager/EventManger.ts @@ -1,5 +1,6 @@ -import { _decorator, Component, EventTarget, Node } from 'cc'; +import { __private, _decorator, Component, EventTarget, Node } from 'cc'; import GameEvent from '../Enum/GameEvent'; +import { GameEventArgMap, GameEventCallbackMap } from '../Interface/GameEventMap'; const { ccclass, property } = _decorator; @ccclass('EventManger') @@ -21,15 +22,27 @@ export class EventManger extends Component { } } - public on(eventType: GameEvent, callback?: (...args: any[]) => void, thisArg?: any) { - this._eventTarget.on(eventType, callback, thisArg); + public on( + eventType: K, + callback: GameEventCallbackMap[K], + target?: any, + ): GameEventCallbackMap[K] { + return this._eventTarget.on(eventType, callback, target); } - public off(eventType: GameEvent, callback?: (...args: any[]) => void, thisArg?: any) { - this._eventTarget.on(eventType, callback, thisArg); + public off( + eventType: K, + callback: GameEventCallbackMap[K], + thisArg?: any, + ): GameEventCallbackMap[K] { + return this._eventTarget.on(eventType, callback, thisArg); } - public emit(eventType: GameEvent, arg0?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any) { - this._eventTarget.emit(eventType, arg0, arg1, arg2, arg3, arg4); + public emit(eventType: K, arg: GameEventArgMap[K]) { + if (Array.isArray(arg)) { + this._eventTarget.emit(eventType, ...arg); + } else { + this._eventTarget.emit(eventType, arg); + } } } diff --git a/assets/_Game/Scripts/Manager/GameManager.ts b/assets/_Game/Scripts/Manager/GameManager.ts index 5c3a0eb..70d6d1d 100644 --- a/assets/_Game/Scripts/Manager/GameManager.ts +++ b/assets/_Game/Scripts/Manager/GameManager.ts @@ -1,6 +1,10 @@ -import { _decorator, Component, Prefab, Node } from 'cc'; +import { _decorator, Component, Prefab, Node, Vec2, Vec3, randomRangeInt, CCInteger, Input } from 'cc'; import ObjectPool from '../Pool/ObjectPool'; import { Ball } from '../Gameplay/Ball'; +import Utilities from '../Utilities/Utilities'; +import GameState from '../Enum/GameState'; +import { EventManger } from './EventManger'; +import GameEvent from '../Enum/GameEvent'; const { ccclass, property } = _decorator; @ccclass('GameManager') @@ -13,15 +17,54 @@ export class GameManager extends Component { @property({ type: Prefab, visible: true }) private _ballPrefab: Prefab; + @property({ type: Vec3, visible: true }) + private _ballSpawnPosition: Vec3; + @property({ type: CCInteger, visible: true }) + private _balls = 3; + private _ballPool: ObjectPool; + private _gameState = GameState.Init; public highestStreak: number; public score = 0; protected onLoad(): void { + GameManager._instance = this; this._ballPool = new ObjectPool(this._ballPrefab, 10, false, Ball); } + protected async start() { + // this.spawnBall(); + const a = [1, 4, 4, 5]; + } + + private changeGameState(state: GameState) { + this._gameState = state; + EventManger.instance.emit(GameEvent.GameStateChange, this._gameState); + } + + public spawnBall(): Ball { + const ball = this._ballPool.get(this.node, Ball); + ball.node.setPosition(this._ballSpawnPosition); + let dir = randomRangeInt(-1, 2); + while (dir == 0) { + dir = randomRangeInt(-1, 2); + } + const force = new Vec2(dir, 1); + ball.addFocre(force.multiply2f(1, 50)); + return ball; + } + + public async ballOut(ball: Node) { + this._balls--; + if (this._balls === 0) { + return; + } + this._ballPool.release(ball); + await Utilities.delay(1000); + // this.spawnBall(); + } + public onRevive() { throw new Error('Method not implemented.'); } diff --git a/assets/_Game/Scripts/Manager/SoundManager.ts b/assets/_Game/Scripts/Manager/SoundManager.ts index dd6dbf8..3044cab 100644 --- a/assets/_Game/Scripts/Manager/SoundManager.ts +++ b/assets/_Game/Scripts/Manager/SoundManager.ts @@ -38,10 +38,10 @@ export class SoundManager extends Component { //singleton private static _instance: SoundManager; public static get instance(): SoundManager { - if (SoundManager._instance) { + if (!SoundManager._instance) { SoundManager._instance = new SoundManager('SoundManager'); } - return SoundManager.instance; + return SoundManager._instance; } private _audioSourcesSfx: { [key: string]: SoundSource } = {}; diff --git a/assets/_Game/Scripts/Pool/ObjectPool.ts b/assets/_Game/Scripts/Pool/ObjectPool.ts index 4489bea..92f3bca 100644 --- a/assets/_Game/Scripts/Pool/ObjectPool.ts +++ b/assets/_Game/Scripts/Pool/ObjectPool.ts @@ -33,7 +33,6 @@ export default class ObjectPool { public get(parent?: Node): Node; public get(parent?: Node, classConstructor?: new () => T): T; - public get(parent?: Node, classConstructor?: new () => T): T | Node { let obj: Node = null; let p = parent || director.getScene();