From 5eae6f29a80cd47e268cb6eaefa96a0ab0a63e54 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 8 Nov 2018 22:03:08 +0100 Subject: Implement more flexible handling of entities and collidables --- src/model/data/collision.ts | 6 ++++++ src/model/data/entity.ts | 19 +++++++++++++++++++ src/model/data/map.ts | 11 +++-------- 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 src/model/data/collision.ts create mode 100644 src/model/data/entity.ts (limited to 'src/model/data') diff --git a/src/model/data/collision.ts b/src/model/data/collision.ts new file mode 100644 index 0000000..5008fa3 --- /dev/null +++ b/src/model/data/collision.ts @@ -0,0 +1,6 @@ +export interface CollisionPolygon { + readonly type: 'polygon'; + readonly vertices: Array<[number, number]>; +} + +export type Collision = CollisionPolygon; diff --git a/src/model/data/entity.ts b/src/model/data/entity.ts new file mode 100644 index 0000000..3474a38 --- /dev/null +++ b/src/model/data/entity.ts @@ -0,0 +1,19 @@ +import { Collision } from './collision'; + +export interface EntityDataInput { + readonly sprite: string; + readonly anchor?: [number, number]; + readonly collision?: Collision[]; +} + +export class EntityData { + public readonly sprite: string; + public readonly anchor: [number, number]; + public readonly collision: Collision[]; + + constructor(input: EntityDataInput) { + this.sprite = input.sprite; + this.anchor = input.anchor || [0.5, 0.5]; + this.collision = input.collision || []; + } +} diff --git a/src/model/data/map.ts b/src/model/data/map.ts index 4d9ecda..b36f6b5 100644 --- a/src/model/data/map.ts +++ b/src/model/data/map.ts @@ -1,11 +1,6 @@ -export interface CollisionPolygon { - readonly type: 'polygon'; - readonly vertices: Array<[number, number]>; -} - -export type Collision = CollisionPolygon; +import { Collision } from './collision'; -export interface Input { +export interface MapDataInput { readonly tiles: string[]; readonly layers: number[][][]; readonly collision: Collision[]; @@ -19,7 +14,7 @@ export class MapData { public readonly width: number; public readonly height: number; - constructor(data: Input) { + constructor(data: MapDataInput) { this.tiles = data.tiles; this.layers = data.layers; this.collision = data.collision; -- cgit v1.2.3