Spaces:
Running
Running
Update index.html
Browse files- index.html +76 -120
index.html
CHANGED
@@ -1,127 +1,83 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
<head>
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
11 |
</head>
|
12 |
<body>
|
13 |
-
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
}
|
82 |
-
if (balls[i].position.z + 0.5 > 25 || balls[i].position.z - 0.5 < -25) {
|
83 |
-
balls[i].velocity.z = -balls[i].velocity.z;
|
84 |
-
}
|
85 |
-
if (balls[i].position.y - 0.5 < -15 && balls[i].position.x + 0.5 > paddle.position.x - 2 && balls[i].position.x - 0.5 < paddle.position.x + 2 && balls[i].position.z + 0.5 > paddle.position.z - 0.5 && balls[i].position.z - 0.5 < paddle.position.z + 0.5) {
|
86 |
-
balls[i].velocity.y = Math.abs(balls[i].velocity.y);
|
87 |
-
}
|
88 |
-
for (var j = 0; j < bricks.length; j++) {
|
89 |
-
if (balls[i].position.distanceTo(bricks[j].position) <= 2) {
|
90 |
-
scene.remove(bricks[j]);
|
91 |
-
bricks.splice(j, 1);
|
92 |
-
balls[i].velocity.negate();
|
93 |
-
addBrick();
|
94 |
-
}
|
95 |
-
}
|
96 |
-
}
|
97 |
-
renderer.render(scene, camera);
|
98 |
-
}
|
99 |
-
var keys = {};
|
100 |
-
var mouseX = null;
|
101 |
-
var mouseY = null;
|
102 |
-
document.addEventListener('mousedown', function(event) {
|
103 |
-
if (event.button === 0) {
|
104 |
-
addBrick();
|
105 |
-
}
|
106 |
-
if (event.button === 2) {
|
107 |
-
addBall();
|
108 |
-
}
|
109 |
-
});
|
110 |
-
document.addEventListener('keydown', function(event) {
|
111 |
-
keys[event.keyCode] = true;
|
112 |
-
});
|
113 |
-
document.addEventListener('keyup', function(event) {
|
114 |
-
keys[event.keyCode] = false;
|
115 |
-
});
|
116 |
-
document.addEventListener('mousemove', function(event) {
|
117 |
-
mouseX = event.clientX;
|
118 |
-
mouseY = event.clientY;
|
119 |
-
});
|
120 |
-
document.addEventListener('mouseleave', function(event) {
|
121 |
-
mouseX = null;
|
122 |
-
mouseY = null;
|
123 |
-
});
|
124 |
-
animate();
|
125 |
-
</script>
|
126 |
</body>
|
127 |
-
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<title>3D Card Game</title>
|
6 |
+
<style>
|
7 |
+
body { margin: 0; }
|
8 |
+
canvas { display: block; }
|
9 |
+
</style>
|
10 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/three.min.js"></script>
|
11 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/cannon.js/0.6.2/cannon.min.js"></script> <!-- For physics -->
|
12 |
</head>
|
13 |
<body>
|
14 |
+
<canvas id="gameCanvas"></canvas>
|
15 |
|
16 |
+
<script>
|
17 |
+
var scene = new THREE.Scene();
|
18 |
+
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
19 |
+
camera.position.set(0, 30, 100);
|
20 |
+
var renderer = new THREE.WebGLRenderer({ canvas: document.getElementById('gameCanvas') });
|
21 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
22 |
+
document.body.appendChild(renderer.domElement);
|
23 |
+
|
24 |
+
// Physics world setup
|
25 |
+
var world = new CANNON.World();
|
26 |
+
world.gravity.set(0, -9.82, 0); // Apply gravity in the negative y direction
|
27 |
+
|
28 |
+
// Card geometry
|
29 |
+
var cardGeometry = new THREE.BoxGeometry(5, 0.1, 7);
|
30 |
+
var cardMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
|
31 |
+
var cards = [];
|
32 |
+
var cardBodies = [];
|
33 |
+
|
34 |
+
// Lighting
|
35 |
+
var ambientLight = new THREE.AmbientLight(0x404040);
|
36 |
+
scene.add(ambientLight);
|
37 |
+
var directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
|
38 |
+
directionalLight.position.set(0, 1, 1);
|
39 |
+
scene.add(directionalLight);
|
40 |
+
|
41 |
+
// Card creation
|
42 |
+
function addCard(x, y, z) {
|
43 |
+
var card = new THREE.Mesh(cardGeometry, cardMaterial);
|
44 |
+
card.position.set(x, y, z);
|
45 |
+
scene.add(card);
|
46 |
+
cards.push(card);
|
47 |
+
|
48 |
+
// Physics for card
|
49 |
+
var cardShape = new CANNON.Box(new CANNON.Vec3(2.5, 0.05, 3.5));
|
50 |
+
var cardBody = new CANNON.Body({ mass: 1 });
|
51 |
+
cardBody.addShape(cardShape);
|
52 |
+
cardBody.position.set(x, y, z);
|
53 |
+
world.addBody(cardBody);
|
54 |
+
cardBodies.push(cardBody);
|
55 |
+
}
|
56 |
+
|
57 |
+
// Example: Add a stack of cards
|
58 |
+
for (let i = 0; i < 52; i++) {
|
59 |
+
addCard(0, i * 0.2, 0); // Adjust position as needed
|
60 |
+
}
|
61 |
+
|
62 |
+
// Drag and drop functionality (simplified)
|
63 |
+
// You will need to implement raycasting to pick up and move cards
|
64 |
+
|
65 |
+
function animate() {
|
66 |
+
requestAnimationFrame(animate);
|
67 |
+
|
68 |
+
// Update physics world
|
69 |
+
world.step(1 / 60);
|
70 |
+
|
71 |
+
// Sync Three.js objects with physics objects
|
72 |
+
for (let i = 0; i < cardBodies.length; i++) {
|
73 |
+
cards[i].position.copy(cardBodies[i].position);
|
74 |
+
cards[i].quaternion.copy(cardBodies[i].quaternion);
|
75 |
+
}
|
76 |
+
|
77 |
+
renderer.render(scene, camera);
|
78 |
+
}
|
79 |
+
|
80 |
+
animate();
|
81 |
+
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
</body>
|
83 |
+
</html>
|