Compare commits

..

2 Commits

Author SHA1 Message Date
475ad8955d fix input drops 2022-08-11 16:23:52 +02:00
c4978fa9a2 set img rendering to pixelated 2022-08-11 16:23:42 +02:00
2 changed files with 16 additions and 5 deletions

19
app.js
View File

@ -4,6 +4,8 @@ const path = require("path");
const fs = require("fs");
let lastFrame = "";
let emulator;
let currentKey = "";
let keyCooldown = 0;
const mainHTML = fs.readFileSync(path.join(__dirname, "html", "gb.html"), "utf8");
const KEYMAP = {
RIGHT: 0,
@ -25,10 +27,15 @@ async function run() {
path: "./rom.gb",
interval: 16.6666667,
onFrame: function(frame) {
if (lastFrame !== frame) {
lastFrame = frame;
if (currentKey !== "") {
emulator.gameboy.pressKey(currentKey);
keyCooldown--;
if (keyCooldown <= 0) {
currentKey = "";
}
}
lastFrame = frame;
}
});
fastify.get("/", async(request, reply) => {
@ -43,8 +50,12 @@ async function run() {
fastify.get("/control", async(request, reply) => {
const button = request.query.button;
if (button) {
const mappedButton = KEYMAP[button.toUpperCase()];
if (mappedButton) emulator.pressKeys(emulator.gameboy, [mappedButton]);
if (keyCooldown > 0)
return;
if (KEYMAP[button]) {
currentKey = button;
keyCooldown = 10;
}
}
});

View File

@ -10,7 +10,7 @@
<body style="background-color: #121212">
<div>
<img id="image" src="http://localhost:3000/image" width="700" style="display: block; margin: auto;" />
<img id="image" src="http://localhost:3000/image" width="700" style="display: block; margin: auto; image-rendering: pixelated;" />
<br>
<div style="position: absolute; left: 50%; transform: translate(-50%, 0);">
<a id="UP" class="button">