new upgrades, restrucutre

This commit is contained in:
Martin 2022-11-28 11:49:16 +01:00
parent 4ca44647d6
commit 2a3ce76c4b
28 changed files with 1072 additions and 272 deletions

View File

@ -1,5 +1,5 @@
{ {
"playerSettings": { "player": {
"defaultHP": 50, "defaultHP": 50,
"requiredXP": [ "requiredXP": [
5, 5,
@ -13,12 +13,16 @@
20, 20,
20 20
], ],
"collisionDelay": 0.5, "collisionDelay": 0.5
"testSettings": {
"test": 0
}
}, },
"weaponSettings": { "weapon": {
"strikeDelay": 2 "strikeDelay": 2
},
"upgrades": {
"maxWeaponLengthUpgrades": 5,
"maxWeaponDamageUpgrades": 5,
"maxHorizontalProjectileUpgrades": 0,
"maxVerticalProjectileUpgrades": 0,
"maxRegenerationUpgrades": 0
} }
} }

View File

@ -169,7 +169,7 @@
"fileId": "5dR8969SVAfLXx5AY1X9B5" "fileId": "5dR8969SVAfLXx5AY1X9B5"
}, },
{ {
"__type__": "e6f96nAJ4NOs7RnNWxo20US", "__type__": "7f8b6NKHsNNW5nLY3fwejhw",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
@ -186,7 +186,7 @@
}, },
{ {
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "94XkV2AslIlKb4oyiOnsKv" "fileId": "b5ONKVkchBpaoqReE981lo"
}, },
{ {
"__type__": "cc.PrefabInfo", "__type__": "cc.PrefabInfo",

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
import { Collider2D, Contact2DType } from "cc"; import { Collider2D, Contact2DType } from "cc";
import { GroupType } from "../GroupType"; import { GroupType } from "../GroupType";
import { Player } from "../Player/Player"; import { Player } from "../Unit/Player/Player";
import { GameTimer } from "../../Services/GameTimer"; import { GameTimer } from "../../Services/GameTimer";
import { Enemy } from "../Enemy/Enemy"; import { Enemy } from "../Enemy/Enemy";
import { XP } from "../XP/XP"; import { XP } from "../XP/XP";

View File

@ -1,15 +1,15 @@
import { Collider2D, Contact2DType } from "cc"; import { Collider2D } from "cc";
import { Enemy } from "../Enemy/Enemy"; import { Enemy } from "../Enemy/Enemy";
import { Weapon } from "../Weapon"; import { Weapon } from "../Unit/Player/Weapon/Weapon";
export class WeaponCollisionSystem { export class WeaponCollisionSystem {
private weapon: Weapon; private weapon: Weapon;
public constructor(weapon: Weapon) { public constructor(weapon: Weapon) {
this.weapon = weapon; this.weapon = weapon;
weapon.Collider.on(Contact2DType.BEGIN_CONTACT, this.onWeaponContactBegin, this); weapon.Collider.ContactBeginEvent.on(this.onWeaponContactBegin, this);
} }
private onWeaponContactBegin(_selfCollider: Collider2D, otherCollider: Collider2D): void { private onWeaponContactBegin(otherCollider: Collider2D): void {
otherCollider.getComponent(Enemy).dealDamage(this.weapon.Damage); otherCollider.getComponent(Enemy).dealDamage(this.weapon.Damage);
} }
} }

View File

@ -1,6 +1,7 @@
export class GameSettings { export class GameSettings {
public playerSettings: PlayerSettings = new PlayerSettings(); public player: PlayerSettings = new PlayerSettings();
public weaponSettings: WeaponSettings = new WeaponSettings(); public weapon: WeaponSettings = new WeaponSettings();
public upgrades: UpgradeSettings = new UpgradeSettings();
} }
export class PlayerSettings { export class PlayerSettings {
@ -11,4 +12,13 @@ export class PlayerSettings {
export class WeaponSettings { export class WeaponSettings {
public strikeDelay = 0; public strikeDelay = 0;
public damage = 0;
}
export class UpgradeSettings {
public maxWeaponLengthUpgrades = 0;
public maxWeaponDamageUpgrades = 0;
public maxHorizontalProjectileUpgrades = 0;
public maxVerticalProjectileUpgrades = 0;
public maxRegenerationUpgrades = 0;
} }

View File

@ -2,7 +2,7 @@
"ver": "1.1.0", "ver": "1.1.0",
"importer": "directory", "importer": "directory",
"imported": true, "imported": true,
"uuid": "e71832fc-dfd7-409d-924d-f87037c811e4", "uuid": "baa05588-9899-4403-91b3-403907780c7a",
"files": [], "files": [],
"subMetas": {}, "subMetas": {},
"userData": { "userData": {

View File

@ -2,7 +2,7 @@
"ver": "4.0.23", "ver": "4.0.23",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "e6f969c0-2783-4eb3-b467-356c68db4512", "uuid": "7f8b634a-1ec3-4d5b-99cb-6377f07a3870",
"files": [], "files": [],
"subMetas": {}, "subMetas": {},
"userData": {} "userData": {}

View File

@ -2,7 +2,7 @@
"ver": "4.0.23", "ver": "4.0.23",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "c5416aed-64b1-426e-959b-bc7d5c745e76", "uuid": "839f4499-bc73-4115-a883-4a9322ea9389",
"files": [], "files": [],
"subMetas": {}, "subMetas": {},
"userData": {} "userData": {}

View File

@ -2,7 +2,7 @@
"ver": "4.0.23", "ver": "4.0.23",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "50aa2052-8c6f-4405-8732-346ac2a942c9", "uuid": "179f7bfa-44fc-4f41-9432-4aec4f3991a6",
"files": [], "files": [],
"subMetas": {}, "subMetas": {},
"userData": {} "userData": {}

View File

@ -2,7 +2,7 @@
"ver": "4.0.23", "ver": "4.0.23",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "8aa2a393-cd51-4bb4-a979-095e6fce95a9", "uuid": "7914ba19-6cca-4ee2-8231-baebd9eb559b",
"files": [], "files": [],
"subMetas": {}, "subMetas": {},
"userData": {} "userData": {}

View File

@ -1,4 +1,4 @@
import { Camera, CCFloat, CCInteger, Component, director, JsonAsset, KeyCode, _decorator } from "cc"; import { Camera, Component, JsonAsset, KeyCode, _decorator } from "cc";
import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager"; import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager";
import { PlayerCollisionSystem } from "./Collision/PlayerCollisionSystem"; import { PlayerCollisionSystem } from "./Collision/PlayerCollisionSystem";
import { WeaponCollisionSystem } from "./Collision/WeaponCollisionSystem"; import { WeaponCollisionSystem } from "./Collision/WeaponCollisionSystem";
@ -10,10 +10,10 @@ import { VirtualJoystic } from "./Input/VirtualJoystic";
import { GameModalLauncher } from "./ModalWIndows/GameModalLauncher"; import { GameModalLauncher } from "./ModalWIndows/GameModalLauncher";
import { Pauser } from "./Pauser"; import { Pauser } from "./Pauser";
import { Player } from "./Player/Player"; import { Player } from "./Player/Player";
import { Weapon } from "./Player/Weapon/Weapon";
import { GameUI } from "./UI/GameUI"; import { GameUI } from "./UI/GameUI";
import { Upgrader } from "./Upgrades/Upgrader"; import { Upgrader } from "./Upgrades/Upgrader";
import { UpgradeType } from "./Upgrades/UpgradeType";
import { Weapon } from "./Weapon";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass("GameBootstrapper") @ccclass("GameBootstrapper")
@ -32,19 +32,19 @@ export class GameBootstrapper extends Component {
private gamePauser: Pauser = new Pauser(); private gamePauser: Pauser = new Pauser();
public start(): void { public start(): void {
const gameSettings: GameSettings = <GameSettings>this.settingsAsset.json; const settings: GameSettings = <GameSettings>this.settingsAsset.json;
this.virtualJoystic.init(); this.virtualJoystic.init();
this.weapon.init(gameSettings.weaponSettings.strikeDelay); this.weapon.init(settings.weapon);
const wasd = new KeyboardInput(KeyCode.KEY_W, KeyCode.KEY_S, KeyCode.KEY_A, KeyCode.KEY_D); 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 arrowKeys = new KeyboardInput(KeyCode.ARROW_UP, KeyCode.ARROW_DOWN, KeyCode.ARROW_LEFT, KeyCode.ARROW_RIGHT);
const dualInput: MultiInput = new MultiInput([this.virtualJoystic, wasd, arrowKeys]); const dualInput: MultiInput = new MultiInput([this.virtualJoystic, wasd, arrowKeys]);
this.player.init(dualInput, this.weapon, gameSettings.playerSettings.defaultHP, gameSettings.playerSettings.requiredXP); this.player.init(dualInput, this.weapon, settings.player.defaultHP, settings.player.requiredXP);
this.playerCollisionSystem = new PlayerCollisionSystem(this.player, gameSettings.playerSettings.collisionDelay); this.playerCollisionSystem = new PlayerCollisionSystem(this.player, settings.player.collisionDelay);
new WeaponCollisionSystem(this.weapon); new WeaponCollisionSystem(this.weapon);
const upgrader = new Upgrader(this.player); const upgrader = new Upgrader(this.player, settings.upgrades);
new GameModalLauncher(this.modalWindowManager, this.player, this.gamePauser, upgrader); new GameModalLauncher(this.modalWindowManager, this.player, this.gamePauser, upgrader);
this.enemyManager.init(this.player.node); this.enemyManager.init(this.player.node);

View File

@ -1,6 +1,6 @@
import { ModalWindowManager } from "../../Services/ModalWindowSystem/ModalWindowManager"; import { ModalWindowManager } from "../../Services/ModalWindowSystem/ModalWindowManager";
import { Pauser } from "../Pauser"; import { Pauser } from "../Pauser";
import { Player } from "../Player/Player"; import { Player } from "../Unit/Player/Player";
import { Upgrader } from "../Upgrades/Upgrader"; import { Upgrader } from "../Upgrades/Upgrader";
import { UpgradeType } from "../Upgrades/UpgradeType"; import { UpgradeType } from "../Upgrades/UpgradeType";
import { GameModalWindowTypes } from "./GameModalWindowTypes"; import { GameModalWindowTypes } from "./GameModalWindowTypes";

View File

@ -2,7 +2,7 @@
"ver": "1.1.0", "ver": "1.1.0",
"importer": "directory", "importer": "directory",
"imported": true, "imported": true,
"uuid": "3697ba4f-16f0-4a2d-9330-47c472df973a", "uuid": "3c590530-b416-4184-9b87-f87755610708",
"files": [], "files": [],
"subMetas": {}, "subMetas": {},
"userData": { "userData": {

View File

@ -2,7 +2,7 @@
"ver": "1.1.0", "ver": "1.1.0",
"importer": "directory", "importer": "directory",
"imported": true, "imported": true,
"uuid": "82d14029-0ea6-4de6-b796-05339d2d19b1", "uuid": "7eadb488-192c-4370-9e59-20f27929fba1",
"files": [], "files": [],
"subMetas": {}, "subMetas": {},
"userData": { "userData": {

View File

@ -2,7 +2,7 @@
"ver": "4.0.23", "ver": "4.0.23",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "84a1c057-2ef8-4ead-8903-5753f36ac735", "uuid": "def45aaf-cc88-4ec6-97ff-4d5b0beb015b",
"files": [], "files": [],
"subMetas": {}, "subMetas": {},
"userData": {} "userData": {}

View File

@ -2,7 +2,7 @@
"ver": "4.0.23", "ver": "4.0.23",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "634f676f-c335-42a2-85e8-f214e9ce5eb7", "uuid": "6247f0de-45c1-4e74-89aa-388c217ce3a3",
"files": [], "files": [],
"subMetas": {}, "subMetas": {},
"userData": {} "userData": {}

View File

@ -2,7 +2,7 @@
"ver": "4.0.23", "ver": "4.0.23",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "8118806a-dc7c-4e94-84c2-b0a95be43209", "uuid": "14972f1d-8009-4d39-8a6f-553ae1b3a011",
"files": [], "files": [],
"subMetas": {}, "subMetas": {},
"userData": {} "userData": {}

View File

@ -2,7 +2,7 @@
"ver": "4.0.23", "ver": "4.0.23",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "5eeabc4f-21b1-4983-b935-e44c12051766", "uuid": "61e76d1e-15a8-42cc-990d-b9c7848ddab3",
"files": [], "files": [],
"subMetas": {}, "subMetas": {},
"userData": {} "userData": {}

View File

@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "b232195c-46e2-4508-9f71-5efb42ab490f",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@ -0,0 +1,43 @@
import { BoxCollider2D, Collider2D, Component, Contact2DType, _decorator } from "cc";
import { ISignal } from "../../../Services/EventSystem/ISignal";
import { Signal } from "../../../Services/EventSystem/Signal";
const { ccclass, property } = _decorator;
@ccclass("UpgradableCollider")
export class UpgradableCollider extends Component {
@property(BoxCollider2D) private colliders: BoxCollider2D[] = [];
private contactBeginEvent: Signal<Collider2D> = new Signal<Collider2D>();
private currentUpgradeLevel = 0;
public init(): void {
this.setUpgradeLevel();
for (const collider of this.colliders) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onColliderContactBegin, this);
}
}
public get ContactBeginEvent(): ISignal<Collider2D> {
return this.contactBeginEvent;
}
public upgrade(): void {
if (this.currentUpgradeLevel == this.colliders.length - 1) throw new Error("Already at max upgrade! " + this.currentUpgradeLevel);
this.currentUpgradeLevel++;
this.setUpgradeLevel();
}
private setUpgradeLevel(): void {
for (const collider of this.colliders) {
collider.node.active = false;
}
this.colliders[this.currentUpgradeLevel].node.active = true;
}
private onColliderContactBegin(thisCollider: Collider2D, otherCollider: Collider2D): void {
this.contactBeginEvent.trigger(otherCollider);
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "bba49b00-3fe5-4042-85f3-7d1f017d75d3",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -1,22 +1,29 @@
import { Animation, AnimationState, BoxCollider2D, Collider2D, Component, _decorator } from "cc"; import { Animation, AnimationState, Component, _decorator } from "cc";
import { GameTimer } from "../Services/GameTimer"; import { GameTimer } from "../../../Services/GameTimer";
import { WeaponSettings } from "../../Data/GameSettings";
import { UpgradableCollider } from "./UpgradableCollider";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass("Weapon") @ccclass("Weapon")
export class Weapon extends Component { export class Weapon extends Component {
@property(Animation) private weaponAnimation: Animation; @property(Animation) private weaponAnimation: Animation;
@property(BoxCollider2D) private collider: BoxCollider2D; @property(UpgradableCollider) private upgradableCollider: UpgradableCollider;
private strikeTimer: GameTimer; private strikeTimer: GameTimer;
private strikeState: AnimationState; private strikeState: AnimationState;
private damage: number;
public init(strikeDelay: number): void { public init(settings: WeaponSettings): void {
this.strikeTimer = new GameTimer(strikeDelay); this.strikeTimer = new GameTimer(settings.strikeDelay);
this.damage = settings.damage;
this.node.active = false; this.node.active = false;
this.weaponAnimation.on(Animation.EventType.FINISHED, this.endStrike, this); this.weaponAnimation.on(Animation.EventType.FINISHED, this.endStrike, this);
this.strikeState = this.weaponAnimation.getState(this.weaponAnimation.clips[0].name); this.strikeState = this.weaponAnimation.getState(this.weaponAnimation.clips[0].name);
this.strikeState.speed = 1; this.strikeState.speed = 1;
this.upgradableCollider.init();
} }
public gameTick(deltaTime: number): void { public gameTick(deltaTime: number): void {
@ -26,16 +33,20 @@ export class Weapon extends Component {
} }
} }
public get Collider(): Collider2D { public get Collider(): UpgradableCollider {
return this.collider; return this.upgradableCollider;
} }
public get Damage(): number { public get Damage(): number {
return 5; return this.damage;
} }
public upgradeWeaponDamage(): void {} public upgradeWeaponDamage(): void {
public upgradeWeaponLength(): void {} this.damage++;
}
public upgradeWeaponLength(): void {
this.upgradableCollider.upgrade();
}
private strike(): void { private strike(): void {
this.node.active = true; this.node.active = true;

View File

@ -1,6 +1,6 @@
import { Component, ProgressBar, _decorator } from "cc"; import { Component, ProgressBar, _decorator } from "cc";
import { Player } from "../Player/Player"; import { Player } from "../Unit/Player/Player";
import { UnitLevel } from "../Player/UnitLevel"; import { UnitLevel } from "../Unit/Player/UnitLevel";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass("GameUI") @ccclass("GameUI")

View File

@ -31,7 +31,7 @@ export class LevelUpModalWindow extends ModalWindow<UpgradeType[], UpgradeType>
} }
} }
private chooseSkill(skill: LevelUpSkill): void { private chooseSkill(upgradeType: UpgradeType): void {
this.dismiss(UpgradeType.WeaponDamage); this.dismiss(upgradeType);
} }
} }

View File

@ -7,17 +7,20 @@ const { ccclass, property } = _decorator;
@ccclass("LevelUpSkill") @ccclass("LevelUpSkill")
export class LevelUpSkill extends Component { export class LevelUpSkill extends Component {
@property(Label) private skillTitle: Label; @property(Label) private skillTitle: Label;
private chooseSkillEvent: Signal<LevelUpSkill> = new Signal<LevelUpSkill>(); private chooseSkillEvent: Signal<UpgradeType> = new Signal<UpgradeType>();
private skillType: UpgradeType;
public init(skillType: UpgradeType): void { public init(skillType: UpgradeType): void {
this.skillType = skillType;
this.skillTitle.string = `Skill ${skillType}`; this.skillTitle.string = `Skill ${skillType}`;
this.node.on(NodeEventType.MOUSE_DOWN, this.chooseSkill, this); this.node.on(NodeEventType.MOUSE_DOWN, this.chooseSkill, this);
} }
public get ChooseSkillEvent(): ISignal<LevelUpSkill> { public get ChooseSkillEvent(): ISignal<UpgradeType> {
return this.chooseSkillEvent; return this.chooseSkillEvent;
} }
private chooseSkill(): void { private chooseSkill(): void {
this.chooseSkillEvent.trigger(this); this.chooseSkillEvent.trigger(this.skillType);
} }
} }

View File

@ -1,4 +1,5 @@
import { Player } from "../Player/Player"; import { UpgradeSettings } from "../Data/GameSettings";
import { Player } from "../Unit/Player/Player";
import { UpgradeType } from "./UpgradeType"; import { UpgradeType } from "./UpgradeType";
export class Upgrader { export class Upgrader {
@ -7,18 +8,20 @@ export class Upgrader {
private typeToLevel: Map<UpgradeType, number> = new Map<UpgradeType, number>(); private typeToLevel: Map<UpgradeType, number> = new Map<UpgradeType, number>();
private typeToMaxLevel: Map<UpgradeType, number> = new Map<UpgradeType, number>(); private typeToMaxLevel: Map<UpgradeType, number> = new Map<UpgradeType, number>();
public constructor(player: Player) { public constructor(player: Player, settings: UpgradeSettings) {
this.player = player; this.player = player;
this.setTypeMaps(UpgradeType.WeaponLength, this.upgradeWeaponLength, 5); this.setTypeMaps(UpgradeType.WeaponLength, this.upgradeWeaponLength.bind(this), settings.maxWeaponLengthUpgrades);
this.setTypeMaps(UpgradeType.WeaponDamage, this.upgradeWeaponDamage, 5); this.setTypeMaps(UpgradeType.WeaponDamage, this.upgradeWeaponDamage, settings.maxWeaponDamageUpgrades);
} }
public upgradeSkill(type: UpgradeType): void { public upgradeSkill(type: UpgradeType): void {
if (!this.typeToAction.has(type)) throw new Error("Upgrade does not have " + type); if (!this.typeToAction.has(type)) throw new Error("Upgrade does not have " + type);
if (this.isMaxLevel(type)) throw new Error("Upgrade is already at max level" + type); if (this.isMaxLevel(type)) throw new Error("Upgrade is already at max level " + type);
this.typeToAction.get(type)(); this.typeToAction.get(type)();
const level: number = this.typeToLevel.get(type);
this.typeToLevel.set(type, level + 1);
} }
public getAvailableUpgrades(): Set<UpgradeType> { public getAvailableUpgrades(): Set<UpgradeType> {