-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Brings this project out of ~2014 and into ~2017
- Loading branch information
1 parent
35366e9
commit dc877f3
Showing
37 changed files
with
1,199 additions
and
2,177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"presets": [ | ||
["env", { | ||
"targets": { | ||
"browsers": "last 2 versions", | ||
"node": "current" | ||
} | ||
}], | ||
"stage-0" | ||
], | ||
"plugins": ["transform-runtime"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules/ | ||
sample/ | ||
.DS_Store | ||
packages/ | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,58 @@ | ||
define(function(require, exports, module) { | ||
|
||
var BackgroundLayer = require("romlib/backgroundLayer"); | ||
var frameId = -1; | ||
var Engine = exports.Engine = function() { | ||
|
||
}; | ||
|
||
(function() { | ||
// the animation loop | ||
exports.start = function(layer1, layer2, fps, aspectRatio, frameskip, alpha) { | ||
var tick = 0, | ||
then = Date.now(), startTime = then, elapsed, | ||
fpsInterval = 1000 / fps, | ||
bitmap; | ||
|
||
var canvas = document.getElementById("ebbb-holder"); | ||
var ctx = canvas.getContext("2d"); | ||
|
||
ctx.clearRect(0, 0, canvas.width, canvas.height); | ||
|
||
var canvasWidth = 256, canvasHeight = 256, | ||
imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight); | ||
|
||
function krakenFrame() { | ||
frameId = requestAnimationFrame(krakenFrame); | ||
|
||
var now = Date.now(); | ||
let frameID = -1; | ||
export const SNES_WIDTH = 256; | ||
export const SNES_HEIGHT = 224; | ||
export default class Engine { | ||
constructor(layers = [], { | ||
fps = 30, | ||
aspectRatio = 0, | ||
frameSkip = 1, | ||
alpha = [0.5, 0.5], | ||
canvas = document.querySelector("canvas") | ||
} = {}) { | ||
this.layers = layers; | ||
this.fps = fps; | ||
this.aspectRatio = aspectRatio; | ||
this.frameSkip = frameSkip; | ||
this.alpha = alpha; | ||
this.tick = 0; | ||
this.canvas = canvas; | ||
} | ||
animate() { | ||
let then = Date.now(); | ||
let elapsed; | ||
const fpsInterval = 1000 / this.fps; | ||
let bitmap; | ||
const canvas = this.canvas; | ||
const context = canvas.getContext("2d"); | ||
if (this.layers[0].entry && !this.layers[1].entry) { | ||
this.alpha[0] = 1; | ||
this.alpha[1] = 0; | ||
} | ||
if (!this.layers[0].entry && this.layers[1].entry) { | ||
this.alpha[0] = 0; | ||
this.alpha[1] = 1; | ||
} | ||
context.imageSmoothingEnabled = false; | ||
canvas.width = SNES_WIDTH; | ||
canvas.height = SNES_HEIGHT; | ||
const image = context.getImageData(0, 0, canvas.width, canvas.height); | ||
const drawFrame = () => { | ||
frameID = requestAnimationFrame(drawFrame); | ||
const now = Date.now(); | ||
elapsed = now - then; | ||
|
||
// console.log("Rendering tick " + tick); | ||
if (elapsed > fpsInterval) { | ||
then = now - (elapsed % fpsInterval); | ||
|
||
bitmap = layer1.overlayFrame(imageData.data, aspectRatio, tick, alpha, true); | ||
bitmap = layer2.overlayFrame(bitmap, aspectRatio, tick, parseFloat(0.5), false); | ||
|
||
tick += (frameskip); | ||
|
||
imageData.data.set(bitmap); | ||
|
||
ctx.putImageData(imageData, 0, 0); | ||
then = now - (elapsed % fpsInterval); | ||
for (let i = 0; i < this.layers.length; ++i) { | ||
bitmap = this.layers[i].overlayFrame(image.data, this.aspectRatio, this.tick, this.alpha[i], i === 0); | ||
} | ||
this.tick += this.frameSkip; | ||
image.data.set(bitmap); | ||
context.putImageData(image, 0, 0); | ||
} | ||
}; | ||
if (frameID > 0) { | ||
global.cancelAnimationFrame(frameID); | ||
} | ||
|
||
if (frameId > 0) | ||
window.cancelAnimationFrame(frameId); | ||
krakenFrame(); | ||
drawFrame(); | ||
} | ||
} | ||
|
||
}).call(Engine.prototype); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import ROM from "./rom/rom"; | ||
import data from "../data/backgrounds.dat"; | ||
export Engine from "./engine"; | ||
export BackgroundLayer from "./rom/background_layer"; | ||
const backgroundData = new Uint8Array(Array.from(data).map(x => x.charCodeAt(0))); | ||
new ROM(backgroundData); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.