Spaces:
Running
Running
Update index.html
Browse files- index.html +333 -170
index.html
CHANGED
|
@@ -1,191 +1,354 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html>
|
| 3 |
<head>
|
| 4 |
-
<style>
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</head>
|
| 20 |
<body>
|
| 21 |
-
<canvas id="
|
| 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 |
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 82 |
-
|
| 83 |
-
const lines = phrase.text.split('\n');
|
| 84 |
-
|
| 85 |
-
lines.forEach((line, index) => {
|
| 86 |
-
const size = phrase.sizes ? phrase.sizes[index] : phrase.size;
|
| 87 |
-
ctx.font = `${size}px Arial`;
|
| 88 |
-
ctx.fillStyle = 'white';
|
| 89 |
-
ctx.textAlign = 'center';
|
| 90 |
-
ctx.textBaseline = 'middle';
|
| 91 |
-
|
| 92 |
-
const spacing = phrase.spacing || size * 1.2;
|
| 93 |
-
const y = (canvas.height/2 - 20) + (index - (lines.length-1)/2) * spacing;
|
| 94 |
-
ctx.fillText(line, canvas.width/2, y);
|
| 95 |
-
});
|
| 96 |
-
|
| 97 |
-
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
|
| 98 |
-
|
| 99 |
-
for(let y = 0; y < canvas.height; y += 4) {
|
| 100 |
-
for(let x = 0; x < canvas.width; x += 4) {
|
| 101 |
-
const index = (y * canvas.width + x) * 4;
|
| 102 |
-
const alpha = imageData[index + 3];
|
| 103 |
-
|
| 104 |
-
if(alpha > 128) {
|
| 105 |
-
newParticles.push(new Particle(x, y, x, y));
|
| 106 |
-
}
|
| 107 |
}
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
particles.forEach(particle => {
|
| 120 |
-
particle.dx = (Math.random() - 0.5) * 20;
|
| 121 |
-
particle.dy = (Math.random() - 0.5) * 20;
|
| 122 |
-
const fadeOut = setInterval(() => {
|
| 123 |
-
particle.alpha -= particle.fadeSpeed;
|
| 124 |
-
if(particle.alpha <= 0) clearInterval(fadeOut);
|
| 125 |
-
}, 50);
|
| 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 |
-
particles.forEach(particle => {
|
| 167 |
-
particle.alpha = 0;
|
| 168 |
-
const fadeIn = setInterval(() => {
|
| 169 |
-
particle.alpha += particle.fadeSpeed;
|
| 170 |
-
if(particle.alpha >= 1) clearInterval(fadeIn);
|
| 171 |
-
}, 50);
|
| 172 |
-
});
|
| 173 |
-
|
| 174 |
-
animate();
|
| 175 |
-
setTimeout(transition, phrases[0].duration);
|
| 176 |
-
|
| 177 |
-
function playAudioForDuration(url, duration) {
|
| 178 |
-
const audio = new Audio(url);
|
| 179 |
-
audio.play();
|
| 180 |
-
setTimeout(() => {
|
| 181 |
-
audio.pause();
|
| 182 |
-
audio.currentTime = 0; // Reset to start
|
| 183 |
-
}, duration);
|
| 184 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
-
|
| 187 |
-
|
|
|
|
| 188 |
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
| 190 |
</body>
|
| 191 |
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html>
|
| 3 |
<head>
|
| 4 |
+
<style>
|
| 5 |
+
body {
|
| 6 |
+
margin: 0;
|
| 7 |
+
overflow: hidden;
|
| 8 |
+
background: black;
|
| 9 |
+
}
|
| 10 |
+
#gameCanvas {
|
| 11 |
+
background-image: url('stage 1.jpg');
|
| 12 |
+
background-size: cover;
|
| 13 |
+
}
|
| 14 |
+
#message {
|
| 15 |
+
position: fixed;
|
| 16 |
+
bottom: 550px;
|
| 17 |
+
left: 0;
|
| 18 |
+
width: 100%;
|
| 19 |
+
color: white;
|
| 20 |
+
text-align: center;
|
| 21 |
+
font-size: 30px;
|
| 22 |
+
font-family: Arial;
|
| 23 |
+
}
|
| 24 |
+
#stats {
|
| 25 |
+
position: fixed;
|
| 26 |
+
top: 20px;
|
| 27 |
+
left: 20px;
|
| 28 |
+
color: white;
|
| 29 |
+
font-family: Arial;
|
| 30 |
+
font-size: 28px;
|
| 31 |
+
}
|
| 32 |
+
#villainCount {
|
| 33 |
+
position: fixed;
|
| 34 |
+
top: 20px;
|
| 35 |
+
right: 20px;
|
| 36 |
+
color: white;
|
| 37 |
+
font-family: Arial;
|
| 38 |
+
font-size: 28px;
|
| 39 |
+
}
|
| 40 |
+
#healthBar {
|
| 41 |
+
width: 300px;
|
| 42 |
+
height: 30px;
|
| 43 |
+
background: #333;
|
| 44 |
+
margin-top: 5px;
|
| 45 |
+
}
|
| 46 |
+
#healthFill {
|
| 47 |
+
width: 100%;
|
| 48 |
+
height: 100%;
|
| 49 |
+
background: red;
|
| 50 |
+
transition: width 0.3s;
|
| 51 |
+
}
|
| 52 |
+
#bulletCount, #enemyCount {
|
| 53 |
+
font-size: 28px;
|
| 54 |
+
}
|
| 55 |
+
#replayButton {
|
| 56 |
+
position: fixed;
|
| 57 |
+
top: 50%;
|
| 58 |
+
left: 50%;
|
| 59 |
+
transform: translate(-50%, -50%);
|
| 60 |
+
padding: 15px 30px;
|
| 61 |
+
font-size: 20px;
|
| 62 |
+
font-family: Arial;
|
| 63 |
+
background-color: white;
|
| 64 |
+
color: black;
|
| 65 |
+
border: none;
|
| 66 |
+
border-radius: 5px;
|
| 67 |
+
display: none;
|
| 68 |
+
cursor: pointer;
|
| 69 |
+
}
|
| 70 |
+
#replayButton:hover {
|
| 71 |
+
background-color: lightgray;
|
| 72 |
+
}
|
| 73 |
+
</style>
|
| 74 |
</head>
|
| 75 |
<body>
|
| 76 |
+
<canvas id="gameCanvas"></canvas>
|
| 77 |
+
<div id="message"></div>
|
| 78 |
+
<div id="stats">
|
| 79 |
+
Health:<div id="healthBar"><div id="healthFill"></div></div>
|
| 80 |
+
Bullets: <span id="bulletCount">35</span>
|
| 81 |
+
</div>
|
| 82 |
+
<div id="villainCount">Villains: <span id="enemyCount">30</span></div>
|
| 83 |
+
<button id="replayButton">Replay</button>
|
| 84 |
+
<audio id="bgMusic" src="cinematic-time-lapse-115672.mp3" loop></audio>
|
| 85 |
+
<audio id="playerShootSound" src="Maincharactergunsound.mp3"></audio>
|
| 86 |
+
<audio id="enemyShootSound" src="Renovatorsgunshot.mp3"></audio>
|
| 87 |
+
<audio id="playerHitSound" src="Maincharactershot.mp3"></audio>
|
| 88 |
+
<audio id="enemyHitSound" src="Renovatorsgetshot.mp3"></audio>
|
| 89 |
+
|
| 90 |
+
<script>
|
| 91 |
+
const canvas = document.getElementById('gameCanvas');
|
| 92 |
+
const ctx = canvas.getContext('2d');
|
| 93 |
+
const message = document.getElementById('message');
|
| 94 |
+
const healthFill = document.getElementById('healthFill');
|
| 95 |
+
const bulletCount = document.getElementById('bulletCount');
|
| 96 |
+
const enemyCount = document.getElementById('enemyCount');
|
| 97 |
+
const bgMusic = document.getElementById('bgMusic');
|
| 98 |
+
const replayButton = document.getElementById('replayButton');
|
| 99 |
+
const playerShootSound = document.getElementById('playerShootSound');
|
| 100 |
+
const enemyShootSound = document.getElementById('enemyShootSound');
|
| 101 |
+
const playerHitSound = document.getElementById('playerHitSound');
|
| 102 |
+
const enemyHitSound = document.getElementById('enemyHitSound');
|
| 103 |
+
|
| 104 |
+
canvas.width = window.innerWidth;
|
| 105 |
+
canvas.height = window.innerHeight;
|
| 106 |
+
|
| 107 |
+
const player = {
|
| 108 |
+
x: canvas.width / 2.3,
|
| 109 |
+
y: canvas.height - 260,
|
| 110 |
+
width: 250,
|
| 111 |
+
height: 250,
|
| 112 |
+
speed: 10,
|
| 113 |
+
health: 10,
|
| 114 |
+
bullets: 35,
|
| 115 |
+
direction: 1,
|
| 116 |
+
image: new Image(),
|
| 117 |
+
imageLeft: 'Maincharacterdefaultleft.png',
|
| 118 |
+
imageRight: 'Maincharacterdefaultright.png',
|
| 119 |
+
imageShootLeft: 'gunshotleft.png',
|
| 120 |
+
imageShootRight: 'gunshotright.png',
|
| 121 |
+
imageHitLeft: 'ExplosionLeft.png',
|
| 122 |
+
imageHitRight: 'ExplosionRight.png'
|
| 123 |
+
};
|
| 124 |
+
player.image.src = player.imageRight;
|
| 125 |
+
|
| 126 |
+
let enemies = [];
|
| 127 |
+
let bullets = [];
|
| 128 |
+
let enemyBullets = [];
|
| 129 |
+
let enemiesRemaining = 30;
|
| 130 |
+
let mouseX = 0;
|
| 131 |
+
let gameStarted = false;
|
| 132 |
+
let gameOver = false;
|
| 133 |
+
|
| 134 |
+
function spawnEnemy() {
|
| 135 |
+
if (!gameStarted || gameOver) {
|
| 136 |
+
return;
|
| 137 |
}
|
|
|
|
|
|
|
| 138 |
|
| 139 |
+
if (enemies.length >= 10) { // λμμ μ‘΄μ¬ν μ μλ μ μ μ μ ν
|
| 140 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
}
|
| 142 |
+
|
| 143 |
+
const side = Math.random() < 0.5 ? 0 : canvas.width;
|
| 144 |
+
const enemy = {
|
| 145 |
+
x: side,
|
| 146 |
+
y: Math.random() * (canvas.height - 150),
|
| 147 |
+
width: 250,
|
| 148 |
+
height: 250,
|
| 149 |
+
speed: side === 0 ? 1 : -1,
|
| 150 |
+
image: new Image(),
|
| 151 |
+
imageLeft: 'Renovators Default Right.png',
|
| 152 |
+
imageRight: 'RenovatorsDefaultLeft.png',
|
| 153 |
+
imageShootLeft: 'RenovatorsgunLeft.png',
|
| 154 |
+
imageShootRight: 'RenovatorsGunRight.png',
|
| 155 |
+
imageHitLeft: 'RenovatorsExplodeLeft.png',
|
| 156 |
+
imageHitRight: 'RenovatorsExplodeRight.png',
|
| 157 |
+
lastShootTime: Date.now()
|
| 158 |
+
};
|
| 159 |
+
enemy.image.src = side === 0 ? enemy.imageLeft : enemy.imageRight;
|
| 160 |
+
enemies.push(enemy);
|
| 161 |
}
|
| 162 |
+
function updateGame() {
|
| 163 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 164 |
+
|
| 165 |
+
player.direction = mouseX > player.x ? 1 : -1;
|
| 166 |
+
player.image.src = player.direction === 1 ? player.imageRight : player.imageLeft;
|
| 167 |
+
ctx.drawImage(player.image, player.x, player.y, player.width, player.height);
|
| 168 |
|
| 169 |
+
// νλ μ΄μ΄κ° λ°μ¬ν μ΄μ μ²λ¦¬
|
| 170 |
+
bullets.forEach((bullet, index) => {
|
| 171 |
+
bullet.x += bullet.speed;
|
| 172 |
+
ctx.fillStyle = 'yellow';
|
| 173 |
+
ctx.fillRect(bullet.x, bullet.y, 10, 5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
});
|
| 175 |
|
| 176 |
+
// μ μ²λ¦¬
|
| 177 |
+
enemies.forEach((enemy, enemyIndex) => {
|
| 178 |
+
enemy.x += enemy.speed;
|
| 179 |
+
ctx.drawImage(enemy.image, enemy.x, enemy.y, enemy.width, enemy.height);
|
| 180 |
+
|
| 181 |
+
// νλ μ΄μ΄μ μ μ΄ μΆ©λνμ κ²½μ° μ²λ¦¬
|
| 182 |
+
if (checkCollision(player, enemy)) {
|
| 183 |
+
player.health--;
|
| 184 |
+
healthFill.style.width = (player.health / 5 * 100) + '%';
|
| 185 |
+
player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
|
| 186 |
+
enemies.splice(enemyIndex, 1); // μ μ κ±°
|
| 187 |
+
playerHitSound.play();
|
| 188 |
+
|
| 189 |
+
if (player.health <= 0) {
|
| 190 |
+
endGame("Game Over! Go back to the past and change the current result!");
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
// νλ μ΄μ΄μ μ΄μμ΄ μ μ λ§μ·μ κ²½μ° μ²λ¦¬
|
| 195 |
+
bullets.forEach((bullet, bulletIndex) => {
|
| 196 |
+
if (checkCollision(bullet, enemy)) {
|
| 197 |
+
// μ΄μμ΄ μ μ λ§μ·μ λ μ²λ¦¬
|
| 198 |
+
enemy.image.src = enemy.speed > 0 ? enemy.imageHitRight : enemy.imageHitLeft;
|
| 199 |
+
setTimeout(() => {
|
| 200 |
+
enemies.splice(enemyIndex, 1); // μ μ κ±°
|
| 201 |
+
bullets.splice(bulletIndex, 1); // μ΄μ μ κ±°
|
| 202 |
+
enemiesRemaining--;
|
| 203 |
+
enemyCount.textContent = enemiesRemaining;
|
| 204 |
+
}, 100);
|
| 205 |
+
enemyHitSound.play();
|
| 206 |
+
|
| 207 |
+
if (enemiesRemaining <= 0) {
|
| 208 |
+
endGame("You have successfully protected New York. Return to the time machine.");
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
});
|
| 212 |
+
|
| 213 |
+
// μ μ μ΄μ λ°μ¬
|
| 214 |
+
enemyShoot(enemy);
|
| 215 |
+
});
|
| 216 |
+
if (enemiesRemaining <= 0 && enemies.length === 0) {
|
| 217 |
+
endGame("You have successfully protected New York. Return to the time machine.");
|
| 218 |
+
return; // κ²μ μ’
λ£ ν λ μ΄μ μ
λ°μ΄νΈνμ§ μμ
|
| 219 |
}
|
| 220 |
+
// μ μ μ΄μ μ²λ¦¬
|
| 221 |
+
enemyBullets.forEach((bullet, index) => {
|
| 222 |
+
bullet.x += bullet.speed;
|
| 223 |
+
ctx.fillStyle = 'orange';
|
| 224 |
+
ctx.fillRect(bullet.x, bullet.y, bullet.width, bullet.height);
|
| 225 |
+
|
| 226 |
+
// μ΄μμ΄ νλ μ΄μ΄μ μΆ©λνμ κ²½μ° μ²λ¦¬
|
| 227 |
+
if (
|
| 228 |
+
bullet.x < player.x + player.width - 30 &&
|
| 229 |
+
bullet.x + bullet.width > player.x + 30 &&
|
| 230 |
+
bullet.y < player.y + player.height - 30 &&
|
| 231 |
+
bullet.y + bullet.height > player.y + 30
|
| 232 |
+
) {
|
| 233 |
+
player.health--;
|
| 234 |
+
healthFill.style.width = (player.health / 5 * 100) + '%';
|
| 235 |
+
player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
|
| 236 |
+
enemyBullets.splice(index, 1); // μ΄μ μ κ±°
|
| 237 |
+
playerHitSound.play();
|
| 238 |
|
| 239 |
+
if (player.health <= 0) {
|
| 240 |
+
endGame("Game Over! Go back to the past and change the current result!");
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
+
});
|
| 244 |
+
|
| 245 |
+
// νλ©΄ λ°μΌλ‘ λκ° μ΄μ μ κ±°
|
| 246 |
+
bullets = bullets.filter(bullet =>
|
| 247 |
+
bullet.x >= 0 && bullet.x <= canvas.width
|
| 248 |
+
);
|
| 249 |
+
enemyBullets = enemyBullets.filter(bullet =>
|
| 250 |
+
bullet.x >= 0 && bullet.x <= canvas.width
|
| 251 |
+
);
|
| 252 |
+
|
| 253 |
+
// κ²μμ΄ μ’
λ£λμ§ μμΌλ©΄ κ³μ μ
λ°μ΄νΈ
|
| 254 |
+
if (!gameOver) {
|
| 255 |
+
requestAnimationFrame(updateGame);
|
| 256 |
+
}
|
| 257 |
}
|
| 258 |
+
setTimeout(() => {
|
| 259 |
+
message.textContent = "Click on the character";
|
| 260 |
+
setTimeout(() => {
|
| 261 |
+
message.textContent = "You can move your character using the arrow keys.";
|
| 262 |
+
setTimeout(() => {
|
| 263 |
+
message.textContent = "The character's direction follows the mouse cursor.";
|
| 264 |
+
setTimeout(() => {
|
| 265 |
+
message.textContent = "Press the space bar to shoot a bullet.";
|
| 266 |
+
setTimeout(() => {
|
| 267 |
+
message.textContent = "Your mission is to defeat the Renovators who have attacked New York. Defeat them all and save New York in 2030!";
|
| 268 |
+
setTimeout(() => {
|
| 269 |
+
message.textContent = "";
|
| 270 |
+
gameStarted = true;
|
| 271 |
+
}, 5000);
|
| 272 |
+
}, 3000);
|
| 273 |
+
}, 4000);
|
| 274 |
+
}, 4000);
|
| 275 |
+
}, 4000);
|
| 276 |
+
}, 0);
|
| 277 |
|
| 278 |
+
function endGame(messageText) {
|
| 279 |
+
gameOver = true;
|
| 280 |
+
message.textContent = messageText;
|
| 281 |
+
replayButton.style.display = 'block';
|
| 282 |
+
}
|
| 283 |
+
function checkCollision(rect1, rect2) {
|
| 284 |
+
return (
|
| 285 |
+
rect1.x + rect1.width * 0.2 < rect2.x + rect2.width * 0.8 &&
|
| 286 |
+
rect1.x + rect1.width * 0.8 > rect2.x + rect2.width * 0.2 &&
|
| 287 |
+
rect1.y + rect1.height * 0.2 < rect2.y + rect2.height * 0.8 &&
|
| 288 |
+
rect1.y + rect1.height * 0.8 > rect2.y + rect2.height * 0.2
|
| 289 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
}
|
| 291 |
+
function enemyShoot(enemy) {
|
| 292 |
+
const now = Date.now();
|
| 293 |
+
if (now - enemy.lastShootTime >= 3000 && !gameOver) {
|
| 294 |
+
enemy.image.src = enemy.speed > 0 ? enemy.imageShootRight : enemy.imageShootLeft;
|
| 295 |
+
enemyBullets.push({
|
| 296 |
+
x: enemy.x + enemy.width / 2,
|
| 297 |
+
y: enemy.y + enemy.height / 2.5,
|
| 298 |
+
width: 10,
|
| 299 |
+
height: 5,
|
| 300 |
+
speed: enemy.speed > 0 ? 5 : -5
|
| 301 |
+
});
|
| 302 |
+
enemy.lastShootTime = now; // Update the last shoot time
|
| 303 |
+
enemyShootSound.play();
|
| 304 |
+
}
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
window.addEventListener('keydown', (e) => {
|
| 308 |
+
if (!gameOver) {
|
| 309 |
+
switch (e.key) {
|
| 310 |
+
case 'ArrowUp':
|
| 311 |
+
if (player.y > 0) player.y -= player.speed;
|
| 312 |
+
break;
|
| 313 |
+
case 'ArrowDown':
|
| 314 |
+
if (player.y < canvas.height - player.height) player.y += player.speed;
|
| 315 |
+
break;
|
| 316 |
+
case 'ArrowLeft':
|
| 317 |
+
if (player.x > 0) player.x -= player.speed;
|
| 318 |
+
break;
|
| 319 |
+
case 'ArrowRight':
|
| 320 |
+
if (player.x < canvas.width - player.width) player.x += player.speed;
|
| 321 |
+
break;
|
| 322 |
+
case ' ':
|
| 323 |
+
if (player.bullets > 0) {
|
| 324 |
+
player.image.src = player.direction === 1 ? player.imageShootRight : player.imageShootLeft;
|
| 325 |
+
bullets.push({
|
| 326 |
+
x: player.x + player.width / 2,
|
| 327 |
+
y: player.y + player.height / 2.5,
|
| 328 |
+
width: 10,
|
| 329 |
+
height: 5,
|
| 330 |
+
speed: player.direction * 10
|
| 331 |
+
});
|
| 332 |
+
player.bullets--;
|
| 333 |
+
bulletCount.textContent = player.bullets;
|
| 334 |
+
playerShootSound.play();
|
| 335 |
+
}
|
| 336 |
+
break;
|
| 337 |
+
}
|
| 338 |
+
}
|
| 339 |
+
});
|
| 340 |
+
|
| 341 |
+
window.addEventListener('mousemove', (e) => {
|
| 342 |
+
mouseX = e.clientX;
|
| 343 |
+
});
|
| 344 |
|
| 345 |
+
replayButton.addEventListener('click', () => {
|
| 346 |
+
location.reload();
|
| 347 |
+
});
|
| 348 |
|
| 349 |
+
setInterval(spawnEnemy, 2000);
|
| 350 |
+
bgMusic.play();
|
| 351 |
+
updateGame();
|
| 352 |
+
</script>
|
| 353 |
</body>
|
| 354 |
</html>
|