Dataset Viewer
messages
list |
---|
[
{
"content": "You are an expert web developer. When creating games, provide step-by-step thinking and complete, functional code.",
"role": "system",
"thinking": null
},
{
"content": "Create an HTML page with an Angry Birds game",
"role": "user",
"thinking": null
},
{
"content": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Angry Birds Game</title>\n <style>\n body {\n margin: 0;\n padding: 0;\n background: linear-gradient(135deg, #87CEEB 0%, #98FB98 100%);\n font-family: Arial, sans-serif;\n overflow: hidden;\n }\n \n #gameCanvas {\n border: 2px solid #8B4513;\n display: block;\n margin: 0 auto;\n background: linear-gradient(to bottom, #87CEEB 0%, #90EE90 70%, #8B4513 100%);\n }\n \n #ui {\n position: absolute;\n top: 10px;\n left: 10px;\n color: white;\n font-size: 18px;\n text-shadow: 2px 2px 4px rgba(0,0,0,0.5);\n }\n \n #instructions {\n position: absolute;\n top: 10px;\n right: 10px;\n color: white;\n font-size: 14px;\n text-shadow: 2px 2px 4px rgba(0,0,0,0.5);\n max-width: 200px;\n }\n </style>\n</head>\n<body>\n <div id=\"ui\">\n <div>Score: <span id=\"score\">0</span></div>\n <div>Birds: <span id=\"birds\">3</span></div>\n </div>\n <div id=\"instructions\">\n Click and drag to aim the slingshot.<br>\n Release to launch the bird at the pigs!\n </div>\n <canvas id=\"gameCanvas\" width=\"800\" height=\"600\"></canvas>\n \n <script>\n const canvas = document.getElementById('gameCanvas');\n const ctx = canvas.getContext('2d');\n \n // Game state\n let score = 0;\n let birdsLeft = 3;\n let isAiming = false;\n let isDragging = false;\n let gameObjects = [];\n \n // Slingshot position\n const slingshot = { x: 100, y: 400 };\n \n // Physics constants\n const gravity = 0.3;\n const friction = 0.98;\n \n // Bird class\n class Bird {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n this.vx = 0;\n this.vy = 0;\n this.radius = 15;\n this.color = '#FF0000';\n this.launched = false;\n this.trail = [];\n }\n \n update() {\n if (this.launched) {\n this.trail.push({x: this.x, y: this.y});\n if (this.trail.length > 10) this.trail.shift();\n \n this.vx *= friction;\n this.vy += gravity;\n this.x += this.vx;\n this.y += this.vy;\n \n // Bounce off ground\n if (this.y > canvas.height - 50 - this.radius) {\n this.y = canvas.height - 50 - this.radius;\n this.vy *= -0.5;\n this.vx *= 0.8;\n }\n \n // Stop if moving too slowly\n if (Math.abs(this.vx) < 0.1 && Math.abs(this.vy) < 0.1) {\n this.vx = 0;\n this.vy = 0;\n }\n }\n }\n \n draw() {\n // Draw trail\n ctx.strokeStyle = 'rgba(255, 0, 0, 0.3)';\n ctx.lineWidth = 3;\n ctx.beginPath();\n for (let i = 0; i < this.trail.length - 1; i++) {\n ctx.moveTo(this.trail[i].x, this.trail[i].y);\n ctx.lineTo(this.trail[i + 1].x, this.trail[i + 1].y);\n }\n ctx.stroke();\n \n // Draw bird\n ctx.fillStyle = this.color;\n ctx.beginPath();\n ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);\n ctx.fill();\n \n // Draw eyes\n ctx.fillStyle = 'white';\n ctx.beginPath();\n ctx.arc(this.x - 5, this.y - 5, 4, 0, Math.PI * 2);\n ctx.arc(this.x + 5, this.y - 5, 4, 0, Math.PI * 2);\n ctx.fill();\n \n ctx.fillStyle = 'black';\n ctx.beginPath();\n ctx.arc(this.x - 5, this.y - 5, 2, 0, Math.PI * 2);\n ctx.arc(this.x + 5, this.y - 5, 2, 0, Math.PI * 2);\n ctx.fill();\n \n // Draw beak\n ctx.fillStyle = '#FFA500';\n ctx.beginPath();\n ctx.moveTo(this.x + 10, this.y);\n ctx.lineTo(this.x + 18, this.y - 3);\n ctx.lineTo(this.x + 18, this.y + 3);\n ctx.closePath();\n ctx.fill();\n }\n }\n \n // Pig class\n class Pig {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n this.radius = 20;\n this.color = '#00FF00';\n this.health = 1;\n this.destroyed = false;\n }\n \n update() {\n // Check collision with birds\n gameObjects.forEach(obj => {\n if (obj instanceof Bird && obj.launched) {\n const dx = this.x - obj.x;\n const dy = this.y - obj.y;\n const distance = Math.sqrt(dx * dx + dy * dy);\n \n if (distance < this.radius + obj.radius && !this.destroyed) {\n this.destroyed = true;\n score += 100;\n updateUI();\n }\n }\n });\n }\n \n draw() {\n if (!this.destroyed) {\n ctx.fillStyle = this.color;\n ctx.beginPath();\n ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);\n ctx.fill();\n \n // Draw pig face\n ctx.fillStyle = 'white';\n ctx.beginPath();\n ctx.arc(this.x - 8, this.y - 5, 5, 0, Math.PI * 2);\n ctx.arc(this.x + 8, this.y - 5, 5, 0, Math.PI * 2);\n ctx.fill();\n \n ctx.fillStyle = 'black';\n ctx.beginPath();\n ctx.arc(this.x - 8, this.y - 5, 2, 0, Math.PI * 2);\n ctx.arc(this.x + 8, this.y - 5, 2, 0, Math.PI * 2);\n ctx.fill();\n \n // Snout\n ctx.fillStyle = '#90EE90';\n ctx.beginPath();\n ctx.ellipse(this.x, this.y + 5, 6, 4, 0, 0, Math.PI * 2);\n ctx.fill();\n \n ctx.fillStyle = 'black';\n ctx.beginPath();\n ctx.arc(this.x - 2, this.y + 5, 1, 0, Math.PI * 2);\n ctx.arc(this.x + 2, this.y + 5, 1, 0, Math.PI * 2);\n ctx.fill();\n }\n }\n }\n \n // Block class\n class Block {\n constructor(x, y, width, height) {\n this.x = x;\n this.y = y;\n this.width = width;\n this.height = height;\n this.color = '#8B4513';\n this.destroyed = false;\n }\n \n update() {\n // Check collision with birds\n gameObjects.forEach(obj => {\n if (obj instanceof Bird && obj.launched) {\n if (obj.x > this.x && obj.x < this.x + this.width &&\n obj.y > this.y && obj.y < this.y + this.height && !this.destroyed) {\n this.destroyed = true;\n obj.vx *= 0.3;\n obj.vy *= 0.3;\n score += 10;\n updateUI();\n }\n }\n });\n }\n \n draw() {\n if (!this.destroyed) {\n ctx.fillStyle = this.color;\n ctx.fillRect(this.x, this.y, this.width, this.height);\n ctx.strokeStyle = '#654321';\n ctx.lineWidth = 2;\n ctx.strokeRect(this.x, this.y, this.width, this.height);\n }\n }\n }\n \n // Initialize game objects\n function initGame() {\n gameObjects = [];\n \n // Add pigs\n gameObjects.push(new Pig(600, 450));\n gameObjects.push(new Pig(650, 400));\n gameObjects.push(new Pig(700, 450));\n \n // Add blocks\n gameObjects.push(new Block(580, 460, 20, 60));\n gameObjects.push(new Block(600, 520, 60, 20));\n gameObjects.push(new Block(680, 460, 20, 60));\n gameObjects.push(new Block(640, 520, 60, 20));\n gameObjects.push(new Block(620, 380, 60, 20));\n }\n \n // Current bird being aimed\n let currentBird = null;\n \n // Mouse handling\n let mouseX = 0;\n let mouseY = 0;\n \n canvas.addEventListener('mousedown', (e) => {\n const rect = canvas.getBoundingClientRect();\n mouseX = e.clientX - rect.left;\n mouseY = e.clientY - rect.top;\n \n const dx = mouseX - slingshot.x;\n const dy = mouseY - slingshot.y;\n const distance = Math.sqrt(dx * dx + dy * dy);\n \n if (distance < 100 && birdsLeft > 0 && !currentBird) {\n currentBird = new Bird(slingshot.x, slingshot.y);\n isDragging = true;\n isAiming = true;\n }\n });\n \n canvas.addEventListener('mousemove', (e) => {\n const rect = canvas.getBoundingClientRect();\n mouseX = e.clientX - rect.left;\n mouseY = e.clientY - rect.top;\n });\n \n canvas.addEventListener('mouseup', () => {\n if (isDragging && currentBird) {\n const dx = slingshot.x - mouseX;\n const dy = slingshot.y - mouseY;\n \n currentBird.vx = dx * 0.1;\n currentBird.vy = dy * 0.1;\n currentBird.launched = true;\n \n gameObjects.push(currentBird);\n birdsLeft--;\n updateUI();\n \n currentBird = null;\n isDragging = false;\n isAiming = false;\n }\n });\n \n function updateUI() {\n document.getElementById('score').textContent = score;\n document.getElementById('birds').textContent = birdsLeft;\n }\n \n function drawSlingshot() {\n // Draw slingshot base\n ctx.fillStyle = '#8B4513';\n ctx.fillRect(slingshot.x - 10, slingshot.y, 20, 50);\n \n // Draw slingshot arms\n ctx.strokeStyle = '#654321';\n ctx.lineWidth = 8;\n ctx.beginPath();\n ctx.moveTo(slingshot.x - 8, slingshot.y);\n ctx.lineTo(slingshot.x - 15, slingshot.y - 40);\n ctx.moveTo(slingshot.x + 8, slingshot.y);\n ctx.lineTo(slingshot.x + 15, slingshot.y - 40);\n ctx.stroke();\n \n // Draw rubber band if aiming\n if (isAiming && currentBird) {\n ctx.strokeStyle = '#8B4513';\n ctx.lineWidth = 3;\n ctx.beginPath();\n ctx.moveTo(slingshot.x - 15, slingshot.y - 40);\n ctx.lineTo(mouseX, mouseY);\n ctx.lineTo(slingshot.x + 15, slingshot.y - 40);\n ctx.stroke();\n \n // Update bird position while aiming\n currentBird.x = mouseX;\n currentBird.y = mouseY;\n }\n }\n \n function drawGround() {\n ctx.fillStyle = '#8B4513';\n ctx.fillRect(0, canvas.height - 50, canvas.width, 50);\n \n // Draw grass\n ctx.fillStyle = '#228B22';\n for (let i = 0; i < canvas.width; i += 20) {\n ctx.fillRect(i, canvas.height - 55, 15, 10);\n }\n }\n \n function checkWinCondition() {\n const pigsLeft = gameObjects.filter(obj => obj instanceof Pig && !obj.destroyed).length;\n if (pigsLeft === 0) {\n ctx.fillStyle = 'rgba(0, 0, 0, 0.7)';\n ctx.fillRect(0, 0, canvas.width, canvas.height);\n ctx.fillStyle = 'white';\n ctx.font = '48px Arial';\n ctx.textAlign = 'center';\n ctx.fillText('YOU WIN!', canvas.width / 2, canvas.height / 2);\n ctx.font = '24px Arial';\n ctx.fillText('Final Score: ' + score, canvas.width / 2, canvas.height / 2 + 50);\n } else if (birdsLeft === 0 && !currentBird) {\n ctx.fillStyle = 'rgba(0, 0, 0, 0.7)';\n ctx.fillRect(0, 0, canvas.width, canvas.height);\n ctx.fillStyle = 'white';\n ctx.font = '48px Arial';\n ctx.textAlign = 'center';\n ctx.fillText('GAME OVER', canvas.width / 2, canvas.height / 2);\n ctx.font = '24px Arial';\n ctx.fillText('Final Score: ' + score, canvas.width / 2, canvas.height / 2 + 50);\n }\n }\n \n function gameLoop() {\n // Clear canvas\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n \n // Draw background elements\n drawGround();\n drawSlingshot();\n \n // Update and draw game objects\n gameObjects.forEach(obj => {\n obj.update();\n obj.draw();\n });\n \n // Draw current bird if aiming\n if (currentBird && !currentBird.launched) {\n currentBird.draw();\n }\n \n checkWinCondition();\n \n requestAnimationFrame(gameLoop);\n }\n \n // Initialize and start game\n initGame();\n updateUI();\n gameLoop();\n </script>\n</body>\n</html>",
"role": "assistant",
"thinking": "I need to create a complete Angry Birds game step by step. Let me think through this systematically:\n\n1. First, I need to plan the game structure:\n - HTML structure with canvas for the game\n - CSS for styling and layout\n - JavaScript for game logic\n\n2. Core game components I need:\n - Bird class with physics (velocity, gravity, collision)\n - Pig class as targets\n - Block class for obstacles\n - Slingshot mechanics for aiming and launching\n - Scoring system\n - Win/lose conditions\n\n3. Game mechanics to implement:\n - Mouse interaction for aiming and launching\n - Physics simulation with gravity and friction\n - Collision detection between birds, pigs, and blocks\n - Trail effect for bird movement\n - Game state management\n\n4. Visual elements:\n - Colorful background with sky and ground\n - Animated bird with eyes and beak\n - Green pigs with faces\n - Brown wooden blocks\n - Slingshot with rubber band visualization\n\n5. User interface:\n - Score display\n - Birds remaining counter\n - Instructions for the player\n - Win/lose screen\n\nLet me implement this step by step, creating a fully functional game with proper physics, graphics, and user interaction."
}
] |
No dataset card yet
- Downloads last month
- 15