mirror of
https://github.com/Sheldan/canvas.git
synced 2026-04-18 12:57:37 +00:00
survivors: adding simple drops
moving size to world object adding dying for enemies and projectiles and theoretically for players adding pull range for player adding money stat display made pistol homing
This commit is contained in:
@@ -3,27 +3,31 @@ import type {Player} from "./Player.ts";
|
||||
import {Player} from "./Player.ts";
|
||||
import {Projectile} from "./projectile.ts";
|
||||
import {Vector} from "./base.ts";
|
||||
import type {Moving} from "./interfaces.ts";
|
||||
import type {Drop, Placeable} from "./interfaces.ts";
|
||||
|
||||
export class World {
|
||||
private _enemies: [Enemy] = [];
|
||||
private _projectiles: [Projectile] = [];
|
||||
private _drops: [Drop] = [];
|
||||
private _player: Player;
|
||||
private _ctx: CanvasRenderingContext2D;
|
||||
private _size: Vector
|
||||
|
||||
|
||||
constructor(player: Player, ctx: CanvasRenderingContext2D) {
|
||||
constructor(player: Player, ctx: CanvasRenderingContext2D, size: Vector) {
|
||||
this._player = player;
|
||||
this._ctx = ctx;
|
||||
this._size = size;
|
||||
}
|
||||
|
||||
enemiesAct() {
|
||||
this._enemies.forEach(enemy => enemy.act())
|
||||
this._projectiles.forEach(projectile => projectile.act())
|
||||
this._drops.forEach(drop => drop.act())
|
||||
}
|
||||
|
||||
draw() {
|
||||
this._enemies.forEach(enemy => enemy.draw(this._ctx))
|
||||
this._drops.forEach(drop => drop.draw(this._ctx))
|
||||
this._projectiles.forEach(projectile => projectile.draw(this._ctx))
|
||||
this._player.draw(this._ctx);
|
||||
}
|
||||
@@ -32,6 +36,14 @@ export class World {
|
||||
this._projectiles.push(projectile)
|
||||
}
|
||||
|
||||
addDrop(drop: Drop) {
|
||||
this._drops.push(drop)
|
||||
}
|
||||
|
||||
removeDrop(drop: Drop) {
|
||||
this._drops = this._drops.filter(item => item !== drop)
|
||||
}
|
||||
|
||||
removeProjectile(projectile: Projectile) {
|
||||
this._projectiles = this._projectiles.filter(item => item !== projectile)
|
||||
}
|
||||
@@ -45,11 +57,20 @@ export class World {
|
||||
return this._enemies;
|
||||
}
|
||||
|
||||
|
||||
get size(): Vector {
|
||||
return this._size;
|
||||
}
|
||||
|
||||
addEnemy(enemy: Enemy) {
|
||||
this._enemies.push(enemy)
|
||||
}
|
||||
|
||||
getClosestTargetTo(point: Vector): [number, Moving | undefined] | undefined {
|
||||
randomPlace(): Vector {
|
||||
return new Vector(this.size.x * Math.random(), this.size.y * Math.random())
|
||||
}
|
||||
|
||||
getClosestTargetTo(point: Vector): [number, Placeable | undefined] | undefined {
|
||||
let currentTarget;
|
||||
let currentDistance = Number.MAX_SAFE_INTEGER;
|
||||
this._enemies.forEach(enemy => {
|
||||
|
||||
Reference in New Issue
Block a user