forked from StrafesNET/roblox-bot-player
37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
import init, {
|
|
setup,
|
|
Graphics,
|
|
Bot,
|
|
PlaybackHead,
|
|
} from "./pkg/strafesnet_roblox_bot_player_wasm_module.js";
|
|
|
|
await init(); // load the wasm module
|
|
|
|
const botBuf = await fetch("bhop_marble_7cf33a64-7120-4514-b9fa-4fe29d9523d.qbot").then((r) => r.arrayBuffer());
|
|
const mapBuf = await fetch("bhop_marble_5692093612.snfm").then((r) => r.arrayBuffer());
|
|
|
|
const canvas = document.querySelector('canvas');
|
|
|
|
const context = await setup(canvas);
|
|
const graphics = new Graphics(context, new Uint8Array(mapBuf));
|
|
const bot = new Bot(new Uint8Array(botBuf));
|
|
const playback = new PlaybackHead(0);
|
|
|
|
const startTime = performance.now();
|
|
|
|
function animate(now) {
|
|
const elapsedMs = now - startTime;
|
|
const elapsedSec = elapsedMs / 1000; // wasm expects seconds
|
|
|
|
// Advance the playback head to the current time
|
|
playback.advance_time(bot, elapsedSec);
|
|
|
|
// Render the frame that the bot is at that time
|
|
graphics.render(bot, playback, elapsedSec);
|
|
|
|
// Keep the loop going
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
requestAnimationFrame(animate);
|