wIp
This commit is contained in:
@@ -1,70 +1,50 @@
|
||||
import { type Box, box } from "#/engine/Box.ts";
|
||||
import { type Circle, createCircle } from "#/engine/Circle.ts";
|
||||
import { moveAndCollide } from "#/engine/Collision.ts";
|
||||
import { defineEntity, type Process } from "#/engine/Entity.ts";
|
||||
// import { createCircle } from "#/engine/Circle.ts";
|
||||
// import { moveAndCollide } from "#/engine/Collision.ts";
|
||||
import { defineEntity } from "#/engine/Entity.ts";
|
||||
import { keyboardInput } from "#/engine/Keyboard.ts";
|
||||
import { pointer } from "#/engine/Pointer.ts";
|
||||
import { def } from "#/engine/Scene.ts";
|
||||
import $ from "#/engine/Scene.ts";
|
||||
import {
|
||||
createSpriteAnimation,
|
||||
type Sprite,
|
||||
type SpriteAnimation,
|
||||
useSpriteSheetSrc,
|
||||
createSprite,
|
||||
createSpritePlayback,
|
||||
defineSpriteSheet,
|
||||
} from "#/engine/Sprite.ts";
|
||||
import { createVector, type Vector } from "#/engine/Vector.ts";
|
||||
import charIdle from "#/game/assets/char-idle.png";
|
||||
|
||||
export type Hero = {
|
||||
position: Vector;
|
||||
velocity: Vector;
|
||||
body: Circle;
|
||||
sprite: Sprite;
|
||||
animation: Box<SpriteAnimation>;
|
||||
};
|
||||
|
||||
const speed = 0.05;
|
||||
const idleSheet = await useSpriteSheetSrc(charIdle, 2, 4);
|
||||
const sprite = {
|
||||
src: idleSheet,
|
||||
xStart: 0,
|
||||
yStart: 0,
|
||||
width: 16,
|
||||
height: 16,
|
||||
};
|
||||
const idleSrc = await defineSpriteSheet(charIdle, 2, 4);
|
||||
|
||||
const state: Hero = {
|
||||
const process = defineEntity("hero", {
|
||||
position: createVector(),
|
||||
sprite: createSprite(idleSrc),
|
||||
playback: createSpritePlayback(500, 2),
|
||||
// body: createCircle(createVector(), 4),
|
||||
velocity: createVector(),
|
||||
body: createCircle(createVector(), 4),
|
||||
sprite,
|
||||
animation: box(createSpriteAnimation(sprite, 500, 2)),
|
||||
};
|
||||
});
|
||||
|
||||
const $ = def("hero");
|
||||
$<Vector>("position", createVector());
|
||||
$<Process>("process", (_id, _delta) => {});
|
||||
process((id, delta) => {
|
||||
const position = $<Vector>("position").get(id)!;
|
||||
const velocity = velocityMap.get(id)!;
|
||||
// const body = bodyMap.get(id);
|
||||
|
||||
const process = defineEntity("hero", state);
|
||||
|
||||
process((entity, delta) => {
|
||||
if (pointer.isDown) {
|
||||
entity.position.x = pointer.position.x;
|
||||
entity.position.y = pointer.position.y;
|
||||
position.x = pointer.position.x;
|
||||
position.y = pointer.position.y;
|
||||
}
|
||||
|
||||
entity.velocity.x -= keyboardInput.arrowLeft ? speed : 0;
|
||||
entity.velocity.x += keyboardInput.arrowRight ? speed : 0;
|
||||
entity.velocity.y -= keyboardInput.arrowUp ? speed : 0;
|
||||
entity.velocity.y += keyboardInput.arrowDown ? speed : 0;
|
||||
velocity.x -= keyboardInput.arrowLeft ? speed : 0;
|
||||
velocity.x += keyboardInput.arrowRight ? speed : 0;
|
||||
velocity.y -= keyboardInput.arrowUp ? speed : 0;
|
||||
velocity.y += keyboardInput.arrowDown ? speed : 0;
|
||||
|
||||
entity.position.x = Math.round(entity.velocity.x * delta + entity.position.x);
|
||||
entity.position.y = Math.round(entity.velocity.y * delta + entity.position.y);
|
||||
// const collision = moveAndCollide(body, velocity, delta);
|
||||
// slideOnCollision(velocity, collision);
|
||||
// slide(velocity, collision.normal);
|
||||
|
||||
entity.velocity.x = 0;
|
||||
entity.velocity.y = 0;
|
||||
position.x = Math.round(velocity.x * delta + position.x);
|
||||
position.y = Math.round(velocity.y * delta + position.y);
|
||||
|
||||
moveAndCollide(entity.body, entity.velocity);
|
||||
|
||||
// entity.body.position.x = entity.body.offset.x + entity.position.x;
|
||||
// entity.body.position.y = entity.body.offset.y + entity.position.y;
|
||||
velocity.x = 0;
|
||||
velocity.y = 0;
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { box } from "#/engine/Box.ts";
|
||||
import { defineEntity } from "#/engine/Entity.ts";
|
||||
import { createSpriteAnimation, useSpriteSheetSrc } from "#/engine/Sprite.ts";
|
||||
import { createSpritePlayback, defineSpriteSheet } from "#/engine/Sprite.ts";
|
||||
import { createVector } from "#/engine/Vector.ts";
|
||||
import portal from "#/game/assets/portal.png";
|
||||
|
||||
const portalSheet = await useSpriteSheetSrc(portal, 3, 1);
|
||||
const portalSheet = await defineSpriteSheet(portal, 3, 1);
|
||||
const sprite = {
|
||||
src: portalSheet,
|
||||
xStart: 0,
|
||||
@@ -16,5 +16,5 @@ const sprite = {
|
||||
defineEntity("portal", {
|
||||
position: createVector(64, 64),
|
||||
sprite,
|
||||
animation: box(createSpriteAnimation(sprite, 400, 0)),
|
||||
animation: box(createSpritePlayback(sprite, 400, 0)),
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { type Box, box } from "#/engine/Box.ts";
|
||||
import { defineEntity } from "#/engine/Entity.ts";
|
||||
import {
|
||||
createSpriteAnimation,
|
||||
createSpritePlayback,
|
||||
defineSpriteSheet,
|
||||
type Sprite,
|
||||
type SpriteAnimation,
|
||||
useSpriteSheetSrc,
|
||||
type SpritePlayback,
|
||||
} from "#/engine/Sprite.ts";
|
||||
import { createVector, type Vector } from "#/engine/Vector.ts";
|
||||
import { viewport } from "#/engine/Viewport.ts";
|
||||
@@ -12,8 +12,8 @@ import charIdle from "#/game/assets/char-idle.png";
|
||||
import charWalk from "#/game/assets/char-walk.png";
|
||||
|
||||
const sheets = {
|
||||
idle: await useSpriteSheetSrc(charIdle, 2, 4),
|
||||
walk: await useSpriteSheetSrc(charWalk, 4, 4),
|
||||
idle: await defineSpriteSheet(charIdle, 2, 4),
|
||||
walk: await defineSpriteSheet(charWalk, 4, 4),
|
||||
};
|
||||
|
||||
const sprites = {
|
||||
@@ -34,16 +34,16 @@ const sprites = {
|
||||
};
|
||||
|
||||
const animations = {
|
||||
idle: createSpriteAnimation(sprites.idle, 500, 2),
|
||||
walk: createSpriteAnimation(sprites.walk, 250, 2),
|
||||
idle: createSpritePlayback(sprites.idle, 500, 2),
|
||||
walk: createSpritePlayback(sprites.walk, 250, 2),
|
||||
};
|
||||
|
||||
const process = defineEntity<{
|
||||
position: Vector;
|
||||
animation: Box<SpriteAnimation>;
|
||||
animation: Box<SpritePlayback>;
|
||||
animations: {
|
||||
idle: SpriteAnimation;
|
||||
walk: SpriteAnimation;
|
||||
idle: SpritePlayback;
|
||||
walk: SpritePlayback;
|
||||
};
|
||||
sprite: Sprite;
|
||||
sprites: {
|
||||
|
||||
Reference in New Issue
Block a user