@alexium216/react-pong 1.1.2
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 +22 -0
- package/README.md +60 -0
- package/dist/ai.d.ts +38 -0
- package/dist/ball.d.ts +44 -0
- package/dist/lib.d.ts +3 -0
- package/dist/player.d.ts +41 -0
- package/dist/pong.d.ts +13 -0
- package/dist/react-pong.es.js +874 -0
- package/dist/react-pong.umd.js +30 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Oakley Hall
|
|
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.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @alexium216/react-pong
|
|
2
|
+
|
|
3
|
+
A simple ping-pong game as a React component built with TypeScript.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Inspired by [Max Wihlborg](https://github.com/maxwihlborg/youtube-tutorials)
|
|
8
|
+
|
|
9
|
+
[See demo here](https://github.com/alexium216/react-pong)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install --save @alexium216/react-pong
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import Pong from "@alexium216/react-pong";
|
|
21
|
+
|
|
22
|
+
<Pong />;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### With custom props
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
<Pong
|
|
29
|
+
height={800}
|
|
30
|
+
width={1000}
|
|
31
|
+
ballSize={15}
|
|
32
|
+
paddleHeight={120}
|
|
33
|
+
paddleSpeed={7}
|
|
34
|
+
/>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Props
|
|
38
|
+
|
|
39
|
+
All props are optional:
|
|
40
|
+
|
|
41
|
+
- `height` - Number - Height of canvas element in px - default: 600
|
|
42
|
+
- `width` - Number - Width of canvas element in px - default: 700
|
|
43
|
+
- `upArrow` - String - Key code for moving paddle up - default: 'ArrowUp'
|
|
44
|
+
- `downArrow` - String - Key code for moving paddle down - default: 'ArrowDown'
|
|
45
|
+
- `ballSize` - Number - Diameter of ball in px - default: 10
|
|
46
|
+
- `paddleHeight` - Number - Height of paddles in px - default: 100
|
|
47
|
+
- `paddleWidth` - Number - Width of paddles in px - default: 20
|
|
48
|
+
- `paddleSpeed` - Number - Pixels moved per key press - default: 5
|
|
49
|
+
|
|
50
|
+
## Development
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install
|
|
54
|
+
npm run dev # Start dev server
|
|
55
|
+
npm run build # Build for production
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
MIT
|
package/dist/ai.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
interface State {
|
|
2
|
+
ballx: number;
|
|
3
|
+
bally: number;
|
|
4
|
+
ballSpeed: number;
|
|
5
|
+
velx: number;
|
|
6
|
+
vely: number;
|
|
7
|
+
aix: number;
|
|
8
|
+
aiy: number;
|
|
9
|
+
playerx: number;
|
|
10
|
+
playery: number;
|
|
11
|
+
playerScore: number;
|
|
12
|
+
aiScore: number;
|
|
13
|
+
}
|
|
14
|
+
interface ComponentContext {
|
|
15
|
+
_context: CanvasRenderingContext2D | null;
|
|
16
|
+
state: State;
|
|
17
|
+
props: {
|
|
18
|
+
height: number;
|
|
19
|
+
width: number;
|
|
20
|
+
upArrow: string;
|
|
21
|
+
downArrow: string;
|
|
22
|
+
ballSize: number;
|
|
23
|
+
paddleHeight: number;
|
|
24
|
+
paddleWidth: number;
|
|
25
|
+
paddleSpeed: number;
|
|
26
|
+
};
|
|
27
|
+
setState: (updater: (prevState: State) => State) => void;
|
|
28
|
+
}
|
|
29
|
+
export default function createAI(this: ComponentContext): {
|
|
30
|
+
update(): void;
|
|
31
|
+
draw(): void;
|
|
32
|
+
name(): string;
|
|
33
|
+
position(): {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export {};
|
package/dist/ball.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
interface State {
|
|
2
|
+
ballx: number;
|
|
3
|
+
bally: number;
|
|
4
|
+
ballSpeed: number;
|
|
5
|
+
velx: number;
|
|
6
|
+
vely: number;
|
|
7
|
+
aix: number;
|
|
8
|
+
aiy: number;
|
|
9
|
+
playerx: number;
|
|
10
|
+
playery: number;
|
|
11
|
+
playerScore: number;
|
|
12
|
+
aiScore: number;
|
|
13
|
+
}
|
|
14
|
+
interface Paddle {
|
|
15
|
+
name: () => string;
|
|
16
|
+
position: () => {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
};
|
|
20
|
+
update: () => void;
|
|
21
|
+
draw: () => void;
|
|
22
|
+
}
|
|
23
|
+
interface ComponentContext {
|
|
24
|
+
_context: CanvasRenderingContext2D | null;
|
|
25
|
+
state: State;
|
|
26
|
+
props: {
|
|
27
|
+
height: number;
|
|
28
|
+
width: number;
|
|
29
|
+
upArrow: string;
|
|
30
|
+
downArrow: string;
|
|
31
|
+
ballSize: number;
|
|
32
|
+
paddleHeight: number;
|
|
33
|
+
paddleWidth: number;
|
|
34
|
+
paddleSpeed: number;
|
|
35
|
+
};
|
|
36
|
+
setState: (updater: (prevState: State) => State) => void;
|
|
37
|
+
_score: (name: string) => void;
|
|
38
|
+
}
|
|
39
|
+
export default function createBall(this: ComponentContext, getPlayer: () => Paddle, getAI: () => Paddle): {
|
|
40
|
+
serve(side: number): void;
|
|
41
|
+
update(): void;
|
|
42
|
+
draw(): void;
|
|
43
|
+
};
|
|
44
|
+
export {};
|
package/dist/lib.d.ts
ADDED
package/dist/player.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
interface State {
|
|
2
|
+
ballx: number;
|
|
3
|
+
bally: number;
|
|
4
|
+
ballSpeed: number;
|
|
5
|
+
velx: number;
|
|
6
|
+
vely: number;
|
|
7
|
+
aix: number;
|
|
8
|
+
aiy: number;
|
|
9
|
+
playerx: number;
|
|
10
|
+
playery: number;
|
|
11
|
+
playerScore: number;
|
|
12
|
+
aiScore: number;
|
|
13
|
+
}
|
|
14
|
+
interface ComponentContext {
|
|
15
|
+
_context: CanvasRenderingContext2D | null;
|
|
16
|
+
state: State;
|
|
17
|
+
props: {
|
|
18
|
+
height: number;
|
|
19
|
+
width: number;
|
|
20
|
+
upArrow: string;
|
|
21
|
+
downArrow: string;
|
|
22
|
+
ballSize: number;
|
|
23
|
+
paddleHeight: number;
|
|
24
|
+
paddleWidth: number;
|
|
25
|
+
paddleSpeed: number;
|
|
26
|
+
};
|
|
27
|
+
_keystate: {
|
|
28
|
+
[key: string]: boolean;
|
|
29
|
+
};
|
|
30
|
+
setState: (updater: (prevState: State) => State) => void;
|
|
31
|
+
}
|
|
32
|
+
export default function createPlayer(this: ComponentContext): {
|
|
33
|
+
update(): void;
|
|
34
|
+
draw(): void;
|
|
35
|
+
name(): string;
|
|
36
|
+
position(y?: number): {
|
|
37
|
+
x: number;
|
|
38
|
+
y: number;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export {};
|
package/dist/pong.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
interface PongProps {
|
|
3
|
+
height?: number;
|
|
4
|
+
width?: number;
|
|
5
|
+
upArrow?: string;
|
|
6
|
+
downArrow?: string;
|
|
7
|
+
ballSize?: number;
|
|
8
|
+
paddleHeight?: number;
|
|
9
|
+
paddleWidth?: number;
|
|
10
|
+
paddleSpeed?: number;
|
|
11
|
+
}
|
|
12
|
+
declare const Pong: React.FC<PongProps>;
|
|
13
|
+
export default Pong;
|
|
@@ -0,0 +1,874 @@
|
|
|
1
|
+
import $e, { useState as dr, useRef as B, useEffect as Fe } from "react";
|
|
2
|
+
var oe = { exports: {} }, Q = {};
|
|
3
|
+
/**
|
|
4
|
+
* @license React
|
|
5
|
+
* react-jsx-runtime.production.min.js
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the MIT license found in the
|
|
10
|
+
* LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/
|
|
12
|
+
var Ie;
|
|
13
|
+
function vr() {
|
|
14
|
+
if (Ie) return Q;
|
|
15
|
+
Ie = 1;
|
|
16
|
+
var _ = $e, c = Symbol.for("react.element"), E = Symbol.for("react.fragment"), x = Object.prototype.hasOwnProperty, o = _.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, f = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
17
|
+
function b(m, h, p) {
|
|
18
|
+
var s, a = {}, O = null, S = null;
|
|
19
|
+
p !== void 0 && (O = "" + p), h.key !== void 0 && (O = "" + h.key), h.ref !== void 0 && (S = h.ref);
|
|
20
|
+
for (s in h) x.call(h, s) && !f.hasOwnProperty(s) && (a[s] = h[s]);
|
|
21
|
+
if (m && m.defaultProps) for (s in h = m.defaultProps, h) a[s] === void 0 && (a[s] = h[s]);
|
|
22
|
+
return { $$typeof: c, type: m, key: O, ref: S, props: a, _owner: o.current };
|
|
23
|
+
}
|
|
24
|
+
return Q.Fragment = E, Q.jsx = b, Q.jsxs = b, Q;
|
|
25
|
+
}
|
|
26
|
+
var ee = {};
|
|
27
|
+
/**
|
|
28
|
+
* @license React
|
|
29
|
+
* react-jsx-runtime.development.js
|
|
30
|
+
*
|
|
31
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
32
|
+
*
|
|
33
|
+
* This source code is licensed under the MIT license found in the
|
|
34
|
+
* LICENSE file in the root directory of this source tree.
|
|
35
|
+
*/
|
|
36
|
+
var We;
|
|
37
|
+
function pr() {
|
|
38
|
+
return We || (We = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
39
|
+
var _ = $e, c = Symbol.for("react.element"), E = Symbol.for("react.portal"), x = Symbol.for("react.fragment"), o = Symbol.for("react.strict_mode"), f = Symbol.for("react.profiler"), b = Symbol.for("react.provider"), m = Symbol.for("react.context"), h = Symbol.for("react.forward_ref"), p = Symbol.for("react.suspense"), s = Symbol.for("react.suspense_list"), a = Symbol.for("react.memo"), O = Symbol.for("react.lazy"), S = Symbol.for("react.offscreen"), N = Symbol.iterator, L = "@@iterator";
|
|
40
|
+
function C(e) {
|
|
41
|
+
if (e === null || typeof e != "object")
|
|
42
|
+
return null;
|
|
43
|
+
var r = N && e[N] || e[L];
|
|
44
|
+
return typeof r == "function" ? r : null;
|
|
45
|
+
}
|
|
46
|
+
var k = _.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
47
|
+
function d(e) {
|
|
48
|
+
{
|
|
49
|
+
for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++)
|
|
50
|
+
t[n - 1] = arguments[n];
|
|
51
|
+
D("error", e, t);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function D(e, r, t) {
|
|
55
|
+
{
|
|
56
|
+
var n = k.ReactDebugCurrentFrame, u = n.getStackAddendum();
|
|
57
|
+
u !== "" && (r += "%s", t = t.concat([u]));
|
|
58
|
+
var v = t.map(function(l) {
|
|
59
|
+
return String(l);
|
|
60
|
+
});
|
|
61
|
+
v.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, v);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
var U = !1, z = !1, F = !1, w = !1, J = !1, K;
|
|
65
|
+
K = Symbol.for("react.module.reference");
|
|
66
|
+
function ie(e) {
|
|
67
|
+
return !!(typeof e == "string" || typeof e == "function" || e === x || e === f || J || e === o || e === p || e === s || w || e === S || U || z || F || typeof e == "object" && e !== null && (e.$$typeof === O || e.$$typeof === a || e.$$typeof === b || e.$$typeof === m || e.$$typeof === h || // This needs to include all possible module reference object
|
|
68
|
+
// types supported by any Flight configuration anywhere since
|
|
69
|
+
// we don't know which Flight build this will end up being used
|
|
70
|
+
// with.
|
|
71
|
+
e.$$typeof === K || e.getModuleId !== void 0));
|
|
72
|
+
}
|
|
73
|
+
function le(e, r, t) {
|
|
74
|
+
var n = e.displayName;
|
|
75
|
+
if (n)
|
|
76
|
+
return n;
|
|
77
|
+
var u = r.displayName || r.name || "";
|
|
78
|
+
return u !== "" ? t + "(" + u + ")" : t;
|
|
79
|
+
}
|
|
80
|
+
function X(e) {
|
|
81
|
+
return e.displayName || "Context";
|
|
82
|
+
}
|
|
83
|
+
function I(e) {
|
|
84
|
+
if (e == null)
|
|
85
|
+
return null;
|
|
86
|
+
if (typeof e.tag == "number" && d("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
|
|
87
|
+
return e.displayName || e.name || null;
|
|
88
|
+
if (typeof e == "string")
|
|
89
|
+
return e;
|
|
90
|
+
switch (e) {
|
|
91
|
+
case x:
|
|
92
|
+
return "Fragment";
|
|
93
|
+
case E:
|
|
94
|
+
return "Portal";
|
|
95
|
+
case f:
|
|
96
|
+
return "Profiler";
|
|
97
|
+
case o:
|
|
98
|
+
return "StrictMode";
|
|
99
|
+
case p:
|
|
100
|
+
return "Suspense";
|
|
101
|
+
case s:
|
|
102
|
+
return "SuspenseList";
|
|
103
|
+
}
|
|
104
|
+
if (typeof e == "object")
|
|
105
|
+
switch (e.$$typeof) {
|
|
106
|
+
case m:
|
|
107
|
+
var r = e;
|
|
108
|
+
return X(r) + ".Consumer";
|
|
109
|
+
case b:
|
|
110
|
+
var t = e;
|
|
111
|
+
return X(t._context) + ".Provider";
|
|
112
|
+
case h:
|
|
113
|
+
return le(e, e.render, "ForwardRef");
|
|
114
|
+
case a:
|
|
115
|
+
var n = e.displayName || null;
|
|
116
|
+
return n !== null ? n : I(e.type) || "Memo";
|
|
117
|
+
case O: {
|
|
118
|
+
var u = e, v = u._payload, l = u._init;
|
|
119
|
+
try {
|
|
120
|
+
return I(l(v));
|
|
121
|
+
} catch {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
var M = Object.assign, y = 0, j, Y, W, V, $, he, be;
|
|
129
|
+
function ge() {
|
|
130
|
+
}
|
|
131
|
+
ge.__reactDisabledLog = !0;
|
|
132
|
+
function Ye() {
|
|
133
|
+
{
|
|
134
|
+
if (y === 0) {
|
|
135
|
+
j = console.log, Y = console.info, W = console.warn, V = console.error, $ = console.group, he = console.groupCollapsed, be = console.groupEnd;
|
|
136
|
+
var e = {
|
|
137
|
+
configurable: !0,
|
|
138
|
+
enumerable: !0,
|
|
139
|
+
value: ge,
|
|
140
|
+
writable: !0
|
|
141
|
+
};
|
|
142
|
+
Object.defineProperties(console, {
|
|
143
|
+
info: e,
|
|
144
|
+
log: e,
|
|
145
|
+
warn: e,
|
|
146
|
+
error: e,
|
|
147
|
+
group: e,
|
|
148
|
+
groupCollapsed: e,
|
|
149
|
+
groupEnd: e
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
y++;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function Le() {
|
|
156
|
+
{
|
|
157
|
+
if (y--, y === 0) {
|
|
158
|
+
var e = {
|
|
159
|
+
configurable: !0,
|
|
160
|
+
enumerable: !0,
|
|
161
|
+
writable: !0
|
|
162
|
+
};
|
|
163
|
+
Object.defineProperties(console, {
|
|
164
|
+
log: M({}, e, {
|
|
165
|
+
value: j
|
|
166
|
+
}),
|
|
167
|
+
info: M({}, e, {
|
|
168
|
+
value: Y
|
|
169
|
+
}),
|
|
170
|
+
warn: M({}, e, {
|
|
171
|
+
value: W
|
|
172
|
+
}),
|
|
173
|
+
error: M({}, e, {
|
|
174
|
+
value: V
|
|
175
|
+
}),
|
|
176
|
+
group: M({}, e, {
|
|
177
|
+
value: $
|
|
178
|
+
}),
|
|
179
|
+
groupCollapsed: M({}, e, {
|
|
180
|
+
value: he
|
|
181
|
+
}),
|
|
182
|
+
groupEnd: M({}, e, {
|
|
183
|
+
value: be
|
|
184
|
+
})
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
y < 0 && d("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
var se = k.ReactCurrentDispatcher, ue;
|
|
191
|
+
function re(e, r, t) {
|
|
192
|
+
{
|
|
193
|
+
if (ue === void 0)
|
|
194
|
+
try {
|
|
195
|
+
throw Error();
|
|
196
|
+
} catch (u) {
|
|
197
|
+
var n = u.stack.trim().match(/\n( *(at )?)/);
|
|
198
|
+
ue = n && n[1] || "";
|
|
199
|
+
}
|
|
200
|
+
return `
|
|
201
|
+
` + ue + e;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
var ce = !1, te;
|
|
205
|
+
{
|
|
206
|
+
var Ue = typeof WeakMap == "function" ? WeakMap : Map;
|
|
207
|
+
te = new Ue();
|
|
208
|
+
}
|
|
209
|
+
function me(e, r) {
|
|
210
|
+
if (!e || ce)
|
|
211
|
+
return "";
|
|
212
|
+
{
|
|
213
|
+
var t = te.get(e);
|
|
214
|
+
if (t !== void 0)
|
|
215
|
+
return t;
|
|
216
|
+
}
|
|
217
|
+
var n;
|
|
218
|
+
ce = !0;
|
|
219
|
+
var u = Error.prepareStackTrace;
|
|
220
|
+
Error.prepareStackTrace = void 0;
|
|
221
|
+
var v;
|
|
222
|
+
v = se.current, se.current = null, Ye();
|
|
223
|
+
try {
|
|
224
|
+
if (r) {
|
|
225
|
+
var l = function() {
|
|
226
|
+
throw Error();
|
|
227
|
+
};
|
|
228
|
+
if (Object.defineProperty(l.prototype, "props", {
|
|
229
|
+
set: function() {
|
|
230
|
+
throw Error();
|
|
231
|
+
}
|
|
232
|
+
}), typeof Reflect == "object" && Reflect.construct) {
|
|
233
|
+
try {
|
|
234
|
+
Reflect.construct(l, []);
|
|
235
|
+
} catch (P) {
|
|
236
|
+
n = P;
|
|
237
|
+
}
|
|
238
|
+
Reflect.construct(e, [], l);
|
|
239
|
+
} else {
|
|
240
|
+
try {
|
|
241
|
+
l.call();
|
|
242
|
+
} catch (P) {
|
|
243
|
+
n = P;
|
|
244
|
+
}
|
|
245
|
+
e.call(l.prototype);
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
try {
|
|
249
|
+
throw Error();
|
|
250
|
+
} catch (P) {
|
|
251
|
+
n = P;
|
|
252
|
+
}
|
|
253
|
+
e();
|
|
254
|
+
}
|
|
255
|
+
} catch (P) {
|
|
256
|
+
if (P && n && typeof P.stack == "string") {
|
|
257
|
+
for (var i = P.stack.split(`
|
|
258
|
+
`), T = n.stack.split(`
|
|
259
|
+
`), g = i.length - 1, R = T.length - 1; g >= 1 && R >= 0 && i[g] !== T[R]; )
|
|
260
|
+
R--;
|
|
261
|
+
for (; g >= 1 && R >= 0; g--, R--)
|
|
262
|
+
if (i[g] !== T[R]) {
|
|
263
|
+
if (g !== 1 || R !== 1)
|
|
264
|
+
do
|
|
265
|
+
if (g--, R--, R < 0 || i[g] !== T[R]) {
|
|
266
|
+
var A = `
|
|
267
|
+
` + i[g].replace(" at new ", " at ");
|
|
268
|
+
return e.displayName && A.includes("<anonymous>") && (A = A.replace("<anonymous>", e.displayName)), typeof e == "function" && te.set(e, A), A;
|
|
269
|
+
}
|
|
270
|
+
while (g >= 1 && R >= 0);
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
} finally {
|
|
275
|
+
ce = !1, se.current = v, Le(), Error.prepareStackTrace = u;
|
|
276
|
+
}
|
|
277
|
+
var H = e ? e.displayName || e.name : "", q = H ? re(H) : "";
|
|
278
|
+
return typeof e == "function" && te.set(e, q), q;
|
|
279
|
+
}
|
|
280
|
+
function ze(e, r, t) {
|
|
281
|
+
return me(e, !1);
|
|
282
|
+
}
|
|
283
|
+
function Ve(e) {
|
|
284
|
+
var r = e.prototype;
|
|
285
|
+
return !!(r && r.isReactComponent);
|
|
286
|
+
}
|
|
287
|
+
function ne(e, r, t) {
|
|
288
|
+
if (e == null)
|
|
289
|
+
return "";
|
|
290
|
+
if (typeof e == "function")
|
|
291
|
+
return me(e, Ve(e));
|
|
292
|
+
if (typeof e == "string")
|
|
293
|
+
return re(e);
|
|
294
|
+
switch (e) {
|
|
295
|
+
case p:
|
|
296
|
+
return re("Suspense");
|
|
297
|
+
case s:
|
|
298
|
+
return re("SuspenseList");
|
|
299
|
+
}
|
|
300
|
+
if (typeof e == "object")
|
|
301
|
+
switch (e.$$typeof) {
|
|
302
|
+
case h:
|
|
303
|
+
return ze(e.render);
|
|
304
|
+
case a:
|
|
305
|
+
return ne(e.type, r, t);
|
|
306
|
+
case O: {
|
|
307
|
+
var n = e, u = n._payload, v = n._init;
|
|
308
|
+
try {
|
|
309
|
+
return ne(v(u), r, t);
|
|
310
|
+
} catch {
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return "";
|
|
315
|
+
}
|
|
316
|
+
var Z = Object.prototype.hasOwnProperty, Re = {}, _e = k.ReactDebugCurrentFrame;
|
|
317
|
+
function ae(e) {
|
|
318
|
+
if (e) {
|
|
319
|
+
var r = e._owner, t = ne(e.type, e._source, r ? r.type : null);
|
|
320
|
+
_e.setExtraStackFrame(t);
|
|
321
|
+
} else
|
|
322
|
+
_e.setExtraStackFrame(null);
|
|
323
|
+
}
|
|
324
|
+
function Be(e, r, t, n, u) {
|
|
325
|
+
{
|
|
326
|
+
var v = Function.call.bind(Z);
|
|
327
|
+
for (var l in e)
|
|
328
|
+
if (v(e, l)) {
|
|
329
|
+
var i = void 0;
|
|
330
|
+
try {
|
|
331
|
+
if (typeof e[l] != "function") {
|
|
332
|
+
var T = Error((n || "React class") + ": " + t + " type `" + l + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[l] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
|
|
333
|
+
throw T.name = "Invariant Violation", T;
|
|
334
|
+
}
|
|
335
|
+
i = e[l](r, l, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
|
|
336
|
+
} catch (g) {
|
|
337
|
+
i = g;
|
|
338
|
+
}
|
|
339
|
+
i && !(i instanceof Error) && (ae(u), d("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", n || "React class", t, l, typeof i), ae(null)), i instanceof Error && !(i.message in Re) && (Re[i.message] = !0, ae(u), d("Failed %s type: %s", t, i.message), ae(null));
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
var Ne = Array.isArray;
|
|
344
|
+
function fe(e) {
|
|
345
|
+
return Ne(e);
|
|
346
|
+
}
|
|
347
|
+
function Je(e) {
|
|
348
|
+
{
|
|
349
|
+
var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
350
|
+
return t;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
function Ke(e) {
|
|
354
|
+
try {
|
|
355
|
+
return Ee(e), !1;
|
|
356
|
+
} catch {
|
|
357
|
+
return !0;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
function Ee(e) {
|
|
361
|
+
return "" + e;
|
|
362
|
+
}
|
|
363
|
+
function xe(e) {
|
|
364
|
+
if (Ke(e))
|
|
365
|
+
return d("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Je(e)), Ee(e);
|
|
366
|
+
}
|
|
367
|
+
var Se = k.ReactCurrentOwner, qe = {
|
|
368
|
+
key: !0,
|
|
369
|
+
ref: !0,
|
|
370
|
+
__self: !0,
|
|
371
|
+
__source: !0
|
|
372
|
+
}, Te, we;
|
|
373
|
+
function Ge(e) {
|
|
374
|
+
if (Z.call(e, "ref")) {
|
|
375
|
+
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
|
|
376
|
+
if (r && r.isReactWarning)
|
|
377
|
+
return !1;
|
|
378
|
+
}
|
|
379
|
+
return e.ref !== void 0;
|
|
380
|
+
}
|
|
381
|
+
function He(e) {
|
|
382
|
+
if (Z.call(e, "key")) {
|
|
383
|
+
var r = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
384
|
+
if (r && r.isReactWarning)
|
|
385
|
+
return !1;
|
|
386
|
+
}
|
|
387
|
+
return e.key !== void 0;
|
|
388
|
+
}
|
|
389
|
+
function Xe(e, r) {
|
|
390
|
+
typeof e.ref == "string" && Se.current;
|
|
391
|
+
}
|
|
392
|
+
function Ze(e, r) {
|
|
393
|
+
{
|
|
394
|
+
var t = function() {
|
|
395
|
+
Te || (Te = !0, d("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
|
|
396
|
+
};
|
|
397
|
+
t.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
398
|
+
get: t,
|
|
399
|
+
configurable: !0
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function Qe(e, r) {
|
|
404
|
+
{
|
|
405
|
+
var t = function() {
|
|
406
|
+
we || (we = !0, d("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
|
|
407
|
+
};
|
|
408
|
+
t.isReactWarning = !0, Object.defineProperty(e, "ref", {
|
|
409
|
+
get: t,
|
|
410
|
+
configurable: !0
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
var er = function(e, r, t, n, u, v, l) {
|
|
415
|
+
var i = {
|
|
416
|
+
// This tag allows us to uniquely identify this as a React Element
|
|
417
|
+
$$typeof: c,
|
|
418
|
+
// Built-in properties that belong on the element
|
|
419
|
+
type: e,
|
|
420
|
+
key: r,
|
|
421
|
+
ref: t,
|
|
422
|
+
props: l,
|
|
423
|
+
// Record the component responsible for creating this element.
|
|
424
|
+
_owner: v
|
|
425
|
+
};
|
|
426
|
+
return i._store = {}, Object.defineProperty(i._store, "validated", {
|
|
427
|
+
configurable: !1,
|
|
428
|
+
enumerable: !1,
|
|
429
|
+
writable: !0,
|
|
430
|
+
value: !1
|
|
431
|
+
}), Object.defineProperty(i, "_self", {
|
|
432
|
+
configurable: !1,
|
|
433
|
+
enumerable: !1,
|
|
434
|
+
writable: !1,
|
|
435
|
+
value: n
|
|
436
|
+
}), Object.defineProperty(i, "_source", {
|
|
437
|
+
configurable: !1,
|
|
438
|
+
enumerable: !1,
|
|
439
|
+
writable: !1,
|
|
440
|
+
value: u
|
|
441
|
+
}), Object.freeze && (Object.freeze(i.props), Object.freeze(i)), i;
|
|
442
|
+
};
|
|
443
|
+
function rr(e, r, t, n, u) {
|
|
444
|
+
{
|
|
445
|
+
var v, l = {}, i = null, T = null;
|
|
446
|
+
t !== void 0 && (xe(t), i = "" + t), He(r) && (xe(r.key), i = "" + r.key), Ge(r) && (T = r.ref, Xe(r, u));
|
|
447
|
+
for (v in r)
|
|
448
|
+
Z.call(r, v) && !qe.hasOwnProperty(v) && (l[v] = r[v]);
|
|
449
|
+
if (e && e.defaultProps) {
|
|
450
|
+
var g = e.defaultProps;
|
|
451
|
+
for (v in g)
|
|
452
|
+
l[v] === void 0 && (l[v] = g[v]);
|
|
453
|
+
}
|
|
454
|
+
if (i || T) {
|
|
455
|
+
var R = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
|
|
456
|
+
i && Ze(l, R), T && Qe(l, R);
|
|
457
|
+
}
|
|
458
|
+
return er(e, i, T, u, n, Se.current, l);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
var de = k.ReactCurrentOwner, Pe = k.ReactDebugCurrentFrame;
|
|
462
|
+
function G(e) {
|
|
463
|
+
if (e) {
|
|
464
|
+
var r = e._owner, t = ne(e.type, e._source, r ? r.type : null);
|
|
465
|
+
Pe.setExtraStackFrame(t);
|
|
466
|
+
} else
|
|
467
|
+
Pe.setExtraStackFrame(null);
|
|
468
|
+
}
|
|
469
|
+
var ve;
|
|
470
|
+
ve = !1;
|
|
471
|
+
function pe(e) {
|
|
472
|
+
return typeof e == "object" && e !== null && e.$$typeof === c;
|
|
473
|
+
}
|
|
474
|
+
function Ce() {
|
|
475
|
+
{
|
|
476
|
+
if (de.current) {
|
|
477
|
+
var e = I(de.current.type);
|
|
478
|
+
if (e)
|
|
479
|
+
return `
|
|
480
|
+
|
|
481
|
+
Check the render method of \`` + e + "`.";
|
|
482
|
+
}
|
|
483
|
+
return "";
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
function tr(e) {
|
|
487
|
+
return "";
|
|
488
|
+
}
|
|
489
|
+
var Oe = {};
|
|
490
|
+
function nr(e) {
|
|
491
|
+
{
|
|
492
|
+
var r = Ce();
|
|
493
|
+
if (!r) {
|
|
494
|
+
var t = typeof e == "string" ? e : e.displayName || e.name;
|
|
495
|
+
t && (r = `
|
|
496
|
+
|
|
497
|
+
Check the top-level render call using <` + t + ">.");
|
|
498
|
+
}
|
|
499
|
+
return r;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
function ke(e, r) {
|
|
503
|
+
{
|
|
504
|
+
if (!e._store || e._store.validated || e.key != null)
|
|
505
|
+
return;
|
|
506
|
+
e._store.validated = !0;
|
|
507
|
+
var t = nr(r);
|
|
508
|
+
if (Oe[t])
|
|
509
|
+
return;
|
|
510
|
+
Oe[t] = !0;
|
|
511
|
+
var n = "";
|
|
512
|
+
e && e._owner && e._owner !== de.current && (n = " It was passed a child from " + I(e._owner.type) + "."), G(e), d('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), G(null);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
function je(e, r) {
|
|
516
|
+
{
|
|
517
|
+
if (typeof e != "object")
|
|
518
|
+
return;
|
|
519
|
+
if (fe(e))
|
|
520
|
+
for (var t = 0; t < e.length; t++) {
|
|
521
|
+
var n = e[t];
|
|
522
|
+
pe(n) && ke(n, r);
|
|
523
|
+
}
|
|
524
|
+
else if (pe(e))
|
|
525
|
+
e._store && (e._store.validated = !0);
|
|
526
|
+
else if (e) {
|
|
527
|
+
var u = C(e);
|
|
528
|
+
if (typeof u == "function" && u !== e.entries)
|
|
529
|
+
for (var v = u.call(e), l; !(l = v.next()).done; )
|
|
530
|
+
pe(l.value) && ke(l.value, r);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
function ar(e) {
|
|
535
|
+
{
|
|
536
|
+
var r = e.type;
|
|
537
|
+
if (r == null || typeof r == "string")
|
|
538
|
+
return;
|
|
539
|
+
var t;
|
|
540
|
+
if (typeof r == "function")
|
|
541
|
+
t = r.propTypes;
|
|
542
|
+
else if (typeof r == "object" && (r.$$typeof === h || // Note: Memo only checks outer props here.
|
|
543
|
+
// Inner props are checked in the reconciler.
|
|
544
|
+
r.$$typeof === a))
|
|
545
|
+
t = r.propTypes;
|
|
546
|
+
else
|
|
547
|
+
return;
|
|
548
|
+
if (t) {
|
|
549
|
+
var n = I(r);
|
|
550
|
+
Be(t, e.props, "prop", n, e);
|
|
551
|
+
} else if (r.PropTypes !== void 0 && !ve) {
|
|
552
|
+
ve = !0;
|
|
553
|
+
var u = I(r);
|
|
554
|
+
d("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", u || "Unknown");
|
|
555
|
+
}
|
|
556
|
+
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && d("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
function or(e) {
|
|
560
|
+
{
|
|
561
|
+
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
|
|
562
|
+
var n = r[t];
|
|
563
|
+
if (n !== "children" && n !== "key") {
|
|
564
|
+
G(e), d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), G(null);
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
e.ref !== null && (G(e), d("Invalid attribute `ref` supplied to `React.Fragment`."), G(null));
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
var Ae = {};
|
|
572
|
+
function De(e, r, t, n, u, v) {
|
|
573
|
+
{
|
|
574
|
+
var l = ie(e);
|
|
575
|
+
if (!l) {
|
|
576
|
+
var i = "";
|
|
577
|
+
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (i += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
|
|
578
|
+
var T = tr();
|
|
579
|
+
T ? i += T : i += Ce();
|
|
580
|
+
var g;
|
|
581
|
+
e === null ? g = "null" : fe(e) ? g = "array" : e !== void 0 && e.$$typeof === c ? (g = "<" + (I(e.type) || "Unknown") + " />", i = " Did you accidentally export a JSX literal instead of a component?") : g = typeof e, d("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", g, i);
|
|
582
|
+
}
|
|
583
|
+
var R = rr(e, r, t, u, v);
|
|
584
|
+
if (R == null)
|
|
585
|
+
return R;
|
|
586
|
+
if (l) {
|
|
587
|
+
var A = r.children;
|
|
588
|
+
if (A !== void 0)
|
|
589
|
+
if (n)
|
|
590
|
+
if (fe(A)) {
|
|
591
|
+
for (var H = 0; H < A.length; H++)
|
|
592
|
+
je(A[H], e);
|
|
593
|
+
Object.freeze && Object.freeze(A);
|
|
594
|
+
} else
|
|
595
|
+
d("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
|
|
596
|
+
else
|
|
597
|
+
je(A, e);
|
|
598
|
+
}
|
|
599
|
+
if (Z.call(r, "key")) {
|
|
600
|
+
var q = I(e), P = Object.keys(r).filter(function(fr) {
|
|
601
|
+
return fr !== "key";
|
|
602
|
+
}), ye = P.length > 0 ? "{key: someKey, " + P.join(": ..., ") + ": ...}" : "{key: someKey}";
|
|
603
|
+
if (!Ae[q + ye]) {
|
|
604
|
+
var cr = P.length > 0 ? "{" + P.join(": ..., ") + ": ...}" : "{}";
|
|
605
|
+
d(`A props object containing a "key" prop is being spread into JSX:
|
|
606
|
+
let props = %s;
|
|
607
|
+
<%s {...props} />
|
|
608
|
+
React keys must be passed directly to JSX without using spread:
|
|
609
|
+
let props = %s;
|
|
610
|
+
<%s key={someKey} {...props} />`, ye, q, cr, q), Ae[q + ye] = !0;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
return e === x ? or(R) : ar(R), R;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
function ir(e, r, t) {
|
|
617
|
+
return De(e, r, t, !0);
|
|
618
|
+
}
|
|
619
|
+
function lr(e, r, t) {
|
|
620
|
+
return De(e, r, t, !1);
|
|
621
|
+
}
|
|
622
|
+
var sr = lr, ur = ir;
|
|
623
|
+
ee.Fragment = x, ee.jsx = sr, ee.jsxs = ur;
|
|
624
|
+
})()), ee;
|
|
625
|
+
}
|
|
626
|
+
var Me;
|
|
627
|
+
function yr() {
|
|
628
|
+
return Me || (Me = 1, process.env.NODE_ENV === "production" ? oe.exports = vr() : oe.exports = pr()), oe.exports;
|
|
629
|
+
}
|
|
630
|
+
var hr = yr();
|
|
631
|
+
function br(_, c) {
|
|
632
|
+
const E = Math.PI, x = () => this._context, o = this.props, f = this._score, b = () => this.state, m = (p) => {
|
|
633
|
+
this.setState(p);
|
|
634
|
+
}, h = Math.random();
|
|
635
|
+
return {
|
|
636
|
+
serve(p) {
|
|
637
|
+
const s = 0.1 * E * (1 - 2 * h);
|
|
638
|
+
m((a) => ({
|
|
639
|
+
...a,
|
|
640
|
+
ballx: p === 1 ? a.playerx + o.paddleWidth : a.aix - o.ballSize,
|
|
641
|
+
bally: (o.height - o.ballSize) * h,
|
|
642
|
+
velx: a.ballSpeed * Math.cos(s) * p,
|
|
643
|
+
vely: a.ballSpeed * Math.sin(s)
|
|
644
|
+
}));
|
|
645
|
+
},
|
|
646
|
+
update() {
|
|
647
|
+
const p = _(), s = c(), a = b(), O = a.ballx, S = a.bally, N = a.velx, L = a.vely;
|
|
648
|
+
if (m((d) => ({
|
|
649
|
+
...d,
|
|
650
|
+
ballx: O + N,
|
|
651
|
+
bally: S + L
|
|
652
|
+
})), 0 > S || S + o.ballSize > o.height) {
|
|
653
|
+
const d = a.vely < 0 ? 0 - a.bally : o.height - (a.bally + o.ballSize);
|
|
654
|
+
m((D) => ({
|
|
655
|
+
...D,
|
|
656
|
+
bally: S + 2 * d,
|
|
657
|
+
vely: L * -1
|
|
658
|
+
}));
|
|
659
|
+
}
|
|
660
|
+
const C = a.velx < 0 ? p : s;
|
|
661
|
+
if (((d, D, U, z, F, w, J, K) => d < F + J && D < w + K && F < d + U && w < D + z)(
|
|
662
|
+
C.position().x,
|
|
663
|
+
C.position().y,
|
|
664
|
+
o.paddleWidth,
|
|
665
|
+
o.paddleHeight,
|
|
666
|
+
a.ballx,
|
|
667
|
+
a.bally,
|
|
668
|
+
o.ballSize,
|
|
669
|
+
o.ballSize
|
|
670
|
+
)) {
|
|
671
|
+
const d = a.velx < 0 ? 1 : -1, D = (a.bally + o.ballSize - C.position().y) / (o.paddleHeight + o.ballSize), U = (D > 0.5 ? -1 : 1) * d, z = 0.25 * E * (2 * D + d) + h, F = Math.abs(z) > 0.2 * E ? 1.1 : 1;
|
|
672
|
+
m((w) => ({
|
|
673
|
+
...w,
|
|
674
|
+
ballx: C === p ? w.playerx + o.paddleWidth : w.aix - o.ballSize,
|
|
675
|
+
velx: F * -1 * w.velx,
|
|
676
|
+
vely: F * U * w.velx * Math.sin(z)
|
|
677
|
+
}));
|
|
678
|
+
}
|
|
679
|
+
(0 > a.ballx + o.ballSize || a.ballx > o.width) && (f(C.name()), this.serve(C.name() === p.name() ? 1 : -1));
|
|
680
|
+
},
|
|
681
|
+
draw() {
|
|
682
|
+
const p = x();
|
|
683
|
+
if (!p) return;
|
|
684
|
+
const s = b();
|
|
685
|
+
p.beginPath(), p.arc(s.ballx, s.bally, o.ballSize, 0, 2 * Math.PI), p.fill(), p.lineWidth = 0, p.strokeStyle = "#fff", p.stroke();
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
function gr() {
|
|
690
|
+
const _ = () => this._context, c = this.props, E = this._keystate, x = () => this.state, o = (f) => {
|
|
691
|
+
this.setState(f);
|
|
692
|
+
};
|
|
693
|
+
return {
|
|
694
|
+
update() {
|
|
695
|
+
const f = x();
|
|
696
|
+
let b = f.playery;
|
|
697
|
+
E[c.upArrow] && (b = f.playery - c.paddleSpeed), E[c.downArrow] && (b = f.playery + c.paddleSpeed), b = Math.max(Math.min(b, c.height - c.paddleHeight), 0), o((m) => ({ ...m, playery: b }));
|
|
698
|
+
},
|
|
699
|
+
draw() {
|
|
700
|
+
const f = _();
|
|
701
|
+
if (!f) return;
|
|
702
|
+
const b = x();
|
|
703
|
+
f.fillRect(b.playerx, b.playery, c.paddleWidth, c.paddleHeight);
|
|
704
|
+
},
|
|
705
|
+
name() {
|
|
706
|
+
return "player";
|
|
707
|
+
},
|
|
708
|
+
position(f) {
|
|
709
|
+
f !== void 0 && o((m) => ({ ...m, playery: f }));
|
|
710
|
+
const b = x();
|
|
711
|
+
return {
|
|
712
|
+
x: b.playerx,
|
|
713
|
+
y: b.playery
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
function mr() {
|
|
719
|
+
const _ = () => this._context, c = this.props, E = () => this.state, x = (o) => {
|
|
720
|
+
this.setState(o);
|
|
721
|
+
};
|
|
722
|
+
return {
|
|
723
|
+
update() {
|
|
724
|
+
const o = E();
|
|
725
|
+
let f = o.aiy;
|
|
726
|
+
const b = o.bally - (c.paddleHeight - c.ballSize) * 0.5;
|
|
727
|
+
f = f + (b - f) * 0.1, x((m) => ({ ...m, aiy: f }));
|
|
728
|
+
},
|
|
729
|
+
draw() {
|
|
730
|
+
const o = _();
|
|
731
|
+
if (!o) return;
|
|
732
|
+
const f = E();
|
|
733
|
+
o.fillRect(f.aix, f.aiy, c.paddleWidth, c.paddleHeight);
|
|
734
|
+
},
|
|
735
|
+
name() {
|
|
736
|
+
return "ai";
|
|
737
|
+
},
|
|
738
|
+
position() {
|
|
739
|
+
const o = E();
|
|
740
|
+
return {
|
|
741
|
+
x: o.aix,
|
|
742
|
+
y: o.aiy
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
const _r = ({
|
|
748
|
+
height: _ = 600,
|
|
749
|
+
width: c = 700,
|
|
750
|
+
upArrow: E = "ArrowUp",
|
|
751
|
+
downArrow: x = "ArrowDown",
|
|
752
|
+
paddleHeight: o = 100,
|
|
753
|
+
paddleWidth: f = 20,
|
|
754
|
+
paddleSpeed: b = 5,
|
|
755
|
+
ballSize: m = 10
|
|
756
|
+
}) => {
|
|
757
|
+
const [h, p] = dr({
|
|
758
|
+
ballx: 100,
|
|
759
|
+
bally: 100,
|
|
760
|
+
ballSpeed: 2,
|
|
761
|
+
velx: 0,
|
|
762
|
+
vely: 0,
|
|
763
|
+
aix: 670,
|
|
764
|
+
aiy: 100,
|
|
765
|
+
playerx: 10,
|
|
766
|
+
playery: 100,
|
|
767
|
+
playerScore: 0,
|
|
768
|
+
aiScore: 0
|
|
769
|
+
}), s = B(null), a = B(null), O = B({}), S = B(null), N = B(h), L = B(null), C = B(null), k = B(null);
|
|
770
|
+
Fe(() => {
|
|
771
|
+
N.current = h;
|
|
772
|
+
}, [h]);
|
|
773
|
+
const d = {
|
|
774
|
+
display: "block",
|
|
775
|
+
position: "absolute",
|
|
776
|
+
margin: "auto",
|
|
777
|
+
top: "0",
|
|
778
|
+
bottom: "0",
|
|
779
|
+
left: "0",
|
|
780
|
+
right: "0"
|
|
781
|
+
}, D = { height: _, width: c, upArrow: E, downArrow: x, paddleHeight: o, paddleWidth: f, paddleSpeed: b, ballSize: m }, U = () => {
|
|
782
|
+
s.current && (a.current = s.current.getContext("2d"));
|
|
783
|
+
}, z = (y) => {
|
|
784
|
+
const j = y === "player" ? "ai" : "player", Y = j + "Score";
|
|
785
|
+
p((W) => ({
|
|
786
|
+
...W,
|
|
787
|
+
[Y]: W[Y] + 1
|
|
788
|
+
})), X(), setTimeout(() => {
|
|
789
|
+
a.current && (a.current.font = "30px Arial", a.current.fillStyle = "#fff", a.current.fillText(
|
|
790
|
+
j + " score!",
|
|
791
|
+
c / 2,
|
|
792
|
+
_ / 2
|
|
793
|
+
), a.current.restore());
|
|
794
|
+
}, 0), setTimeout(() => {
|
|
795
|
+
U(), I();
|
|
796
|
+
}, 1e3);
|
|
797
|
+
}, F = () => ({
|
|
798
|
+
get _context() {
|
|
799
|
+
return a.current;
|
|
800
|
+
},
|
|
801
|
+
get state() {
|
|
802
|
+
return N.current;
|
|
803
|
+
},
|
|
804
|
+
props: D,
|
|
805
|
+
_keystate: O.current,
|
|
806
|
+
setState: (y) => {
|
|
807
|
+
p(y);
|
|
808
|
+
},
|
|
809
|
+
_score: z
|
|
810
|
+
});
|
|
811
|
+
C.current || (C.current = gr.call(F())), k.current || (k.current = mr.call(F())), L.current || (L.current = br.call(
|
|
812
|
+
F(),
|
|
813
|
+
() => C.current,
|
|
814
|
+
() => k.current
|
|
815
|
+
));
|
|
816
|
+
const w = L.current, J = C.current, K = k.current, ie = () => {
|
|
817
|
+
if (!a.current) return;
|
|
818
|
+
const y = a.current;
|
|
819
|
+
y.fillStyle = "#000", y.fillRect(0, 0, c, _), y.save(), y.fillStyle = "#fff", y.font = "10px Arial", y.fillText("Player: " + String(h.playerScore), 10, 10), y.fillText("CPU: " + String(h.aiScore), 500, 10), w.draw(), J.draw(), K.draw();
|
|
820
|
+
const j = 4, Y = (c - j) * 0.5;
|
|
821
|
+
let W = 0;
|
|
822
|
+
const V = _ / 20;
|
|
823
|
+
for (; W < _; )
|
|
824
|
+
y.fillRect(Y, W + V * 0.25, j, V * 0.5), W += V;
|
|
825
|
+
y.restore();
|
|
826
|
+
}, le = () => {
|
|
827
|
+
J.update(), K.update(), w.update();
|
|
828
|
+
}, X = () => {
|
|
829
|
+
S.current !== null && (clearInterval(S.current), S.current = null), setTimeout(() => {
|
|
830
|
+
a.current && s.current && a.current.clearRect(0, 0, s.current.width, s.current.height);
|
|
831
|
+
}, 0);
|
|
832
|
+
}, I = () => {
|
|
833
|
+
if (S.current)
|
|
834
|
+
return;
|
|
835
|
+
const y = O.current, j = ($) => {
|
|
836
|
+
y[$.code] = !0;
|
|
837
|
+
}, Y = ($) => {
|
|
838
|
+
y[$.code] = !1;
|
|
839
|
+
}, W = ($) => {
|
|
840
|
+
$.preventDefault();
|
|
841
|
+
}, V = ($) => {
|
|
842
|
+
$.preventDefault();
|
|
843
|
+
};
|
|
844
|
+
document.addEventListener("keydown", j), document.addEventListener("keyup", Y), document.addEventListener("touchstart", W, !1), document.addEventListener("touchmove", V, !1), S.current = window.setInterval(() => {
|
|
845
|
+
le(), ie();
|
|
846
|
+
}, 1), w.serve(1);
|
|
847
|
+
}, M = (y) => {
|
|
848
|
+
if (s.current) {
|
|
849
|
+
const j = y.touches[0].pageY - s.current.offsetTop - o / 2;
|
|
850
|
+
J.position(j);
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
return Fe(() => {
|
|
854
|
+
U(), a.current && (a.current.font = "30px Arial", a.current.fillText("Starting Game", c / 2, _ / 2));
|
|
855
|
+
const y = setTimeout(I, 1e3);
|
|
856
|
+
return () => {
|
|
857
|
+
clearTimeout(y), X();
|
|
858
|
+
};
|
|
859
|
+
}, []), /* @__PURE__ */ hr.jsx(
|
|
860
|
+
"canvas",
|
|
861
|
+
{
|
|
862
|
+
ref: s,
|
|
863
|
+
onTouchStart: M,
|
|
864
|
+
onTouchMove: M,
|
|
865
|
+
style: d,
|
|
866
|
+
width: c,
|
|
867
|
+
height: _
|
|
868
|
+
}
|
|
869
|
+
);
|
|
870
|
+
};
|
|
871
|
+
export {
|
|
872
|
+
_r as Pong,
|
|
873
|
+
_r as default
|
|
874
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
(function(z,_){typeof exports=="object"&&typeof module<"u"?_(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],_):(z=typeof globalThis<"u"?globalThis:z||self,_(z.ReactPong={},z.React))})(this,(function(z,_){"use strict";var te={exports:{}},$={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.min.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var be;function Le(){if(be)return $;be=1;var E=_,c=Symbol.for("react.element"),x=Symbol.for("react.fragment"),S=Object.prototype.hasOwnProperty,o=E.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,f={key:!0,ref:!0,__self:!0,__source:!0};function b(R,h,p){var l,a={},j=null,T=null;p!==void 0&&(j=""+p),h.key!==void 0&&(j=""+h.key),h.ref!==void 0&&(T=h.ref);for(l in h)S.call(h,l)&&!f.hasOwnProperty(l)&&(a[l]=h[l]);if(R&&R.defaultProps)for(l in h=R.defaultProps,h)a[l]===void 0&&(a[l]=h[l]);return{$$typeof:c,type:R,key:j,ref:T,props:a,_owner:o.current}}return $.Fragment=x,$.jsx=b,$.jsxs=b,$}var q={};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.development.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var ge;function Ue(){return ge||(ge=1,process.env.NODE_ENV!=="production"&&(function(){var E=_,c=Symbol.for("react.element"),x=Symbol.for("react.portal"),S=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),f=Symbol.for("react.profiler"),b=Symbol.for("react.provider"),R=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),p=Symbol.for("react.suspense"),l=Symbol.for("react.suspense_list"),a=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),T=Symbol.for("react.offscreen"),K=Symbol.iterator,V="@@iterator";function O(e){if(e===null||typeof e!="object")return null;var r=K&&e[K]||e[V];return typeof r=="function"?r:null}var k=E.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function d(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];F("error",e,t)}}function F(e,r,t){{var n=k.ReactDebugCurrentFrame,u=n.getStackAddendum();u!==""&&(r+="%s",t=t.concat([u]));var v=t.map(function(s){return String(s)});v.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,v)}}var B=!1,N=!1,I=!1,P=!1,G=!1,H;H=Symbol.for("react.module.reference");function se(e){return!!(typeof e=="string"||typeof e=="function"||e===S||e===f||G||e===o||e===p||e===l||P||e===T||B||N||I||typeof e=="object"&&e!==null&&(e.$$typeof===j||e.$$typeof===a||e.$$typeof===b||e.$$typeof===R||e.$$typeof===h||e.$$typeof===H||e.getModuleId!==void 0))}function le(e,r,t){var n=e.displayName;if(n)return n;var u=r.displayName||r.name||"";return u!==""?t+"("+u+")":t}function ee(e){return e.displayName||"Context"}function M(e){if(e==null)return null;if(typeof e.tag=="number"&&d("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case S:return"Fragment";case x:return"Portal";case f:return"Profiler";case o:return"StrictMode";case p:return"Suspense";case l:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case R:var r=e;return ee(r)+".Consumer";case b:var t=e;return ee(t._context)+".Provider";case h:return le(e,e.render,"ForwardRef");case a:var n=e.displayName||null;return n!==null?n:M(e.type)||"Memo";case j:{var u=e,v=u._payload,s=u._init;try{return M(s(v))}catch{return null}}}return null}var Y=Object.assign,y=0,A,U,W,J,L,_e,Ee;function xe(){}xe.__reactDisabledLog=!0;function Ke(){{if(y===0){A=console.log,U=console.info,W=console.warn,J=console.error,L=console.group,_e=console.groupCollapsed,Ee=console.groupEnd;var e={configurable:!0,enumerable:!0,value:xe,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}y++}}function Ge(){{if(y--,y===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:Y({},e,{value:A}),info:Y({},e,{value:U}),warn:Y({},e,{value:W}),error:Y({},e,{value:J}),group:Y({},e,{value:L}),groupCollapsed:Y({},e,{value:_e}),groupEnd:Y({},e,{value:Ee})})}y<0&&d("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ue=k.ReactCurrentDispatcher,ce;function ne(e,r,t){{if(ce===void 0)try{throw Error()}catch(u){var n=u.stack.trim().match(/\n( *(at )?)/);ce=n&&n[1]||""}return`
|
|
18
|
+
`+ce+e}}var fe=!1,ae;{var He=typeof WeakMap=="function"?WeakMap:Map;ae=new He}function Se(e,r){if(!e||fe)return"";{var t=ae.get(e);if(t!==void 0)return t}var n;fe=!0;var u=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var v;v=ue.current,ue.current=null,Ke();try{if(r){var s=function(){throw Error()};if(Object.defineProperty(s.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(s,[])}catch(C){n=C}Reflect.construct(e,[],s)}else{try{s.call()}catch(C){n=C}e.call(s.prototype)}}else{try{throw Error()}catch(C){n=C}e()}}catch(C){if(C&&n&&typeof C.stack=="string"){for(var i=C.stack.split(`
|
|
19
|
+
`),w=n.stack.split(`
|
|
20
|
+
`),g=i.length-1,m=w.length-1;g>=1&&m>=0&&i[g]!==w[m];)m--;for(;g>=1&&m>=0;g--,m--)if(i[g]!==w[m]){if(g!==1||m!==1)do if(g--,m--,m<0||i[g]!==w[m]){var D=`
|
|
21
|
+
`+i[g].replace(" at new "," at ");return e.displayName&&D.includes("<anonymous>")&&(D=D.replace("<anonymous>",e.displayName)),typeof e=="function"&&ae.set(e,D),D}while(g>=1&&m>=0);break}}}finally{fe=!1,ue.current=v,Ge(),Error.prepareStackTrace=u}var Q=e?e.displayName||e.name:"",X=Q?ne(Q):"";return typeof e=="function"&&ae.set(e,X),X}function Xe(e,r,t){return Se(e,!1)}function Ze(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function oe(e,r,t){if(e==null)return"";if(typeof e=="function")return Se(e,Ze(e));if(typeof e=="string")return ne(e);switch(e){case p:return ne("Suspense");case l:return ne("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case h:return Xe(e.render);case a:return oe(e.type,r,t);case j:{var n=e,u=n._payload,v=n._init;try{return oe(v(u),r,t)}catch{}}}return""}var re=Object.prototype.hasOwnProperty,Te={},we=k.ReactDebugCurrentFrame;function ie(e){if(e){var r=e._owner,t=oe(e.type,e._source,r?r.type:null);we.setExtraStackFrame(t)}else we.setExtraStackFrame(null)}function Qe(e,r,t,n,u){{var v=Function.call.bind(re);for(var s in e)if(v(e,s)){var i=void 0;try{if(typeof e[s]!="function"){var w=Error((n||"React class")+": "+t+" type `"+s+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw w.name="Invariant Violation",w}i=e[s](r,s,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(g){i=g}i&&!(i instanceof Error)&&(ie(u),d("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,s,typeof i),ie(null)),i instanceof Error&&!(i.message in Te)&&(Te[i.message]=!0,ie(u),d("Failed %s type: %s",t,i.message),ie(null))}}}var $e=Array.isArray;function de(e){return $e(e)}function qe(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function er(e){try{return Pe(e),!1}catch{return!0}}function Pe(e){return""+e}function Ce(e){if(er(e))return d("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",qe(e)),Pe(e)}var Oe=k.ReactCurrentOwner,rr={key:!0,ref:!0,__self:!0,__source:!0},je,ke;function tr(e){if(re.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function nr(e){if(re.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function ar(e,r){typeof e.ref=="string"&&Oe.current}function or(e,r){{var t=function(){je||(je=!0,d("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function ir(e,r){{var t=function(){ke||(ke=!0,d("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var sr=function(e,r,t,n,u,v,s){var i={$$typeof:c,type:e,key:r,ref:t,props:s,_owner:v};return i._store={},Object.defineProperty(i._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(i,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(i,"_source",{configurable:!1,enumerable:!1,writable:!1,value:u}),Object.freeze&&(Object.freeze(i.props),Object.freeze(i)),i};function lr(e,r,t,n,u){{var v,s={},i=null,w=null;t!==void 0&&(Ce(t),i=""+t),nr(r)&&(Ce(r.key),i=""+r.key),tr(r)&&(w=r.ref,ar(r,u));for(v in r)re.call(r,v)&&!rr.hasOwnProperty(v)&&(s[v]=r[v]);if(e&&e.defaultProps){var g=e.defaultProps;for(v in g)s[v]===void 0&&(s[v]=g[v])}if(i||w){var m=typeof e=="function"?e.displayName||e.name||"Unknown":e;i&&or(s,m),w&&ir(s,m)}return sr(e,i,w,u,n,Oe.current,s)}}var ve=k.ReactCurrentOwner,Ae=k.ReactDebugCurrentFrame;function Z(e){if(e){var r=e._owner,t=oe(e.type,e._source,r?r.type:null);Ae.setExtraStackFrame(t)}else Ae.setExtraStackFrame(null)}var pe;pe=!1;function ye(e){return typeof e=="object"&&e!==null&&e.$$typeof===c}function De(){{if(ve.current){var e=M(ve.current.type);if(e)return`
|
|
22
|
+
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function ur(e){return""}var Fe={};function cr(e){{var r=De();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
|
|
24
|
+
|
|
25
|
+
Check the top-level render call using <`+t+">.")}return r}}function Ie(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=cr(r);if(Fe[t])return;Fe[t]=!0;var n="";e&&e._owner&&e._owner!==ve.current&&(n=" It was passed a child from "+M(e._owner.type)+"."),Z(e),d('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),Z(null)}}function Me(e,r){{if(typeof e!="object")return;if(de(e))for(var t=0;t<e.length;t++){var n=e[t];ye(n)&&Ie(n,r)}else if(ye(e))e._store&&(e._store.validated=!0);else if(e){var u=O(e);if(typeof u=="function"&&u!==e.entries)for(var v=u.call(e),s;!(s=v.next()).done;)ye(s.value)&&Ie(s.value,r)}}}function fr(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===h||r.$$typeof===a))t=r.propTypes;else return;if(t){var n=M(r);Qe(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!pe){pe=!0;var u=M(r);d("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",u||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&d("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function dr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){Z(e),d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),Z(null);break}}e.ref!==null&&(Z(e),d("Invalid attribute `ref` supplied to `React.Fragment`."),Z(null))}}var We={};function Ye(e,r,t,n,u,v){{var s=se(e);if(!s){var i="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(i+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var w=ur();w?i+=w:i+=De();var g;e===null?g="null":de(e)?g="array":e!==void 0&&e.$$typeof===c?(g="<"+(M(e.type)||"Unknown")+" />",i=" Did you accidentally export a JSX literal instead of a component?"):g=typeof e,d("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",g,i)}var m=lr(e,r,t,u,v);if(m==null)return m;if(s){var D=r.children;if(D!==void 0)if(n)if(de(D)){for(var Q=0;Q<D.length;Q++)Me(D[Q],e);Object.freeze&&Object.freeze(D)}else d("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Me(D,e)}if(re.call(r,"key")){var X=M(e),C=Object.keys(r).filter(function(gr){return gr!=="key"}),he=C.length>0?"{key: someKey, "+C.join(": ..., ")+": ...}":"{key: someKey}";if(!We[X+he]){var br=C.length>0?"{"+C.join(": ..., ")+": ...}":"{}";d(`A props object containing a "key" prop is being spread into JSX:
|
|
26
|
+
let props = %s;
|
|
27
|
+
<%s {...props} />
|
|
28
|
+
React keys must be passed directly to JSX without using spread:
|
|
29
|
+
let props = %s;
|
|
30
|
+
<%s key={someKey} {...props} />`,he,X,br,X),We[X+he]=!0}}return e===S?dr(m):fr(m),m}}function vr(e,r,t){return Ye(e,r,t,!0)}function pr(e,r,t){return Ye(e,r,t,!1)}var yr=pr,hr=vr;q.Fragment=S,q.jsx=yr,q.jsxs=hr})()),q}var Re;function ze(){return Re||(Re=1,process.env.NODE_ENV==="production"?te.exports=Le():te.exports=Ue()),te.exports}var Ve=ze();function Be(E,c){const x=Math.PI,S=()=>this._context,o=this.props,f=this._score,b=()=>this.state,R=p=>{this.setState(p)},h=Math.random();return{serve(p){const l=.1*x*(1-2*h);R(a=>({...a,ballx:p===1?a.playerx+o.paddleWidth:a.aix-o.ballSize,bally:(o.height-o.ballSize)*h,velx:a.ballSpeed*Math.cos(l)*p,vely:a.ballSpeed*Math.sin(l)}))},update(){const p=E(),l=c(),a=b(),j=a.ballx,T=a.bally,K=a.velx,V=a.vely;if(R(d=>({...d,ballx:j+K,bally:T+V})),0>T||T+o.ballSize>o.height){const d=a.vely<0?0-a.bally:o.height-(a.bally+o.ballSize);R(F=>({...F,bally:T+2*d,vely:V*-1}))}const O=a.velx<0?p:l;if(((d,F,B,N,I,P,G,H)=>d<I+G&&F<P+H&&I<d+B&&P<F+N)(O.position().x,O.position().y,o.paddleWidth,o.paddleHeight,a.ballx,a.bally,o.ballSize,o.ballSize)){const d=a.velx<0?1:-1,F=(a.bally+o.ballSize-O.position().y)/(o.paddleHeight+o.ballSize),B=(F>.5?-1:1)*d,N=.25*x*(2*F+d)+h,I=Math.abs(N)>.2*x?1.1:1;R(P=>({...P,ballx:O===p?P.playerx+o.paddleWidth:P.aix-o.ballSize,velx:I*-1*P.velx,vely:I*B*P.velx*Math.sin(N)}))}(0>a.ballx+o.ballSize||a.ballx>o.width)&&(f(O.name()),this.serve(O.name()===p.name()?1:-1))},draw(){const p=S();if(!p)return;const l=b();p.beginPath(),p.arc(l.ballx,l.bally,o.ballSize,0,2*Math.PI),p.fill(),p.lineWidth=0,p.strokeStyle="#fff",p.stroke()}}}function Ne(){const E=()=>this._context,c=this.props,x=this._keystate,S=()=>this.state,o=f=>{this.setState(f)};return{update(){const f=S();let b=f.playery;x[c.upArrow]&&(b=f.playery-c.paddleSpeed),x[c.downArrow]&&(b=f.playery+c.paddleSpeed),b=Math.max(Math.min(b,c.height-c.paddleHeight),0),o(R=>({...R,playery:b}))},draw(){const f=E();if(!f)return;const b=S();f.fillRect(b.playerx,b.playery,c.paddleWidth,c.paddleHeight)},name(){return"player"},position(f){f!==void 0&&o(R=>({...R,playery:f}));const b=S();return{x:b.playerx,y:b.playery}}}}function Je(){const E=()=>this._context,c=this.props,x=()=>this.state,S=o=>{this.setState(o)};return{update(){const o=x();let f=o.aiy;const b=o.bally-(c.paddleHeight-c.ballSize)*.5;f=f+(b-f)*.1,S(R=>({...R,aiy:f}))},draw(){const o=E();if(!o)return;const f=x();o.fillRect(f.aix,f.aiy,c.paddleWidth,c.paddleHeight)},name(){return"ai"},position(){const o=x();return{x:o.aix,y:o.aiy}}}}const me=({height:E=600,width:c=700,upArrow:x="ArrowUp",downArrow:S="ArrowDown",paddleHeight:o=100,paddleWidth:f=20,paddleSpeed:b=5,ballSize:R=10})=>{const[h,p]=_.useState({ballx:100,bally:100,ballSpeed:2,velx:0,vely:0,aix:670,aiy:100,playerx:10,playery:100,playerScore:0,aiScore:0}),l=_.useRef(null),a=_.useRef(null),j=_.useRef({}),T=_.useRef(null),K=_.useRef(h),V=_.useRef(null),O=_.useRef(null),k=_.useRef(null);_.useEffect(()=>{K.current=h},[h]);const d={display:"block",position:"absolute",margin:"auto",top:"0",bottom:"0",left:"0",right:"0"},F={height:E,width:c,upArrow:x,downArrow:S,paddleHeight:o,paddleWidth:f,paddleSpeed:b,ballSize:R},B=()=>{l.current&&(a.current=l.current.getContext("2d"))},N=y=>{const A=y==="player"?"ai":"player",U=A+"Score";p(W=>({...W,[U]:W[U]+1})),ee(),setTimeout(()=>{a.current&&(a.current.font="30px Arial",a.current.fillStyle="#fff",a.current.fillText(A+" score!",c/2,E/2),a.current.restore())},0),setTimeout(()=>{B(),M()},1e3)},I=()=>({get _context(){return a.current},get state(){return K.current},props:F,_keystate:j.current,setState:y=>{p(y)},_score:N});O.current||(O.current=Ne.call(I())),k.current||(k.current=Je.call(I())),V.current||(V.current=Be.call(I(),()=>O.current,()=>k.current));const P=V.current,G=O.current,H=k.current,se=()=>{if(!a.current)return;const y=a.current;y.fillStyle="#000",y.fillRect(0,0,c,E),y.save(),y.fillStyle="#fff",y.font="10px Arial",y.fillText("Player: "+String(h.playerScore),10,10),y.fillText("CPU: "+String(h.aiScore),500,10),P.draw(),G.draw(),H.draw();const A=4,U=(c-A)*.5;let W=0;const J=E/20;for(;W<E;)y.fillRect(U,W+J*.25,A,J*.5),W+=J;y.restore()},le=()=>{G.update(),H.update(),P.update()},ee=()=>{T.current!==null&&(clearInterval(T.current),T.current=null),setTimeout(()=>{a.current&&l.current&&a.current.clearRect(0,0,l.current.width,l.current.height)},0)},M=()=>{if(T.current)return;const y=j.current,A=L=>{y[L.code]=!0},U=L=>{y[L.code]=!1},W=L=>{L.preventDefault()},J=L=>{L.preventDefault()};document.addEventListener("keydown",A),document.addEventListener("keyup",U),document.addEventListener("touchstart",W,!1),document.addEventListener("touchmove",J,!1),T.current=window.setInterval(()=>{le(),se()},1),P.serve(1)},Y=y=>{if(l.current){const A=y.touches[0].pageY-l.current.offsetTop-o/2;G.position(A)}};return _.useEffect(()=>{B(),a.current&&(a.current.font="30px Arial",a.current.fillText("Starting Game",c/2,E/2));const y=setTimeout(M,1e3);return()=>{clearTimeout(y),ee()}},[]),Ve.jsx("canvas",{ref:l,onTouchStart:Y,onTouchMove:Y,style:d,width:c,height:E})};z.Pong=me,z.default=me,Object.defineProperties(z,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alexium216/react-pong",
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"description": "A React 18 ping pong game component built with TypeScript",
|
|
5
|
+
"main": "./dist/react-pong.umd.js",
|
|
6
|
+
"module": "./dist/react-pong.es.js",
|
|
7
|
+
"types": "./dist/lib.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/lib.d.ts",
|
|
15
|
+
"import": "./dist/react-pong.es.js",
|
|
16
|
+
"require": "./dist/react-pong.umd.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "vite",
|
|
21
|
+
"prebuild": "npm run lint:fix",
|
|
22
|
+
"build": "tsc && vite build",
|
|
23
|
+
"preview": "vite preview",
|
|
24
|
+
"lint": "eslint src/",
|
|
25
|
+
"lint:fix": "eslint src/ --fix"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/alex216/react-pong.git"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"react-component",
|
|
33
|
+
"react",
|
|
34
|
+
"ping",
|
|
35
|
+
"pong",
|
|
36
|
+
"game"
|
|
37
|
+
],
|
|
38
|
+
"author": "Oakley Hall",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/alex216/react-pong/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/alex216/react-pong",
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"lodash": "^4.17.21"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
49
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/lodash": "^4.17.15",
|
|
53
|
+
"@types/react": "^18.3.18",
|
|
54
|
+
"@types/react-dom": "^18.3.5",
|
|
55
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
56
|
+
"eslint": "^9.18.0",
|
|
57
|
+
"react": "^18.3.1",
|
|
58
|
+
"react-dom": "^18.3.1",
|
|
59
|
+
"typescript": "^5.7.2",
|
|
60
|
+
"typescript-eslint": "^8.20.0",
|
|
61
|
+
"vite": "^6.0.7",
|
|
62
|
+
"vite-plugin-dts": "^4.5.4"
|
|
63
|
+
}
|
|
64
|
+
}
|