Compare commits
No commits in common. "38f5f95827e6e5c9f47e0050203be088f41c98f2" and "3af0bb400212d23514178d823f9410b9289caffd" have entirely different histories.
38f5f95827
...
3af0bb4002
6 changed files with 246 additions and 510 deletions
106
game/actor.ts
106
game/actor.ts
|
|
@ -1,43 +1,27 @@
|
||||||
import { load_texture } from "./assets";
|
import { load_texture } from "./assets";
|
||||||
import { btn, Button } from "./input";
|
import { btn, Button } from "./input";
|
||||||
import { Vec2, new_v2, vadd, vsub, vnorm, vmul } from "./vector";
|
import { Vec2, new_v2, vadd, vnorm, vmul } from "./vector";
|
||||||
import { spr, use_texture, Texture } from "./graphics";
|
import { spr, use_texture, Texture } from "./graphics";
|
||||||
import { has_collision, Level } from "./level";
|
|
||||||
|
|
||||||
export interface ActorProps {
|
export interface ActorProps {
|
||||||
id: string;
|
|
||||||
|
|
||||||
cx: number;
|
|
||||||
cy: number;
|
|
||||||
xr: number;
|
|
||||||
yr: number;
|
|
||||||
|
|
||||||
position: Vec2;
|
|
||||||
velocity: Vec2;
|
velocity: Vec2;
|
||||||
friction: number;
|
friction: number;
|
||||||
collide_radius: number;
|
id: string;
|
||||||
|
position: Vec2;
|
||||||
|
bounds: Vec2;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function new_actor_props(
|
export function new_actor_props(
|
||||||
id: string,
|
id: string,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
collide_radius: number
|
bounds: Vec2
|
||||||
): ActorProps {
|
): ActorProps {
|
||||||
const cx = Math.trunc(position.x / 16);
|
|
||||||
const cy = Math.trunc(position.y / 16);
|
|
||||||
const xr = (position.x - cx * 16) / 16;
|
|
||||||
const yr = (position.y - cy * 16) / 16;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cx,
|
|
||||||
cy,
|
|
||||||
xr,
|
|
||||||
yr,
|
|
||||||
velocity: new_v2(0),
|
velocity: new_v2(0),
|
||||||
friction: 0.7,
|
friction: 0.6,
|
||||||
id,
|
id,
|
||||||
position,
|
position,
|
||||||
collide_radius,
|
bounds,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,15 +36,9 @@ export class Actor {
|
||||||
|
|
||||||
update() {}
|
update() {}
|
||||||
|
|
||||||
// IDEAS: Make gameplay logic at 30fps and render updates at 60fps? Does
|
update_physics() {
|
||||||
// this mean we do some "update" in render?
|
const velocity = vmul(this.props.velocity, this.props.friction);
|
||||||
//
|
// Zero if we're smaller than some epsilon.
|
||||||
// TODO: Update physics in a better kind of way rather than an object call.
|
|
||||||
update_physics(level: Level | undefined) {
|
|
||||||
// This is very nice: https://deepnight.net/tutorial/a-simple-platformer-engine-part-1-basics/
|
|
||||||
// Apply friction to velocity and zero if we're close enough to zero.
|
|
||||||
const props = this.props;
|
|
||||||
const velocity = vmul(props.velocity, props.friction);
|
|
||||||
if (Math.abs(velocity.x) < 0.01) {
|
if (Math.abs(velocity.x) < 0.01) {
|
||||||
velocity.x = 0;
|
velocity.x = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -68,62 +46,13 @@ export class Actor {
|
||||||
velocity.y = 0;
|
velocity.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let cx = props.cx;
|
const new_position = vadd(this.props.position, velocity);
|
||||||
let cy = props.cy;
|
|
||||||
|
|
||||||
// Adjust xr with velocity, check for collisions, etc.
|
|
||||||
let xr = props.xr + velocity.x;
|
|
||||||
do {
|
|
||||||
// TODO: Cap velocity to 1 tile/frame? Then we wouldn't need this loop...
|
|
||||||
if (xr >= 0.7 && has_collision(level, cx + 1, cy)) {
|
|
||||||
xr = 0.7;
|
|
||||||
velocity.x = 0;
|
|
||||||
}
|
|
||||||
if (xr <= 0.3 && has_collision(level, cx - 1, cy)) {
|
|
||||||
xr = 0.3;
|
|
||||||
velocity.x = 0;
|
|
||||||
}
|
|
||||||
if (xr > 1) {
|
|
||||||
cx += 1;
|
|
||||||
xr -= 1;
|
|
||||||
}
|
|
||||||
if (xr < 0) {
|
|
||||||
cx -= 1;
|
|
||||||
xr += 1;
|
|
||||||
}
|
|
||||||
} while (xr > 1 || xr < 0);
|
|
||||||
|
|
||||||
let yr = props.yr + velocity.y;
|
|
||||||
do {
|
|
||||||
if (yr >= 0.4 && has_collision(level, cx, cy + 1)) {
|
|
||||||
yr = 0.4;
|
|
||||||
velocity.y = 0;
|
|
||||||
}
|
|
||||||
if (yr <= 0.1 && has_collision(level, cx, cy - 1)) {
|
|
||||||
yr = 0.1;
|
|
||||||
velocity.y = 0;
|
|
||||||
}
|
|
||||||
if (yr > 1) {
|
|
||||||
cy += 1;
|
|
||||||
yr -= 1;
|
|
||||||
}
|
|
||||||
if (yr < 0) {
|
|
||||||
cy -= 1;
|
|
||||||
yr += 1;
|
|
||||||
}
|
|
||||||
} while (yr > 1 || yr < 0);
|
|
||||||
|
|
||||||
// TODO: Collision detection
|
// TODO: Collision detection
|
||||||
// const { w, h } = this.bounds;
|
// const { w, h } = this.bounds;
|
||||||
|
|
||||||
const new_position = new_v2((cx + xr) * 16, (cy + yr) * 16);
|
this.props.velocity = velocity;
|
||||||
|
this.props.position = new_position;
|
||||||
props.cx = cx;
|
|
||||||
props.cy = cy;
|
|
||||||
props.xr = xr;
|
|
||||||
props.yr = yr;
|
|
||||||
props.velocity = velocity;
|
|
||||||
props.position = new_position;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
draw(_clock: number) {}
|
draw(_clock: number) {}
|
||||||
|
|
@ -132,8 +61,7 @@ export class Actor {
|
||||||
}
|
}
|
||||||
|
|
||||||
const robo_info = {
|
const robo_info = {
|
||||||
anchor: new_v2(16, 16), // Distance from upper-left of sprite.
|
bounds: new_v2(32),
|
||||||
bounds: new_v2(32), // Width/height of sprite.
|
|
||||||
sprite: "./bot.png",
|
sprite: "./bot.png",
|
||||||
animations: [
|
animations: [
|
||||||
{ start: 0, length: 1, speed: 20 },
|
{ start: 0, length: 1, speed: 20 },
|
||||||
|
|
@ -167,7 +95,7 @@ export class Robo extends Actor {
|
||||||
a.x += 1;
|
a.x += 1;
|
||||||
}
|
}
|
||||||
vnorm(a);
|
vnorm(a);
|
||||||
this.props.velocity = vadd(this.props.velocity, vmul(a, 0.06));
|
this.props.velocity = vadd(this.props.velocity, vmul(a, 1.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
draw(clock: number) {
|
draw(clock: number) {
|
||||||
|
|
@ -178,8 +106,8 @@ export class Robo extends Actor {
|
||||||
const moving = vel.x != 0 || vel.y != 0;
|
const moving = vel.x != 0 || vel.y != 0;
|
||||||
const anim = robo_info.animations[moving ? 1 : 0];
|
const anim = robo_info.animations[moving ? 1 : 0];
|
||||||
|
|
||||||
const { x: w, y: h } = robo_info.bounds;
|
const { x: w, y: h } = this.props.bounds;
|
||||||
const { x, y } = vsub(this.props.position, robo_info.anchor);
|
const { x, y } = this.props.position;
|
||||||
|
|
||||||
const frame = (anim.start + ((clock / anim.speed) % anim.length)) >> 0;
|
const frame = (anim.start + ((clock / anim.speed) % anim.length)) >> 0;
|
||||||
spr(x, y, w, h, frame * w, 0, 32, 32);
|
spr(x, y, w, h, frame * w, 0, 32, 32);
|
||||||
|
|
|
||||||
204
game/level.ts
204
game/level.ts
|
|
@ -7,65 +7,52 @@ import { load_string } from "./io";
|
||||||
|
|
||||||
// TODO: Use io-ts? YIKES.
|
// TODO: Use io-ts? YIKES.
|
||||||
|
|
||||||
export interface Tile {
|
export type Tile = {
|
||||||
px: [number, number];
|
px: [number, number];
|
||||||
src: [number, number];
|
src: [number, number];
|
||||||
f: number;
|
f: number;
|
||||||
t: number;
|
t: number;
|
||||||
a: number;
|
a: number;
|
||||||
}
|
};
|
||||||
|
|
||||||
export interface TileSet {
|
export type TileLayer = {
|
||||||
id: number;
|
|
||||||
texture: Texture;
|
|
||||||
tags: Map<string, number[]>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TileLayer {
|
|
||||||
type: "tile";
|
type: "tile";
|
||||||
tileset: TileSet;
|
texture: Texture;
|
||||||
grid_size: number;
|
grid_size: number;
|
||||||
offset: [number, number];
|
offset: [number, number];
|
||||||
tiles: Tile[];
|
tiles: Tile[];
|
||||||
}
|
};
|
||||||
|
|
||||||
export interface Entity {
|
export type Entity = {
|
||||||
type: string;
|
type: string;
|
||||||
id: string;
|
id: string;
|
||||||
px: [number, number];
|
px: [number, number];
|
||||||
bounds: [number, number];
|
bounds: [number, number];
|
||||||
// TODO: More props here.
|
// TODO: More props here.
|
||||||
}
|
};
|
||||||
|
|
||||||
export interface EntityLayer {
|
export type EntityLayer = {
|
||||||
type: "entity";
|
type: "entity";
|
||||||
entities: Entity[];
|
entities: Entity[];
|
||||||
}
|
};
|
||||||
|
|
||||||
export interface Level {
|
export type Level = {
|
||||||
world_x: number;
|
world_x: number;
|
||||||
world_y: number;
|
world_y: number;
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
cw: number;
|
|
||||||
ch: number;
|
|
||||||
tile_layers: TileLayer[];
|
tile_layers: TileLayer[];
|
||||||
entities: Entity[];
|
entity_layers: EntityLayer[];
|
||||||
values: number[];
|
};
|
||||||
}
|
|
||||||
|
|
||||||
export interface World {
|
export type TileSet = { id: number; texture: Texture };
|
||||||
levels: Level[];
|
|
||||||
tilesets: Map<number, TileSet>;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface LDTKTilesetDef {
|
export type World = { levels: Level[]; tilesets: Map<number, TileSet> };
|
||||||
|
|
||||||
|
async function load_tileset(def: {
|
||||||
uid: number;
|
uid: number;
|
||||||
relPath: string;
|
relPath: string;
|
||||||
enumTags: { enumValueId: string; tileIds: number[] }[];
|
}): Promise<TileSet> {
|
||||||
}
|
|
||||||
|
|
||||||
async function load_tileset(def: LDTKTilesetDef): Promise<TileSet> {
|
|
||||||
let relPath = def.relPath as string;
|
let relPath = def.relPath as string;
|
||||||
if (relPath.endsWith(".aseprite")) {
|
if (relPath.endsWith(".aseprite")) {
|
||||||
// Whoops let's load the export instead?
|
// Whoops let's load the export instead?
|
||||||
|
|
@ -73,16 +60,11 @@ async function load_tileset(def: LDTKTilesetDef): Promise<TileSet> {
|
||||||
}
|
}
|
||||||
let texture = await load_texture(relPath);
|
let texture = await load_texture(relPath);
|
||||||
|
|
||||||
let tags = new Map();
|
|
||||||
for (const et of def.enumTags) {
|
|
||||||
tags.set(et.enumValueId, et.tileIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
print("Loaded tileset", def.uid, "from", relPath, "as ID", texture.id());
|
print("Loaded tileset", def.uid, "from", relPath, "as ID", texture.id());
|
||||||
return { id: def.uid, texture, tags };
|
return { id: def.uid, texture };
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LDTKTileLayerInstance {
|
type TileLayerInstance = {
|
||||||
__type: "Tiles";
|
__type: "Tiles";
|
||||||
__gridSize: number;
|
__gridSize: number;
|
||||||
__pxTotalOffsetX: number;
|
__pxTotalOffsetX: number;
|
||||||
|
|
@ -95,11 +77,11 @@ interface LDTKTileLayerInstance {
|
||||||
t: number;
|
t: number;
|
||||||
a: number;
|
a: number;
|
||||||
}[];
|
}[];
|
||||||
}
|
};
|
||||||
|
|
||||||
function load_tile_layer_instance(
|
function load_tile_layer_instance(
|
||||||
tile_sets: Map<number, TileSet>,
|
tile_sets: Map<number, TileSet>,
|
||||||
li: LDTKTileLayerInstance
|
li: TileLayerInstance
|
||||||
): TileLayer {
|
): TileLayer {
|
||||||
const tileset = tile_sets.get(li.__tilesetDefUid);
|
const tileset = tile_sets.get(li.__tilesetDefUid);
|
||||||
if (!tileset) {
|
if (!tileset) {
|
||||||
|
|
@ -108,14 +90,14 @@ function load_tile_layer_instance(
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: "tile",
|
type: "tile",
|
||||||
tileset,
|
texture: tileset.texture,
|
||||||
grid_size: li.__gridSize,
|
grid_size: li.__gridSize,
|
||||||
offset: [li.__pxTotalOffsetX, li.__pxTotalOffsetY],
|
offset: [li.__pxTotalOffsetX, li.__pxTotalOffsetY],
|
||||||
tiles: li.gridTiles,
|
tiles: li.gridTiles,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LDTKEntityLayerInstance {
|
type EntityLayerInstance = {
|
||||||
__type: "Entities";
|
__type: "Entities";
|
||||||
entityInstances: {
|
entityInstances: {
|
||||||
__identifier: string;
|
__identifier: string;
|
||||||
|
|
@ -124,135 +106,72 @@ interface LDTKEntityLayerInstance {
|
||||||
height: number;
|
height: number;
|
||||||
px: [number, number];
|
px: [number, number];
|
||||||
}[];
|
}[];
|
||||||
|
};
|
||||||
|
|
||||||
|
function load_entity_layer_instance(li: EntityLayerInstance): EntityLayer {
|
||||||
|
return {
|
||||||
|
type: "entity",
|
||||||
|
entities: li.entityInstances.map((ei) => {
|
||||||
|
return {
|
||||||
|
type: ei.__identifier,
|
||||||
|
id: ei.iid,
|
||||||
|
px: ei.px,
|
||||||
|
bounds: [ei.width, ei.height],
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function load_entity_layer_instance(li: LDTKEntityLayerInstance): Entity[] {
|
type LayerInstance = TileLayerInstance | EntityLayerInstance;
|
||||||
return li.entityInstances.map((ei) => {
|
|
||||||
return {
|
|
||||||
type: ei.__identifier,
|
|
||||||
id: ei.iid,
|
|
||||||
px: ei.px,
|
|
||||||
bounds: [ei.width, ei.height],
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
interface LDTKIntGridLayerInstance {
|
function is_tile_layer_instance(x: LayerInstance): x is TileLayerInstance {
|
||||||
__type: "IntGrid";
|
|
||||||
__cWid: number;
|
|
||||||
__cHei: number;
|
|
||||||
intGridCsv: number[];
|
|
||||||
}
|
|
||||||
|
|
||||||
type LDTKLayerInstance =
|
|
||||||
| LDTKTileLayerInstance
|
|
||||||
| LDTKEntityLayerInstance
|
|
||||||
| LDTKIntGridLayerInstance;
|
|
||||||
|
|
||||||
function is_tile_layer_instance(
|
|
||||||
x: LDTKLayerInstance
|
|
||||||
): x is LDTKTileLayerInstance {
|
|
||||||
return x.__type == "Tiles";
|
return x.__type == "Tiles";
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_entity_layer_instance(
|
function is_entity_layer_instance(x: LayerInstance): x is EntityLayerInstance {
|
||||||
x: LDTKLayerInstance
|
|
||||||
): x is LDTKEntityLayerInstance {
|
|
||||||
return x.__type == "Entities";
|
return x.__type == "Entities";
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_intgrid_layer_instance(
|
function load_level(
|
||||||
x: LDTKLayerInstance
|
tile_sets: Map<number, TileSet>,
|
||||||
): x is LDTKIntGridLayerInstance {
|
def: {
|
||||||
return x.__type == "IntGrid";
|
worldX: number;
|
||||||
}
|
worldY: number;
|
||||||
|
pxWid: number;
|
||||||
type LDTKLevel = {
|
pxHei: number;
|
||||||
worldX: number;
|
layerInstances: LayerInstance[];
|
||||||
worldY: number;
|
}
|
||||||
pxWid: number;
|
): Level {
|
||||||
pxHei: number;
|
|
||||||
layerInstances: LDTKLayerInstance[];
|
|
||||||
};
|
|
||||||
|
|
||||||
function load_level(tile_sets: Map<number, TileSet>, def: LDTKLevel): Level {
|
|
||||||
const result: Level = {
|
const result: Level = {
|
||||||
world_x: def.worldX,
|
world_x: def.worldX,
|
||||||
world_y: def.worldY,
|
world_y: def.worldY,
|
||||||
width: def.pxWid,
|
width: def.pxWid,
|
||||||
height: def.pxHei,
|
height: def.pxHei,
|
||||||
cw: 0,
|
|
||||||
ch: 0,
|
|
||||||
tile_layers: [],
|
tile_layers: [],
|
||||||
entities: [],
|
entity_layers: [],
|
||||||
values: [],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const li of def.layerInstances) {
|
for (const li of def.layerInstances) {
|
||||||
if (is_tile_layer_instance(li)) {
|
if (is_tile_layer_instance(li)) {
|
||||||
const tli = load_tile_layer_instance(tile_sets, li);
|
result.tile_layers.push(load_tile_layer_instance(tile_sets, li));
|
||||||
|
|
||||||
result.tile_layers.push(tli);
|
|
||||||
} else if (is_entity_layer_instance(li)) {
|
} else if (is_entity_layer_instance(li)) {
|
||||||
// TODO: Why would I support multiple entity layers?
|
result.entity_layers.push(load_entity_layer_instance(li));
|
||||||
result.entities = load_entity_layer_instance(li);
|
|
||||||
} else if (is_intgrid_layer_instance(li)) {
|
|
||||||
result.cw = li.__cWid;
|
|
||||||
result.ch = li.__cHei;
|
|
||||||
result.values = li.intGridCsv; // ?
|
|
||||||
} else {
|
|
||||||
print("WARNING: Unknown layer type");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LDTKMap {
|
|
||||||
__header__: {
|
|
||||||
fileType: "LDtk Project JSON";
|
|
||||||
app: "LDtk";
|
|
||||||
doc: "https://ldtk.io/json";
|
|
||||||
schema: "https://ldtk.io/files/JSON_SCHEMA.json";
|
|
||||||
appAuthor: "Sebastien 'deepnight' Benard";
|
|
||||||
appVersion: "1.3.3";
|
|
||||||
url: "https://ldtk.io";
|
|
||||||
};
|
|
||||||
defs: {
|
|
||||||
tilesets: LDTKTilesetDef[];
|
|
||||||
};
|
|
||||||
levels: LDTKLevel[];
|
|
||||||
}
|
|
||||||
|
|
||||||
function is_ldtk_map(map: unknown): map is LDTKMap {
|
|
||||||
if (
|
|
||||||
map instanceof Object &&
|
|
||||||
"__header__" in map &&
|
|
||||||
map.__header__ instanceof Object
|
|
||||||
) {
|
|
||||||
const header = map.__header__;
|
|
||||||
if ("fileType" in header && header.fileType == "LDtk Project JSON") {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function load_world(path: string): Promise<World> {
|
export async function load_world(path: string): Promise<World> {
|
||||||
print("Loading map:", path);
|
print("Loading map:", path);
|
||||||
const blob = await load_string(path);
|
const blob = await load_string(path);
|
||||||
const map = JSON.parse(blob);
|
const map = JSON.parse(blob);
|
||||||
|
|
||||||
if (!is_ldtk_map(map)) {
|
|
||||||
throw new Error("Map does not appear to be an LDTK level");
|
|
||||||
}
|
|
||||||
|
|
||||||
const tilesets = new Map<number, TileSet>();
|
const tilesets = new Map<number, TileSet>();
|
||||||
let loaded_tilesets = await Promise.all(
|
let loaded_tilesets = await Promise.all(
|
||||||
map.defs.tilesets
|
map.defs.tilesets
|
||||||
.filter((def) => def.relPath != null)
|
.filter((def: any) => def.relPath != null)
|
||||||
.map((def) => load_tileset(def))
|
.map((def: any) => load_tileset(def))
|
||||||
);
|
);
|
||||||
for (const ts of loaded_tilesets) {
|
for (const ts of loaded_tilesets) {
|
||||||
tilesets.set(ts.id, ts);
|
tilesets.set(ts.id, ts);
|
||||||
|
|
@ -262,24 +181,13 @@ export async function load_world(path: string): Promise<World> {
|
||||||
return { levels, tilesets };
|
return { levels, tilesets };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function has_collision(
|
|
||||||
level: Level | undefined,
|
|
||||||
cx: number,
|
|
||||||
cy: number
|
|
||||||
): boolean {
|
|
||||||
if (!level) return true;
|
|
||||||
if (cx < 0 || cx >= level.cw) return false;
|
|
||||||
if (cy < 0 || cy >= level.ch) return false;
|
|
||||||
return level.values[cy * level.cw + cx] == 1; // TODO: MAGIC NUMBER?
|
|
||||||
}
|
|
||||||
|
|
||||||
export function draw_level(
|
export function draw_level(
|
||||||
level: Level,
|
level: Level,
|
||||||
offset_x: number = 0,
|
offset_x: number = 0,
|
||||||
offset_y: number = 0
|
offset_y: number = 0
|
||||||
) {
|
) {
|
||||||
for (const layer of level.tile_layers) {
|
for (const layer of level.tile_layers) {
|
||||||
use_texture(layer.tileset.texture);
|
use_texture(layer.texture);
|
||||||
|
|
||||||
let [ofx, ofy] = layer.offset;
|
let [ofx, ofy] = layer.offset;
|
||||||
ofx += offset_x;
|
ofx += offset_x;
|
||||||
|
|
|
||||||
20
game/main.ts
20
game/main.ts
|
|
@ -36,14 +36,16 @@ function load_assets() {
|
||||||
|
|
||||||
// TODO: SPAWN ACTORS BASED ON LEVEL.
|
// TODO: SPAWN ACTORS BASED ON LEVEL.
|
||||||
actors.length = 0;
|
actors.length = 0;
|
||||||
for (const entity of level.entities) {
|
for (const entity_layer of level.entity_layers) {
|
||||||
if (is_actor_type(entity.type)) {
|
for (const entity of entity_layer.entities) {
|
||||||
const [x, y] = entity.px;
|
if (is_actor_type(entity.type)) {
|
||||||
const [w, _] = entity.bounds;
|
const [x, y] = entity.px;
|
||||||
const props = new_actor_props(entity.id, new_v2(x, y), w);
|
const [w, h] = entity.bounds;
|
||||||
actors.push(spawn_actor(entity.type, props));
|
const props = new_actor_props(entity.id, new_v2(x, y), new_v2(w, h));
|
||||||
} else {
|
actors.push(spawn_actor(entity.type, props));
|
||||||
print("WARNING: Ignoring entity of type", entity.type);
|
} else {
|
||||||
|
print("WARNING: Ignoring entity of type", entity.type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -89,7 +91,7 @@ export function update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const actor of actors) {
|
for (const actor of actors) {
|
||||||
actor.update_physics(level);
|
actor.update_physics();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Bonks
|
// TODO: Bonks
|
||||||
|
|
|
||||||
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
|
Before Width: | Height: | Size: 703 B After Width: | Height: | Size: 543 B |
Loading…
Add table
Add a link
Reference in a new issue