-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpep.html
More file actions
226 lines (192 loc) · 5.2 KB
/
pep.html
File metadata and controls
226 lines (192 loc) · 5.2 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Coke Destroyer</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: blue;
color: red;
}
canvas {
display: block;
}
#score {
position: absolute;
top: 10px;
left: 10px;
font-size: 20px;
color: white;
}
</style>
</head>
<body>
<h1>Coke Destroyer</h1>
<canvas id="gameCanvas"></canvas>
<div id="score"></div>
<br />
<h2>Why Coke Sucks</h2>
<p>simple really, it just does. <br /> It just tastes like chemicals, and yes i know that all soda tastes like chemicals. <br />Coke does especcialy though</p>
<br />
<a href="index.html"><img src="home.gif"></a>
<script>
const canvas = document.getElementById("gameCanvas");
const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const tankImg = new Image();
tankImg.src = 'img/coked/Pepsi_2023.svg.png';
const projectileImg = new Image();
projectileImg.src = 'img/coked/Pepsi_2023.svg.png';
const enemyImg = new Image();
enemyImg.src = 'img/coked/coke.png';
const backgroundImg = new Image();
backgroundImg.src = 'img/coked/pepsiman.jpg';
const tank = {
x: canvas.width / 2,
y: canvas.height / 2,
width: 50,
height: 50,
img: tankImg,
};
const projectiles = [];
const enemies = [];
let score = 0;
function increaseDifficulty() {
return {
speed: Math.max(2, Math.min(5, Math.floor(score / 10))),
spawnRate: Math.max(0.02, Math.min(0.2, score / 1000)),
};
}
canvas.addEventListener("click", (e) => {
const angle = Math.atan2(e.clientY - tank.y, e.clientX - tank.x);
projectiles.push({
x: tank.x,
y: tank.y,
size: 10,
img: projectileImg,
speed: 7,
angle: angle,
});
});
function spawnEnemy() {
const side = Math.floor(Math.random() * 4);
let x, y;
switch (side) {
case 0:
x = Math.random() * canvas.width;
y = 0;
break;
case 1:
x = canvas.width;
y = Math.random() * canvas.height;
break;
case 2:
x = Math.random() * canvas.width;
y = canvas.height;
break;
case 3:
x = 0;
y = Math.random() * canvas.height;
break;
}
const difficulty = increaseDifficulty();
enemies.push({
x,
y,
size: 50,
img: enemyImg,
speed: difficulty.speed,
});
}
function update() {
projectiles.forEach((projectile, index) => {
projectile.x += Math.cos(projectile.angle) * projectile.speed;
projectile.y += Math.sin(projectile.angle) * projectile.speed;
if (
projectile.x < 0 ||
projectile.x > canvas.width ||
projectile.y < 0 ||
projectile.y > canvas.height
) {
projectiles.splice(index, 1);
}
enemies.forEach((enemy, enemyIndex) => {
const distance = Math.hypot(
projectile.x - enemy.x,
projectile.y - enemy.y
);
if (distance < projectile.size + enemy.size) {
enemies.splice(enemyIndex, 1);
projectiles.splice(index, 1);
score++;
}
});
});
enemies.forEach((enemy, index) => {
const angle = Math.atan2(tank.y - enemy.y, tank.x - enemy.x);
enemy.x += Math.cos(angle) * enemy.speed;
enemy.y += Math.sin(angle) * enemy.speed;
const distance = Math.hypot(tank.x - enemy.x, tank.y - enemy.y);
if (distance < tank.width / 2 + enemy.size / 2) {
// Game over
updateScoreText();
resetGame();
}
if (
enemy.x < 0 ||
enemy.x > canvas.width ||
enemy.y < 0 ||
enemy.y > canvas.height
) {
enemies.splice(index, 1);
score--;
}
});
if (Math.random() < increaseDifficulty().spawnRate) {
spawnEnemy();
}
}
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw background
ctx.drawImage(backgroundImg, 0, 0, canvas.width, canvas.height);
// Draw tank
ctx.drawImage(tank.img, tank.x - tank.width / 2, tank.y - tank.height / 2, tank.width, tank.height);
// Draw projectiles
projectiles.forEach((projectile) => {
ctx.drawImage(projectile.img, projectile.x - projectile.size / 2, projectile.y - projectile.size / 2, projectile.size, projectile.size);
});
// Draw enemies
enemies.forEach((enemy) => {
ctx.drawImage(enemy.img, enemy.x - enemy.size / 2, enemy.y - enemy.size / 2, enemy.size, enemy.size);
});
// Draw score
ctx.fillStyle = "black";
ctx.font = "20px Arial";
ctx.fillText("Score: " + score, 20, 30);
}
function updateScoreText() {
const scoreText = document.getElementById("score");
scoreText.textContent = "Last Score: " + score;
}
function resetGame() {
updateScoreText();
tank.x = canvas.width / 2;
tank.y = canvas.height / 2;
projectiles.length = 0;
enemies.length = 0;
score = 0;
}
function gameLoop() {
update();
draw();
requestAnimationFrame(gameLoop);
}
gameLoop();
</script>
</body>
</html>