retro-pong-game 3.0.0 → 4.0.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/README.md +58 -27
- package/dist/pong-game.es.js +2326 -1997
- package/dist/pong-game.umd.js +77 -77
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -4,18 +4,36 @@ A retro-style Pong game that runs in any browser. Drop it onto your website with
|
|
|
4
4
|
|
|
5
5
|
**[Live demo](https://chriscreativecode.com/retro-pong-game/)**
|
|
6
6
|
|
|
7
|
-

|
|
8
8
|
|
|
9
9
|
- Animated starfield or nebular background
|
|
10
10
|
- Particle effects on paddle hits
|
|
11
11
|
- Countdown timer with configurable duration
|
|
12
12
|
- Adaptive AI difficulty (auto-adjusts after scoring streaks)
|
|
13
|
+
- Power-ups and power-downs that randomly appear in the field
|
|
13
14
|
- In-game settings panel (changes saved to `localStorage`)
|
|
14
15
|
- Stereo-panned sound effects
|
|
15
16
|
- Fully configurable colors, sizes, and speeds
|
|
16
17
|
- TypeScript types included
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
## How to play
|
|
20
|
+
|
|
21
|
+
You control the **bottom paddle** using the arrow keys. The **top paddle** is the AI opponent.
|
|
22
|
+
|
|
23
|
+
**Goal:** score as many points as possible before the timer runs out. A point is scored when the ball passes the opponent's paddle and exits through their side of the field. The player with the most points when the timer reaches zero wins.
|
|
24
|
+
|
|
25
|
+
**Controls:**
|
|
26
|
+
|
|
27
|
+
| Key | Action |
|
|
28
|
+
| --- | --- |
|
|
29
|
+
| `←` Arrow Left or `A` | Move paddle left |
|
|
30
|
+
| `→` Arrow Right or `D` | Move paddle right |
|
|
31
|
+
| `P` or `Space` | Pause / resume |
|
|
32
|
+
| `B` | Cycle ball image (planet → coin → face → ship → Star Wars → beer → none → …) |
|
|
33
|
+
|
|
34
|
+
**Scoring streaks** affect the AI: if you score three times in a row the AI gets harder; if the AI scores three times in a row it gets easier, so the game stays competitive.
|
|
35
|
+
|
|
36
|
+
**Power-ups and power-downs** appear randomly in the field every 12 seconds. Steer the ball into them to activate the effect. Power-ups (bright solid circles) give you a temporary advantage. Power-downs (dark circles with a rotating dashed ring) make the game harder for a few seconds. See [Power-ups & power-downs](#power-ups--power-downs) for the full list.
|
|
19
37
|
|
|
20
38
|
## Installation
|
|
21
39
|
|
|
@@ -23,8 +41,6 @@ A retro-style Pong game that runs in any browser. Drop it onto your website with
|
|
|
23
41
|
npm install retro-pong-game
|
|
24
42
|
```
|
|
25
43
|
|
|
26
|
-
---
|
|
27
|
-
|
|
28
44
|
## Quick start
|
|
29
45
|
|
|
30
46
|
### 1. Add a container element to your HTML
|
|
@@ -37,7 +53,9 @@ The game appends a `<canvas>` inside this element automatically.
|
|
|
37
53
|
|
|
38
54
|
### 2. Import and create the game
|
|
39
55
|
|
|
40
|
-
**New to this package?** Start with `isAdmin: true` to configure everything visually first
|
|
56
|
+
**New to this package?** Start with `isAdmin: true` to configure everything visually first.
|
|
57
|
+
|
|
58
|
+
> **Fun tip:** press `B` during any game to cycle the ball through fun images (planet, coin, face, spaceship, Star Wars logo, beer). Press again to go to the next image; one more press after the last image clears it back to a plain ball.
|
|
41
59
|
|
|
42
60
|
```js
|
|
43
61
|
import { PongGame } from 'retro-pong-game';
|
|
@@ -82,8 +100,6 @@ Call `destroy()` before removing the element from the page:
|
|
|
82
100
|
game.destroy();
|
|
83
101
|
```
|
|
84
102
|
|
|
85
|
-
---
|
|
86
|
-
|
|
87
103
|
## CDN (no npm required)
|
|
88
104
|
|
|
89
105
|
```html
|
|
@@ -107,8 +123,6 @@ game.destroy();
|
|
|
107
123
|
</html>
|
|
108
124
|
```
|
|
109
125
|
|
|
110
|
-
---
|
|
111
|
-
|
|
112
126
|
## Framework examples
|
|
113
127
|
|
|
114
128
|
### React
|
|
@@ -222,8 +236,6 @@ const config: PongGameConfig = {
|
|
|
222
236
|
const game = new PongGame(config, '#game');
|
|
223
237
|
```
|
|
224
238
|
|
|
225
|
-
---
|
|
226
|
-
|
|
227
239
|
## Configuration
|
|
228
240
|
|
|
229
241
|
All options are optional. Omitted values fall back to built-in defaults.
|
|
@@ -253,6 +265,7 @@ The config is deep-merged in this order (later layers win):
|
|
|
253
265
|
| `paddleMoveStep` | `number` | `4` | Paddle speed while an arrow key is held (px per frame) |
|
|
254
266
|
| `difficultyLevel` | `number` | `1` | Starting AI difficulty; higher = faster and more precise AI |
|
|
255
267
|
| `particleBounce` | `boolean` | `true` | Particle burst when the ball hits a paddle |
|
|
268
|
+
| `powerUps` | `boolean` | `true` | Enable power-ups and power-downs that randomly appear in the field |
|
|
256
269
|
| `hasSound` | `boolean` | `false` | Enable sound effects |
|
|
257
270
|
| `showSettings` | `boolean` | `true` | Show the gear icon that opens the in-game settings panel. Set to `false` to lock the settings from players |
|
|
258
271
|
| `isAdmin` | `boolean` | `false` | Unlock difficulty and timing controls in the settings panel, plus a JSON export of the current config (see [Admin mode](#admin-mode)) |
|
|
@@ -299,8 +312,6 @@ The config is deep-merged in this order (later layers win):
|
|
|
299
312
|
|---|---|---|---|
|
|
300
313
|
| `particlesCount` | `number` | `20` | Number of particles spawned per paddle hit |
|
|
301
314
|
|
|
302
|
-
---
|
|
303
|
-
|
|
304
315
|
## Methods
|
|
305
316
|
|
|
306
317
|
```js
|
|
@@ -354,19 +365,47 @@ wireButton(document.getElementById('btn-right'),
|
|
|
354
365
|
() => game.pressRight(), () => game.releaseRight());
|
|
355
366
|
```
|
|
356
367
|
|
|
357
|
-
---
|
|
358
|
-
|
|
359
368
|
## Keyboard controls
|
|
360
369
|
|
|
361
370
|
| Key | Action |
|
|
362
|
-
|
|
363
|
-
| `←` Arrow Left | Move paddle left |
|
|
364
|
-
| `→` Arrow Right | Move paddle right |
|
|
371
|
+
| --- | --- |
|
|
372
|
+
| `←` Arrow Left or `A` | Move paddle left |
|
|
373
|
+
| `→` Arrow Right or `D` | Move paddle right |
|
|
365
374
|
| `P` or `Space` | Pause / resume |
|
|
375
|
+
| `B` | Cycle ball image (planet → coin → face → ship → Star Wars → beer → none → …) |
|
|
366
376
|
|
|
367
377
|
The player controls the **bottom** paddle. The **top** paddle is the AI opponent.
|
|
368
378
|
|
|
369
|
-
|
|
379
|
+
## Power-ups & power-downs
|
|
380
|
+
|
|
381
|
+
Every 12 seconds a glowing item appears somewhere in the middle of the field. Hit it with the ball to activate its effect. The item then disappears and a new one spawns 12 seconds later.
|
|
382
|
+
|
|
383
|
+
### How to tell them apart
|
|
384
|
+
|
|
385
|
+
| Visual | Type |
|
|
386
|
+
| --- | --- |
|
|
387
|
+
| **Bright solid circle** — slow pulsing outer ring | Power-up — helps you |
|
|
388
|
+
| **Dark circle with rotating dashed ring** — fast flickering | Power-down — hurts you |
|
|
389
|
+
|
|
390
|
+
### Power-ups (beneficial)
|
|
391
|
+
|
|
392
|
+
| Letter | Color | Effect | Duration |
|
|
393
|
+
| --- | --- | --- | --- |
|
|
394
|
+
| **W** | Green | Your paddle becomes twice as wide | 6 s |
|
|
395
|
+
| **S** | Cyan | Ball speed is reduced by ~55% | 5 s |
|
|
396
|
+
| **F** | Orange | The AI paddle is frozen and cannot move | 4 s |
|
|
397
|
+
|
|
398
|
+
### Power-downs (detrimental)
|
|
399
|
+
|
|
400
|
+
| Letter | Color | Effect | Duration |
|
|
401
|
+
| --- | --- | --- | --- |
|
|
402
|
+
| **N** | Red | Your paddle shrinks to half its normal width | 5 s |
|
|
403
|
+
| **X** | Orange-red | Ball speed increases by 80% | 5 s |
|
|
404
|
+
| **C** | Purple | The AI paddle becomes twice as wide | 5 s |
|
|
405
|
+
|
|
406
|
+
A flash message appears on screen when an effect activates (e.g. **"CPU FROZEN!"** or **"NARROW PADDLE!"**) and fades out over the effect's duration so you always know what is active.
|
|
407
|
+
|
|
408
|
+
Power-ups and power-downs can be disabled via the in-game settings panel (toggle **Power-ups**) or through the config option `powerUps: false`.
|
|
370
409
|
|
|
371
410
|
## Settings panel
|
|
372
411
|
|
|
@@ -378,8 +417,6 @@ To reset all saved settings back to defaults:
|
|
|
378
417
|
localStorage.removeItem('chriscreativecode.com-retro-pong-game');
|
|
379
418
|
```
|
|
380
419
|
|
|
381
|
-
---
|
|
382
|
-
|
|
383
420
|
## Admin mode
|
|
384
421
|
|
|
385
422
|
`isAdmin: true` is the recommended starting point when you are setting up the game for the first time. It unlocks the full settings panel so you can configure everything visually before committing to a config object.
|
|
@@ -404,8 +441,6 @@ In admin mode the settings panel exposes:
|
|
|
404
441
|
|
|
405
442
|
Without `isAdmin`, these fields are hidden from players so they cannot alter the game balance. Do not ship `isAdmin: true` to end users.
|
|
406
443
|
|
|
407
|
-
---
|
|
408
|
-
|
|
409
444
|
## Resize handling
|
|
410
445
|
|
|
411
446
|
### Automatic (recommended)
|
|
@@ -440,14 +475,10 @@ window.addEventListener('resize', () => game.resizeGame());
|
|
|
440
475
|
|
|
441
476
|
`autoSize: true` alone sizes the canvas once at startup. The game then has a fixed size until you call `resizeGame()` manually.
|
|
442
477
|
|
|
443
|
-
---
|
|
444
|
-
|
|
445
478
|
## Browser support
|
|
446
479
|
|
|
447
480
|
All modern browsers with HTML Canvas support (Chrome, Firefox, Safari, Edge). When importing the ES module build, a bundler (Vite, Webpack, esbuild, Parcel) is recommended for production use.
|
|
448
481
|
|
|
449
|
-
---
|
|
450
|
-
|
|
451
482
|
## License
|
|
452
483
|
|
|
453
484
|
MIT © [Chris Schardijn](https://chriscreativecode.com)
|