@jfcmontmorency/dragon-smaug
v1.0.2
Published
A minimal umd snake game.
Maintainers
Readme
Dragon Smaug (UMD bundle)
Small snake game packaged as a UMD bundle for direct inclusion in the browser.
Usage
- Include the UMD bundle in your page:
<script src="/path/to/dist/dragon-smaug.umd.js"></script>- Mount the game on an element and start it:
<div id="game"></div>
<script>
const game = DragonSmaug.mount('#game', {
cols: 24,
rows: 18,
speedMs: 110,
onGameOver(score) { console.log('Final score:', score); }
});
game.start();
</script>Controls
- Arrow keys or WASD: move the snake
- R: restart after Game Over
Example
See example/index.html for a small usage example.
Auto cell sizing
If you omit the cell option when calling DragonSmaug.mount(...), the UMD bundle will compute a sensible cell value automatically based on the container size and the requested cols/rows. This helps the game fit various screen sizes without manual tuning. The computed cell is clamped to a reasonable range.
Recommended container styling
For best results it's recommended to give the mounting element some constraints so the game can scale predictably. Add a small CSS rule for the container element (here #game) in your page or global stylesheet. Example:
#game { max-width: 95vmin; margin: 0 auto; max-height: 75vmin; }This keeps the canvas from growing too large on very wide/large screens and centers it horizontally. Adjust the values to taste for your layout or replace #game with the selector you mount to.
