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">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Fortress Game</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
margin: 0;
|
10 |
+
display: flex;
|
11 |
+
justify-content: center;
|
12 |
+
align-items: center;
|
13 |
+
min-height: 100vh;
|
14 |
+
background: #1a1a1a;
|
15 |
+
}
|
16 |
+
|
17 |
+
#gameCanvas {
|
18 |
+
background: #000;
|
19 |
+
border: 2px solid #444;
|
20 |
+
}
|
21 |
+
|
22 |
+
.controls {
|
23 |
+
position: fixed;
|
24 |
+
bottom: 20px;
|
25 |
+
display: flex;
|
26 |
+
gap: 10px;
|
27 |
+
}
|
28 |
+
|
29 |
+
button {
|
30 |
+
padding: 10px 20px;
|
31 |
+
font-size: 16px;
|
32 |
+
cursor: pointer;
|
33 |
+
background: #444;
|
34 |
+
color: white;
|
35 |
+
border: none;
|
36 |
+
border-radius: 4px;
|
37 |
+
}
|
38 |
+
|
39 |
+
button:hover {
|
40 |
+
background: #555;
|
41 |
+
}
|
42 |
+
|
43 |
+
#power {
|
44 |
+
color: white;
|
45 |
+
position: fixed;
|
46 |
+
top: 20px;
|
47 |
+
left: 20px;
|
48 |
+
}
|
49 |
+
|
50 |
+
#angle {
|
51 |
+
color: white;
|
52 |
+
position: fixed;
|
53 |
+
top: 50px;
|
54 |
+
left: 20px;
|
55 |
+
}
|
56 |
+
</style>
|
57 |
+
</head>
|
58 |
+
<body>
|
59 |
+
<canvas id="gameCanvas" width="800" height="600"></canvas>
|
60 |
+
<div id="power">Power: 50</div>
|
61 |
+
<div id="angle">Angle: 45°</div>
|
62 |
+
<div class="controls">
|
63 |
+
<button id="powerDown">Power -</button>
|
64 |
+
<button id="powerUp">Power +</button>
|
65 |
+
<button id="angleDown">Angle -</button>
|
66 |
+
<button id="angleUp">Angle +</button>
|
67 |
+
<button id="fire">FIRE!</button>
|
68 |
+
</div>
|
69 |
+
|
70 |
+
<script>
|
71 |
+
const canvas = document.getElementById('gameCanvas');
|
72 |
+
const ctx = canvas.getContext('2d');
|
73 |
+
const powerDisplay = document.getElementById('power');
|
74 |
+
const angleDisplay = document.getElementById('angle');
|
75 |
+
|
76 |
+
let power = 50;
|
77 |
+
let angle = 45;
|
78 |
+
let projectiles = [];
|
79 |
+
let targets = [];
|
80 |
+
let isGameOver = false;
|
81 |
+
|
82 |
+
// Tank properties
|
83 |
+
const tank = {
|
84 |
+
x: 50,
|
85 |
+
y: canvas.height - 30,
|
86 |
+
width: 40,
|
87 |
+
height: 20,
|
88 |
+
barrelLength: 30
|
89 |
+
};
|
90 |
+
|
91 |
+
// Generate random targets
|
92 |
+
for(let i = 0; i < 3; i++) {
|
93 |
+
targets.push({
|
94 |
+
x: Math.random() * (canvas.width - 200) + 400,
|
95 |
+
y: canvas.height - 30,
|
96 |
+
width: 30,
|
97 |
+
height: 30,
|
98 |
+
isHit: false
|
99 |
+
});
|
100 |
+
}
|
101 |
+
|
102 |
+
function drawTank() {
|
103 |
+
ctx.fillStyle = '#4a4';
|
104 |
+
ctx.fillRect(tank.x, tank.y, tank.width, tank.height);
|
105 |
+
|
106 |
+
// Draw barrel
|
107 |
+
ctx.beginPath();
|
108 |
+
ctx.strokeStyle = '#4a4';
|
109 |
+
ctx.lineWidth = 5;
|
110 |
+
const radians = angle * Math.PI / 180;
|
111 |
+
ctx.moveTo(tank.x + tank.width/2, tank.y);
|
112 |
+
ctx.lineTo(
|
113 |
+
tank.x + tank.width/2 + Math.cos(radians) * tank.barrelLength,
|
114 |
+
tank.y - Math.sin(radians) * tank.barrelLength
|
115 |
+
);
|
116 |
+
ctx.stroke();
|
117 |
+
}
|
118 |
+
|
119 |
+
function drawTargets() {
|
120 |
+
targets.forEach(target => {
|
121 |
+
if(!target.isHit) {
|
122 |
+
ctx.fillStyle = '#a44';
|
123 |
+
ctx.fillRect(target.x, target.y, target.width, target.height);
|
124 |
+
}
|
125 |
+
});
|
126 |
+
}
|
127 |
+
|
128 |
+
function fire() {
|
129 |
+
const radians = angle * Math.PI / 180;
|
130 |
+
projectiles.push({
|
131 |
+
x: tank.x + tank.width/2 + Math.cos(radians) * tank.barrelLength,
|
132 |
+
y: tank.y - Math.sin(radians) * tank.barrelLength,
|
133 |
+
vx: Math.cos(radians) * power / 10,
|
134 |
+
vy: -Math.sin(radians) * power / 10
|
135 |
+
});
|
136 |
+
}
|
137 |
+
|
138 |
+
function update() {
|
139 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
140 |
+
|
141 |
+
drawTank();
|
142 |
+
drawTargets();
|
143 |
+
|
144 |
+
// Update and draw projectiles
|
145 |
+
projectiles.forEach((proj, index) => {
|
146 |
+
proj.x += proj.vx;
|
147 |
+
proj.y += proj.vy;
|
148 |
+
proj.vy += 0.2; // gravity
|
149 |
+
|
150 |
+
ctx.beginPath();
|
151 |
+
ctx.arc(proj.x, proj.y, 3, 0, Math.PI * 2);
|
152 |
+
ctx.fillStyle = '#fff';
|
153 |
+
ctx.fill();
|
154 |
+
|
155 |
+
// Check for collisions with targets
|
156 |
+
targets.forEach(target => {
|
157 |
+
if(!target.isHit &&
|
158 |
+
proj.x > target.x &&
|
159 |
+
proj.x < target.x + target.width &&
|
160 |
+
proj.y > target.y &&
|
161 |
+
proj.y < target.y + target.height) {
|
162 |
+
target.isHit = true;
|
163 |
+
projectiles.splice(index, 1);
|
164 |
+
}
|
165 |
+
});
|
166 |
+
|
167 |
+
// Remove projectiles that are off screen
|
168 |
+
if(proj.y > canvas.height || proj.x > canvas.width) {
|
169 |
+
projectiles.splice(index, 1);
|
170 |
+
}
|
171 |
+
});
|
172 |
+
|
173 |
+
// Check win condition
|
174 |
+
if(targets.every(target => target.isHit)) {
|
175 |
+
ctx.fillStyle = '#fff';
|
176 |
+
ctx.font = '48px Arial';
|
177 |
+
ctx.fillText('YOU WIN!', canvas.width/2 - 100, canvas.height/2);
|
178 |
+
isGameOver = true;
|
179 |
+
}
|
180 |
+
|
181 |
+
if(!isGameOver) {
|
182 |
+
requestAnimationFrame(update);
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
// Controls
|
187 |
+
document.getElementById('powerDown').addEventListener('click', () => {
|
188 |
+
if(power > 10) power -= 5;
|
189 |
+
powerDisplay.textContent = `Power: ${power}`;
|
190 |
+
});
|
191 |
+
|
192 |
+
document.getElementById('powerUp').addEventListener('click', () => {
|
193 |
+
if(power < 100) power += 5;
|
194 |
+
powerDisplay.textContent = `Power: ${power}`;
|
195 |
+
});
|
196 |
+
|
197 |
+
document.getElementById('angleDown').addEventListener('click', () => {
|
198 |
+
if(angle > 0) angle -= 5;
|
199 |
+
angleDisplay.textContent = `Angle: ${angle}°`;
|
200 |
+
});
|
201 |
+
|
202 |
+
document.getElementById('angleUp').addEventListener('click', () => {
|
203 |
+
if(angle < 90) angle += 5;
|
204 |
+
angleDisplay.textContent = `Angle: ${angle}°`;
|
205 |
+
});
|
206 |
+
|
207 |
+
document.getElementById('fire').addEventListener('click', fire);
|
208 |
+
|
209 |
+
update();
|
210 |
+
</script>
|
211 |
+
</body>
|
212 |
+
</html>
|