@hiddentao/clockwork-engine
Version:
A TypeScript/PIXI.js game engine for deterministic, replayable games with built-in rendering
115 lines • 4.12 kB
TypeScript
import { EventEmitter } from "./EventEmitter";
import type { ICollisionSource } from "./geometry/ICollisionSource";
import type { IPositionable } from "./geometry/IPositionable";
import { Vector2D } from "./geometry/Vector2D";
export interface GameEngineInterface {
registerGameObject(gameObject: GameObject): void;
getTotalTicks(): number;
getPRNG(): any;
}
export declare enum GameObjectEventType {
POSITION_CHANGED = "positionChanged",
HEALTH_CHANGED = "healthChanged",
MAX_HEALTH_CHANGED = "maxHealthChanged",
DESTROYED = "destroyed",
SIZE_CHANGED = "sizeChanged",
VELOCITY_CHANGED = "velocityChanged",
ROTATION_CHANGED = "rotationChanged"
}
export interface SerializedGameObject {
position: {
x: number;
y: number;
};
size: {
x: number;
y: number;
};
velocity: {
x: number;
y: number;
};
rotation: number;
health: number;
maxHealth: number;
isDestroyed: boolean;
}
/**
* Base events that all GameObjects can emit
* All events include the GameObject instance as the first parameter
*/
export interface GameObjectEvents extends Record<string, (...args: any[]) => void> {
[GameObjectEventType.POSITION_CHANGED]: (gameObject: GameObject, oldPosition: Vector2D, newPosition: Vector2D) => void;
[GameObjectEventType.HEALTH_CHANGED]: (gameObject: GameObject, health: number, maxHealth: number) => void;
[GameObjectEventType.MAX_HEALTH_CHANGED]: (gameObject: GameObject, oldMaxHealth: number, newMaxHealth: number) => void;
[GameObjectEventType.DESTROYED]: (gameObject: GameObject) => void;
}
export declare abstract class GameObject<T extends GameObjectEvents = GameObjectEvents> extends EventEmitter<T> implements IPositionable, ICollisionSource {
static debug: boolean;
protected id: string;
protected position: Vector2D;
protected size: Vector2D;
protected velocity: Vector2D;
protected rotation: number;
protected health: number;
protected maxHealth: number;
protected destroyed: boolean;
protected engine?: GameEngineInterface;
private isRepaintNeeded;
constructor(id: string, position: Vector2D, size: Vector2D, health?: number, engine?: GameEngineInterface);
update(deltaTicks: number, _totalTicks: number): void;
getPosition(): Vector2D;
setPosition(position: Vector2D): void;
getSize(): Vector2D;
setSize(size: Vector2D): void;
getVelocity(): Vector2D;
setVelocity(velocity: Vector2D): void;
getRotation(): number;
setRotation(rotation: number): void;
getHealth(): number;
getMaxHealth(): number;
setMaxHealth(maxHealth: number): void;
setHealth(health: number): void;
takeDamage(amount: number): void;
heal(amount: number): void;
isDestroyed(): boolean;
destroy(): void;
/**
* Get the repaint flag for this game object
* @returns Whether the object needs to be repainted
*/
get needsRepaint(): boolean;
/**
* Set the repaint flag for this game object
* @param value Whether the object needs to be repainted
*/
set needsRepaint(value: boolean);
/**
* Get the unique identifier for this game object
* @returns The unique ID of this game object
*/
getId(): string;
/**
* Get the type of this game object
* @returns The type identifier of this game object
*/
abstract getType(): string;
/**
* Get the engine this GameObject is registered with
* @returns The game engine instance, or undefined if not registered
*/
getEngine(): GameEngineInterface | undefined;
/**
* Register this GameObject with an engine
* @param engine The engine to register with
*/
registerWithEngine(engine: GameEngineInterface): void;
/**
* Get the collision source identifier for this game object
* @returns The collision source ID of this game object
*/
getCollisionSourceId(): string;
serialize(): SerializedGameObject;
static deserialize(_data: any): GameObject;
}
//# sourceMappingURL=GameObject.d.ts.map