diff --git a/assets/Media/Animation/WeaponSwing.anim b/assets/Media/Animation/WeaponSwing.anim index 02972b5..2975402 100644 --- a/assets/Media/Animation/WeaponSwing.anim +++ b/assets/Media/Animation/WeaponSwing.anim @@ -11,7 +11,7 @@ "speed": 1, "wrapMode": 1, "enableTrsBlending": false, - "_duration": 0.31666666666666665, + "_duration": 1.3, "_hash": 500763545, "_tracks": [ { @@ -62,7 +62,9 @@ "__type__": "cc.RealCurve", "_times": [ 0, - 0.31666666666666665 + 0.4666666666666667, + 0.8666666666666667, + 1.3 ], "_values": [ { @@ -74,10 +76,7 @@ "rightTangentWeight": 1, "leftTangent": 0, "leftTangentWeight": 1, - "easingMethod": 0, - "__editorExtras__": { - "tangentMode": 0 - } + "easingMethod": 0 }, { "__type__": "cc.RealKeyframeValue", @@ -88,10 +87,29 @@ "rightTangentWeight": 1, "leftTangent": 0, "leftTangentWeight": 1, - "easingMethod": 0, - "__editorExtras__": { - "tangentMode": 0 - } + "easingMethod": 0 + }, + { + "__type__": "cc.RealKeyframeValue", + "interpolationMode": 0, + "tangentWeightMode": 0, + "value": 0, + "rightTangent": 0, + "rightTangentWeight": 1, + "leftTangent": 0, + "leftTangentWeight": 1, + "easingMethod": 0 + }, + { + "__type__": "cc.RealKeyframeValue", + "interpolationMode": 0, + "tangentWeightMode": 0, + "value": 0, + "rightTangent": 0, + "rightTangentWeight": 1, + "leftTangent": 0, + "leftTangentWeight": 1, + "easingMethod": 0 } ], "preExtrapolation": 1, @@ -107,7 +125,9 @@ "__type__": "cc.RealCurve", "_times": [ 0, - 0.31666666666666665 + 0.4666666666666667, + 0.8666666666666667, + 1.3 ], "_values": [ { @@ -119,10 +139,7 @@ "rightTangentWeight": 1, "leftTangent": 0, "leftTangentWeight": 1, - "easingMethod": 0, - "__editorExtras__": { - "tangentMode": 0 - } + "easingMethod": 0 }, { "__type__": "cc.RealKeyframeValue", @@ -133,10 +150,29 @@ "rightTangentWeight": 1, "leftTangent": 0, "leftTangentWeight": 1, - "easingMethod": 0, - "__editorExtras__": { - "tangentMode": 0 - } + "easingMethod": 0 + }, + { + "__type__": "cc.RealKeyframeValue", + "interpolationMode": 0, + "tangentWeightMode": 0, + "value": 0, + "rightTangent": 0, + "rightTangentWeight": 1, + "leftTangent": 0, + "leftTangentWeight": 1, + "easingMethod": 0 + }, + { + "__type__": "cc.RealKeyframeValue", + "interpolationMode": 0, + "tangentWeightMode": 0, + "value": 0, + "rightTangent": 0, + "rightTangentWeight": 1, + "leftTangent": 0, + "leftTangentWeight": 1, + "easingMethod": 0 } ], "preExtrapolation": 1, @@ -152,36 +188,54 @@ "__type__": "cc.RealCurve", "_times": [ 0, - 0.31666666666666665 + 0.4666666666666667, + 0.8666666666666667, + 1.3 ], "_values": [ { "__type__": "cc.RealKeyframeValue", "interpolationMode": 0, "tangentWeightMode": 0, - "value": 0, + "value": 170, "rightTangent": 0, "rightTangentWeight": 1, "leftTangent": 0, "leftTangentWeight": 1, - "easingMethod": 0, - "__editorExtras__": { - "tangentMode": 0 - } + "easingMethod": 0 }, { "__type__": "cc.RealKeyframeValue", "interpolationMode": 0, "tangentWeightMode": 0, - "value": 90, + "value": 170, "rightTangent": 0, "rightTangentWeight": 1, "leftTangent": 0, "leftTangentWeight": 1, - "easingMethod": 0, - "__editorExtras__": { - "tangentMode": 0 - } + "easingMethod": 0 + }, + { + "__type__": "cc.RealKeyframeValue", + "interpolationMode": 0, + "tangentWeightMode": 0, + "value": 370, + "rightTangent": 0, + "rightTangentWeight": 1, + "leftTangent": 0, + "leftTangentWeight": 1, + "easingMethod": 0 + }, + { + "__type__": "cc.RealKeyframeValue", + "interpolationMode": 0, + "tangentWeightMode": 0, + "value": 370, + "rightTangent": 0, + "rightTangentWeight": 1, + "leftTangent": 0, + "leftTangentWeight": 1, + "easingMethod": 0 } ], "preExtrapolation": 1, diff --git a/assets/Media/Prefabs/XP.prefab b/assets/Media/Prefabs/XP.prefab new file mode 100644 index 0000000..3a67cd5 --- /dev/null +++ b/assets/Media/Prefabs/XP.prefab @@ -0,0 +1,194 @@ +[ + { + "__type__": "cc.Prefab", + "_name": "XP", + "_objFlags": 0, + "_native": "", + "data": { + "__id__": 1 + }, + "optimizationPolicy": 0, + "persistent": false, + "asyncLoadAssets": false + }, + { + "__type__": "cc.Node", + "_name": "XP", + "_objFlags": 0, + "__editorExtras__": {}, + "_parent": null, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 2 + }, + { + "__id__": 4 + }, + { + "__id__": 6 + }, + { + "__id__": 8 + } + ], + "_prefab": { + "__id__": 10 + }, + "_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", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 3 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 26, + "height": 26 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "c3Jb8uGT9DFpm574XDqiKL" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 5 + }, + "_customMaterial": null, + "_srcBlendFactor": 2, + "_dstBlendFactor": 4, + "_color": { + "__type__": "cc.Color", + "r": 88, + "g": 101, + "b": 255, + "a": 255 + }, + "_spriteFrame": { + "__uuid__": "f12a23c4-b924-4322-a260-3d982428f1e8@f9941", + "__expectedType__": "cc.SpriteFrame" + }, + "_type": 0, + "_fillType": 0, + "_sizeMode": 1, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_useGrayscale": false, + "_atlas": null, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "cfXyVJoitMGp/0liEUZfNP" + }, + { + "__type__": "cc.CircleCollider2D", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 7 + }, + "tag": 0, + "_group": 16, + "_density": 1, + "_sensor": false, + "_friction": 0.2, + "_restitution": 0, + "_offset": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_radius": 13, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "75WVRoLrtKLrJihCVsxa4D" + }, + { + "__type__": "7a536G2OudFtpTsoF8yLXiW", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 9 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "72AObOIbxCf6LIYsYqoFZF" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "405dEytktEvavOK8J9RVEp" + } +] \ No newline at end of file diff --git a/assets/Media/Prefabs/XP.prefab.meta b/assets/Media/Prefabs/XP.prefab.meta new file mode 100644 index 0000000..c9d73ed --- /dev/null +++ b/assets/Media/Prefabs/XP.prefab.meta @@ -0,0 +1,13 @@ +{ + "ver": "1.1.40", + "importer": "prefab", + "imported": true, + "uuid": "b83dbe32-6b43-4ea9-b0e2-5f96c09f459d", + "files": [ + ".json" + ], + "subMetas": {}, + "userData": { + "syncNodeName": "XP" + } +} diff --git a/assets/Scenes/scene.scene b/assets/Scenes/scene.scene index 779ee92..2770ea0 100644 --- a/assets/Scenes/scene.scene +++ b/assets/Scenes/scene.scene @@ -21,11 +21,11 @@ "_active": true, "_components": [], "_prefab": { - "__id__": 53 + "__id__": 65 }, "autoReleaseAssets": false, "_globals": { - "__id__": 54 + "__id__": 66 }, "_id": "cffa5b19-2043-4cef-8221-1a10ab7a2c1f" }, @@ -41,38 +41,35 @@ "__id__": 3 }, { - "__id__": 5 + "__id__": 12 }, { - "__id__": 14 + "__id__": 32 }, { - "__id__": 34 - }, - { - "__id__": 47 + "__id__": 38 } ], "_active": true, "_components": [ { - "__id__": 49 + "__id__": 61 }, { - "__id__": 50 + "__id__": 62 }, { - "__id__": 51 + "__id__": 63 }, { - "__id__": 52 + "__id__": 64 } ], "_prefab": null, "_lpos": { "__type__": "cc.Vec3", - "x": 479.99999999999994, - "y": 319.99999999999994, + "x": 319.99999999999994, + "y": 479.99999999999994, "z": 0 }, "_lrot": { @@ -97,92 +94,6 @@ }, "_id": "beI88Z2HpFELqR4T5EMHpg" }, - { - "__type__": "cc.Node", - "_name": "Camera", - "_objFlags": 0, - "_parent": { - "__id__": 2 - }, - "_children": [], - "_active": true, - "_components": [ - { - "__id__": 4 - } - ], - "_prefab": null, - "_lpos": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 1000 - }, - "_lrot": { - "__type__": "cc.Quat", - "x": 0, - "y": 0, - "z": 0, - "w": 1 - }, - "_lscale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 - }, - "_layer": 1073741824, - "_euler": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - }, - "_id": "ebFwiq8gBFaYpqYbdoDODe" - }, - { - "__type__": "cc.Camera", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 3 - }, - "_enabled": true, - "__prefab": null, - "_projection": 0, - "_priority": 1073741824, - "_fov": 45, - "_fovAxis": 0, - "_orthoHeight": 656.050156739812, - "_near": 0, - "_far": 2000, - "_color": { - "__type__": "cc.Color", - "r": 0, - "g": 0, - "b": 0, - "a": 255 - }, - "_depth": 1, - "_stencil": 0, - "_clearFlags": 7, - "_rect": { - "__type__": "cc.Rect", - "x": 0, - "y": 0, - "width": 1, - "height": 1 - }, - "_aperture": 19, - "_shutter": 7, - "_iso": 0, - "_screenScale": 1, - "_visibility": 41943040, - "_targetTexture": null, - "_cameraType": -1, - "_trackingType": 0, - "_id": "63WIch3o5BEYRlXzTT0oWc" - }, { "__type__": "cc.Node", "_name": "Weapon", @@ -192,13 +103,13 @@ }, "_children": [ { - "__id__": 6 + "__id__": 4 } ], "_active": true, "_components": [ { - "__id__": 13 + "__id__": 11 } ], "_prefab": null, @@ -235,20 +146,20 @@ "_name": "AnimatedWeapon", "_objFlags": 0, "_parent": { - "__id__": 5 + "__id__": 3 }, "_children": [ { - "__id__": 7 + "__id__": 5 } ], "_active": true, "_components": [ { - "__id__": 11 + "__id__": 9 }, { - "__id__": 12 + "__id__": 10 } ], "_prefab": null, @@ -285,19 +196,19 @@ "_name": "WeaponCollider", "_objFlags": 0, "_parent": { - "__id__": 6 + "__id__": 4 }, "_children": [], "_active": true, "_components": [ + { + "__id__": 6 + }, + { + "__id__": 7 + }, { "__id__": 8 - }, - { - "__id__": 9 - }, - { - "__id__": 10 } ], "_prefab": null, @@ -334,7 +245,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 7 + "__id__": 5 }, "_enabled": true, "__prefab": null, @@ -355,7 +266,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 7 + "__id__": 5 }, "_enabled": true, "__prefab": null, @@ -393,7 +304,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 7 + "__id__": 5 }, "_enabled": true, "__prefab": null, @@ -420,7 +331,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 6 + "__id__": 4 }, "_enabled": true, "__prefab": null, @@ -441,7 +352,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 6 + "__id__": 4 }, "_enabled": true, "__prefab": null, @@ -463,15 +374,15 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 5 + "__id__": 3 }, "_enabled": true, "__prefab": null, "weaponAnimation": { - "__id__": 12 + "__id__": 10 }, "collider": { - "__id__": 10 + "__id__": 8 }, "_id": "femtdMmA5Ax5K78hjELCcD" }, @@ -484,29 +395,29 @@ }, "_children": [ { - "__id__": 15 + "__id__": 13 } ], "_active": true, "_components": [ + { + "__id__": 28 + }, + { + "__id__": 29 + }, { "__id__": 30 }, { "__id__": 31 - }, - { - "__id__": 32 - }, - { - "__id__": 33 } ], "_prefab": null, "_lpos": { "__type__": "cc.Vec3", - "x": -78, - "y": -42, + "x": 0, + "y": 0, "z": 0 }, "_lrot": { @@ -536,20 +447,20 @@ "_name": "PlayerUI", "_objFlags": 0, "_parent": { - "__id__": 14 + "__id__": 12 }, "_children": [ { - "__id__": 16 + "__id__": 14 } ], "_active": true, "_components": [ { - "__id__": 28 + "__id__": 26 }, { - "__id__": 29 + "__id__": 27 } ], "_prefab": null, @@ -586,23 +497,23 @@ "_name": "PlayerHealthUI", "_objFlags": 0, "_parent": { - "__id__": 15 + "__id__": 13 }, "_children": [ { - "__id__": 17 + "__id__": 15 }, { - "__id__": 20 + "__id__": 18 } ], "_active": true, "_components": [ { - "__id__": 26 + "__id__": 24 }, { - "__id__": 27 + "__id__": 25 } ], "_prefab": null, @@ -639,16 +550,16 @@ "_name": "Background", "_objFlags": 0, "_parent": { - "__id__": 16 + "__id__": 14 }, "_children": [], "_active": true, "_components": [ { - "__id__": 18 + "__id__": 16 }, { - "__id__": 19 + "__id__": 17 } ], "_prefab": null, @@ -685,7 +596,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 17 + "__id__": 15 }, "_enabled": true, "__prefab": null, @@ -706,7 +617,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 17 + "__id__": 15 }, "_enabled": true, "__prefab": null, @@ -744,20 +655,20 @@ "_name": "HpBar", "_objFlags": 0, "_parent": { - "__id__": 16 + "__id__": 14 }, "_children": [ { - "__id__": 21 + "__id__": 19 } ], "_active": true, "_components": [ { - "__id__": 24 + "__id__": 22 }, { - "__id__": 25 + "__id__": 23 } ], "_prefab": null, @@ -794,16 +705,16 @@ "_name": "MovableBar", "_objFlags": 0, "_parent": { - "__id__": 20 + "__id__": 18 }, "_children": [], "_active": true, "_components": [ { - "__id__": 22 + "__id__": 20 }, { - "__id__": 23 + "__id__": 21 } ], "_prefab": null, @@ -840,7 +751,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 21 + "__id__": 19 }, "_enabled": true, "__prefab": null, @@ -861,7 +772,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 21 + "__id__": 19 }, "_enabled": true, "__prefab": null, @@ -899,7 +810,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 20 + "__id__": 18 }, "_enabled": true, "__prefab": null, @@ -920,12 +831,12 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 20 + "__id__": 18 }, "_enabled": true, "__prefab": null, "_barSprite": { - "__id__": 23 + "__id__": 21 }, "_mode": 0, "_totalLength": 80, @@ -938,7 +849,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 16 + "__id__": 14 }, "_enabled": true, "__prefab": null, @@ -959,12 +870,12 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 16 + "__id__": 14 }, "_enabled": true, "__prefab": null, "healthBar": { - "__id__": 25 + "__id__": 23 }, "_id": "fdR9eSdI9Kh7IrotzIY0Rb" }, @@ -973,7 +884,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 15 + "__id__": 13 }, "_enabled": true, "__prefab": null, @@ -994,12 +905,12 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 15 + "__id__": 13 }, "_enabled": true, "__prefab": null, "healthUI": { - "__id__": 27 + "__id__": 25 }, "_id": "d2D9WtiThPe6mF1BVz5+iU" }, @@ -1008,7 +919,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 14 + "__id__": 12 }, "_enabled": true, "__prefab": null, @@ -1029,7 +940,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 14 + "__id__": 12 }, "_enabled": true, "__prefab": null, @@ -1067,16 +978,16 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 14 + "__id__": 12 }, "_enabled": true, "__prefab": null, "speed": 100, "collider": { - "__id__": 33 + "__id__": 31 }, "playerUI": { - "__id__": 29 + "__id__": 27 }, "_id": "5aDEGDNWpIaL+U2iIxK4vA" }, @@ -1085,7 +996,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 14 + "__id__": 12 }, "_enabled": true, "__prefab": null, @@ -1109,26 +1020,23 @@ }, { "__type__": "cc.Node", - "_name": "UI", + "_name": "EnemyManager", "_objFlags": 0, "_parent": { "__id__": 2 }, "_children": [ { - "__id__": 35 + "__id__": 33 }, { - "__id__": 42 + "__id__": 35 } ], "_active": true, "_components": [ { - "__id__": 45 - }, - { - "__id__": 46 + "__id__": 37 } ], "_prefab": null, @@ -1158,38 +1066,672 @@ "y": 0, "z": 0 }, - "_id": "f7dUFumMdE6a8MQ6kKE3qi" + "_id": "c5hUW3WnRPzJB48SFIf+Ud" + }, + { + "__type__": "cc.Node", + "_name": "EnemySpawner", + "_objFlags": 0, + "_parent": { + "__id__": 32 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 34 + } + ], + "_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" + }, + { + "__type__": "8aa2aOTzVFLtKl5CV5vzpWp", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 33 + }, + "_enabled": true, + "__prefab": null, + "enemies": [ + { + "__uuid__": "fc9a455d-1b5f-460e-96eb-7c0ebf07d3d0", + "__expectedType__": "cc.Prefab" + } + ], + "_id": "0bYOmE6uFKe6bZiYUsXVFn" + }, + { + "__type__": "cc.Node", + "_name": "XPSpawner", + "_objFlags": 0, + "_parent": { + "__id__": 32 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 36 + } + ], + "_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": "b7cM/vyZtNY6PANwPA4aXG" + }, + { + "__type__": "ab9e2Br8RpBfIFLB9KcWe1u", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 35 + }, + "_enabled": true, + "__prefab": null, + "xpPrefab": { + "__uuid__": "b83dbe32-6b43-4ea9-b0e2-5f96c09f459d", + "__expectedType__": "cc.Prefab" + }, + "_id": "cbPY3r6KtPXJ5MuqA3BqfN" + }, + { + "__type__": "c5416rtZLFCbpWbvH1cdF52", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 32 + }, + "_enabled": true, + "__prefab": null, + "enemySpawner": { + "__id__": 34 + }, + "xpSpawner": { + "__id__": 36 + }, + "_id": "389jvXDeVHmanyKnmtceKg" + }, + { + "__type__": "cc.Node", + "_name": "Camera", + "_objFlags": 0, + "_parent": { + "__id__": 2 + }, + "_children": [ + { + "__id__": 39 + }, + { + "__id__": 48 + }, + { + "__id__": 51 + } + ], + "_active": true, + "_components": [ + { + "__id__": 60 + } + ], + "_prefab": null, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 1000 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_layer": 1073741824, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "ebFwiq8gBFaYpqYbdoDODe" + }, + { + "__type__": "cc.Node", + "_name": "TopUI", + "_objFlags": 0, + "_parent": { + "__id__": 38 + }, + "_children": [ + { + "__id__": 40 + } + ], + "_active": true, + "_components": [ + { + "__id__": 46 + }, + { + "__id__": 47 + } + ], + "_prefab": null, + "_lpos": { + "__type__": "cc.Vec3", + "x": -320, + "y": 480, + "z": -1000 + }, + "_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": "09P9BGU/hKsrU6TN/o+eh1" + }, + { + "__type__": "cc.Node", + "_name": "XpBar", + "_objFlags": 0, + "_parent": { + "__id__": 39 + }, + "_children": [ + { + "__id__": 41 + } + ], + "_active": true, + "_components": [ + { + "__id__": 44 + }, + { + "__id__": 45 + } + ], + "_prefab": null, + "_lpos": { + "__type__": "cc.Vec3", + "x": 320, + "y": -30, + "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": "18zUMyOVxFpZOVUeGAq95y" + }, + { + "__type__": "cc.Node", + "_name": "MovableBar", + "_objFlags": 0, + "_parent": { + "__id__": 40 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 42 + }, + { + "__id__": 43 + } + ], + "_prefab": null, + "_lpos": { + "__type__": "cc.Vec3", + "x": -300, + "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": "0dmdJ4cytHZaC5Nt7WklqK" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 41 + }, + "_enabled": true, + "__prefab": null, + "_contentSize": { + "__type__": "cc.Size", + "width": 600, + "height": 16 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0.5 + }, + "_id": "93ubNu/2lIcq4CHNxuVKSV" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 41 + }, + "_enabled": true, + "__prefab": null, + "_customMaterial": null, + "_srcBlendFactor": 2, + "_dstBlendFactor": 4, + "_color": { + "__type__": "cc.Color", + "r": 71, + "g": 0, + "b": 255, + "a": 255 + }, + "_spriteFrame": { + "__uuid__": "20835ba4-6145-4fbc-a58a-051ce700aa3e@f9941", + "__expectedType__": "cc.SpriteFrame" + }, + "_type": 0, + "_fillType": 0, + "_sizeMode": 0, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_useGrayscale": false, + "_atlas": null, + "_id": "e0hWPPgZdBCL3I0jm0gUxk" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 40 + }, + "_enabled": true, + "__prefab": null, + "_contentSize": { + "__type__": "cc.Size", + "width": 600, + "height": 16 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "63JWN+EuhGUYNXaXZyVBrw" + }, + { + "__type__": "cc.ProgressBar", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 40 + }, + "_enabled": true, + "__prefab": null, + "_barSprite": { + "__id__": 43 + }, + "_mode": 0, + "_totalLength": 600, + "_progress": 1, + "_reverse": false, + "_id": "5a1CWtS5hFdK4pcdIQ6qWC" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 39 + }, + "_enabled": true, + "__prefab": null, + "_contentSize": { + "__type__": "cc.Size", + "width": 640, + "height": 960 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0, + "y": 1 + }, + "_id": "43XpfTdURK8oO437AF7vpy" + }, + { + "__type__": "cc.Widget", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 39 + }, + "_enabled": true, + "__prefab": null, + "_alignFlags": 41, + "_target": null, + "_left": -320, + "_right": 320, + "_top": 480, + "_bottom": -320.1, + "_horizontalCenter": 0, + "_verticalCenter": 0, + "_isAbsLeft": true, + "_isAbsRight": true, + "_isAbsTop": true, + "_isAbsBottom": true, + "_isAbsHorizontalCenter": true, + "_isAbsVerticalCenter": true, + "_originalWidth": 960, + "_originalHeight": 640, + "_alignMode": 2, + "_lockFlags": 0, + "_id": "8e0CbTwKlKs4y+iGPQLoIp" + }, + { + "__type__": "cc.Node", + "_name": "Sprite", + "_objFlags": 0, + "_parent": { + "__id__": 38 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 49 + }, + { + "__id__": 50 + } + ], + "_prefab": null, + "_lpos": { + "__type__": "cc.Vec3", + "x": -416.943, + "y": 0, + "z": -1000 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 10, + "y": 100, + "z": 1 + }, + "_layer": 33554432, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "eciG5PXBZIYakPww8N1gdA" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 48 + }, + "_enabled": true, + "__prefab": null, + "_contentSize": { + "__type__": "cc.Size", + "width": 20, + "height": 20 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "24LCHUZX1BGqhU98TXdgIG" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 48 + }, + "_enabled": true, + "__prefab": null, + "_customMaterial": null, + "_srcBlendFactor": 2, + "_dstBlendFactor": 4, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_spriteFrame": { + "__uuid__": "b730527c-3233-41c2-aaf7-7cdab58f9749@f9941", + "__expectedType__": "cc.SpriteFrame" + }, + "_type": 0, + "_fillType": 0, + "_sizeMode": 1, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_useGrayscale": false, + "_atlas": null, + "_id": "abWXBojhNGrqL4z7N5ErXT" + }, + { + "__type__": "cc.Node", + "_name": "UI", + "_objFlags": 0, + "_parent": { + "__id__": 38 + }, + "_children": [ + { + "__id__": 52 + } + ], + "_active": true, + "_components": [ + { + "__id__": 59 + } + ], + "_prefab": null, + "_lpos": { + "__type__": "cc.Vec3", + "x": -320, + "y": -480, + "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": 1073741824, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "7fx6U0rE1IQZ+lXwBOP7iN" }, { "__type__": "cc.Node", "_name": "VirtualJoystic", "_objFlags": 0, "_parent": { - "__id__": 34 + "__id__": 51 }, "_children": [ { - "__id__": 36 + "__id__": 53 } ], "_active": true, "_components": [ { - "__id__": 39 + "__id__": 56 }, { - "__id__": 40 + "__id__": 57 }, { - "__id__": 41 + "__id__": 58 } ], "_prefab": null, "_lpos": { "__type__": "cc.Vec3", - "x": 450, - "y": -290, - "z": 0 + "x": 434.2, + "y": 480, + "z": -1000 }, "_lrot": { "__type__": "cc.Quat", @@ -1218,22 +1760,22 @@ "_name": "Knob", "_objFlags": 0, "_parent": { - "__id__": 35 + "__id__": 52 }, "_children": [], "_active": true, "_components": [ { - "__id__": 37 + "__id__": 54 }, { - "__id__": 38 + "__id__": 55 } ], "_prefab": null, "_lpos": { "__type__": "cc.Vec3", - "x": 50, + "x": 0, "y": 0, "z": 0 }, @@ -1264,7 +1806,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 36 + "__id__": 53 }, "_enabled": true, "__prefab": null, @@ -1285,7 +1827,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 36 + "__id__": 53 }, "_enabled": true, "__prefab": null, @@ -1323,7 +1865,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 35 + "__id__": 52 }, "_enabled": true, "__prefab": null, @@ -1344,7 +1886,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 35 + "__id__": 52 }, "_enabled": true, "__prefab": null, @@ -1382,221 +1924,79 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 35 + "__id__": 52 }, "_enabled": true, "__prefab": null, "maxDistance": 50, "knob": { - "__id__": 36 + "__id__": 53 }, "_id": "50ceZG62tGlYXvZWEvSDKl" }, - { - "__type__": "cc.Node", - "_name": "BottomRight", - "_objFlags": 0, - "_parent": { - "__id__": 34 - }, - "_children": [], - "_active": true, - "_components": [ - { - "__id__": 43 - }, - { - "__id__": 44 - } - ], - "_prefab": null, - "_lpos": { - "__type__": "cc.Vec3", - "x": 480, - "y": -320, - "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": "3fNgg55TROd5fiBHQ6rg2P" - }, { "__type__": "cc.UITransform", "_name": "", "_objFlags": 0, "node": { - "__id__": 42 + "__id__": 51 }, "_enabled": true, "__prefab": null, "_contentSize": { "__type__": "cc.Size", - "width": 960, - "height": 640 + "width": 640, + "height": 980 }, "_anchorPoint": { "__type__": "cc.Vec2", - "x": 1, + "x": 0, "y": 0 }, - "_id": "92o9sv8UhHW4OdPh3Kjepb" + "_id": "6aEvduvntLK7qhBhdzIohI" }, { - "__type__": "cc.Widget", + "__type__": "cc.Camera", "_name": "", "_objFlags": 0, "node": { - "__id__": 42 + "__id__": 38 }, "_enabled": true, "__prefab": null, - "_alignFlags": 36, - "_target": null, - "_left": 0, - "_right": 0, - "_top": 0, - "_bottom": 0, - "_horizontalCenter": 0, - "_verticalCenter": 0, - "_isAbsLeft": true, - "_isAbsRight": true, - "_isAbsTop": true, - "_isAbsBottom": true, - "_isAbsHorizontalCenter": true, - "_isAbsVerticalCenter": true, - "_originalWidth": 0, - "_originalHeight": 0, - "_alignMode": 2, - "_lockFlags": 0, - "_id": "2aj0UaaWdLtbfAKa1FSREH" - }, - { - "__type__": "cc.UITransform", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 34 + "_projection": 0, + "_priority": 1073741824, + "_fov": 45, + "_fovAxis": 0, + "_orthoHeight": 480, + "_near": 0, + "_far": 2000, + "_color": { + "__type__": "cc.Color", + "r": 0, + "g": 0, + "b": 0, + "a": 255 }, - "_enabled": true, - "__prefab": null, - "_contentSize": { - "__type__": "cc.Size", - "width": 960, - "height": 640 - }, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0.5, - "y": 0.5 - }, - "_id": "91NVUti2NNiKk3eGxDjk2O" - }, - { - "__type__": "cc.Widget", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 34 - }, - "_enabled": true, - "__prefab": null, - "_alignFlags": 45, - "_target": null, - "_left": 0, - "_right": 0, - "_top": 0, - "_bottom": 0, - "_horizontalCenter": 0, - "_verticalCenter": 0, - "_isAbsLeft": true, - "_isAbsRight": true, - "_isAbsTop": true, - "_isAbsBottom": true, - "_isAbsHorizontalCenter": true, - "_isAbsVerticalCenter": true, - "_originalWidth": 960, - "_originalHeight": 640, - "_alignMode": 2, - "_lockFlags": 0, - "_id": "63krxYCjdP0quUNgpkCXUc" - }, - { - "__type__": "cc.Node", - "_name": "EnemySpawner", - "_objFlags": 0, - "_parent": { - "__id__": 2 - }, - "_children": [], - "_active": true, - "_components": [ - { - "__id__": 48 - } - ], - "_prefab": null, - "_lpos": { - "__type__": "cc.Vec3", + "_depth": 1, + "_stencil": 0, + "_clearFlags": 7, + "_rect": { + "__type__": "cc.Rect", "x": 0, "y": 0, - "z": 0 + "width": 1, + "height": 1 }, - "_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" - }, - { - "__type__": "8aa2aOTzVFLtKl5CV5vzpWp", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 47 - }, - "_enabled": true, - "__prefab": null, - "enemies": [ - { - "__uuid__": "fc9a455d-1b5f-460e-96eb-7c0ebf07d3d0", - "__expectedType__": "cc.Prefab" - } - ], - "_id": "0bYOmE6uFKe6bZiYUsXVFn" + "_aperture": 19, + "_shutter": 7, + "_iso": 0, + "_screenScale": 1, + "_visibility": 41943040, + "_targetTexture": null, + "_cameraType": -1, + "_trackingType": 0, + "_id": "63WIch3o5BEYRlXzTT0oWc" }, { "__type__": "cc.UITransform", @@ -1609,8 +2009,8 @@ "__prefab": null, "_contentSize": { "__type__": "cc.Size", - "width": 960, - "height": 640 + "width": 640, + "height": 960 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -1629,7 +2029,7 @@ "_enabled": true, "__prefab": null, "_cameraComponent": { - "__id__": 4 + "__id__": 60 }, "_alignCanvasWithScreen": true, "_id": "12O/ljcVlEqLmVm3U2gEOQ" @@ -1647,7 +2047,7 @@ "_target": null, "_left": -5.684341886080802e-14, "_right": 0, - "_top": -5.684341886080802e-14, + "_top": 0, "_bottom": -5.684341886080802e-14, "_horizontalCenter": 0, "_verticalCenter": 0, @@ -1657,8 +2057,8 @@ "_isAbsBottom": true, "_isAbsHorizontalCenter": true, "_isAbsVerticalCenter": true, - "_originalWidth": 960, - "_originalHeight": 0, + "_originalWidth": 640, + "_originalHeight": 960, "_alignMode": 2, "_lockFlags": 0, "_id": "c5V1EV8IpMtrIvY1OE9t2u" @@ -1673,20 +2073,23 @@ "_enabled": true, "__prefab": null, "virtualJoystic": { - "__id__": 41 + "__id__": 58 }, "player": { - "__id__": 32 + "__id__": 30 }, "weapon": { - "__id__": 13 + "__id__": 11 }, - "enemySpawner": { - "__id__": 48 + "enemyManager": { + "__id__": 37 }, "strikeDelay": 2, "collisionDelay": 0.5, - "_id": "81HHJkTWZDO60EyXTSS38c" + "camera": { + "__id__": 60 + }, + "_id": "3a9z1bqlFCGL4/WyDwU4L5" }, { "__type__": "cc.PrefabInfo", @@ -1695,19 +2098,19 @@ { "__type__": "cc.SceneGlobals", "ambient": { - "__id__": 55 + "__id__": 67 }, "shadows": { - "__id__": 56 + "__id__": 68 }, "_skybox": { - "__id__": 57 + "__id__": 69 }, "fog": { - "__id__": 58 + "__id__": 70 }, "octree": { - "__id__": 59 + "__id__": 71 } }, { diff --git a/assets/Scripts/Game/Collision/PlayerCollisionSystem.ts b/assets/Scripts/Game/Collision/PlayerCollisionSystem.ts index 785b35f..173d7a4 100644 --- a/assets/Scripts/Game/Collision/PlayerCollisionSystem.ts +++ b/assets/Scripts/Game/Collision/PlayerCollisionSystem.ts @@ -3,6 +3,7 @@ import { GroupType } from "../GroupType"; import { Player } from "../Player/Player"; import { GameTimer } from "../../Services/GameTimer"; import { Enemy } from "../Enemy/Enemy"; +import { XP } from "../XP/XP"; export class PlayerCollisionSystem { private playerContacts: Collider2D[] = []; @@ -20,6 +21,7 @@ export class PlayerCollisionSystem { this.collisionTimer = new GameTimer(collisionDelay); this.groupToResolver.set(GroupType.ENEMY, this.resolveEnemyContact.bind(this)); + this.groupToResolver.set(GroupType.XP, this.resolveXpContact.bind(this)); } public gameTick(deltaTime: number): void { @@ -60,4 +62,12 @@ export class PlayerCollisionSystem { console.log("Collided with enemy: Damage: " + damage); this.player.Health.damage(damage); } + + private resolveXpContact(xpCollider: Collider2D): void { + const xp: XP = xpCollider.node.getComponent(XP); + this.player.addXp(xp.Value); + xp.pickup(); + + console.log("Collided with xp: " + xp); + } } diff --git a/assets/Scripts/Game/Enemy/Enemy.ts b/assets/Scripts/Game/Enemy/Enemy.ts index 72e316c..9410682 100644 --- a/assets/Scripts/Game/Enemy/Enemy.ts +++ b/assets/Scripts/Game/Enemy/Enemy.ts @@ -1,4 +1,4 @@ -import { BoxCollider2D, Component, Vec2, Vec3, _decorator } from "cc"; +import { BoxCollider2D, Component, randomRange, Vec3, _decorator } from "cc"; import { ISignal } from "../../Services/EventSystem/ISignal"; import { Signal } from "../../Services/EventSystem/Signal"; import { UnitHealth } from "../Player/UnitHealth"; @@ -10,10 +10,13 @@ export class Enemy extends Component implements IDamageDealing { private health: UnitHealth = new UnitHealth(1); private deathEvent: Signal = new Signal(); + private speed: number; - public setup(): void { - this.node.active = true; + public setup(position: Vec3): void { this.health = new UnitHealth(1); + this.speed = randomRange(0.5, 1); + this.node.setWorldPosition(position); + this.node.active = true; } public get Collider(): BoxCollider2D { @@ -41,8 +44,8 @@ export class Enemy extends Component implements IDamageDealing { public moveBy(move: Vec3): void { const newPosition: Vec3 = this.node.worldPosition; - newPosition.x += move.x; - newPosition.y += move.y; + newPosition.x += move.x * this.speed; + newPosition.y += move.y * this.speed; this.node.setWorldPosition(newPosition); } diff --git a/assets/Scripts/Game/Enemy/EnemyManager.ts b/assets/Scripts/Game/Enemy/EnemyManager.ts new file mode 100644 index 0000000..ff5e8ef --- /dev/null +++ b/assets/Scripts/Game/Enemy/EnemyManager.ts @@ -0,0 +1,41 @@ +import { Component, Node, _decorator } from "cc"; +import { XPSpawner } from "../XP/XPSpawner"; +import { Enemy } from "./Enemy"; +import { EnemyMover } from "./EnemyMover"; +import { EnemySpawner } from "./EnemySpawner"; +const { ccclass, property } = _decorator; + +@ccclass("EnemyManager") +export class EnemyManager extends Component { + @property(EnemySpawner) private enemySpawner: EnemySpawner; + @property(XPSpawner) private xpSpawner: XPSpawner; + + private enemyMover: EnemyMover; + + public init(targetNode: Node): void { + this.enemyMover = new EnemyMover(targetNode); + + this.enemySpawner.init(); + this.enemySpawner.EnemyAddedEvent.on(this.onEnemyAdded, this); + + this.xpSpawner.init(); + } + + public gameTick(deltaTime: number): void { + this.enemySpawner.gameTick(deltaTime); + this.enemyMover.gameTick(deltaTime); + } + + private onEnemyAdded(enemy: Enemy): void { + enemy.DeathEvent.on(this.onEnemyDied, this); + + this.enemyMover.addEnemy(enemy); + } + + private onEnemyDied(enemy: Enemy): void { + enemy.DeathEvent.off(this.onEnemyDied); + + this.xpSpawner.spawnXp(enemy.node.worldPosition, 1); + this.enemyMover.removeEnemy(enemy); + } +} diff --git a/assets/Scripts/Game/Enemy/EnemyManager.ts.meta b/assets/Scripts/Game/Enemy/EnemyManager.ts.meta new file mode 100644 index 0000000..7505b76 --- /dev/null +++ b/assets/Scripts/Game/Enemy/EnemyManager.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "c5416aed-64b1-426e-959b-bc7d5c745e76", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/Game/Enemy/EnemyMover.ts b/assets/Scripts/Game/Enemy/EnemyMover.ts index 779185f..9ddb3fa 100644 --- a/assets/Scripts/Game/Enemy/EnemyMover.ts +++ b/assets/Scripts/Game/Enemy/EnemyMover.ts @@ -21,7 +21,7 @@ export class EnemyMover { public gameTick(deltaTime: number): void { this.enemies.forEach((enemy) => { let direction: Vec3 = new Vec3(); - direction = Vec3.subtract(direction, this.targetNode.position, enemy.node.position); + direction = Vec3.subtract(direction, this.targetNode.worldPosition, enemy.node.worldPosition); enemy.moveBy(direction.multiplyScalar(deltaTime).normalize()); }); } diff --git a/assets/Scripts/Game/Enemy/EnemySpawner.ts b/assets/Scripts/Game/Enemy/EnemySpawner.ts index 14c257a..f9e9e53 100644 --- a/assets/Scripts/Game/Enemy/EnemySpawner.ts +++ b/assets/Scripts/Game/Enemy/EnemySpawner.ts @@ -1,22 +1,23 @@ import { Component, Prefab, randomRange, Vec3, _decorator } from "cc"; +import { ISignal } from "../../Services/EventSystem/ISignal"; +import { Signal } from "../../Services/EventSystem/Signal"; import { GameTimer } from "../../Services/GameTimer"; import { ObjectPool } from "../../Services/ObjectPool"; import { Enemy } from "./Enemy"; -import { EnemyMover } from "./EnemyMover"; const { ccclass, property } = _decorator; @ccclass("EnemySpawner") export class EnemySpawner extends Component { @property(Prefab) private enemies: Prefab[] = []; + public enemyAddedEvent: Signal = new Signal(); + private enemyPool: ObjectPool; private spawnTimer: GameTimer; - private enemyMover: EnemyMover; - public init(enemyMover: EnemyMover): void { - this.enemyPool = new ObjectPool(this.enemies[0], this.node, 5, Enemy); + public init(): void { + this.enemyPool = new ObjectPool(this.enemies[0], this.node, 5, "Enemy"); this.spawnTimer = new GameTimer(1); - this.enemyMover = enemyMover; } public gameTick(deltaTime: number): void { @@ -24,26 +25,23 @@ export class EnemySpawner extends Component { if (this.spawnTimer.tryFinishPeriod()) { this.spawnNewEnemy(); } + } - this.enemyMover.gameTick(deltaTime); + public get EnemyAddedEvent(): ISignal { + return this.enemyAddedEvent; } private spawnNewEnemy(): void { const enemy = this.enemyPool.borrow(); - enemy.node.active = true; - enemy.node.setPosition(new Vec3(randomRange(-300, 300), randomRange(-300, 300))); - - enemy.setup(); + enemy.setup(new Vec3(randomRange(0, 300), randomRange(0, 800))); enemy.DeathEvent.on(this.returnEnemyToPool, this); - this.enemyMover.addEnemy(enemy); + this.enemyAddedEvent.trigger(enemy); } private returnEnemyToPool(enemy: Enemy): void { enemy.DeathEvent.off(this.returnEnemyToPool); this.enemyPool.return(enemy); - - this.enemyMover.removeEnemy(enemy); } } diff --git a/assets/Scripts/Game/GameBootstrapper.ts b/assets/Scripts/Game/GameBootstrapper.ts index defae38..dcc00d8 100644 --- a/assets/Scripts/Game/GameBootstrapper.ts +++ b/assets/Scripts/Game/GameBootstrapper.ts @@ -1,13 +1,12 @@ -import { Component, KeyCode, _decorator } from "cc"; +import { Camera, CCFloat, Component, KeyCode, _decorator } from "cc"; import { PlayerCollisionSystem } from "./Collision/PlayerCollisionSystem"; import { WeaponCollisionSystem } from "./Collision/WeaponCollisionSystem"; -import { EnemySpawner } from "./Enemy/EnemySpawner"; +import { EnemyManager } from "./Enemy/EnemyManager"; +import { KeyboardInput } from "./Input/KeyboardInput"; import { MultiInput } from "./Input/MultiInput"; import { VirtualJoystic } from "./Input/VirtualJoystic"; -import { KeyboardInput } from "./Input/KeyboardInput"; import { Player } from "./Player/Player"; import { Weapon } from "./Weapon"; -import { EnemyMover } from "./Enemy/EnemyMover"; const { ccclass, property } = _decorator; @ccclass("GameBootstrapper") @@ -15,9 +14,10 @@ export class GameBootstrapper extends Component { @property(VirtualJoystic) private virtualJoystic: VirtualJoystic; @property(Player) private player: Player; @property(Weapon) private weapon: Weapon; - @property(EnemySpawner) private enemySpawner: EnemySpawner; - @property(Number) private strikeDelay = 0; - @property(Number) private collisionDelay = 0; + @property(EnemyManager) private enemyManager: EnemyManager; + @property(CCFloat) private strikeDelay = 0; + @property(CCFloat) private collisionDelay = 0; + @property(Camera) private camera: Camera; private playerCollisionSystem: PlayerCollisionSystem; public start(): void { @@ -28,15 +28,17 @@ export class GameBootstrapper extends Component { const dualInput: MultiInput = new MultiInput([this.virtualJoystic, wasd, arrowKeys]); this.player.init(dualInput, this.weapon, 50); - const enemyMover = new EnemyMover(this.player.node); - this.enemySpawner.init(enemyMover); this.playerCollisionSystem = new PlayerCollisionSystem(this.player, this.collisionDelay); new WeaponCollisionSystem(this.weapon); + + this.enemyManager.init(this.player.node); } public update(deltaTime: number): void { this.player.gameTick(deltaTime); this.playerCollisionSystem.gameTick(deltaTime); - this.enemySpawner.gameTick(deltaTime); + this.enemyManager.gameTick(deltaTime); + + this.camera.node.worldPosition = this.player.node.worldPosition; } } diff --git a/assets/Scripts/Game/GroupType.ts b/assets/Scripts/Game/GroupType.ts index 4e9887e..a0e31c4 100644 --- a/assets/Scripts/Game/GroupType.ts +++ b/assets/Scripts/Game/GroupType.ts @@ -4,5 +4,6 @@ export enum GroupType { DEFAULT = 1 << 0, PLAYER = 1 << 1, ENEMY = 1 << 2, - WEAPON = 1 << 3 + WEAPON = 1 << 3, + XP = 1 << 4 } diff --git a/assets/Scripts/Game/Input/VirtualJoystic.ts b/assets/Scripts/Game/Input/VirtualJoystic.ts index 193bc8c..221c0bd 100644 --- a/assets/Scripts/Game/Input/VirtualJoystic.ts +++ b/assets/Scripts/Game/Input/VirtualJoystic.ts @@ -1,10 +1,10 @@ -import { _decorator, Component, Node, Vec3, input, Input, EventMouse, Vec2, EventTouch } from "cc"; +import { _decorator, Component, Node, Vec3, input, Input, EventMouse, Vec2, EventTouch, CCFloat } from "cc"; import { IInput } from "./IInput"; const { ccclass, property } = _decorator; @ccclass("VirtualJoystic") export class VirtualJoystic extends Component implements IInput { - @property(Number) private maxDistance = 10; + @property(CCFloat) private maxDistance = 10; @property(Node) private knob: Node; #isUsingJoystic = false; @@ -35,6 +35,7 @@ export class VirtualJoystic extends Component implements IInput { } private activateMouseJoystic(e: EventMouse): void { + console.log(e.getUILocation()); this.activateJoystic(e.getUILocation()); } @@ -43,7 +44,7 @@ export class VirtualJoystic extends Component implements IInput { this.node.active = true; this.#defaultPosition = location; - this.node.setWorldPosition(new Vec3(this.#defaultPosition.x, this.#defaultPosition.y, 0)); + this.node.setPosition(new Vec3(this.#defaultPosition.x, this.#defaultPosition.y, 0)); this.knob.position = new Vec3(); } diff --git a/assets/Scripts/Game/Player/Player.ts b/assets/Scripts/Game/Player/Player.ts index 07683ea..1b19cca 100644 --- a/assets/Scripts/Game/Player/Player.ts +++ b/assets/Scripts/Game/Player/Player.ts @@ -1,4 +1,4 @@ -import { BoxCollider2D, Collider2D, Component, Vec2, Vec3, _decorator } from "cc"; +import { BoxCollider2D, Collider2D, Component, PointToPointConstraint, Vec2, Vec3, _decorator } from "cc"; import { IInput } from "../Input/IInput"; import { Weapon } from "../Weapon"; import { PlayerUI } from "./PlayerUI/PlayerUI"; @@ -15,6 +15,8 @@ export class Player extends Component { private weapon: Weapon; private health: UnitHealth; + private xp: number; + public init(input: IInput, weapon: Weapon, maxHp: number): void { this.input = input; this.weapon = weapon; @@ -34,6 +36,10 @@ export class Player extends Component { return this.collider; } + public addXp(points: number): void { + this.xp += points; + } + public gameTick(deltaTime: number): void { const movement: Vec2 = this.input.getAxis(); movement.x *= deltaTime * this.speed; @@ -45,6 +51,6 @@ export class Player extends Component { this.node.setWorldPosition(newPosition); - this.weapon.gameTick(deltaTime, movement); + this.weapon.gameTick(deltaTime); } } diff --git a/assets/Scripts/Game/Weapon.ts b/assets/Scripts/Game/Weapon.ts index b94c30a..cea3279 100644 --- a/assets/Scripts/Game/Weapon.ts +++ b/assets/Scripts/Game/Weapon.ts @@ -1,6 +1,5 @@ -import { Animation, BoxCollider2D, Collider2D, Component, Vec2, Vec3, _decorator } from "cc"; +import { Animation, AnimationState, BoxCollider2D, Collider2D, Component, _decorator } from "cc"; import { GameTimer } from "../Services/GameTimer"; -import { delay } from "../Services/Utils/AsyncUtils"; const { ccclass, property } = _decorator; @ccclass("Weapon") @@ -9,24 +8,21 @@ export class Weapon extends Component { @property(BoxCollider2D) private collider: BoxCollider2D; private strikeTimer: GameTimer; - private lastDirection = new Vec2(); + private strikeState: AnimationState; public init(strikeDelay: number): void { this.strikeTimer = new GameTimer(strikeDelay); this.node.active = false; + + this.weaponAnimation.on(Animation.EventType.FINISHED, this.endStrike, this); + this.strikeState = this.weaponAnimation.getState(this.weaponAnimation.clips[0].name); + this.strikeState.speed = 1; } - public gameTick(deltaTime: number, movement: Vec2): void { - let direction: Vec2 = movement.normalize(); - if (direction.x == 0 && direction.y == 0) { - direction = this.lastDirection; - } else { - this.lastDirection = direction; - } - + public gameTick(deltaTime: number): void { this.strikeTimer.gameTick(deltaTime); if (this.strikeTimer.tryFinishPeriod()) { - this.strike(direction); + this.strike(); } } @@ -38,16 +34,12 @@ export class Weapon extends Component { return 5; } - private async strike(direction: Vec2): Promise { + private strike(): void { this.node.active = true; + this.weaponAnimation.play(this.strikeState.name); + } - const angle: number = (Math.atan2(direction.y, direction.x) * 180) / Math.PI - 45; - this.node.eulerAngles = new Vec3(0, 0, angle); - - this.weaponAnimation.getState("WeaponSwing").speed = 4; - this.weaponAnimation.play("WeaponSwing"); - - await delay(1000); + private endStrike(): void { this.node.active = false; } } diff --git a/assets/Scripts/Game/XP.meta b/assets/Scripts/Game/XP.meta new file mode 100644 index 0000000..90098ab --- /dev/null +++ b/assets/Scripts/Game/XP.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "1e85dd0e-3cbc-4870-9a6a-50e0c29cfeb7", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/assets/Scripts/Game/XP/XP.ts b/assets/Scripts/Game/XP/XP.ts new file mode 100644 index 0000000..b4b5078 --- /dev/null +++ b/assets/Scripts/Game/XP/XP.ts @@ -0,0 +1,29 @@ +import { Component, Vec3, _decorator } from "cc"; +import { ISignal } from "../../Services/EventSystem/ISignal"; +import { Signal } from "../../Services/EventSystem/Signal"; +const { ccclass, property } = _decorator; + +@ccclass("XP") +export class XP extends Component { + private pickUpEvent: Signal = new Signal(); + private value = 2; + + public setup(position: Vec3, value: number): void { + this.node.setWorldPosition(position); + this.value = value; + this.node.active = true; + } + + public get Value(): number { + return this.value; + } + + public get PickupEvent(): ISignal { + return this.pickUpEvent; + } + + public pickup(): void { + this.pickUpEvent.trigger(this); + this.node.active = false; + } +} diff --git a/assets/Scripts/Game/XP/XP.ts.meta b/assets/Scripts/Game/XP/XP.ts.meta new file mode 100644 index 0000000..acc43ae --- /dev/null +++ b/assets/Scripts/Game/XP/XP.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "7a5361b6-3ae7-45b6-94ec-a05f322d7896", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/Game/XP/XPSpawner.ts b/assets/Scripts/Game/XP/XPSpawner.ts new file mode 100644 index 0000000..37e3223 --- /dev/null +++ b/assets/Scripts/Game/XP/XPSpawner.ts @@ -0,0 +1,25 @@ +import { Component, Prefab, Vec3, _decorator } from "cc"; +import { ObjectPool } from "../../Services/ObjectPool"; +import { XP } from "./XP"; +const { ccclass, property } = _decorator; + +@ccclass("XPSpawner") +export class XPSpawner extends Component { + @property(Prefab) public xpPrefab: Prefab; + + private xpPool: ObjectPool; + public init(): void { + this.xpPool = new ObjectPool(this.xpPrefab, this.node, 5, "XP"); + } + + public spawnXp(position: Vec3, value: number): void { + const xp: XP = this.xpPool.borrow(); + xp.setup(position, value); + xp.PickupEvent.on(this.returnXp, this); + } + + private returnXp(xp: XP): void { + xp.PickupEvent.off(this.returnXp); + this.xpPool.return(xp); + } +} diff --git a/assets/Scripts/Game/XP/XPSpawner.ts.meta b/assets/Scripts/Game/XP/XPSpawner.ts.meta new file mode 100644 index 0000000..6b28c13 --- /dev/null +++ b/assets/Scripts/Game/XP/XPSpawner.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "ab9e206b-f11a-417c-814b-07d29c59ed6e", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/Services/EventSystem/Signal.ts b/assets/Scripts/Services/EventSystem/Signal.ts index 86e480f..c520a83 100644 --- a/assets/Scripts/Services/EventSystem/Signal.ts +++ b/assets/Scripts/Services/EventSystem/Signal.ts @@ -17,8 +17,12 @@ export class Signal implements ISignal { } public trigger(data: T): void { - for (let i = 0; i < this.handlers.length; i++) { - this.handlers[i].call(this.thisArgs[i], data); + // protect from trigger >> off + const handlers: ((data: T) => void)[] = [...this.handlers]; + const thisArgs: any[] = [...this.thisArgs]; + + for (let i = 0; i < handlers.length; i++) { + handlers[i].call(thisArgs[i], data); } } } diff --git a/assets/Scripts/Services/ObjectPool.ts b/assets/Scripts/Services/ObjectPool.ts index bf1117d..bb07ae6 100644 --- a/assets/Scripts/Services/ObjectPool.ts +++ b/assets/Scripts/Services/ObjectPool.ts @@ -4,12 +4,12 @@ export class ObjectPool { private prefab: Prefab; private parent: Node; private pooledObjects: PooledObject[] = []; - private componentType: { new (): T }; + private componentName: string; - public constructor(prefab: Prefab, parent: Node, defaultPoolCount: number, componentType: { new (): T }) { + public constructor(prefab: Prefab, parent: Node, defaultPoolCount: number, componentName: string) { this.prefab = prefab; this.parent = parent; - this.componentType = componentType; + this.componentName = componentName; for (let i = 0; i < defaultPoolCount; i++) { this.pooledObjects.push(this.createNew()); @@ -35,7 +35,7 @@ export class ObjectPool { } private createNew(): PooledObject { - const newPooledObject: PooledObject = new PooledObject(this.prefab, this.parent, this.componentType); + const newPooledObject: PooledObject = new PooledObject(this.prefab, this.parent, this.componentName); this.pooledObjects.push(newPooledObject); return newPooledObject; @@ -48,13 +48,13 @@ class PooledObject { private instancedNode: Node; private instancedComponent: T; - public constructor(prefab: Prefab, defaultParent: Node, componentType: { new (): T }) { + public constructor(prefab: Prefab, defaultParent: Node, componentName: string) { this.defaultParent = defaultParent; this.instancedNode = instantiate(prefab); - this.instancedComponent = this.instancedNode.getComponent(componentType.name); + this.instancedComponent = this.instancedNode.getComponent(componentName); if (this.instancedComponent == null) { - throw new Error("Object " + prefab.name + " does not have component " + componentType.name); + console.log("Object " + prefab.name + " does not have component " + componentName); } this.clear(); diff --git a/settings/v2/packages/project.json b/settings/v2/packages/project.json index f00e93e..1e14b92 100644 --- a/settings/v2/packages/project.json +++ b/settings/v2/packages/project.json @@ -12,13 +12,25 @@ { "index": 3, "name": "WEAPON" + }, + { + "index": 4, + "name": "XP" } ], "collisionMatrix": { "0": 0, - "1": 4, + "1": 20, "2": 10, - "3": 4 + "3": 4, + "4": 2 + } + }, + "general": { + "designResolution": { + "width": 640, + "height": 960, + "fitHeight": true } } }