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in: 0;
|
| 10 |
+
overflow: hidden;
|
| 11 |
+
background: #333;
|
| 12 |
+
font-family: Arial, sans-serif;
|
| 13 |
+
cursor: crosshair;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
#score, #health, #timer {
|
| 17 |
+
position: fixed;
|
| 18 |
+
color: white;
|
| 19 |
+
font-size: 20px;
|
| 20 |
+
z-index: 100;
|
| 21 |
+
}
|
| 22 |
+
#score {
|
| 23 |
+
top: 10px;
|
| 24 |
+
left: 10px;
|
| 25 |
+
}
|
| 26 |
+
#health {
|
| 27 |
+
top: 10px;
|
| 28 |
+
right: 10px;
|
| 29 |
+
}
|
| 30 |
+
#timer {
|
| 31 |
+
top: 10px;
|
| 32 |
+
left: 50%;
|
| 33 |
+
transform: translateX(-50%);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
#startScreen {
|
| 37 |
+
position: fixed;
|
| 38 |
+
top: 0;
|
| 39 |
+
left: 0;
|
| 40 |
+
width: 100%;
|
| 41 |
+
height: 100%;
|
| 42 |
+
background: rgba(0, 0, 0, 0.8);
|
| 43 |
+
color: white;
|
| 44 |
+
display: flex;
|
| 45 |
+
justify-content: center;
|
| 46 |
+
align-items: center;
|
| 47 |
+
flex-direction: column;
|
| 48 |
+
z-index: 1000;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
#startButton {
|
| 52 |
+
padding: 10px 20px;
|
| 53 |
+
font-size: 18px;
|
| 54 |
+
background: green;
|
| 55 |
+
color: white;
|
| 56 |
+
border: none;
|
| 57 |
+
cursor: pointer;
|
| 58 |
+
border-radius: 5px;
|
| 59 |
+
margin-top: 20px;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
#player {
|
| 63 |
+
position: absolute;
|
| 64 |
+
width: 40px;
|
| 65 |
+
height: 40px;
|
| 66 |
+
background: lime;
|
| 67 |
+
border-radius: 50%;
|
| 68 |
+
transform-origin: center;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
.zombie {
|
| 72 |
+
position: absolute;
|
| 73 |
+
width: 40px;
|
| 74 |
+
height: 40px;
|
| 75 |
+
background: crimson;
|
| 76 |
+
border-radius: 50%;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
.bullet {
|
| 80 |
+
position: absolute;
|
| 81 |
+
width: 8px;
|
| 82 |
+
height: 8px;
|
| 83 |
+
background: yellow;
|
| 84 |
+
border-radius: 50%;
|
| 85 |
+
}
|
| 86 |
+
</style>
|
| 87 |
+
</head>
|
| 88 |
+
<body>
|
| 89 |
+
<div id="startScreen">
|
| 90 |
+
<h1>Zombie Survival</h1>
|
| 91 |
+
<button id="startButton">Start Game</button>
|
| 92 |
+
</div>
|
| 93 |
+
<div id="score">Score: 0</div>
|
| 94 |
+
<div id="health">Health: 100</div>
|
| 95 |
+
<div id="timer">Time: 0</div>
|
| 96 |
+
<div id="player"></div>
|
| 97 |
+
|
| 98 |
+
<script>
|
| 99 |
+
const startScreen = document.getElementById('startScreen');
|
| 100 |
+
const startButton = document.getElementById('startButton');
|
| 101 |
+
const player = document.getElementById('player');
|
| 102 |
+
const scoreDisplay = document.getElementById('score');
|
| 103 |
+
const healthDisplay = document.getElementById('health');
|
| 104 |
+
const timerDisplay = document.getElementById('timer');
|
| 105 |
+
|
| 106 |
+
let score = 0;
|
| 107 |
+
let health = 100;
|
| 108 |
+
let gameRunning = false;
|
| 109 |
+
let bullets = [];
|
| 110 |
+
let zombies = [];
|
| 111 |
+
let mouseX = 0, mouseY = 0;
|
| 112 |
+
let playerX = window.innerWidth / 2;
|
| 113 |
+
let playerY = window.innerHeight / 2;
|
| 114 |
+
let gameTime = 0;
|
| 115 |
+
let zombieSpeedMultiplier = 1;
|
| 116 |
+
let timeInterval;
|
| 117 |
+
|
| 118 |
+
// νλ μ΄μ΄ μ΄λ μ
λ°μ΄νΈ
|
| 119 |
+
function updatePlayer() {
|
| 120 |
+
player.style.left = `${playerX - 20}px`;
|
| 121 |
+
player.style.top = `${playerY - 20}px`;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
// μ’λΉ μμ±
|
| 125 |
+
function spawnZombie() {
|
| 126 |
+
if (!gameRunning) return;
|
| 127 |
+
|
| 128 |
+
const zombie = document.createElement('div');
|
| 129 |
+
zombie.className = 'zombie';
|
| 130 |
+
const size = 40;
|
| 131 |
+
|
| 132 |
+
const side = Math.floor(Math.random() * 4); // 0: μ, 1: μ€λ₯Έμͺ½, 2: μλ, 3: μΌμͺ½
|
| 133 |
+
let x, y;
|
| 134 |
+
|
| 135 |
+
if (side === 0) { // μμͺ½μμ μμ±
|
| 136 |
+
x = Math.random() * window.innerWidth;
|
| 137 |
+
y = -size;
|
| 138 |
+
} else if (side === 1) { // μ€λ₯Έμͺ½μμ μμ±
|
| 139 |
+
x = window.innerWidth + size;
|
| 140 |
+
y = Math.random() * window.innerHeight;
|
| 141 |
+
} else if (side === 2) { // μλμͺ½μμ μμ±
|
| 142 |
+
x = Math.random() * window.innerWidth;
|
| 143 |
+
y = window.innerHeight + size;
|
| 144 |
+
} else { // μΌμͺ½μμ μμ±
|
| 145 |
+
x = -size;
|
| 146 |
+
y = Math.random() * window.innerHeight;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
document.body.appendChild(zombie);
|
| 150 |
+
zombies.push({ element: zombie, x, y, speed: (1.5 + Math.random() * 2) * zombieSpeedMultiplier });
|
| 151 |
+
|
| 152 |
+
updateZombies();
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
// μ’λΉ μ΄λ λ° μΆ©λ μ²λ¦¬
|
| 156 |
+
function updateZombies() {
|
| 157 |
+
zombies.forEach((zombie, index) => {
|
| 158 |
+
const angle = Math.atan2(playerY - zombie.y, playerX - zombie.x);
|
| 159 |
+
zombie.x += Math.cos(angle) * zombie.speed;
|
| 160 |
+
zombie.y += Math.sin(angle) * zombie.speed;
|
| 161 |
+
zombie.element.style.left = `${zombie.x - 20}px`;
|
| 162 |
+
zombie.element.style.top = `${zombie.y - 20}px`;
|
| 163 |
+
|
| 164 |
+
const distanceToPlayer = Math.hypot(zombie.x - playerX, zombie.y - playerY);
|
| 165 |
+
if (distanceToPlayer < 40) {
|
| 166 |
+
health -= 10;
|
| 167 |
+
healthDisplay.textContent = `Health: ${health}`;
|
| 168 |
+
zombie.element.remove();
|
| 169 |
+
zombies.splice(index, 1);
|
| 170 |
+
|
| 171 |
+
if (health <= 0) {
|
| 172 |
+
endGame();
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
});
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
// μ΄μ μμ±
|
| 179 |
+
function shootBullet() {
|
| 180 |
+
if (!gameRunning) return;
|
| 181 |
+
|
| 182 |
+
const bullet = document.createElement('div');
|
| 183 |
+
bullet.className = 'bullet';
|
| 184 |
+
const angle = Math.atan2(mouseY - playerY, mouseX - playerX);
|
| 185 |
+
const speed = 10;
|
| 186 |
+
|
| 187 |
+
bullets.push({
|
| 188 |
+
element: bullet,
|
| 189 |
+
x: playerX,
|
| 190 |
+
y: playerY,
|
| 191 |
+
vx: Math.cos(angle) * speed,
|
| 192 |
+
vy: Math.sin(angle) * speed
|
| 193 |
+
});
|
| 194 |
+
|
| 195 |
+
document.body.appendChild(bullet);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
// μ΄μ μ
λ°μ΄νΈ
|
| 199 |
+
function updateBullets() {
|
| 200 |
+
bullets.forEach((bullet, index) => {
|
| 201 |
+
bullet.x += bullet.vx;
|
| 202 |
+
bullet.y += bullet.vy;
|
| 203 |
+
|
| 204 |
+
bullet.element.style.left = `${bullet.x - 4}px`;
|
| 205 |
+
bullet.element.style.top = `${bullet.y - 4}px`;
|
| 206 |
+
|
| 207 |
+
// νλ©΄ λ°μΌλ‘ λκ° μ΄μ μ κ±°
|
| 208 |
+
if (bullet.x < 0 || bullet.x > window.innerWidth || bullet.y < 0 || bullet.y > window.innerHeight) {
|
| 209 |
+
bullet.element.remove();
|
| 210 |
+
bullets.splice(index, 1);
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
// μ’λΉμ μΆ©λ 체ν¬
|
| 214 |
+
zombies.forEach((zombie, zombieIndex) => {
|
| 215 |
+
const distance = Math.hypot(bullet.x - zombie.x, bullet.y - zombie.y);
|
| 216 |
+
if (distance < 20) {
|
| 217 |
+
bullet.element.remove();
|
| 218 |
+
zombie.element.remove();
|
| 219 |
+
bullets.splice(index, 1);
|
| 220 |
+
zombies.splice(zombieIndex, 1);
|
| 221 |
+
score += 10;
|
| 222 |
+
scoreDisplay.textContent = `Score: ${score}`;
|
| 223 |
+
}
|
| 224 |
+
});
|
| 225 |
+
});
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
// κ²μ 루ν
|
| 229 |
+
function gameLoop() {
|
| 230 |
+
if (!gameRunning) return;
|
| 231 |
+
|
| 232 |
+
updateBullets();
|
| 233 |
+
updateZombies();
|
| 234 |
+
requestAnimationFrame(gameLoop);
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
// κ²μ μκ° μ
λ°μ΄νΈ
|
| 238 |
+
function updateTimer() {
|
| 239 |
+
if (!gameRunning) return;
|
| 240 |
+
gameTime++;
|
| 241 |
+
timerDisplay.textContent = `Time: ${gameTime}`;
|
| 242 |
+
if (gameTime % 10 === 0) {
|
| 243 |
+
zombieSpeedMultiplier *= 2;
|
| 244 |
+
zombies.forEach(zombie => {
|
| 245 |
+
zombie.speed = (1.5 + Math.random() * 2) * zombieSpeedMultiplier;
|
| 246 |
+
});
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
// κ²μ μμ
|
| 252 |
+
startButton.addEventListener('click', () => {
|
| 253 |
+
startScreen.style.display = 'none';
|
| 254 |
+
gameRunning = true;
|
| 255 |
+
health = 100;
|
| 256 |
+
score = 0;
|
| 257 |
+
gameTime = 0;
|
| 258 |
+
zombieSpeedMultiplier = 1;
|
| 259 |
+
healthDisplay.textContent = `Health: ${health}`;
|
| 260 |
+
scoreDisplay.textContent = `Score: ${score}`;
|
| 261 |
+
timerDisplay.textContent = `Time: ${gameTime}`;
|
| 262 |
+
spawnZombie();
|
| 263 |
+
setInterval(spawnZombie, 1000);
|
| 264 |
+
gameLoop();
|
| 265 |
+
timeInterval = setInterval(updateTimer, 1000);
|
| 266 |
+
});
|
| 267 |
+
|
| 268 |
+
// κ²μ μ’
λ£
|
| 269 |
+
function endGame() {
|
| 270 |
+
gameRunning = false;
|
| 271 |
+
clearInterval(timeInterval);
|
| 272 |
+
alert(`Game Over! Final Score: ${score}, Time: ${gameTime}`);
|
| 273 |
+
location.reload();
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
// λ§μ°μ€ μ΄λ
|
| 277 |
+
document.addEventListener('mousemove', (e) => {
|
| 278 |
+
mouseX = e.clientX;
|
| 279 |
+
mouseY = e.clientY;
|
| 280 |
+
});
|
| 281 |
+
|
| 282 |
+
// μ΄μ λ°μ¬
|
| 283 |
+
document.addEventListener('click', shootBullet);
|
| 284 |
+
|
| 285 |
+
// μ΄κΈ° νλ μ΄μ΄ μμΉ
|
| 286 |
+
updatePlayer();
|
| 287 |
+
</script>
|
| 288 |
+
</body>
|
| 289 |
+
</html>
|