create-airjam 0.1.0 → 0.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/dist/index.js +11 -3
- package/package.json +6 -3
- package/templates/pong/.env.example +11 -0
- package/templates/pong/.env.local +10 -0
- package/templates/pong/AI_INSTRUCTIONS.md +44 -0
- package/templates/pong/README.md +111 -0
- package/templates/pong/airjam-docs/getting-started/architecture/page.md +165 -0
- package/templates/pong/airjam-docs/getting-started/game-ideas/page.md +114 -0
- package/templates/pong/airjam-docs/getting-started/introduction/page.md +122 -0
- package/templates/pong/airjam-docs/how-it-works/host-system/page.md +241 -0
- package/templates/pong/airjam-docs/sdk/hooks/page.md +403 -0
- package/templates/pong/airjam-docs/sdk/input-system/page.md +336 -0
- package/templates/pong/airjam-docs/sdk/networked-state/page.md +575 -0
- package/templates/pong/dist/assets/index-B9l0NKly.js +269 -0
- package/templates/pong/dist/assets/index-CHKqdIQG.css +1 -0
- package/templates/pong/dist/index.html +14 -0
- package/templates/pong/eslint.config.js +33 -0
- package/templates/pong/index.html +6 -1
- package/templates/pong/node_modules/.bin/air-jam-server +17 -0
- package/templates/pong/node_modules/.bin/eslint +17 -0
- package/templates/pong/node_modules/.bin/eslint-config-prettier +17 -0
- package/templates/pong/node_modules/.bin/jiti +17 -0
- package/templates/pong/node_modules/.bin/tsc +17 -0
- package/templates/pong/node_modules/.bin/tsserver +17 -0
- package/templates/pong/node_modules/.bin/tsx +17 -0
- package/templates/pong/node_modules/.bin/vite +17 -0
- package/templates/pong/node_modules/.vite/deps/@air-jam_sdk.js +66143 -0
- package/templates/pong/node_modules/.vite/deps/@air-jam_sdk.js.map +7 -0
- package/templates/pong/node_modules/.vite/deps/_metadata.json +73 -0
- package/templates/pong/node_modules/.vite/deps/chunk-3TUQC5ZT.js +292 -0
- package/templates/pong/node_modules/.vite/deps/chunk-3TUQC5ZT.js.map +7 -0
- package/templates/pong/node_modules/.vite/deps/chunk-DC5AMYBS.js +38 -0
- package/templates/pong/node_modules/.vite/deps/chunk-DC5AMYBS.js.map +7 -0
- package/templates/pong/node_modules/.vite/deps/chunk-QUPSG5AV.js +280 -0
- package/templates/pong/node_modules/.vite/deps/chunk-QUPSG5AV.js.map +7 -0
- package/templates/pong/node_modules/.vite/deps/chunk-TYOCAO5S.js +13810 -0
- package/templates/pong/node_modules/.vite/deps/chunk-TYOCAO5S.js.map +7 -0
- package/templates/pong/node_modules/.vite/deps/chunk-YG4BJP3V.js +1004 -0
- package/templates/pong/node_modules/.vite/deps/chunk-YG4BJP3V.js.map +7 -0
- package/templates/pong/node_modules/.vite/deps/package.json +3 -0
- package/templates/pong/node_modules/.vite/deps/react-dom.js +6 -0
- package/templates/pong/node_modules/.vite/deps/react-dom.js.map +7 -0
- package/templates/pong/node_modules/.vite/deps/react-dom_client.js +20217 -0
- package/templates/pong/node_modules/.vite/deps/react-dom_client.js.map +7 -0
- package/templates/pong/node_modules/.vite/deps/react-router-dom.js +13900 -0
- package/templates/pong/node_modules/.vite/deps/react-router-dom.js.map +7 -0
- package/templates/pong/node_modules/.vite/deps/react.js +5 -0
- package/templates/pong/node_modules/.vite/deps/react.js.map +7 -0
- package/templates/pong/node_modules/.vite/deps/react_jsx-dev-runtime.js +278 -0
- package/templates/pong/node_modules/.vite/deps/react_jsx-dev-runtime.js.map +7 -0
- package/templates/pong/node_modules/.vite/deps/react_jsx-runtime.js +6 -0
- package/templates/pong/node_modules/.vite/deps/react_jsx-runtime.js.map +7 -0
- package/templates/pong/node_modules/.vite/deps/zod.js +476 -0
- package/templates/pong/node_modules/.vite/deps/zod.js.map +7 -0
- package/templates/pong/package.json +12 -1
- package/templates/pong/src/App.tsx +2 -2
- package/templates/pong/src/controller-view.tsx +143 -0
- package/templates/pong/src/host-view.tsx +401 -0
- package/templates/pong/src/main.tsx +2 -1
- package/templates/pong/src/store.ts +80 -0
- package/templates/pong/tsconfig.json +3 -2
- package/templates/pong/vite.config.ts +3 -0
- package/templates/pong/src/ControllerView.tsx +0 -64
- package/templates/pong/src/HostView.tsx +0 -148
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { useAirJamHost, useGetInput } from "@air-jam/sdk";
|
|
2
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
-
import { type GameInput, gameInputSchema } from "./types";
|
|
4
|
-
|
|
5
|
-
const PADDLE_HEIGHT = 100;
|
|
6
|
-
const PADDLE_WIDTH = 15;
|
|
7
|
-
const BALL_SIZE = 15;
|
|
8
|
-
const PADDLE_SPEED = 8;
|
|
9
|
-
const BALL_SPEED = 5;
|
|
10
|
-
|
|
11
|
-
export function HostView() {
|
|
12
|
-
const host = useAirJamHost<typeof gameInputSchema>();
|
|
13
|
-
const getInput = useGetInput<typeof gameInputSchema>();
|
|
14
|
-
const canvasRef = useRef<HTMLCanvasElement>(null);
|
|
15
|
-
const [scores, setScores] = useState({ player1: 0, player2: 0 });
|
|
16
|
-
|
|
17
|
-
// Game state refs (to avoid re-renders in game loop)
|
|
18
|
-
const gameState = useRef({
|
|
19
|
-
paddle1Y: 250,
|
|
20
|
-
paddle2Y: 250,
|
|
21
|
-
ballX: 400,
|
|
22
|
-
ballY: 300,
|
|
23
|
-
ballVX: BALL_SPEED,
|
|
24
|
-
ballVY: BALL_SPEED,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const resetBall = useCallback(() => {
|
|
28
|
-
const state = gameState.current;
|
|
29
|
-
state.ballX = 400;
|
|
30
|
-
state.ballY = 300;
|
|
31
|
-
state.ballVX = BALL_SPEED * (Math.random() > 0.5 ? 1 : -1);
|
|
32
|
-
state.ballVY = BALL_SPEED * (Math.random() > 0.5 ? 1 : -1);
|
|
33
|
-
}, []);
|
|
34
|
-
|
|
35
|
-
// Game loop
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
const canvas = canvasRef.current;
|
|
38
|
-
if (!canvas) return;
|
|
39
|
-
const ctx = canvas.getContext("2d");
|
|
40
|
-
if (!ctx) return;
|
|
41
|
-
|
|
42
|
-
let animationId: number;
|
|
43
|
-
|
|
44
|
-
const gameLoop = () => {
|
|
45
|
-
const state = gameState.current;
|
|
46
|
-
const controllers = host.controllers;
|
|
47
|
-
|
|
48
|
-
// Get input from first two controllers
|
|
49
|
-
const controllerIds = Object.keys(controllers);
|
|
50
|
-
const player1Input = controllerIds[0] ? getInput(controllerIds[0]) : null;
|
|
51
|
-
const player2Input = controllerIds[1] ? getInput(controllerIds[1]) : null;
|
|
52
|
-
|
|
53
|
-
// Move paddles based on input
|
|
54
|
-
if (player1Input) {
|
|
55
|
-
state.paddle1Y += (player1Input as GameInput).direction * PADDLE_SPEED;
|
|
56
|
-
state.paddle1Y = Math.max(0, Math.min(600 - PADDLE_HEIGHT, state.paddle1Y));
|
|
57
|
-
}
|
|
58
|
-
if (player2Input) {
|
|
59
|
-
state.paddle2Y += (player2Input as GameInput).direction * PADDLE_SPEED;
|
|
60
|
-
state.paddle2Y = Math.max(0, Math.min(600 - PADDLE_HEIGHT, state.paddle2Y));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Move ball
|
|
64
|
-
state.ballX += state.ballVX;
|
|
65
|
-
state.ballY += state.ballVY;
|
|
66
|
-
|
|
67
|
-
// Ball collision with top/bottom walls
|
|
68
|
-
if (state.ballY <= 0 || state.ballY >= 600 - BALL_SIZE) {
|
|
69
|
-
state.ballVY *= -1;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Ball collision with paddles
|
|
73
|
-
// Left paddle
|
|
74
|
-
if (
|
|
75
|
-
state.ballX <= 30 + PADDLE_WIDTH &&
|
|
76
|
-
state.ballX >= 30 &&
|
|
77
|
-
state.ballY + BALL_SIZE >= state.paddle1Y &&
|
|
78
|
-
state.ballY <= state.paddle1Y + PADDLE_HEIGHT
|
|
79
|
-
) {
|
|
80
|
-
state.ballVX = Math.abs(state.ballVX);
|
|
81
|
-
}
|
|
82
|
-
// Right paddle
|
|
83
|
-
if (
|
|
84
|
-
state.ballX >= 800 - 30 - PADDLE_WIDTH - BALL_SIZE &&
|
|
85
|
-
state.ballX <= 800 - 30 &&
|
|
86
|
-
state.ballY + BALL_SIZE >= state.paddle2Y &&
|
|
87
|
-
state.ballY <= state.paddle2Y + PADDLE_HEIGHT
|
|
88
|
-
) {
|
|
89
|
-
state.ballVX = -Math.abs(state.ballVX);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Scoring
|
|
93
|
-
if (state.ballX <= 0) {
|
|
94
|
-
setScores((s) => ({ ...s, player2: s.player2 + 1 }));
|
|
95
|
-
resetBall();
|
|
96
|
-
}
|
|
97
|
-
if (state.ballX >= 800 - BALL_SIZE) {
|
|
98
|
-
setScores((s) => ({ ...s, player1: s.player1 + 1 }));
|
|
99
|
-
resetBall();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Draw
|
|
103
|
-
ctx.fillStyle = "#000";
|
|
104
|
-
ctx.fillRect(0, 0, 800, 600);
|
|
105
|
-
|
|
106
|
-
ctx.fillStyle = "#fff";
|
|
107
|
-
// Paddles
|
|
108
|
-
ctx.fillRect(30, state.paddle1Y, PADDLE_WIDTH, PADDLE_HEIGHT);
|
|
109
|
-
ctx.fillRect(800 - 30 - PADDLE_WIDTH, state.paddle2Y, PADDLE_WIDTH, PADDLE_HEIGHT);
|
|
110
|
-
// Ball
|
|
111
|
-
ctx.fillRect(state.ballX, state.ballY, BALL_SIZE, BALL_SIZE);
|
|
112
|
-
// Center line
|
|
113
|
-
ctx.setLineDash([5, 15]);
|
|
114
|
-
ctx.beginPath();
|
|
115
|
-
ctx.moveTo(400, 0);
|
|
116
|
-
ctx.lineTo(400, 600);
|
|
117
|
-
ctx.strokeStyle = "#333";
|
|
118
|
-
ctx.stroke();
|
|
119
|
-
|
|
120
|
-
animationId = requestAnimationFrame(gameLoop);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
gameLoop();
|
|
124
|
-
return () => cancelAnimationFrame(animationId);
|
|
125
|
-
}, [host.controllers, getInput, resetBall]);
|
|
126
|
-
|
|
127
|
-
return (
|
|
128
|
-
<div className="flex min-h-screen flex-col items-center justify-center bg-gray-900 p-4">
|
|
129
|
-
<h1 className="mb-4 text-3xl font-bold text-white">Pong</h1>
|
|
130
|
-
<div className="mb-4 text-2xl text-white">
|
|
131
|
-
{scores.player1} - {scores.player2}
|
|
132
|
-
</div>
|
|
133
|
-
<canvas
|
|
134
|
-
ref={canvasRef}
|
|
135
|
-
width={800}
|
|
136
|
-
height={600}
|
|
137
|
-
className="rounded-lg border-2 border-white"
|
|
138
|
-
/>
|
|
139
|
-
<div className="mt-4 text-gray-400">
|
|
140
|
-
{Object.keys(host.controllers).length === 0 ? (
|
|
141
|
-
<p>Waiting for players to connect... Scan the QR code!</p>
|
|
142
|
-
) : (
|
|
143
|
-
<p>{Object.keys(host.controllers).length} player(s) connected</p>
|
|
144
|
-
)}
|
|
145
|
-
</div>
|
|
146
|
-
</div>
|
|
147
|
-
);
|
|
148
|
-
}
|