Changed around line 1
+ const canvas = document.getElementById('gameCanvas');
+ const ctx = canvas.getContext('2d');
+ let aspectRatio = 16/9;
+
+ function resizeCanvas() {
+ canvas.width = Math.min(window.innerWidth - 40, 1200);
+ canvas.height = canvas.width / aspectRatio;
+ }
+ resizeCanvas();
+ window.addEventListener('resize', resizeCanvas);
+
+ const plane = {
+ x: 0.5, y: 0.5, size: 0.03,
+ velocity: [0, 0], maxSpeed: 0.02
+ };
+
+ let entities = [];
+ let lastSpawn = 0;
+
+ class GameEntity {
+ constructor(type) {
+ this.type = type;
+ this.x = Math.random();
+ this.y = Math.random();
+ this.strategy = Math.random() > 0.5 ? 'cooperative' : 'aggressive';
+ this.lastAction = performance.now();
+ }
+
+ decideAction() {
+ const timeSince = performance.now() - this.lastAction;
+ if(timeSince > 2000) {
+ this.strategy = plane.score > 50 ? 'aggressive' : 'cooperative';
+ this.lastAction = performance.now();
+ }
+ }
+ }
+
+ function gameLoop(timestamp) {
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+
+ // Update positions
+ plane.x = Math.max(0, Math.min(1, plane.x + plane.velocity[0]));
+ plane.y = Math.max(0, Math.min(1, plane.y + plane.velocity[1]));
+
+ // Spawn entities
+ if(timestamp - lastSpawn > 2000) {
+ entities.push(new GameEntity(
+ Math.random() > 0.3 ? 'ally' : 'enemy'
+ ));
+ lastSpawn = timestamp;
+ }
+
+ // Draw plane
+ ctx.save();
+ const px = plane.x * canvas.width;
+ const py = plane.y * canvas.height;
+ ctx.translate(px, py);
+ ctx.rotate(Math.atan2(plane.velocity[1], plane.velocity[0]) + Math.PI/2);
+ ctx.beginPath();
+ ctx.moveTo(0, -plane.size * canvas.width);
+ ctx.lineTo(-plane.size * canvas.width/2, plane.size * canvas.width);
+ ctx.lineTo(plane.size * canvas.width/2, plane.size * canvas.width);
+ ctx.closePath();
+ ctx.fillStyle = var(--plane-color);
+ ctx.shadowBlur = 15;
+ ctx.shadowColor = rgba(255,215,0,0.5);
+ ctx.fill();
+ ctx.restore();
+
+ requestAnimationFrame(gameLoop);
+ }
+
+ // Input handling
+ const touchPos = {x: null, y: null};
+
+ canvas.addEventListener('mousemove', e => {
+ const rect = canvas.getBoundingClientRect();
+ touchPos.x = (e.clientX - rect.left) / canvas.width;
+ touchPos.y = (e.clientY - rect.top) / canvas.height;
+ });
+
+ canvas.addEventListener('touchmove', e => {
+ e.preventDefault();
+ const rect = canvas.getBoundingClientRect();
+ touchPos.x = (e.touches[0].clientX - rect.left) / canvas.width;
+ touchPos.y = (e.touches[0].clientY - rect.top) / canvas.height;
+ });
+
+ function updateVelocity() {
+ if(touchPos.x !== null) {
+ plane.velocity[0] = (touchPos.x - plane.x) * 0.05;
+ plane.velocity[1] = (touchPos.y - plane.y) * 0.05;
+ }
+ requestAnimationFrame(updateVelocity);
+ }
+ updateVelocity();
+ requestAnimationFrame(gameLoop);