404game 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +151 -0
- package/dist/404game.js +571 -0
- package/dist/404game.js.map +1 -0
- package/dist/404game.umd.cjs +31 -0
- package/dist/404game.umd.cjs.map +1 -0
- package/dist/core/Engine.d.ts +31 -0
- package/dist/core/Input.d.ts +21 -0
- package/dist/core/Renderer.d.ts +16 -0
- package/dist/core/Storage.d.ts +4 -0
- package/dist/games/Breakout.d.ts +2 -0
- package/dist/games/Dino.d.ts +2 -0
- package/dist/games/Flappy.d.ts +2 -0
- package/dist/games/Snake.d.ts +2 -0
- package/dist/index.d.ts +21 -0
- package/dist/types.d.ts +76 -0
- package/dist/ui/Overlay.d.ts +29 -0
- package/dist/ui/themes.d.ts +3 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# 404game.js
|
|
2
|
+
|
|
3
|
+
> Turn boring 404 pages into playable mini-games. Drop-in, zero dependencies, < 30KB.
|
|
4
|
+
|
|
5
|
+
**ðŪ [Live Demo â](https://x1n-q.github.io/404game/)**
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<script src="404game.js"></script>
|
|
9
|
+
<div id="game"></div>
|
|
10
|
+
<script>Game404.mount('#game');</script>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
That's it. Your 404 page now has Snake, Flappy Bird, Breakout, or a Dino runner.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## ðŪ Games included
|
|
18
|
+
|
|
19
|
+
| Game | Controls (Desktop) | Controls (Mobile) |
|
|
20
|
+
|------|------|------|
|
|
21
|
+
| ð **Snake** | Arrow keys | Swipe |
|
|
22
|
+
| ðĶ **Flappy** | Space / Click | Tap |
|
|
23
|
+
| ð§ą **Breakout** | Arrow keys + Space | Swipe + Tap |
|
|
24
|
+
| ðĶ **Dino** | Space | Tap |
|
|
25
|
+
|
|
26
|
+
Plus 4 themes: `neon`, `retro`, `minimal`, `dark`.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## ðĶ Install
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install 404game
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
or use the CDN-style UMD bundle:
|
|
37
|
+
|
|
38
|
+
```html
|
|
39
|
+
<script src="https://unpkg.com/404game/dist/404game.umd.cjs"></script>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## ð Usage
|
|
45
|
+
|
|
46
|
+
### Vanilla / `<script>` tag
|
|
47
|
+
|
|
48
|
+
```html
|
|
49
|
+
<div id="game"></div>
|
|
50
|
+
<script src="404game.umd.cjs"></script>
|
|
51
|
+
<script>
|
|
52
|
+
Game404.mount('#game', {
|
|
53
|
+
game: 'random', // 'snake' | 'flappy' | 'breakout' | 'dino' | 'random'
|
|
54
|
+
theme: 'neon', // 'neon' | 'retro' | 'minimal' | 'dark'
|
|
55
|
+
});
|
|
56
|
+
</script>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### ES Modules / bundlers
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
import Game404 from '404game';
|
|
63
|
+
|
|
64
|
+
Game404.mount('#game', { game: 'snake' });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### React
|
|
68
|
+
|
|
69
|
+
```jsx
|
|
70
|
+
import { useEffect, useRef } from 'react';
|
|
71
|
+
import Game404 from '404game';
|
|
72
|
+
|
|
73
|
+
function NotFoundPage() {
|
|
74
|
+
const ref = useRef(null);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const instance = Game404.mount(ref.current, { game: 'random' });
|
|
77
|
+
return () => instance.destroy();
|
|
78
|
+
}, []);
|
|
79
|
+
return <div ref={ref} />;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## âïļ Options
|
|
86
|
+
|
|
87
|
+
| Option | Type | Default | Description |
|
|
88
|
+
|--------|------|---------|-------------|
|
|
89
|
+
| `game` | `'snake' \| 'flappy' \| 'breakout' \| 'dino' \| 'random'` | `'random'` | Which game to load |
|
|
90
|
+
| `theme` | `'neon' \| 'retro' \| 'minimal' \| 'dark'` | `'neon'` | Visual theme |
|
|
91
|
+
| `width` | `number` | container width or 480 | Canvas width (px) |
|
|
92
|
+
| `height` | `number` | `360` | Canvas height (px) |
|
|
93
|
+
| `message` | `string` | `'404 â Page Not Found'` | Big banner text |
|
|
94
|
+
| `subMessage` | `string` | `'But hey, want to play instead?'` | Small banner text |
|
|
95
|
+
| `showHighscore` | `boolean` | `true` | Show "Best" score in HUD |
|
|
96
|
+
| `autoStart` | `boolean` | `false` | Skip start screen |
|
|
97
|
+
| `onStart` | `() => void` | â | Fired when player starts |
|
|
98
|
+
| `onScore` | `(score: number) => void` | â | Fired on every score update |
|
|
99
|
+
| `onGameOver` | `(score: number) => void` | â | Fired when player loses |
|
|
100
|
+
| `onWin` | `(score: number) => void` | â | Fired when player wins (Breakout) |
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## ð§ API
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
const instance = Game404.mount(selector, options);
|
|
108
|
+
|
|
109
|
+
instance.restart(); // Restart current game
|
|
110
|
+
instance.getScore(); // Current score
|
|
111
|
+
instance.destroy(); // Remove from DOM, free resources
|
|
112
|
+
|
|
113
|
+
Game404.unmount(selector); // Same as instance.destroy()
|
|
114
|
+
|
|
115
|
+
Game404.games; // ['snake', 'flappy', 'breakout', 'dino']
|
|
116
|
+
Game404.version; // '0.1.0'
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## âĻ Features
|
|
122
|
+
|
|
123
|
+
- ðŪ **4 classic games** built in
|
|
124
|
+
- ðĻ **4 themes** included
|
|
125
|
+
- ðą **Touch + keyboard** controls â works everywhere
|
|
126
|
+
- ðū **Local high scores** per game
|
|
127
|
+
- ðŠķ **Zero dependencies** â pure browser APIs
|
|
128
|
+
- ðĶ **< 30KB** minified + gzipped
|
|
129
|
+
- ð§Đ **TypeScript** types included
|
|
130
|
+
- âŧïļ **Auto-cleanup** with `destroy()`
|
|
131
|
+
- ðŊ **Framework-friendly** (React, Vue, Svelte, vanilla, anywhere)
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## ð ïļ Development
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
npm install
|
|
139
|
+
npm run dev # Vite dev server at http://localhost:5173
|
|
140
|
+
npm run build # Build to dist/
|
|
141
|
+
npm run preview # Preview built demo at http://localhost:4173
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Open `demo/index.html` after building to see all 4 games at once.
|
|
145
|
+
Open `demo/404.html` to see a real-world 404 page integration.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## ð License
|
|
150
|
+
|
|
151
|
+
MIT
|