mirror of
https://github.com/Sheldan/canvas.git
synced 2026-06-16 23:23:45 +00:00
survivors: moving more abilities to RangeWeapon
This commit is contained in:
@@ -45,22 +45,14 @@ export abstract class BasicWeapon implements Weapon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RangeWeapon extends BasicWeapon {
|
export abstract class RangeWeapon extends BasicWeapon {
|
||||||
calculateRange(): number {
|
|
||||||
return this.world.player.stats.effectiveWeaponRange + this.stats.effectiveWeaponRange;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class HomingPistol extends RangeWeapon {
|
protected projectiles: [Projectile] = []
|
||||||
|
protected shootInterval: number;
|
||||||
|
protected shootCooldown: number = 0;
|
||||||
|
|
||||||
private shootInterval: number;
|
|
||||||
private shootCooldown: number = 0;
|
|
||||||
|
|
||||||
private projectiles: [Projectile] = []
|
abstract createProjectile(): boolean;
|
||||||
|
|
||||||
draw(ctx: CanvasRenderingContext2D) {
|
|
||||||
drawDot(this.getPosition(), 1, this.color, ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
act() {
|
act() {
|
||||||
if(this.shootCooldown <= 0) {
|
if(this.shootCooldown <= 0) {
|
||||||
@@ -71,7 +63,18 @@ export class HomingPistol extends RangeWeapon {
|
|||||||
this.shootCooldown -= 1;
|
this.shootCooldown -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private createProjectile(): boolean {
|
calculateRange(): number {
|
||||||
|
return this.world.player.stats.effectiveWeaponRange + this.stats.effectiveWeaponRange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class HomingPistol extends RangeWeapon {
|
||||||
|
|
||||||
|
draw(ctx: CanvasRenderingContext2D) {
|
||||||
|
drawDot(this.getPosition(), 1, this.color, ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
createProjectile(): boolean {
|
||||||
let range = this.calculateRange()
|
let range = this.calculateRange()
|
||||||
let closestTargetTo = this.world.getClosestTargetTo(this.world.player.position, range);
|
let closestTargetTo = this.world.getClosestTargetTo(this.world.player.position, range);
|
||||||
if(closestTargetTo !== undefined && closestTargetTo[1] !== undefined) {
|
if(closestTargetTo !== undefined && closestTargetTo[1] !== undefined) {
|
||||||
@@ -109,15 +112,6 @@ export class Pistol extends RangeWeapon {
|
|||||||
drawDot(this.getPosition(), 1, this.color, ctx)
|
drawDot(this.getPosition(), 1, this.color, ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
act() {
|
|
||||||
if(this.shootCooldown <= 0) {
|
|
||||||
if(this.createProjectile()) {
|
|
||||||
this.shootCooldown = this.shootInterval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.shootCooldown -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private createProjectile(): boolean {
|
private createProjectile(): boolean {
|
||||||
let range = this.calculateRange()
|
let range = this.calculateRange()
|
||||||
let closestTargetTo = this.world.getClosestTargetTo(this.world.player.position, range);
|
let closestTargetTo = this.world.getClosestTargetTo(this.world.player.position, range);
|
||||||
|
|||||||
Reference in New Issue
Block a user