awacke1 commited on
Commit
f115e64
·
1 Parent(s): 21e61c6

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +79 -17
index.html CHANGED
@@ -1,19 +1,81 @@
1
  <!DOCTYPE html>
2
  <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <!DOCTYPE html>
2
  <html>
3
+ <head>
4
+ <title>Snakes Game in A-Frame</title>
5
+ <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
6
+ </head>
7
+ <body>
8
+ <!-- Step 8: Finishing Touches - Add Instructions and Key Map -->
9
+ <div>
10
+ <h1>Instructions:</h1>
11
+ <p>Use the arrow keys to control the snake. Eat the red food box to grow!</p>
12
+ <h2>Key Map:</h2>
13
+ <ul>
14
+ <li>Arrow Up: Move Up</li>
15
+ <li>Arrow Down: Move Down</li>
16
+ <li>Arrow Left: Move Left</li>
17
+ <li>Arrow Right: Move Right</li>
18
+ </ul>
19
+ </div>
20
+
21
+ <a-scene>
22
+ <!-- Step 3: Create the Game Board -->
23
+ <a-box id="game-board" position="0 0 -5" rotation="0 0 0" color="#4CC3D9" depth="10" height="10" width="10"></a-box>
24
+
25
+ <!-- Initialize Snake -->
26
+ <a-box id="snake-head" position="0 0 -4" rotation="0 0 0" color="green" depth="1" height="1" width="1"></a-box>
27
+ </a-scene>
28
+
29
+ <script>
30
+ // Step 4: Implementing Snake Movement
31
+ let x = 0;
32
+ let y = 0;
33
+ let z = -4;
34
+ let direction = 'right'; // initial direction
35
+ let snakeHead = document.getElementById('snake-head');
36
+
37
+ document.addEventListener('keydown', function(event) {
38
+ if (event.code === 'ArrowUp') { direction = 'up'; }
39
+ if (event.code === 'ArrowDown') { direction = 'down'; }
40
+ if (event.code === 'ArrowLeft') { direction = 'left'; }
41
+ if (event.code === 'ArrowRight') { direction = 'right'; }
42
+ });
43
+
44
+ function moveSnake() {
45
+ if (direction === 'up') { y = Math.min(4, y + 1); }
46
+ if (direction === 'down') { y = Math.max(-4, y - 1); }
47
+ if (direction === 'left') { x = Math.max(-4, x - 1); }
48
+ if (direction === 'right') { x = Math.min(4, x + 1); }
49
+
50
+ snakeHead.setAttribute('position', `${x} ${y} ${z}`);
51
+ }
52
+
53
+ // Step 5: Adding Food Items (simplified, one food item)
54
+ let food = document.createElement('a-box');
55
+ food.setAttribute('id', 'food');
56
+ food.setAttribute('position', '2 2 -4');
57
+ food.setAttribute('color', 'red');
58
+ food.setAttribute('depth', '1');
59
+ food.setAttribute('height', '1');
60
+ food.setAttribute('width', '1');
61
+ document.querySelector('a-scene').appendChild(food);
62
+
63
+ // Step 6: Game Logic (simplified)
64
+ function checkCollision() {
65
+ let foodPosition = food.getAttribute('position');
66
+ let snakeHeadPosition = snakeHead.getAttribute('position');
67
+
68
+ if (foodPosition.x === snakeHeadPosition.x && foodPosition.y === snakeHeadPosition.y) {
69
+ // Implement growth and scoring logic here
70
+ alert('You ate the food!');
71
+ }
72
+ }
73
+
74
+ // Game Loop
75
+ setInterval(function() {
76
+ moveSnake();
77
+ checkCollision();
78
+ }, 500);
79
+ </script>
80
+ </body>
81
+ </html>