rejigger drawing layer storage

This commit is contained in:
Tangent Wantwight 2020-02-15 23:38:54 -05:00
parent 390e6744b9
commit 57c2364796
4 changed files with 16 additions and 18 deletions

View file

@ -51,14 +51,14 @@ export class CollisionClass {
export class RenderBounds { export class RenderBounds {
constructor( constructor(
public color = "#f00", public color = "#f00",
public layer: Layer public layer: number
) {}; ) {};
}; };
export class RenderSprite { export class RenderSprite {
constructor( constructor(
public sheet: SpriteSheet, public sheet: SpriteSheet,
public layer: Layer, public layer: number,
public index = 0, public index = 0,
public offsetX = 0, public offsetX = 0,
public offsetY = 0 public offsetY = 0
@ -73,6 +73,8 @@ export class Data extends CoreData {
collisionSourceClass: SparseStore<CollisionClass> = {}; collisionSourceClass: SparseStore<CollisionClass> = {};
collisionTargetClass: SparseStore<CollisionClass> = {}; collisionTargetClass: SparseStore<CollisionClass> = {};
layers: Layer[] = [new Layer(0)];
constructor(source?: Partial<Data>) { constructor(source?: Partial<Data>) {
super(source); super(source);
if(source?.location) this.location = source.location.slice(); if(source?.location) this.location = source.location.slice();

View file

@ -1,11 +1,11 @@
import { DrawSet, Layer } from "../Applet/Render";
import { Data } from "./Components"; import { Data } from "./Components";
import { Join } from "./Data"; import { Join } from "./Data";
import { TransformCx } from "./Location"; import { TransformCx } from "./Location";
import { DrawSet, Layer } from "../Applet/Render";
export function RunRenderBounds(data: Data, drawSet: DrawSet) { export function RunRenderBounds(data: Data, drawSet: DrawSet) {
drawSet.queue(...Join(data, "renderBounds", "location", "bounds").map( drawSet.queue(...Join(data, "renderBounds", "location", "bounds").map(
([{color, layer}, location, {points}]) => layer.toRender((cx, dt) => { ([{color, layer}, location, {points}]) => data.layers[layer].toRender((cx, dt) => {
TransformCx(cx, location, dt); TransformCx(cx, location, dt);
cx.fillStyle = color; cx.fillStyle = color;
cx.beginPath(); cx.beginPath();
@ -19,7 +19,7 @@ export function RunRenderBounds(data: Data, drawSet: DrawSet) {
export function RunRenderSprites(data: Data, drawSet: DrawSet) { export function RunRenderSprites(data: Data, drawSet: DrawSet) {
drawSet.queue(...Join(data, "renderSprite", "location").map( drawSet.queue(...Join(data, "renderSprite", "location").map(
([{sheet, layer, index, offsetX, offsetY}, location]) => layer.toRender((cx, dt) => { ([{sheet, layer, index, offsetX, offsetY}, location]) => data.layers[layer].toRender((cx, dt) => {
TransformCx(cx, location, dt); TransformCx(cx, location, dt);
sheet.render(cx, index, offsetX, offsetY); sheet.render(cx, index, offsetX, offsetY);
})) }))

View file

@ -1,10 +1,10 @@
import { Bind, Game } from "../Applet/Init"; import { Bind, Game } from "../Applet/Init";
import { KeyControl } from "../Applet/Keyboard"; import { KeyControl } from "../Applet/Keyboard";
import { Loop } from "../Applet/Loop"; import { Loop } from "../Applet/Loop";
import { Layer, DrawSet } from "../Applet/Render"; import { DrawSet, Layer } from "../Applet/Render";
import { Data, Location, Polygon, RenderBounds, CollisionClass } from "./Components";
import { FindCollisions } from "./Collision"; import { FindCollisions } from "./Collision";
import { Join, Liveness, Remove, Create, Lookup, Store, SparseStore } from "./Data"; import { CollisionClass, Data, Location, Polygon, RenderBounds } from "./Components";
import { Create, Join, Liveness, Lookup, Remove, SparseStore, Store } from "./Data";
import { DumbMotion } from "./Location"; import { DumbMotion } from "./Location";
import { RunRenderBounds } from "./Renderers"; import { RunRenderBounds } from "./Renderers";
@ -108,7 +108,6 @@ export class LoopTest {
data = new Data(); data = new Data();
constructor(public canvas: HTMLCanvasElement, cx: CanvasRenderingContext2D, keys: KeyControl) { constructor(public canvas: HTMLCanvasElement, cx: CanvasRenderingContext2D, keys: KeyControl) {
const layer = new Layer(0);
const drawSet = new DrawSet(); const drawSet = new DrawSet();
// spinner box // spinner box
@ -120,10 +119,7 @@ export class LoopTest {
}), }),
bounds: new Polygon([-50, 50, -60, 250, 60, 250, 50, 50]), bounds: new Polygon([-50, 50, -60, 250, 60, 250, 50, 50]),
collisionTargetClass: new CollisionClass("block"), collisionTargetClass: new CollisionClass("block"),
renderBounds: new RenderBounds( renderBounds: new RenderBounds("#0a0", 0),
"#0a0",
layer
)
}); });
// triangles // triangles
@ -138,7 +134,7 @@ export class LoopTest {
collisionSourceClass: new CollisionClass("tri"), collisionSourceClass: new CollisionClass("tri"),
renderBounds: new RenderBounds( renderBounds: new RenderBounds(
"#d40", "#d40",
layer 0
) )
})); }));

View file

@ -1,7 +1,7 @@
import { PlaySfx } from "../Applet/Audio"; import { PlaySfx } from "../Applet/Audio";
import { RenderBounds, Polygon, Location } from "../Ecs/Components"; import { Location, Polygon, RenderBounds } from "../Ecs/Components";
import { Join, Remove, Lookup, Create, Id } from "../Ecs/Data"; import { Create, Id, Join, Lookup, Remove } from "../Ecs/Data";
import { Data, World, Lifetime, Teams } from "./GameComponents"; import { Data, Lifetime, Teams, World } from "./GameComponents";
export function SelfDestructMinions(data: Data, world: World) { export function SelfDestructMinions(data: Data, world: World) {
const bossKilled = Join(data, "boss", "hp") const bossKilled = Join(data, "boss", "hp")
@ -66,7 +66,7 @@ function SpawnPuff(data: Data, world: World, x: number, y: number, size: number,
size, size, size, size,
size, -size size, -size
]), ]),
renderBounds: new RenderBounds(color, world.smokeLayer), renderBounds: new RenderBounds(color, /*world.smokeLayer*/ 0),
lifetime: new Lifetime(Math.random() / 3) lifetime: new Lifetime(Math.random() / 3)
}); });
} }