WIP
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { defineEntity } from "#/engine/Entity.ts";
|
||||
import { keyboardInput } from "#/engine/Keyboard.ts";
|
||||
import { createEffect, createSignal } from "#/engine/lib/Signal.ts";
|
||||
import { pointer } from "#/engine/Pointer.ts";
|
||||
import { createRect } from "#/engine/Rect.ts";
|
||||
import $ from "#/engine/Scene.ts";
|
||||
@@ -21,7 +22,7 @@ import {
|
||||
} from "#/engine/Vector.ts";
|
||||
import charIdle from "#/game/assets/char-idle.png";
|
||||
|
||||
const speed = 0.1;
|
||||
const [speed, setSpeed] = createSignal(0.1);
|
||||
const idleSrc = await defineSpriteSheet(charIdle, 2, 4);
|
||||
|
||||
const process = defineEntity("hero", {
|
||||
@@ -32,6 +33,12 @@ const process = defineEntity("hero", {
|
||||
collider: createCollider(Shape.Rect, createRect(createVector(), 16, 16)),
|
||||
});
|
||||
|
||||
createEffect(() => {
|
||||
console.log(speed());
|
||||
});
|
||||
|
||||
let onceGuard = true;
|
||||
|
||||
process((id, delta) => {
|
||||
const position = $<Vector>("position").get(id)!.value;
|
||||
const velocity = $<Vector>("velocity").get(id)!.value;
|
||||
@@ -39,8 +46,15 @@ process((id, delta) => {
|
||||
if (pointer.isDown) {
|
||||
position.x = pointer.position.x;
|
||||
position.y = pointer.position.y;
|
||||
|
||||
if (onceGuard) {
|
||||
onceGuard = false;
|
||||
setSpeed(0.1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
onceGuard = true;
|
||||
|
||||
velocity.x -= keyboardInput.arrowLeft ? 1 : 0;
|
||||
velocity.x += keyboardInput.arrowRight ? 1 : 0;
|
||||
@@ -48,7 +62,7 @@ process((id, delta) => {
|
||||
velocity.y += keyboardInput.arrowDown ? 1 : 0;
|
||||
|
||||
normalize(velocity);
|
||||
scale(velocity, speed);
|
||||
scale(velocity, speed());
|
||||
moveAndSlide(id, velocity, delta);
|
||||
|
||||
position.x += velocity.x * delta;
|
||||
|
||||
Reference in New Issue
Block a user