Compare commits
No commits in common. "475ad8955d1d1b6348b0cc41c4c25884d7904769" and "5f271367f0bd830270ea9c07d1238bf2d15d3642" have entirely different histories.
475ad8955d
...
5f271367f0
19
app.js
19
app.js
@ -4,8 +4,6 @@ const path = require("path");
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
let lastFrame = "";
|
let lastFrame = "";
|
||||||
let emulator;
|
let emulator;
|
||||||
let currentKey = "";
|
|
||||||
let keyCooldown = 0;
|
|
||||||
const mainHTML = fs.readFileSync(path.join(__dirname, "html", "gb.html"), "utf8");
|
const mainHTML = fs.readFileSync(path.join(__dirname, "html", "gb.html"), "utf8");
|
||||||
const KEYMAP = {
|
const KEYMAP = {
|
||||||
RIGHT: 0,
|
RIGHT: 0,
|
||||||
@ -27,15 +25,10 @@ async function run() {
|
|||||||
path: "./rom.gb",
|
path: "./rom.gb",
|
||||||
interval: 16.6666667,
|
interval: 16.6666667,
|
||||||
onFrame: function(frame) {
|
onFrame: function(frame) {
|
||||||
if (currentKey !== "") {
|
if (lastFrame !== frame) {
|
||||||
emulator.gameboy.pressKey(currentKey);
|
|
||||||
keyCooldown--;
|
|
||||||
if (keyCooldown <= 0) {
|
|
||||||
currentKey = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lastFrame = frame;
|
lastFrame = frame;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get("/", async(request, reply) => {
|
fastify.get("/", async(request, reply) => {
|
||||||
@ -50,12 +43,8 @@ async function run() {
|
|||||||
fastify.get("/control", async(request, reply) => {
|
fastify.get("/control", async(request, reply) => {
|
||||||
const button = request.query.button;
|
const button = request.query.button;
|
||||||
if (button) {
|
if (button) {
|
||||||
if (keyCooldown > 0)
|
const mappedButton = KEYMAP[button.toUpperCase()];
|
||||||
return;
|
if (mappedButton) emulator.pressKeys(emulator.gameboy, [mappedButton]);
|
||||||
if (KEYMAP[button]) {
|
|
||||||
currentKey = button;
|
|
||||||
keyCooldown = 10;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<body style="background-color: #121212">
|
<body style="background-color: #121212">
|
||||||
<div>
|
<div>
|
||||||
<img id="image" src="http://localhost:3000/image" width="700" style="display: block; margin: auto; image-rendering: pixelated;" />
|
<img id="image" src="http://localhost:3000/image" width="700" style="display: block; margin: auto;" />
|
||||||
<br>
|
<br>
|
||||||
<div style="position: absolute; left: 50%; transform: translate(-50%, 0);">
|
<div style="position: absolute; left: 50%; transform: translate(-50%, 0);">
|
||||||
<a id="UP" class="button">
|
<a id="UP" class="button">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user