1945 공군: 클래식 비행기 게임 웹페이지로 만들어줘
- User
1945 공군: 클래식 비행기 게임 웹페이지로 만들어줘
Assistant
1945 공군: 클래식 비행기 게임 웹페이지로 만들어줘
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>1945 공군: 클래식 비행기 게임</title>
<style>
body {
margin: 0;
padding: 0;
background-color: #0a0a1a;
color: white;
font-family: 'Arial', sans-serif;
overflow: hidden;
background-image: radial-gradient(circle at 10% 20%, #1a1a3a, #0a0a1a);
}
header {
text-align: center;
padding: 20px;
background-color: rgba(0, 0, 0, 0.7);
border-bottom: 2px solid #4a4a6a;
}
h1 {
font-size: 3em;
margin: 0;
color: #ffd700;
text-shadow: 0 0 10px #ffd700, 0 0 20px #ff4500;
letter-spacing: 3px;
}
.game-container {
display: flex;
justify-content: center;
align-items: center;
height: 80vh;
position: relative;
}
#gameCanvas {
background-color: #000;
border: 3px solid #4a4a6a;
border-radius: 5px;
}
.controls {
position: absolute;
bottom: 20px;
width: 100%;
text-align: center;
background-color: rgba(0, 0, 0, 0.7);
padding: 10px;
}
button {
background-color: #4a4a6a;
color: white;
border: none;
padding: 10px 20px;
margin: 0 10px;
border-radius: 5px;
cursor: pointer;
font-size: 1em;
transition: all 0.3s;
}
button:hover {
background-color: #ffd700;
color: black;
transform: scale(1.05);
}
.instructions {
background-color: rgba(0, 0, 0, 0.7);
padding: 20px;
margin: 20px auto;
max-width: 800px;
border-radius: 5px;
border: 1px solid #4a4a6a;
}
footer {
text-align: center;
padding: 10px;
background-color: rgba(0, 0, 0, 0.7);
position: fixed;
bottom: 0;
width: 100%;
}
.plane-icon {
font-size: 1.5em;
margin: 0 5px;
}
@media (max-width: 768px) {
h1 {
font-size: 2em;
}
.controls {
position: static;
margin-top: 20px;
}
}
</style>
</head>
<body>
<header>
<h1>1945 공군</h1>
<p>클래식 비행기 게임으로 돌아가보세요!</p>
</header>
<div class="instructions">
<h2>게임 설명</h2>
<p>1945 공군은 1980년대 아케이드 게임의 분위기를 재현한 클래식 슈팅 게임입니다.</p>
<p>적 비행기들을 피하면서 공격하여 높은 점수를 획득하세요!</p>
<h3>조작 방법</h3>
<ul>
<li>← → 키: 비행기 이동</li>
<li>↑ ↓ 키: 비행기 속도 조절</li>
<li>스페이스 바: 발사</li>
<li>P 키: 일시정지</li>
</ul>
</div>
<div class="game-container">
<canvas id="gameCanvas" width="800" height="600"></canvas>
</div>
<div class="controls">
<button id="startBtn">게임 시작</button>
<button id="pauseBtn">일시정지</button>
<button id="soundBtn">사운드 ON/OFF</button>
</div>
<footer>
<p>© 2023 클래식 비행기 게임 | 모든 권리 보유</p>
</footer>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
const startBtn = document.getElementById('startBtn');
const pauseBtn = document.getElementById('pauseBtn');
const soundBtn = document.getElementById('soundBtn');
// 게임 상태
let gameRunning = false;
let gamePaused = false;
let soundOn = true;
// 플레이어 비행기
const player = {
x: canvas.width / 2,
y: canvas.height - 50,
width: 50,
height: 40,
speed: 5,
dx: 0,
dy: 0,
color: '#ffd700',
draw() {
ctx.fillStyle = this.color;
ctx.beginPath();
ctx.moveTo(this.x, this.y);
ctx.lineTo(this.x - this.width / 2, this.y + this.height);
ctx.lineTo(this.x, this.y + this.height / 2);
ctx.lineTo(this.x + this.width / 2, this.y + this.height);
ctx.closePath();
ctx.fill();
// 동체
ctx.fillStyle = '#4a4a6a';
ctx.fillRect(this.x - this.width / 4, this.y + this.height / 2, this.width / 2, this.height / 4);
// 프로펠러
ctx.fillStyle = '#000';
ctx.beginPath();
ctx.arc(this.x, this.y, 5, 0, Math.PI * 2);
ctx.fill();
},
update() {
this.x += this.dx;
this.y += this.dy;
// 화면 경계 체크
if (this.x < this.width / 2) this.x = this.width / 2;
if (this.x > canvas.width - this.width / 2) this.x = canvas.width - this.width / 2;
if (this.y < this.height) this.y = this.height;
if (this.y > canvas.height - this.height) this.y = canvas.height - this.height;
}
};
// 총알
const bullets = [];
const bulletSpeed = 7;
const bulletSize = 5;
// 적
const enemies = [];
const enemySize = 30;
let enemySpeed = 2;
let enemySpawnRate = 60;
let enemySpawnCounter = 0;
// 점수
let score = 0;
let highScore = localStorage.getItem('highScore') || 0;
// 게임 루프
function gameLoop() {
if (!gameRunning || gamePaused) return;
// 화면 지우기
ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// 플레이어 업데이트 및 그리기
player.update();
player.draw();
// 총알 업데이트 및 그리기
for (let i = 0; i < bullets.length; i++) {
bullets[i].y -= bulletSpeed;
// 화면 밖으로 나간 총알 제거
if (bullets[i].y < 0) {
bullets.splice(i, 1);
i--;
continue;
}
// 총알 그리기
ctx.fillStyle = '#ff4500';
ctx.beginPath();
ctx.arc(bullets[i].x, bullets[i].y, bulletSize, 0, Math.PI * 2);
ctx.fill();
}
// 적 생성
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnRate) {
const x = Math.random() * (canvas.width - enemySize);
enemies.push({ x, y: -enemySize, width: enemySize, height: enemySize });
// 난이도 증가
if (enemySpawnRate > 20) enemySpawnRate--;
if (enemySpeed < 5) enemySpeed += 0.1;
enemySpawnCounter = 0;
}
// 적 업데이트 및 그리기
for (let i = 0; i < enemies.length; i++) {
enemies[i].y += enemySpeed;
// 화면 밖으로 나간 적 제거
if (enemies[i].y > canvas.height) {
enemies.splice(i, 1);
i--;
continue;
}
// 적 그리기
ctx.fillStyle = '#ff0000';
ctx.beginPath();
ctx.moveTo(enemies[i].x, enemies[i].y);
ctx.lineTo(enemies[i].x - enemies[i].width / 2, enemies[i].y + enemies[i].height);
ctx.lineTo(enemies[i].x, enemies[i].y + enemies[i].height / 2);
ctx.lineTo(enemies[i].x + enemies[i].width / 2, enemies[i].y + enemies[i].height);
ctx.closePath();
ctx.fill();
// 충돌 검사
for (let j = 0; j < bullets.length; j++) {
if (checkCollision(bullets[j], enemies[i])) {
// 충돌 발생
bullets.splice(j, 1);
enemies.splice(i, 1);
score += 10;
i--;
break;
}
}
// 플레이어와 적 충돌 검사
if (checkCollision(player, enemies[i])) {
gameOver();
return;
}
}
// 점수 표시
ctx.fillStyle = 'white';
ctx.font = '20px Arial';
ctx.fillText(`점수: ${score}`, 20, 30);
ctx.fillText(`최고 점수: ${highScore}`, 20, 60);
requestAnimationFrame(gameLoop);
}
// 충돌 검사 함수
function checkCollision(obj1, obj2) {
return obj1.x < obj2.x + obj2.width &&
obj1.x + (obj1.width || bulletSize * 2) > obj2.x &&
obj1.y < obj2.y + obj2.height &&
obj1.y + (obj1.height || bulletSize * 2) > obj2.y;
}
// 게임 오버 함수
function gameOver() {
gameRunning = false;
// 최고 점수 업데이트
if (score > highScore) {
highScore = score;
localStorage.setItem('highScore', highScore);
}
// 게임 오버 메시지 표시
ctx.fillStyle = 'rgba(0, 0, 0, 0.7)';
ctx.fillRect(0, canvas.height / 2 - 50, canvas.width, 100);
ctx.fillStyle = 'white';
ctx.font = '30px Arial';
ctx.textAlign = 'center';
ctx.fillText('게임 오버!', canvas.width / 2, canvas.height / 2);
ctx.font = '20px Arial';
ctx.fillText(`최종 점수: ${score}`, canvas.width / 2, canvas.height / 2 + 30);
ctx.fillText('시작 버튼을 눌러 다시 플레이하세요', canvas.width / 2, canvas.height / 2 + 60);
ctx.textAlign = 'left';
}
// 키보드 이벤트 리스너
document.addEventListener('keydown', (e) => {
if (!gameRunning) return;
switch (e.key) {
case 'ArrowLeft':
player.dx = -player.speed;
break;
case 'ArrowRight':
player.dx = player.speed;
break;
case 'ArrowUp':
player.dy = -player.speed;
break;
case 'ArrowDown':
player.dy = player.speed;
break;
case ' ':
// 총알 발사
bullets.push({ x: player.x, y: player.y });
if (soundOn) {
const audio = new Audio('https://assets.mixkit.co/sfx/preview/mixkit-laser-gun-sound-effect-2449.mp3');
audio.volume = 0.2;
audio.play();
}
break;
case 'p':
case 'P':
togglePause();
break;
}
});
document.addEventListener('keyup', (e) => {
switch (e.key) {
case 'ArrowLeft':
case 'ArrowRight':
player.dx = 0;
break;
case 'ArrowUp':
case 'ArrowDown':
player.dy = 0;
break;
}
});
// 시작 버튼 이벤트
startBtn.addEventListener('click', () => {
if (!gameRunning) {
// 게임 초기화
player.x = canvas.width / 2;
player.y = canvas.height - 50;
player.dx = 0;
player.dy = 0;
bullets.length = 0;
enemies.length = 0;
score = 0;
enemySpeed = 2;
enemySpawnRate = 60;
enemySpawnCounter = 0;
gameRunning = true;
gamePaused = false;
gameLoop();
}
});
// 일시정지 버튼 이벤트
pauseBtn.addEventListener('click', togglePause);
function togglePause() {
gamePaused = !gamePaused;
pauseBtn.textContent = gamePaused ? '계속하기' : '일시정지';
if (!gamePaused && gameRunning) {
gameLoop();
}
}
// 사운드 버튼 이벤트
soundBtn.addEventListener('click', () => {
soundOn = !soundOn;
soundBtn.textContent = soundOn ? '사운드 ON/OFF' : '사운드 OFF/ON';
});
// 초기 게임 오버 메시지 표시
ctx.fillStyle = 'white';
ctx.font = '30px Arial';
ctx.textAlign = 'center';
ctx.fillText('시작 버튼을 눌러 게임을 시작하세요', canvas.width / 2, canvas.height / 2);
ctx.textAlign = 'left';
</script>
</body>
</html>
이 코드는 1945년을 배경으로 한 클래식 비행기 슈팅 게임 웹페이지입니다. 주요 기능은 다음과 같습니다:
게임 플레이:
게임 요소:
UI/UX:
기술적 특징:
이 게임은 1980년대 아케이드 게임의 분위기를 재현하면서도 현대적인 웹 기술로 구현되었습니다.