mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-25 12:17:22 +00:00
Add layer class
This commit is contained in:
34
birb.js
34
birb.js
@@ -49,13 +49,33 @@ const styles = `
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
class Frame {
|
class Layer {
|
||||||
/**
|
/**
|
||||||
* @param {number[][]} pixels
|
* @param {number[][]} pixels
|
||||||
*/
|
*/
|
||||||
constructor(pixels) {
|
constructor(pixels) {
|
||||||
this.pixels = pixels;
|
this.pixels = pixels;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Frame {
|
||||||
|
/**
|
||||||
|
* @param {Layer[]} layers
|
||||||
|
*/
|
||||||
|
constructor(layers) {
|
||||||
|
this.pixels = layers[0].pixels.map(row => row.slice());
|
||||||
|
for (let i = 1; i < layers.length; i++) {
|
||||||
|
let layerPixels = layers[i].pixels;
|
||||||
|
for (let y = 0; y < layerPixels.length; y++) {
|
||||||
|
for (let x = 0; x < layerPixels[y].length; x++) {
|
||||||
|
if (this.pixels[y] === undefined) {
|
||||||
|
this.pixels[y] = [];
|
||||||
|
}
|
||||||
|
this.pixels[y][x] = layerPixels[y][x];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {CanvasRenderingContext2D} ctx
|
* @param {CanvasRenderingContext2D} ctx
|
||||||
@@ -178,7 +198,7 @@ const colors = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const sharedFrames = {
|
const sharedFrames = {
|
||||||
base: new Frame([
|
base: new Frame([new Layer([
|
||||||
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
||||||
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
||||||
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
||||||
@@ -191,8 +211,8 @@ const sharedFrames = {
|
|||||||
[___, ___, ___, BLY, BLY, BLY, W24, W34, W43, ___, ___],
|
[___, ___, ___, BLY, BLY, BLY, W24, W34, W43, ___, ___],
|
||||||
[___, ___, ___, ___, BLY, BLY, BUM, BUM, ___, ___, ___],
|
[___, ___, ___, ___, BLY, BLY, BUM, BUM, ___, ___, ___],
|
||||||
[___, ___, ___, ___, TOE, LEG, ___, ___, ___, ___, ___]
|
[___, ___, ___, ___, TOE, LEG, ___, ___, ___, ___, ___]
|
||||||
]),
|
])]),
|
||||||
headDown: new Frame([
|
headDown: new Frame([new Layer([
|
||||||
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
||||||
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
||||||
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
||||||
@@ -205,8 +225,8 @@ const sharedFrames = {
|
|||||||
[___, ___, ___, BLY, BLY, BLY, W24, W34, W43, ___, ___],
|
[___, ___, ___, BLY, BLY, BLY, W24, W34, W43, ___, ___],
|
||||||
[___, ___, ___, ___, BLY, BLY, BUM, BUM, ___, ___, ___],
|
[___, ___, ___, ___, BLY, BLY, BUM, BUM, ___, ___, ___],
|
||||||
[___, ___, ___, ___, TOE, LEG, ___, ___, ___, ___, ___]
|
[___, ___, ___, ___, TOE, LEG, ___, ___, ___, ___, ___]
|
||||||
]),
|
])]),
|
||||||
wingsUp: new Frame([
|
wingsUp: new Frame([new Layer([
|
||||||
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
||||||
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
||||||
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
[___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___],
|
||||||
@@ -219,7 +239,7 @@ const sharedFrames = {
|
|||||||
[___, ___, ___, BLY, BLY, BLY, W12, W24, UND, ___, ___],
|
[___, ___, ___, BLY, BLY, BLY, W12, W24, UND, ___, ___],
|
||||||
[___, ___, ___, ___, BLY, BLY, BUM, BUM, ___, ___, ___],
|
[___, ___, ___, ___, BLY, BLY, BUM, BUM, ___, ___, ___],
|
||||||
[___, ___, ___, ___, TOE, LEG, ___, ___, ___, ___, ___]
|
[___, ___, ___, ___, TOE, LEG, ___, ___, ___, ___, ___]
|
||||||
]),
|
])]),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user