diff options
Diffstat (limited to 'src/renderer/runtime/model')
-rw-r--r-- | src/renderer/runtime/model/data/collision.ts | 12 | ||||
-rw-r--r-- | src/renderer/runtime/model/data/entity.ts | 29 | ||||
-rw-r--r-- | src/renderer/runtime/model/data/map.ts | 29 |
3 files changed, 70 insertions, 0 deletions
diff --git a/src/renderer/runtime/model/data/collision.ts b/src/renderer/runtime/model/data/collision.ts new file mode 100644 index 0000000..29d0879 --- /dev/null +++ b/src/renderer/runtime/model/data/collision.ts @@ -0,0 +1,12 @@ +export interface PolygonCollision { + readonly type: 'polygon'; + readonly vertices: Array<[number, number]>; +} + +export interface CircleCollision { + readonly type: 'circle'; + readonly center: [number, number]; + readonly radius: number; +} + +export type Collision = PolygonCollision | CircleCollision; diff --git a/src/renderer/runtime/model/data/entity.ts b/src/renderer/runtime/model/data/entity.ts new file mode 100644 index 0000000..f52c130 --- /dev/null +++ b/src/renderer/runtime/model/data/entity.ts @@ -0,0 +1,29 @@ +import { Collision } from './collision'; + +export interface EntityAnimation { + readonly sequence: ReadonlyArray<[number, number]>; +} + +export interface EntityDataInput { + readonly sprite: string; + readonly anchor?: [number, number]; + readonly collision?: Collision[]; + readonly frames?: number; + readonly animation?: EntityAnimation; +} + +export class EntityData { + public readonly sprite: string; + public readonly anchor: [number, number]; + public readonly collision: Collision[]; + public readonly frames: number; + public readonly animation?: EntityAnimation; + + constructor(input: EntityDataInput) { + this.sprite = input.sprite; + this.anchor = input.anchor || [0.5, 0.5]; + this.collision = input.collision || []; + this.frames = input.frames || 1; + this.animation = input.animation; + } +} diff --git a/src/renderer/runtime/model/data/map.ts b/src/renderer/runtime/model/data/map.ts new file mode 100644 index 0000000..81ce051 --- /dev/null +++ b/src/renderer/runtime/model/data/map.ts @@ -0,0 +1,29 @@ +import { Collision } from './collision'; + +export interface MapLayer { + readonly tiles: number[][]; +} + +export interface MapDataInput { + readonly tiles: string[]; + readonly layers: MapLayer[]; + readonly collision: Collision[]; +} + +export class MapData { + public readonly tiles: string[]; + public readonly layers: MapLayer[]; + public readonly collision: Collision[]; + + public readonly width: number; + public readonly height: number; + + constructor(data: MapDataInput) { + this.tiles = data.tiles; + this.layers = data.layers; + this.collision = data.collision; + + this.height = this.layers[0].tiles.length; + this.width = this.layers[0].tiles[0].length; + } +} |