-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_copilot.html
More file actions
114 lines (100 loc) · 3.06 KB
/
test_copilot.html
File metadata and controls
114 lines (100 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Simple Dinosaur Game</title>
<style>
body { background: #f7f7f7; text-align: center; font-family: sans-serif; }
#gameContainer { margin: 40px auto; width: 600px; }
#gameCanvas { background: #fff; border: 2px solid #333; display: block; margin: 0 auto; }
#instructions { font-size: 18px; margin-top: 24px; }
</style>
</head>
<body>
<h1>Simple Dinosaur Game</h1>
<div id="gameContainer">
<canvas id="gameCanvas" width="600" height="200"></canvas>
<div id="instructions">Press Space or Tap to Jump!</div>
</div>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
let dino = {x:50, y:150, w:40, h:40, vy:0, jump: false};
let ground = 190;
let gravity = 1.2;
let obstacle = {x:600, y:160, w:20, h:40, speed:5};
let score = 0, gameOver = false;
function drawDino() {
ctx.fillStyle = "#2d2";
ctx.fillRect(dino.x, dino.y, dino.w, dino.h);
// Eye
ctx.fillStyle = "#fff";
ctx.fillRect(dino.x + 26, dino.y + 10, 7, 7);
ctx.fillStyle = "#000";
ctx.fillRect(dino.x + 29, dino.y + 13, 3, 3);
}
function drawObstacle() {
ctx.fillStyle = "#b22";
ctx.fillRect(obstacle.x, obstacle.y, obstacle.w, obstacle.h);
}
function update() {
if (gameOver) return;
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Ground
ctx.fillStyle = "#888";
ctx.fillRect(0, ground + 40, canvas.width, 10);
drawDino();
drawObstacle();
// Dino jump physics
if (dino.jump) {
dino.vy -= gravity;
dino.y -= dino.vy;
if (dino.y >= ground) {
dino.y = ground;
dino.jump = false;
dino.vy = 0;
}
}
// Obstacle movement
obstacle.x -= obstacle.speed;
if (obstacle.x + obstacle.w < 0) {
obstacle.x = canvas.width + Math.random() * 100;
score++;
obstacle.speed += 0.2; // Increase difficulty
}
// Collision detection
if (dino.x < obstacle.x + obstacle.w &&
dino.x + dino.w > obstacle.x &&
dino.y < obstacle.y + obstacle.h &&
dino.y + dino.h > obstacle.y) {
gameOver = true;
ctx.font = "36px sans-serif";
ctx.fillStyle = "#b22";
ctx.fillText("Game Over!", 220, 100);
ctx.font = "24px sans-serif";
ctx.fillStyle = "#333";
ctx.fillText("Score: " + score, 260, 150);
ctx.fillText("Refresh to play again", 170, 180);
return;
}
// Score
ctx.font = "24px sans-serif";
ctx.fillStyle = "#333";
ctx.fillText("Score: " + score, 10, 30);
requestAnimationFrame(update);
}
function jump() {
if (!dino.jump && !gameOver) {
dino.vy = 16;
dino.jump = true;
}
}
document.addEventListener('keydown', (e) => {
if (e.code === 'Space') jump();
});
canvas.addEventListener('pointerdown', jump);
// Start game
update();
</script>
</body>
</html>