mirror of
https://github.com/Sheldan/canvas.git
synced 2026-04-23 14:17:37 +00:00
survivors: adding first version
This commit is contained in:
18
absurd-survivors/src/utils.ts
Normal file
18
absurd-survivors/src/utils.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import {Vector} from "./base.ts";
|
||||
|
||||
export function drawDot(position: Vector, size: number, color: string, ctx: CanvasRenderingContext2D) {
|
||||
ctx.beginPath();
|
||||
ctx.fillStyle = color;
|
||||
ctx.arc(position.x, position.y, size, 0, 2 * Math.PI);
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
export function moveInDirectionOf(position: Vector, target: Vector, speedFactor): Vector {
|
||||
let playerVector = Vector.createVector(target, position);
|
||||
let direction = playerVector.normalize()
|
||||
return position.add(direction.multiply(speedFactor))
|
||||
}
|
||||
|
||||
export function straightMove(position: Vector, speed: Vector): Vector {
|
||||
return position.add(speed)
|
||||
}
|
||||
Reference in New Issue
Block a user