diff --git a/assets/Scenes/scene.scene b/assets/Scenes/scene.scene index 2770ea0..1c0eafc 100644 --- a/assets/Scenes/scene.scene +++ b/assets/Scenes/scene.scene @@ -21,11 +21,11 @@ "_active": true, "_components": [], "_prefab": { - "__id__": 65 + "__id__": 79 }, "autoReleaseAssets": false, "_globals": { - "__id__": 66 + "__id__": 80 }, "_id": "cffa5b19-2043-4cef-8221-1a10ab7a2c1f" }, @@ -53,16 +53,16 @@ "_active": true, "_components": [ { - "__id__": 61 + "__id__": 75 }, { - "__id__": 62 + "__id__": 76 }, { - "__id__": 63 + "__id__": 77 }, { - "__id__": 64 + "__id__": 78 } ], "_prefab": null, @@ -1215,16 +1215,22 @@ "__id__": 39 }, { - "__id__": 48 + "__id__": 62 }, { - "__id__": 51 + "__id__": 65 + }, + { + "__id__": 68 + }, + { + "__id__": 71 } ], "_active": true, "_components": [ { - "__id__": 60 + "__id__": 74 } ], "_prefab": null, @@ -1258,7 +1264,7 @@ }, { "__type__": "cc.Node", - "_name": "TopUI", + "_name": "GameUI", "_objFlags": 0, "_parent": { "__id__": 38 @@ -1266,15 +1272,65 @@ "_children": [ { "__id__": 40 + }, + { + "__id__": 52 } ], "_active": true, "_components": [ { - "__id__": 46 + "__id__": 61 + } + ], + "_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": 1073741824, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "7dvgYzw4JMhrK3PYjGRkdq" + }, + { + "__type__": "cc.Node", + "_name": "TopUI", + "_objFlags": 0, + "_parent": { + "__id__": 39 + }, + "_children": [ + { + "__id__": 41 + } + ], + "_active": true, + "_components": [ + { + "__id__": 50 }, { - "__id__": 47 + "__id__": 51 } ], "_prefab": null, @@ -1311,20 +1367,23 @@ "_name": "XpBar", "_objFlags": 0, "_parent": { - "__id__": 39 + "__id__": 40 }, "_children": [ { - "__id__": 41 + "__id__": 42 + }, + { + "__id__": 45 } ], "_active": true, "_components": [ { - "__id__": 44 + "__id__": 48 }, { - "__id__": 45 + "__id__": 49 } ], "_prefab": null, @@ -1358,19 +1417,124 @@ }, { "__type__": "cc.Node", - "_name": "MovableBar", + "_name": "Background", "_objFlags": 0, "_parent": { - "__id__": 40 + "__id__": 41 }, "_children": [], "_active": true, "_components": [ { - "__id__": 42 + "__id__": 43 }, { - "__id__": 43 + "__id__": 44 + } + ], + "_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": "e4JF72OIBCC5ucGza4GcsP" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 42 + }, + "_enabled": true, + "__prefab": null, + "_contentSize": { + "__type__": "cc.Size", + "width": 600, + "height": 16 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0.5 + }, + "_id": "2duT630xZNPr9+UsJ+JGvq" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 42 + }, + "_enabled": true, + "__prefab": null, + "_customMaterial": null, + "_srcBlendFactor": 2, + "_dstBlendFactor": 4, + "_color": { + "__type__": "cc.Color", + "r": 207, + "g": 207, + "b": 207, + "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": "accSS/dStHUq2WXFMgN0oy" + }, + { + "__type__": "cc.Node", + "_name": "MovableBar", + "_objFlags": 0, + "_parent": { + "__id__": 41 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 46 + }, + { + "__id__": 47 } ], "_prefab": null, @@ -1407,7 +1571,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 41 + "__id__": 45 }, "_enabled": true, "__prefab": null, @@ -1428,7 +1592,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 41 + "__id__": 45 }, "_enabled": true, "__prefab": null, @@ -1466,7 +1630,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 40 + "__id__": 41 }, "_enabled": true, "__prefab": null, @@ -1487,12 +1651,12 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 40 + "__id__": 41 }, "_enabled": true, "__prefab": null, "_barSprite": { - "__id__": 43 + "__id__": 47 }, "_mode": 0, "_totalLength": 600, @@ -1505,7 +1669,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 39 + "__id__": 40 }, "_enabled": true, "__prefab": null, @@ -1526,7 +1690,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 39 + "__id__": 40 }, "_enabled": true, "__prefab": null, @@ -1550,127 +1714,22 @@ "_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 + "__id__": 39 }, "_children": [ { - "__id__": 52 + "__id__": 53 } ], "_active": true, "_components": [ { - "__id__": 59 + "__id__": 60 } ], "_prefab": null, @@ -1707,23 +1766,23 @@ "_name": "VirtualJoystic", "_objFlags": 0, "_parent": { - "__id__": 51 + "__id__": 52 }, "_children": [ { - "__id__": 53 + "__id__": 54 } ], "_active": true, "_components": [ - { - "__id__": 56 - }, { "__id__": 57 }, { "__id__": 58 + }, + { + "__id__": 59 } ], "_prefab": null, @@ -1760,16 +1819,16 @@ "_name": "Knob", "_objFlags": 0, "_parent": { - "__id__": 52 + "__id__": 53 }, "_children": [], "_active": true, "_components": [ { - "__id__": 54 + "__id__": 55 }, { - "__id__": 55 + "__id__": 56 } ], "_prefab": null, @@ -1806,7 +1865,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 53 + "__id__": 54 }, "_enabled": true, "__prefab": null, @@ -1827,7 +1886,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 53 + "__id__": 54 }, "_enabled": true, "__prefab": null, @@ -1865,7 +1924,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 52 + "__id__": 53 }, "_enabled": true, "__prefab": null, @@ -1886,7 +1945,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 52 + "__id__": 53 }, "_enabled": true, "__prefab": null, @@ -1924,13 +1983,13 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 52 + "__id__": 53 }, "_enabled": true, "__prefab": null, "maxDistance": 50, "knob": { - "__id__": 53 + "__id__": 54 }, "_id": "50ceZG62tGlYXvZWEvSDKl" }, @@ -1939,7 +1998,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 51 + "__id__": 52 }, "_enabled": true, "__prefab": null, @@ -1955,6 +2014,440 @@ }, "_id": "6aEvduvntLK7qhBhdzIohI" }, + { + "__type__": "2e3934mbwxGZ64mwdThAm0I", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 39 + }, + "_enabled": true, + "__prefab": null, + "xpBar": { + "__id__": 49 + }, + "_id": "bau/7eItRFrKKoAZZb/uYL" + }, + { + "__type__": "cc.Node", + "_name": "Sprite", + "_objFlags": 0, + "_parent": { + "__id__": 38 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 63 + }, + { + "__id__": 64 + } + ], + "_prefab": null, + "_lpos": { + "__type__": "cc.Vec3", + "x": -422.023, + "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__": 62 + }, + "_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__": 62 + }, + "_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": "Sprite-001", + "_objFlags": 0, + "_parent": { + "__id__": 38 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 66 + }, + { + "__id__": 67 + } + ], + "_prefab": null, + "_lpos": { + "__type__": "cc.Vec3", + "x": 421.607, + "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": 1073741824, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "0bsPlR3A9BVLUEgdMPcMzQ" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 65 + }, + "_enabled": true, + "__prefab": null, + "_contentSize": { + "__type__": "cc.Size", + "width": 20, + "height": 20 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "35c186pjlJjZpcolGrBSLw" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 65 + }, + "_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": "a4SeBfquZKppCAYtapBI6G" + }, + { + "__type__": "cc.Node", + "_name": "Sprite-002", + "_objFlags": 0, + "_parent": { + "__id__": 38 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 69 + }, + { + "__id__": 70 + } + ], + "_prefab": null, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": 583.668, + "z": -1000 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0.7071067811865475, + "w": 0.7071067811865476 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 10, + "y": 100, + "z": 1 + }, + "_layer": 1073741824, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 90 + }, + "_id": "c4YoIxyxNNd4HAT0YfruY/" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 68 + }, + "_enabled": true, + "__prefab": null, + "_contentSize": { + "__type__": "cc.Size", + "width": 20, + "height": 20 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "03D5+XdJ1Eu5q0hhEBNAy2" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 68 + }, + "_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": "91rZOycgRB/q6qLN7CmHsX" + }, + { + "__type__": "cc.Node", + "_name": "Sprite-003", + "_objFlags": 0, + "_parent": { + "__id__": 38 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 72 + }, + { + "__id__": 73 + } + ], + "_prefab": null, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": -581.241, + "z": -1000 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0.7071067811865475, + "w": 0.7071067811865476 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 10, + "y": 100, + "z": 1 + }, + "_layer": 1073741824, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 90 + }, + "_id": "c3MvbHYdlAHomun1bzu9YB" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 71 + }, + "_enabled": true, + "__prefab": null, + "_contentSize": { + "__type__": "cc.Size", + "width": 20, + "height": 20 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "99+/imZNFLMbt5F9KEbob3" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 71 + }, + "_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": "c10GOwwXFMVLLPNmW6igZR" + }, { "__type__": "cc.Camera", "_name": "", @@ -2029,7 +2522,7 @@ "_enabled": true, "__prefab": null, "_cameraComponent": { - "__id__": 60 + "__id__": 74 }, "_alignCanvasWithScreen": true, "_id": "12O/ljcVlEqLmVm3U2gEOQ" @@ -2073,7 +2566,7 @@ "_enabled": true, "__prefab": null, "virtualJoystic": { - "__id__": 58 + "__id__": 59 }, "player": { "__id__": 30 @@ -2087,7 +2580,22 @@ "strikeDelay": 2, "collisionDelay": 0.5, "camera": { - "__id__": 60 + "__id__": 74 + }, + "requiredLevelXps": [ + 5, + 5, + 5, + 10, + 10, + 10, + 20, + 20, + 20, + 20 + ], + "gameUI": { + "__id__": 61 }, "_id": "3a9z1bqlFCGL4/WyDwU4L5" }, @@ -2098,19 +2606,19 @@ { "__type__": "cc.SceneGlobals", "ambient": { - "__id__": 67 + "__id__": 81 }, "shadows": { - "__id__": 68 + "__id__": 82 }, "_skybox": { - "__id__": 69 + "__id__": 83 }, "fog": { - "__id__": 70 + "__id__": 84 }, "octree": { - "__id__": 71 + "__id__": 85 } }, { diff --git a/assets/Scripts/Game/Collision/PlayerCollisionSystem.ts b/assets/Scripts/Game/Collision/PlayerCollisionSystem.ts index 173d7a4..8b3abee 100644 --- a/assets/Scripts/Game/Collision/PlayerCollisionSystem.ts +++ b/assets/Scripts/Game/Collision/PlayerCollisionSystem.ts @@ -65,7 +65,7 @@ export class PlayerCollisionSystem { private resolveXpContact(xpCollider: Collider2D): void { const xp: XP = xpCollider.node.getComponent(XP); - this.player.addXp(xp.Value); + this.player.Level.addXp(xp.Value); xp.pickup(); console.log("Collided with xp: " + xp); diff --git a/assets/Scripts/Game/Enemy/EnemyManager.ts b/assets/Scripts/Game/Enemy/EnemyManager.ts index ff5e8ef..2edd2e7 100644 --- a/assets/Scripts/Game/Enemy/EnemyManager.ts +++ b/assets/Scripts/Game/Enemy/EnemyManager.ts @@ -15,7 +15,7 @@ export class EnemyManager extends Component { public init(targetNode: Node): void { this.enemyMover = new EnemyMover(targetNode); - this.enemySpawner.init(); + this.enemySpawner.init(targetNode); this.enemySpawner.EnemyAddedEvent.on(this.onEnemyAdded, this); this.xpSpawner.init(); diff --git a/assets/Scripts/Game/Enemy/EnemySpawner.ts b/assets/Scripts/Game/Enemy/EnemySpawner.ts index f9e9e53..e18819e 100644 --- a/assets/Scripts/Game/Enemy/EnemySpawner.ts +++ b/assets/Scripts/Game/Enemy/EnemySpawner.ts @@ -1,4 +1,4 @@ -import { Component, Prefab, randomRange, Vec3, _decorator } from "cc"; +import { Component, Prefab, randomRange, Vec3, _decorator, Node } from "cc"; import { ISignal } from "../../Services/EventSystem/ISignal"; import { Signal } from "../../Services/EventSystem/Signal"; import { GameTimer } from "../../Services/GameTimer"; @@ -15,7 +15,10 @@ export class EnemySpawner extends Component { private enemyPool: ObjectPool; private spawnTimer: GameTimer; - public init(): void { + private targetNode: Node; + + public init(targetNode: Node): void { + this.targetNode = targetNode; this.enemyPool = new ObjectPool(this.enemies[0], this.node, 5, "Enemy"); this.spawnTimer = new GameTimer(1); } @@ -33,7 +36,10 @@ export class EnemySpawner extends Component { private spawnNewEnemy(): void { const enemy = this.enemyPool.borrow(); - enemy.setup(new Vec3(randomRange(0, 300), randomRange(0, 800))); + const spawnPosition = new Vec3(); + spawnPosition.x = this.targetNode.worldPosition.x + randomRange(-300, 300); + spawnPosition.y = this.targetNode.worldPosition.y + randomRange(-800, 800); + enemy.setup(spawnPosition); enemy.DeathEvent.on(this.returnEnemyToPool, this); diff --git a/assets/Scripts/Game/GameBootstrapper.ts b/assets/Scripts/Game/GameBootstrapper.ts index dcc00d8..f7fe60a 100644 --- a/assets/Scripts/Game/GameBootstrapper.ts +++ b/assets/Scripts/Game/GameBootstrapper.ts @@ -1,4 +1,4 @@ -import { Camera, CCFloat, Component, KeyCode, _decorator } from "cc"; +import { Camera, CCFloat, CCInteger, Component, KeyCode, _decorator } from "cc"; import { PlayerCollisionSystem } from "./Collision/PlayerCollisionSystem"; import { WeaponCollisionSystem } from "./Collision/WeaponCollisionSystem"; import { EnemyManager } from "./Enemy/EnemyManager"; @@ -6,6 +6,7 @@ import { KeyboardInput } from "./Input/KeyboardInput"; import { MultiInput } from "./Input/MultiInput"; import { VirtualJoystic } from "./Input/VirtualJoystic"; import { Player } from "./Player/Player"; +import { GameUI } from "./UI/GameUI"; import { Weapon } from "./Weapon"; const { ccclass, property } = _decorator; @@ -18,6 +19,8 @@ export class GameBootstrapper extends Component { @property(CCFloat) private strikeDelay = 0; @property(CCFloat) private collisionDelay = 0; @property(Camera) private camera: Camera; + @property(GameUI) private gameUI: GameUI; + @property(Number) private requiredLevelXps: number[] = []; private playerCollisionSystem: PlayerCollisionSystem; public start(): void { @@ -26,12 +29,14 @@ export class GameBootstrapper extends Component { const wasd = new KeyboardInput(KeyCode.KEY_W, KeyCode.KEY_S, KeyCode.KEY_A, KeyCode.KEY_D); const arrowKeys = new KeyboardInput(KeyCode.ARROW_UP, KeyCode.ARROW_DOWN, KeyCode.ARROW_LEFT, KeyCode.ARROW_RIGHT); const dualInput: MultiInput = new MultiInput([this.virtualJoystic, wasd, arrowKeys]); - this.player.init(dualInput, this.weapon, 50); + this.player.init(dualInput, this.weapon, 50, this.requiredLevelXps); this.playerCollisionSystem = new PlayerCollisionSystem(this.player, this.collisionDelay); new WeaponCollisionSystem(this.weapon); this.enemyManager.init(this.player.node); + + this.gameUI.init(this.player); } public update(deltaTime: number): void { diff --git a/assets/Scripts/Game/Player/Player.ts b/assets/Scripts/Game/Player/Player.ts index 1b19cca..4ea5eb1 100644 --- a/assets/Scripts/Game/Player/Player.ts +++ b/assets/Scripts/Game/Player/Player.ts @@ -3,6 +3,7 @@ import { IInput } from "../Input/IInput"; import { Weapon } from "../Weapon"; import { PlayerUI } from "./PlayerUI/PlayerUI"; import { UnitHealth } from "./UnitHealth"; +import { UnitLevel } from "./UnitLevel"; const { ccclass, property } = _decorator; @ccclass("Player") @@ -14,13 +15,15 @@ export class Player extends Component { private input: IInput; private weapon: Weapon; private health: UnitHealth; + private level: UnitLevel; private xp: number; - public init(input: IInput, weapon: Weapon, maxHp: number): void { + public init(input: IInput, weapon: Weapon, maxHp: number, requiredLevelXps: number[]): void { this.input = input; this.weapon = weapon; this.health = new UnitHealth(maxHp); + this.level = new UnitLevel(requiredLevelXps); this.weapon.node.parent = this.node; this.weapon.node.setPosition(new Vec3()); @@ -32,12 +35,12 @@ export class Player extends Component { return this.health; } - public get Collider(): Collider2D { - return this.collider; + public get Level(): UnitLevel { + return this.level; } - public addXp(points: number): void { - this.xp += points; + public get Collider(): Collider2D { + return this.collider; } public gameTick(deltaTime: number): void { diff --git a/assets/Scripts/Game/Player/UnitLevel.ts b/assets/Scripts/Game/Player/UnitLevel.ts new file mode 100644 index 0000000..c90e8b5 --- /dev/null +++ b/assets/Scripts/Game/Player/UnitLevel.ts @@ -0,0 +1,46 @@ +import { ISignal } from "../../Services/EventSystem/ISignal"; +import { Signal } from "../../Services/EventSystem/Signal"; + +export class UnitLevel { + private xp = 0; + private requiredXPs: number[]; + private currentLevel = 0; + private levelUpEvent: Signal = new Signal(); + private xpAddedEvent: Signal = new Signal(); + + public constructor(requiredXPs: number[]) { + this.requiredXPs = requiredXPs; + } + + public addXp(points: number): void { + this.xp += points; + this.xpAddedEvent.trigger(this.xp); + this.tryLevelUp(); + } + + public get XP(): number { + return this.xp; + } + + public get RequiredXP(): number { + return this.requiredXPs[this.currentLevel]; + } + + public get LevelUpEvent(): ISignal { + return this.levelUpEvent; + } + + public get XpAddedEvent(): ISignal { + return this.xpAddedEvent; + } + + private tryLevelUp(): void { + if (this.requiredXPs.length <= this.currentLevel) return; + if (this.xp < this.requiredXPs[this.currentLevel]) return; + + this.xp -= this.requiredXPs[this.currentLevel]; + this.currentLevel++; + + this.levelUpEvent.trigger(this.currentLevel); + } +} diff --git a/assets/Scripts/Game/Player/UnitLevel.ts.meta b/assets/Scripts/Game/Player/UnitLevel.ts.meta new file mode 100644 index 0000000..000207a --- /dev/null +++ b/assets/Scripts/Game/Player/UnitLevel.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "5eeabc4f-21b1-4983-b935-e44c12051766", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/Game/UI.meta b/assets/Scripts/Game/UI.meta new file mode 100644 index 0000000..23c3946 --- /dev/null +++ b/assets/Scripts/Game/UI.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "614dff3d-73df-4abb-8276-7931d2dc3596", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/assets/Scripts/Game/UI/GameUI.ts b/assets/Scripts/Game/UI/GameUI.ts new file mode 100644 index 0000000..446b999 --- /dev/null +++ b/assets/Scripts/Game/UI/GameUI.ts @@ -0,0 +1,22 @@ +import { Component, ProgressBar, _decorator } from "cc"; +import { Player } from "../Player/Player"; +import { UnitLevel } from "../Player/UnitLevel"; +const { ccclass, property } = _decorator; + +@ccclass("GameUI") +export class GameUI extends Component { + @property(ProgressBar) private xpBar: ProgressBar; + + private playerLevel: UnitLevel; + + public init(player: Player): void { + this.playerLevel = player.Level; + this.playerLevel.XpAddedEvent.on(this.updateProgressBar, this); + this.playerLevel.LevelUpEvent.on(this.updateProgressBar, this); + this.xpBar.progress = 0; + } + + private updateProgressBar(): void { + this.xpBar.progress = this.playerLevel.XP / this.playerLevel.RequiredXP; + } +} diff --git a/assets/Scripts/Game/UI/GameUI.ts.meta b/assets/Scripts/Game/UI/GameUI.ts.meta new file mode 100644 index 0000000..6792dc7 --- /dev/null +++ b/assets/Scripts/Game/UI/GameUI.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "2e393e26-6f0c-4667-ae26-c1d4e1026d08", + "files": [], + "subMetas": {}, + "userData": {} +}