WIP WIP WIP
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { createCircle } from "#/engine/Circle.ts";
|
||||
import { defineEntity } from "#/engine/Entity.ts";
|
||||
import { keyboardInput } from "#/engine/Keyboard.ts";
|
||||
import { pointer } from "#/engine/Pointer.ts";
|
||||
@@ -7,6 +8,10 @@ import {
|
||||
createSpriteAnimation,
|
||||
defineSpriteSheet,
|
||||
} from "#/engine/Sprite.ts";
|
||||
import {
|
||||
type Collider,
|
||||
moveAndCollide,
|
||||
} from "#/engine/system/processPhysics.ts";
|
||||
import { createVector, type Vector } from "#/engine/Vector.ts";
|
||||
import charIdle from "#/game/assets/char-idle.png";
|
||||
|
||||
@@ -18,11 +23,13 @@ const process = defineEntity("hero", {
|
||||
sprite: createSprite(idleSrc),
|
||||
animation: createSpriteAnimation(500, 2),
|
||||
velocity: createVector(),
|
||||
collider: createCircle(createVector(), 8),
|
||||
});
|
||||
|
||||
process((id, delta) => {
|
||||
const position = $<Vector>("position").get(id)!.value;
|
||||
const velocity = $<Vector>("velocity").get(id)!.value;
|
||||
const collider = $<Collider>("collider").get(id)!.value;
|
||||
|
||||
if (pointer.isDown) {
|
||||
position.x = pointer.position.x;
|
||||
@@ -39,4 +46,7 @@ process((id, delta) => {
|
||||
|
||||
velocity.x = 0;
|
||||
velocity.y = 0;
|
||||
|
||||
const collision = moveAndCollide(collider, velocity, delta);
|
||||
console.log(collision);
|
||||
});
|
||||
|
||||
@@ -1,53 +1,8 @@
|
||||
import { createPolygon, type Polygon } from "#/engine/Polygon.ts";
|
||||
import { defineScene } from "#/engine/Scene.ts";
|
||||
import { createVector, type Vector } from "#/engine/Vector.ts";
|
||||
import data from "./data.json";
|
||||
|
||||
const { process, linkScenes } = defineScene(data);
|
||||
|
||||
linkScenes(["testScene"] as const);
|
||||
|
||||
const polygon = createPolygon(createVector(32, 32), [
|
||||
createVector(0, 0),
|
||||
createVector(0, 16),
|
||||
createVector(16, 16),
|
||||
]);
|
||||
|
||||
function drawPoint(
|
||||
ctx: CanvasRenderingContext2D,
|
||||
position: Vector,
|
||||
radius: number = 2,
|
||||
color: string = "#fff",
|
||||
): void {
|
||||
ctx.beginPath();
|
||||
ctx.arc(position.x, position.y, radius, 0, 2 * Math.PI);
|
||||
ctx.fillStyle = color;
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
function drawPoly(
|
||||
ctx: CanvasRenderingContext2D,
|
||||
poly: Polygon,
|
||||
trigger: boolean = false,
|
||||
): void {
|
||||
drawPoint(ctx, poly.position);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(
|
||||
poly.points[0].x + poly.position.x + 0.5,
|
||||
poly.points[0].y + poly.position.y + 0.5,
|
||||
);
|
||||
|
||||
for (let i = poly.points.length - 1; i >= 0; i--) {
|
||||
ctx.lineTo(
|
||||
poly.points[i].x + poly.position.x + 0.5,
|
||||
poly.points[i].y + poly.position.y + 0.5,
|
||||
);
|
||||
}
|
||||
|
||||
ctx.strokeStyle = trigger ? "red" : "orange";
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
process((ctx, _delta) => {
|
||||
drawPoly(ctx, polygon);
|
||||
});
|
||||
process((_ctx, _delta) => {});
|
||||
|
||||
Reference in New Issue
Block a user