mirror of
https://github.com/Sheldan/canvas.git
synced 2026-01-03 07:31:45 +00:00
survivors: homing projectiles now continuously try to find a new target after their initial has died
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import type {Placeable} from "./interfaces.ts";
|
import type {Healthy, Placeable} from "./interfaces.ts";
|
||||||
|
|
||||||
export class Vector {
|
export class Vector {
|
||||||
|
|
||||||
@@ -125,4 +125,35 @@ export class Point implements Placeable {
|
|||||||
move(any?: any) {
|
move(any?: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DeadPoint implements Placeable, Healthy {
|
||||||
|
|
||||||
|
private position: Vector;
|
||||||
|
|
||||||
|
|
||||||
|
constructor(position: Vector) {
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
getPosition(): Vector {
|
||||||
|
return this.position;
|
||||||
|
}
|
||||||
|
|
||||||
|
getSize() {
|
||||||
|
}
|
||||||
|
|
||||||
|
move(any?: any) {
|
||||||
|
}
|
||||||
|
|
||||||
|
dead() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
die() {
|
||||||
|
}
|
||||||
|
|
||||||
|
takeDamage(damage: number) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -125,10 +125,7 @@ docReady(function () {
|
|||||||
player.addWeapon(HomingPistol.generateHomingPistol(world))
|
player.addWeapon(HomingPistol.generateHomingPistol(world))
|
||||||
hud = new HUD(world);
|
hud = new HUD(world);
|
||||||
|
|
||||||
|
|
||||||
requestAnimationFrame(updateCanvas);
|
requestAnimationFrame(updateCanvas);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type {Acting, Placeable, Healthy} from "./interfaces.ts";
|
import type {Acting, Placeable, Healthy} from "./interfaces.ts";
|
||||||
import type {Vector} from "./base.ts";
|
import type {Vector} from "./base.ts";
|
||||||
import {World} from "./World.ts";
|
import {World} from "./World.ts";
|
||||||
import {Cooldown, Point, Vector} from "./base.ts";
|
import {Cooldown, DeadPoint, Point, Vector} from "./base.ts";
|
||||||
import {
|
import {
|
||||||
circleLineCollision,
|
circleLineCollision,
|
||||||
drawDot,
|
drawDot,
|
||||||
@@ -162,13 +162,13 @@ export class HomingProjectile extends Projectile {
|
|||||||
if(pointOnLineWithinLine(this.target.getPosition(), this.lastPosition, this.position)) {
|
if(pointOnLineWithinLine(this.target.getPosition(), this.lastPosition, this.position)) {
|
||||||
justMovedDirection = olderMovedDirection
|
justMovedDirection = olderMovedDirection
|
||||||
}
|
}
|
||||||
this.target = new Point(this.position.add(justMovedDirection.multiply(this.world.maxValue())))
|
this.target = new DeadPoint(this.position.add(justMovedDirection.multiply(this.world.maxValue())))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(pointOnLineWithinLine(this.target.getPosition(), this.lastPosition, this.position)) {
|
if(pointOnLineWithinLine(this.target.getPosition(), this.lastPosition, this.position)) {
|
||||||
justMovedDirection = olderMovedDirection
|
justMovedDirection = olderMovedDirection
|
||||||
}
|
}
|
||||||
this.target = new Point(this.position.add(justMovedDirection.multiply(Math.max(this.world.size.x, this.world.size.y))))
|
this.target = new DeadPoint(this.position.add(justMovedDirection.multiply(Math.max(this.world.size.x, this.world.size.y))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user