aboutsummaryrefslogtreecommitdiff
path: root/static/src
diff options
context:
space:
mode:
Diffstat (limited to 'static/src')
-rw-r--r--static/src/engine/component.ts22
-rw-r--r--static/src/engine/debounce_publisher.ts2
-rw-r--r--static/src/engine/entity.ts6
-rw-r--r--static/src/main.ts3
4 files changed, 25 insertions, 8 deletions
diff --git a/static/src/engine/component.ts b/static/src/engine/component.ts
index 9607fec..a16215b 100644
--- a/static/src/engine/component.ts
+++ b/static/src/engine/component.ts
@@ -2,6 +2,7 @@ export enum ComponentType {
POSITION = "POSITION",
RENDERABLE = "RENDERABLE",
TRAILING_POSITION = "TRAILING_POSITION",
+ SPRITESHEET = "SPRITESHEET",
}
export interface Component {
@@ -22,3 +23,24 @@ export interface TrailingPositionComponent extends Component {
export interface RenderableComponent extends Component {
name: ComponentType.RENDERABLE;
}
+
+export interface SpriteSpec {
+ ms_per_frame: number;
+ frames: number;
+ top_x: number;
+ top_y: number;
+ end_x: number;
+ end_y: number;
+}
+
+export interface SpriteSheetComponent extends Component {
+ name: ComponentType.SPRITESHEET;
+ source: string;
+ sheet: HTMLImageElement;
+
+ current_frame: number;
+ last_update: number;
+ current_state: string;
+
+ state_to_spritespec: Record<string, SpriteSpec>;
+}
diff --git a/static/src/engine/debounce_publisher.ts b/static/src/engine/debounce_publisher.ts
index 8ee4bb0..bc5e95f 100644
--- a/static/src/engine/debounce_publisher.ts
+++ b/static/src/engine/debounce_publisher.ts
@@ -5,7 +5,7 @@ export class DebouncePublisher<T> {
constructor(
private readonly publisher: (data: T) => void | Promise<void>,
- private readonly debounce_ms = 100,
+ private readonly debounce_ms = 150,
) {}
public start() {
diff --git a/static/src/engine/entity.ts b/static/src/engine/entity.ts
index 2c8d38e..87c9a67 100644
--- a/static/src/engine/entity.ts
+++ b/static/src/engine/entity.ts
@@ -1,7 +1,6 @@
import {
Component,
ComponentType,
- PositionComponent,
RenderableComponent,
TrailingPositionComponent,
} from "./component";
@@ -36,10 +35,5 @@ export const create_cat = (base: Entity) => {
name: ComponentType.RENDERABLE,
};
base.components[ComponentType.RENDERABLE] = renderable;
- base.components[ComponentType.POSITION] = {
- component: ComponentType.POSITION,
- x: Math.random() * 1_000,
- y: Math.random() * 1_000,
- } as unknown as PositionComponent; // TODO: hack
return base;
};
diff --git a/static/src/main.ts b/static/src/main.ts
index c11e41e..cc6f42c 100644
--- a/static/src/main.ts
+++ b/static/src/main.ts
@@ -10,7 +10,7 @@ import { NetworkSystem } from "./engine/network";
import { RenderSystem } from "./engine/render";
import { InputSystem } from "./engine/input";
import { TrailingPositionSystem } from "./engine/trailing_position";
-import { drainPoints, setDelay } from "laser-pen";
+import { drainPoints, setDelay, setRoundCap } from "laser-pen";
$(async () => {
const client_id = await fetch("/assign", {
@@ -32,6 +32,7 @@ $(async () => {
const input_system = new InputSystem(publisher, gamecanvas);
setDelay(500);
+ setRoundCap(true);
const render_system = new RenderSystem(gamecanvas);
const trailing_position = new TrailingPositionSystem(drainPoints);