mirror of
https://github.com/Sheldan/canvas.git
synced 2026-01-16 03:36:25 +00:00
survivors: split between base stats, temp stats and effective stats for players
changed the way how stats are increased/decreased moving stats/status into separate files
This commit is contained in:
@@ -3,9 +3,11 @@ import {fillDot, moveInDirectionOf} from "./utils.ts";
|
||||
import {Vector} from "./base.ts";
|
||||
import {World} from "./World.ts";
|
||||
import type {Projectile} from "./projectile.ts";
|
||||
import {ProjectileStats, StraightProjectile} from "./projectile.ts";
|
||||
import {StraightProjectile} from "./projectile.ts";
|
||||
import {HealthPack, ItemDrop, LevelDrop, MoneyDrop} from "./drop.ts";
|
||||
import {ItemManagement} from "./items.ts";
|
||||
import {ProjectileStats} from "./stats.ts";
|
||||
import {EnemyStatus} from "./status.ts";
|
||||
|
||||
export abstract class Enemy implements Placeable, Drawable, Acting, Healthy {
|
||||
protected _position: Vector;
|
||||
@@ -165,24 +167,6 @@ export class ShootingEnemy extends BasicEnemy implements Shooting {
|
||||
}
|
||||
}
|
||||
|
||||
export class EnemyStatus {
|
||||
constructor(private _health: number) {
|
||||
}
|
||||
|
||||
|
||||
get health(): number {
|
||||
return this._health;
|
||||
}
|
||||
|
||||
get dead(): boolean {
|
||||
return this._health <= 0;
|
||||
}
|
||||
|
||||
set health(value: number) {
|
||||
this._health = value;
|
||||
}
|
||||
}
|
||||
|
||||
export class HealthEnemy extends Enemy {
|
||||
|
||||
constructor(position: Vector) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type {Acting, Drawable, Healthy, Item, Leveling, Weapon} from "./interfaces.ts";
|
||||
import type {Acting, Drawable, Healthy, Item, Weapon} from "./interfaces.ts";
|
||||
import {Vector} from "./base.ts";
|
||||
import {fillDot, getCoordinatesSplit} from "./utils.ts";
|
||||
import {PlayerStats} from "./stats.ts";
|
||||
import {PlayerStatus} from "./status.ts";
|
||||
|
||||
export class Player implements Drawable, Acting, Healthy {
|
||||
private _position: Vector;
|
||||
@@ -143,143 +145,3 @@ export class Player implements Drawable, Acting, Healthy {
|
||||
}
|
||||
}
|
||||
|
||||
export class PlayerStatus {
|
||||
constructor(private _health: number,
|
||||
private _wealth: number,
|
||||
private _level: number) {
|
||||
}
|
||||
|
||||
|
||||
get level(): number {
|
||||
return this._level;
|
||||
}
|
||||
|
||||
set level(value: number) {
|
||||
this._level = value;
|
||||
}
|
||||
|
||||
get health(): number {
|
||||
return this._health;
|
||||
}
|
||||
|
||||
set health(value: number) {
|
||||
this._health = value;
|
||||
}
|
||||
|
||||
get dead(): boolean {
|
||||
return this._health <= 0
|
||||
}
|
||||
|
||||
get wealth(): number {
|
||||
return this._wealth;
|
||||
}
|
||||
|
||||
set wealth(value: number) {
|
||||
this._wealth = value;
|
||||
}
|
||||
|
||||
increaseLevel() {
|
||||
this._level += 1
|
||||
}
|
||||
}
|
||||
|
||||
export class PlayerStats {
|
||||
|
||||
private _speed: number;
|
||||
private _size: number;
|
||||
private _health: number;
|
||||
private _pullRange: number;
|
||||
private _weaponRange: number;
|
||||
private _weaponRangeFactor: number;
|
||||
|
||||
constructor() {
|
||||
this._speed = 3;
|
||||
this._size = 5;
|
||||
this._health = 10;
|
||||
this._pullRange = 150;
|
||||
this._weaponRange = 250;
|
||||
this._weaponRangeFactor = 1;
|
||||
}
|
||||
|
||||
resetToBasic() {
|
||||
this._speed = 0;
|
||||
this._health = 0;
|
||||
this._pullRange = 0;
|
||||
this._weaponRange = 0;
|
||||
this._weaponRangeFactor = 1
|
||||
}
|
||||
|
||||
increaseLevel() {
|
||||
this._speed *= 1.1;
|
||||
this._health += 1
|
||||
this._pullRange *= 1.1;
|
||||
this._weaponRange *= 1.25
|
||||
this._weaponRangeFactor += 0.1
|
||||
}
|
||||
|
||||
mergeStats(otherStats: PlayerStats) {
|
||||
this._speed += otherStats._speed;
|
||||
this._health += otherStats._health;
|
||||
this._pullRange += otherStats._pullRange;
|
||||
this._weaponRange += otherStats._weaponRange
|
||||
this._weaponRangeFactor += otherStats._weaponRangeFactor;
|
||||
}
|
||||
|
||||
clone() {
|
||||
let newStats = new PlayerStats();
|
||||
newStats.mergeStats(this)
|
||||
return newStats;
|
||||
}
|
||||
|
||||
changeStat(value: number, statFun: (stats: PlayerStats, value: number) => void) {
|
||||
statFun(this, value)
|
||||
}
|
||||
|
||||
static increaseSpeed(stats: PlayerStats, value: number) {
|
||||
stats._speed += value
|
||||
}
|
||||
|
||||
static factorSpeed(stats: PlayerStats, value: number) {
|
||||
stats._speed *= value
|
||||
}
|
||||
|
||||
static increasePullRange(stats: PlayerStats, value: number) {
|
||||
stats._pullRange += value
|
||||
}
|
||||
|
||||
static factorPullRange(stats: PlayerStats, value: number) {
|
||||
stats._pullRange += value
|
||||
}
|
||||
|
||||
static increaseHealth(stats: PlayerStats, value: number) {
|
||||
stats._health += value
|
||||
}
|
||||
|
||||
get speed(): number {
|
||||
return this._speed;
|
||||
}
|
||||
|
||||
get size(): number {
|
||||
return this._size;
|
||||
}
|
||||
|
||||
get pullRange(): number {
|
||||
return this._pullRange;
|
||||
}
|
||||
|
||||
get health(): number {
|
||||
return this._health;
|
||||
}
|
||||
|
||||
get weaponRange(): number {
|
||||
return this._weaponRange
|
||||
}
|
||||
|
||||
get effectiveWeaponRange(): number {
|
||||
return this._weaponRange * this._weaponRangeFactor;
|
||||
}
|
||||
|
||||
public static defaultPlayerStats(): PlayerStats {
|
||||
return new PlayerStats();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import type {Acting, Placeable, Healthy, Weapon} from "./interfaces.ts";
|
||||
import type {Acting, Placeable, Healthy } from "./interfaces.ts";
|
||||
import type {Vector} from "./base.ts";
|
||||
import {World} from "./World.ts";
|
||||
import {Cooldown, DeadPoint, Point, Vector} from "./base.ts";
|
||||
import {DeadPoint, Vector} from "./base.ts";
|
||||
import {
|
||||
circleLineCollision,
|
||||
fillDot,
|
||||
@@ -14,6 +14,8 @@ import {
|
||||
import {InstanceOfUtils} from "./instance.ts";
|
||||
import {ChainBall, MeleeWeapon} from "./weapons.ts";
|
||||
import type {Enemy} from "./Enemies.ts";
|
||||
import {ProjectileStats} from "./stats.ts";
|
||||
import {ProjectileStatus} from "./status.ts";
|
||||
|
||||
export abstract class Projectile implements Acting, Placeable {
|
||||
|
||||
@@ -322,100 +324,3 @@ export class HomingProjectile extends Projectile {
|
||||
}
|
||||
}
|
||||
|
||||
export class ProjectileStatus {
|
||||
private _piercingsLeft: number;
|
||||
private _collisionCooldown: Cooldown;
|
||||
|
||||
constructor(piercingsLeft: number) {
|
||||
this._piercingsLeft = piercingsLeft;
|
||||
this._collisionCooldown = new Cooldown(10)
|
||||
}
|
||||
|
||||
get piercingsLeft(): number {
|
||||
return this._piercingsLeft;
|
||||
}
|
||||
|
||||
hasPiercingLeft(): boolean {
|
||||
return this.piercingsLeft > 0;
|
||||
}
|
||||
|
||||
|
||||
get collisionCooldown(): Cooldown {
|
||||
return this._collisionCooldown;
|
||||
}
|
||||
|
||||
decreasePiercings() {
|
||||
this._piercingsLeft -= 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class ProjectileStats {
|
||||
|
||||
private _piercings: number;
|
||||
private _size: number;
|
||||
private _damage: number;
|
||||
private _speed: number;
|
||||
private _deathSplit: number;
|
||||
private _deathSplitChance: number;
|
||||
|
||||
constructor() {
|
||||
this._size = 1
|
||||
}
|
||||
|
||||
withPiercings(value: number) {
|
||||
this._piercings = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
withSize(value: number) {
|
||||
this._size = Math.max(value, 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
withDamage(value: number) {
|
||||
this._damage = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
withSpeed(value: number) {
|
||||
this._speed = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
withDeathSplit(value: number) {
|
||||
this._deathSplit = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
withDeathSplitChance(value: number) {
|
||||
this._deathSplitChance = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
get piercings(): number {
|
||||
return this._piercings;
|
||||
}
|
||||
|
||||
get size(): number {
|
||||
return this._size;
|
||||
}
|
||||
|
||||
|
||||
get speed(): number {
|
||||
return this._speed;
|
||||
}
|
||||
|
||||
get damage(): number {
|
||||
return this._damage;
|
||||
}
|
||||
|
||||
|
||||
get deathSplitChance(): number {
|
||||
return this._deathSplitChance;
|
||||
}
|
||||
|
||||
get deathSplit(): number {
|
||||
return this._deathSplit;
|
||||
}
|
||||
}
|
||||
172
absurd-survivors/src/stats.ts
Normal file
172
absurd-survivors/src/stats.ts
Normal file
@@ -0,0 +1,172 @@
|
||||
|
||||
export class PlayerStats {
|
||||
|
||||
private _speed: number;
|
||||
private _size: number;
|
||||
private _health: number;
|
||||
private _pullRange: number;
|
||||
private _weaponRange: number;
|
||||
private _weaponRangeFactor: number;
|
||||
|
||||
constructor() {
|
||||
this._speed = 3;
|
||||
this._size = 5;
|
||||
this._health = 10;
|
||||
this._pullRange = 150;
|
||||
this._weaponRange = 250;
|
||||
this._weaponRangeFactor = 1;
|
||||
}
|
||||
|
||||
resetToBasic() {
|
||||
this._speed = 0;
|
||||
this._health = 0;
|
||||
this._pullRange = 0;
|
||||
this._weaponRange = 0;
|
||||
this._weaponRangeFactor = 1
|
||||
}
|
||||
|
||||
increaseLevel() {
|
||||
this._speed *= 1.1;
|
||||
this._health += 1
|
||||
this._pullRange *= 1.1;
|
||||
this._weaponRange *= 1.25
|
||||
this._weaponRangeFactor += 0.1
|
||||
}
|
||||
|
||||
mergeStats(otherStats: PlayerStats) {
|
||||
this._speed += otherStats._speed;
|
||||
this._health += otherStats._health;
|
||||
this._pullRange += otherStats._pullRange;
|
||||
this._weaponRange += otherStats._weaponRange
|
||||
this._weaponRangeFactor += otherStats._weaponRangeFactor;
|
||||
}
|
||||
|
||||
clone() {
|
||||
let newStats = new PlayerStats();
|
||||
newStats.mergeStats(this)
|
||||
return newStats;
|
||||
}
|
||||
|
||||
changeStat(value: number, statFun: (stats: PlayerStats, value: number) => void) {
|
||||
statFun(this, value)
|
||||
}
|
||||
|
||||
static increaseSpeed(stats: PlayerStats, value: number) {
|
||||
stats._speed += value
|
||||
}
|
||||
|
||||
static factorSpeed(stats: PlayerStats, value: number) {
|
||||
stats._speed *= value
|
||||
}
|
||||
|
||||
static increasePullRange(stats: PlayerStats, value: number) {
|
||||
stats._pullRange += value
|
||||
}
|
||||
|
||||
static factorPullRange(stats: PlayerStats, value: number) {
|
||||
stats._pullRange += value
|
||||
}
|
||||
|
||||
static increaseHealth(stats: PlayerStats, value: number) {
|
||||
stats._health += value
|
||||
}
|
||||
|
||||
get speed(): number {
|
||||
return this._speed;
|
||||
}
|
||||
|
||||
get size(): number {
|
||||
return this._size;
|
||||
}
|
||||
|
||||
get pullRange(): number {
|
||||
return this._pullRange;
|
||||
}
|
||||
|
||||
get health(): number {
|
||||
return this._health;
|
||||
}
|
||||
|
||||
get weaponRange(): number {
|
||||
return this._weaponRange
|
||||
}
|
||||
|
||||
get effectiveWeaponRange(): number {
|
||||
return this._weaponRange * this._weaponRangeFactor;
|
||||
}
|
||||
|
||||
public static defaultPlayerStats(): PlayerStats {
|
||||
return new PlayerStats();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class ProjectileStats {
|
||||
|
||||
private _piercings: number;
|
||||
private _size: number;
|
||||
private _damage: number;
|
||||
private _speed: number;
|
||||
private _deathSplit: number;
|
||||
private _deathSplitChance: number;
|
||||
|
||||
constructor() {
|
||||
this._size = 1
|
||||
}
|
||||
|
||||
withPiercings(value: number) {
|
||||
this._piercings = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
withSize(value: number) {
|
||||
this._size = Math.max(value, 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
withDamage(value: number) {
|
||||
this._damage = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
withSpeed(value: number) {
|
||||
this._speed = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
withDeathSplit(value: number) {
|
||||
this._deathSplit = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
withDeathSplitChance(value: number) {
|
||||
this._deathSplitChance = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
get piercings(): number {
|
||||
return this._piercings;
|
||||
}
|
||||
|
||||
get size(): number {
|
||||
return this._size;
|
||||
}
|
||||
|
||||
|
||||
get speed(): number {
|
||||
return this._speed;
|
||||
}
|
||||
|
||||
get damage(): number {
|
||||
return this._damage;
|
||||
}
|
||||
|
||||
|
||||
get deathSplitChance(): number {
|
||||
return this._deathSplitChance;
|
||||
}
|
||||
|
||||
get deathSplit(): number {
|
||||
return this._deathSplit;
|
||||
}
|
||||
}
|
||||
88
absurd-survivors/src/status.ts
Normal file
88
absurd-survivors/src/status.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import {Cooldown} from "./base.ts";
|
||||
|
||||
export class PlayerStatus {
|
||||
constructor(private _health: number,
|
||||
private _wealth: number,
|
||||
private _level: number) {
|
||||
}
|
||||
|
||||
|
||||
get level(): number {
|
||||
return this._level;
|
||||
}
|
||||
|
||||
set level(value: number) {
|
||||
this._level = value;
|
||||
}
|
||||
|
||||
get health(): number {
|
||||
return this._health;
|
||||
}
|
||||
|
||||
set health(value: number) {
|
||||
this._health = value;
|
||||
}
|
||||
|
||||
get dead(): boolean {
|
||||
return this._health <= 0
|
||||
}
|
||||
|
||||
get wealth(): number {
|
||||
return this._wealth;
|
||||
}
|
||||
|
||||
set wealth(value: number) {
|
||||
this._wealth = value;
|
||||
}
|
||||
|
||||
increaseLevel() {
|
||||
this._level += 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class EnemyStatus {
|
||||
constructor(private _health: number) {
|
||||
}
|
||||
|
||||
|
||||
get health(): number {
|
||||
return this._health;
|
||||
}
|
||||
|
||||
get dead(): boolean {
|
||||
return this._health <= 0;
|
||||
}
|
||||
|
||||
set health(value: number) {
|
||||
this._health = value;
|
||||
}
|
||||
}
|
||||
|
||||
export class ProjectileStatus {
|
||||
private _piercingsLeft: number;
|
||||
private _collisionCooldown: Cooldown;
|
||||
|
||||
constructor(piercingsLeft: number) {
|
||||
this._piercingsLeft = piercingsLeft;
|
||||
this._collisionCooldown = new Cooldown(10)
|
||||
}
|
||||
|
||||
get piercingsLeft(): number {
|
||||
return this._piercingsLeft;
|
||||
}
|
||||
|
||||
hasPiercingLeft(): boolean {
|
||||
return this.piercingsLeft > 0;
|
||||
}
|
||||
|
||||
|
||||
get collisionCooldown(): Cooldown {
|
||||
return this._collisionCooldown;
|
||||
}
|
||||
|
||||
decreasePiercings() {
|
||||
this._piercingsLeft -= 1;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user