Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Eldoria's Legacy: The Quest for Food</title>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/3.55.2/phaser.min.js"></script>
- <style>
- body {
- margin: 0;
- padding: 0;
- display: flex;
- justify-content: center;
- align-items: center;
- min-height: 100vh;
- background: #000;
- font-family: Arial, sans-serif;
- color: white;
- }
- #game-container {
- position: relative;
- width: 800px;
- height: 600px;
- }
- #welcome-screen,
- #story-panel,
- #dialog-panel,
- #response-panel,
- #trade-panel,
- #store-panel,
- #inventory-panel {
- position: absolute;
- left: 50%;
- transform: translateX(-50%);
- width: 80%;
- background: rgba(0, 0, 0, 0.8);
- padding: 20px;
- border-radius: 10px;
- box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
- text-align: center;
- color: white;
- }
- #buttons {
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- button {
- background: #4CAF50;
- color: white;
- border: none;
- padding: 10px 15px;
- margin: 5px 0;
- border-radius: 6px;
- cursor: pointer;
- font-size: 16px;
- transition: background 0.3s;
- width: 80%;
- }
- button:hover {
- background: #45a049;
- }
- input {
- padding: 8px;
- margin: 5px 0;
- border: 2px solid #4CAF50;
- border-radius: 4px;
- width: 80%;
- font-size: 16px;
- background: rgba(255, 255, 255, 0.9);
- color: #000;
- }
- #stats-panel {
- position: absolute;
- top: 10px;
- left: 10px;
- background: rgba(0, 0, 0, 0.9);
- padding: 10px;
- border-radius: 10px;
- border: 1px solid #4CAF50;
- min-width: 150px;
- }
- .item {
- display: flex;
- align-items: center;
- margin: 5px 0;
- }
- .item img {
- width: 30px;
- height: 30px;
- margin-right: 10px;
- }
- </style>
- </head>
- <body>
- <audio id="bg-music" loop>
- <source src="https://www.bensound.com/bensound-music/bensound-ukulele.mp3" type="audio/mpeg">
- </audio>
- <div id="game-container"></div>
- <script>
- const config = {
- type: Phaser.AUTO,
- width: 800,
- height: 600,
- physics: {
- default: 'arcade',
- arcade: { gravity: { y: 0 }, debug: false },
- },
- scene: {
- preload: preload,
- create: create,
- update: update,
- }
- };
- const game = new Phaser.Game(config);
- let player;
- let fruitGroup;
- let trees;
- let currentTreeIndex = 0;
- let background;
- let currentChapter = 0;
- let collectedFruits = 0;
- let moneyEarned = 0;
- let experience = 0;
- const bgMusic = document.getElementById('bg-music');
- let playerHealth = 100; // Player's health
- let creatureHealth = 50; // Creature's health
- const dialogues = [
- { pattern: /trade/i, response: "What do you want to trade? I can exchange 1 fruit for a special item.", type: "trade" },
- { pattern: /give food/i, response: "Yum! More food means more adventures!", type: "bland" },
- { pattern: /help/i, response: "I'll help if you've got the fruits!", type: "bland" },
- { pattern: /threat/i, response: "Threat? Only if you refuse to share!", type: "fight" },
- { pattern: /need food/i, response: "Food? Let’s whip up a meal!", type: "bland" },
- { pattern: /share/i, response: "Sharing is caring! What do you have?", type: "bland" },
- { pattern: /fight/i, response: "Fight? Only if it's a fruit brawl!", type: "fight" },
- { pattern: /hungry/i, response: "I could eat a thousand fruits!", type: "bland" },
- { pattern: /friend/i, response: "I love friends! Let’s hunt together!", type: "bland" },
- { pattern: /join/i, response: "Join? Only if you promise fruits!", type: "trade" },
- { pattern: /banana/i, response: "I'm a big fan of bananas, let's find some!", type: "bland" },
- { pattern: /yes/i, response: "Great! Fruits await us!", type: "bland" },
- { pattern: /no/i, response: "No? That’s a surprising answer!", type: "bland" },
- { pattern: /food fight/i, response: "Count me in! Let's make a mess!", type: "fight" },
- { pattern: /tell me a joke/i, response: "Why was the fruit so good at chess? It made all the right moves!", type: "bland" },
- { pattern: /how are you/i, response: "Feeling berry good!", type: "bland" }
- ];
- let story = [
- { title: "Need for Survival", description: "In the land of Eldoria, resources are scarce. Your journey to gather fruits begins!" },
- { title: "The First Encounter", description: "You meet a hungry traveler. Will you help each other out?" },
- { title: "Conflict Arises", description: "The traveler demands some of your fruits; a skirmish for food begins." },
- { title: "Unexpected Allies", description: "You find a group of monkeys willing to trade! What do they want?" },
- { title: "The Magical Grove", description: "You stumble upon a grove said to be enchanted. What could that mean for your quest?" },
- { title: "Bargaining", description: "You encounter a merchant creature. Can you bargain for some special fruits?" },
- { title: "Battling for Fruits", description: "Some creatures just want to fight for your fruits! Be prepared for a tussle!" },
- { title: "The Legendary Fruit", description: "Rumors speak of a fruit that can make its eater feel amazing. Will you find it?" },
- { title: "The Great Exchange", description: "You discover a marketplace. Trade your excess fruits for treasures!" },
- { title: "Return of the Rival", description: "Your rival appears. Will they join your journey or cause trouble?" },
- { title: "The Feast", description: "Celebrate with the fruits you’ve gathered. Invite locals to share!" },
- { title: "The Last Stand", description: "A powerful creature threatens your new friends. Gather your strength!" },
- { title: "A Mysterious Island", description: "You come across an island filled with exotic fruits and creatures." },
- { title: "The Berry Challenge", description: "A berry-loving creature challenges you to find the rarest fruits." },
- { title: "A Tale of Two Creatures", description: "Two creatures dispute about who owns a hidden stash of fruits." },
- { title: "Whispers of the Wind", description: "The wind carries tales of a hidden fruit treasure awaiting discovery." },
- { title: "The Old Sage", description: "An old sage offers wisdom for the price of a fruit." },
- { title: "Dancing with Spirits", description: "Spirits of the grove dance, granting you a glimpse of forgotten fruits." },
- { title: "Grapple with Goblins", description: "Goblins challenge you; can you outsmart them to gain their stash?" },
- { title: "The Bountiful Harvest", description: "A season of plenty begins! How many fruits can you gather?" },
- { title: "Secrets of the Forest", description: "Deep within the woods, secrets of fruit magic await!" },
- { title: "The Fruit Festival", description: "Join the fruit festival with various games and challenges!" },
- { title: "Rivalry Renewed", description: "Your old rival has returned, but this time, they want to team up!" },
- { title: "The Great Awakening", description: "Your efforts pay off. What will you do next?" }
- ];
- let inventory = []; // Array to hold items added to the inventory
- function preload() {
- this.load.image('background', 'https://play.rosebud.ai/assets/night_02.png?OjjR'); // Background Image
- this.load.image('player', 'https://play.rosebud.ai/assets/red.png?jqlr'); // Player sprite (red apple)
- this.load.image('fruit', 'https://play.rosebud.ai/assets/apple_without_Shadow.png?Lzp9'); // Apple Image
- this.load.image('tree', 'https://pngimg.com/uploads/43740.png'); // Tree Image
- bgMusic.play(); // Start playing background music
- }
- function create() {
- background = this.add.image(400, 300, 'background').setDisplaySize(800, 600);
- player = this.physics.add.sprite(100, 500, 'player').setScale(0.3).setCollideWorldBounds(true);
- fruitGroup = this.physics.add.group();
- // Create trees group
- trees = this.physics.add.group({
- key: 'tree',
- repeat: 4,
- setXY: { x: 150, y: 450, stepX: 150 }
- });
- trees.children.iterate(function (tree) {
- tree.setScale(0.15).setOrigin(0.5, 1);
- });
- // Spawn fruits
- this.time.addEvent({
- delay: 3000,
- callback: spawnFruit,
- callbackScope: this,
- loop: true
- });
- // Add overlap detection for collecting fruit
- this.physics.add.overlap(player, fruitGroup, collectFruit, null, this);
- // Add input listener for jumping to the next tree
- this.input.on('pointerdown', jumpToNextTree, this);
- // Create buttons
- createButtons();
- updateStats();
- showWelcomeScreen();
- }
- function update() {
- // Update game mechanics
- }
- function createButtons() {
- const buttonPanel = document.createElement('div');
- buttonPanel.id = 'buttons';
- const resetButton = document.createElement('button');
- resetButton.innerHTML = "Reset Chapters";
- resetButton.onclick = resetChapters;
- buttonPanel.appendChild(resetButton);
- const saveButton = document.createElement('button');
- saveButton.innerHTML = "Save Progress";
- saveButton.onclick = saveProgress;
- buttonPanel.appendChild(saveButton);
- const eatFruitButton = document.createElement('button');
- eatFruitButton.innerHTML = "Eat Fruit";
- eatFruitButton.onclick = eatFruitButtonHandler;
- buttonPanel.appendChild(eatFruitButton);
- const amazonStoreButton = document.createElement('button');
- amazonStoreButton.innerHTML = "Visit Amazon Store";
- amazonStoreButton.onclick = showAmazonStore; // Function to show Amazon Store
- buttonPanel.appendChild(amazonStoreButton);
- const inventoryButton = document.createElement('button');
- inventoryButton.innerHTML = "Open Inventory";
- inventoryButton.onclick = showInventory; // Function to show inventory
- buttonPanel.appendChild(inventoryButton);
- document.getElementById('game-container').appendChild(buttonPanel);
- }
- function spawnFruit() {
- const fruit = fruitGroup.create(Phaser.Math.Between(50, 750), Phaser.Math.Between(50, 550), 'fruit');
- fruit.setScale(0.1);
- }
- function collectFruit(player, fruit) {
- fruit.destroy(); // Remove the fruit from the game
- collectedFruits++; // Increment the fruit count
- updateStats(); // Update stats display
- alert(`You collected a fruit! Total fruits now: ${collectedFruits}`);
- }
- function eatFruit() {
- if (collectedFruits > 0) {
- collectedFruits--;
- let healthRestored = 10; // Amount of health restored
- let experienceGained = 5; // Experience gained from eating fruit
- let moneyGained = 1; // Money gained from eating fruit
- playerHealth += healthRestored;
- experience += experienceGained;
- moneyEarned += moneyGained;
- // Ensure health does not exceed maximum value
- if (playerHealth > 100) {
- playerHealth = 100;
- }
- updateStats(); // Update stats display
- alert(`You ate a fruit! You restored ${healthRestored} HP and gained ${experienceGained} experience, as well as $${moneyGained}. Total fruits left: ${collectedFruits}`);
- } else {
- alert("You don't have any fruits to eat!");
- }
- }
- function eatFruitButtonHandler() {
- eatFruit();
- }
- function jumpToNextTree() {
- if (currentTreeIndex < trees.getLength()) {
- const targetTree = trees.getChildren()[currentTreeIndex];
- player.setPosition(targetTree.x, targetTree.y - (targetTree.height * 0.15));
- currentTreeIndex++;
- if (currentTreeIndex >= trees.getLength()) {
- currentTreeIndex = 0; // Reset to the first tree after the last
- }
- }
- }
- function showWelcomeScreen() {
- const welcomePanel = document.createElement('div');
- welcomePanel.id = 'welcome-screen';
- welcomePanel.innerHTML = `
- <h1>Welcome to Eldoria's Legacy</h1>
- <input type="text" id="playerName" placeholder="Enter your name..." />
- <button id="start-button" onclick="createCharacter()">Start Game</button>
- `;
- document.getElementById('game-container').appendChild(welcomePanel);
- }
- function createCharacter() {
- const nameInput = document.getElementById('playerName').value;
- if (nameInput.trim()) {
- document.getElementById('welcome-screen').remove();
- updateStats();
- showStory();
- } else {
- alert('Please enter a name to start the adventure.');
- }
- }
- function showStory() {
- const currentChapterInfo = story[currentChapter];
- const storyPanel = document.createElement('div');
- storyPanel.id = 'story-panel';
- storyPanel.innerHTML = `
- <h2>${currentChapterInfo.title}</h2>
- <p>${currentChapterInfo.description}</p>
- <button onclick="nextChapter()">Continue Story</button>
- <button onclick="tradeAtChapter()">Trade Fruits</button>
- <button onclick="createDialogPanel()">Talk to a Creature</button>
- `;
- document.getElementById('game-container').appendChild(storyPanel);
- }
- function nextChapter() {
- if (currentChapter < story.length - 1) {
- currentChapter++;
- document.getElementById('story-panel').remove();
- showStory();
- } else {
- alert("You've completed all chapters! Thank you for playing!");
- resetGame();
- }
- }
- function tradeAtChapter() {
- const tradePanel = document.getElementById('trade-panel') || document.createElement('div');
- tradePanel.id = 'trade-panel';
- tradePanel.innerHTML = `
- <h2>Trade Fruits</h2>
- <p>You have ${collectedFruits} fruits. How many would you like to trade?</p>
- <input type="number" id="trade-input" min="1" max="${collectedFruits}" value="1" />
- <button onclick="executeTrade()">Trade</button>
- <button onclick="closeTradePanel()">Cancel</button>
- `;
- document.getElementById('game-container').appendChild(tradePanel);
- }
- function closeTradePanel() {
- const tradePanel = document.getElementById('trade-panel');
- if (tradePanel) {
- tradePanel.remove();
- }
- }
- function executeTrade() {
- const tradeAmount = parseInt(document.getElementById('trade-input').value);
- if (tradeAmount > collectedFruits) {
- alert("You don't have enough fruits to trade!");
- return;
- }
- collectedFruits -= tradeAmount;
- moneyEarned += tradeAmount; // Earn money equal to amount traded
- experience += tradeAmount; // Earn experience equal to amount traded
- const itemDescription = `Traded ${tradeAmount} fruit(s)`; // Description of the item
- const itemImage = 'https://play.rosebud.ai/assets/apple_without_Shadow.png?Lzp9'; // Image link for inventory item
- inventory.push({ description: itemDescription, image: itemImage }); // Add to inventory
- alert(`You traded ${tradeAmount} fruits for a special item! You now have ${collectedFruits} fruits left.`);
- updateStats();
- closeTradePanel();
- }
- function updateStats() {
- const statsPanel = document.getElementById('stats-panel') || document.createElement('div');
- statsPanel.id = 'stats-panel';
- statsPanel.innerHTML = `
- <div><strong>Collected Fruits:</strong> ${collectedFruits}</div>
- <div><strong>Money Earned:</strong> ${moneyEarned}</div>
- <div><strong>Experience:</strong> ${experience}</div>
- <div><strong>Player Health:</strong> ${playerHealth}</div>
- <div><strong>Creature Health:</strong> ${creatureHealth}</div>
- `;
- if (!document.getElementById('stats-panel')) {
- document.getElementById('game-container').appendChild(statsPanel);
- }
- }
- function resetGame() {
- currentChapter = 0;
- collectedFruits = 0;
- moneyEarned = 0;
- experience = 0;
- playerHealth = 100; // Reset player's health
- creatureHealth = 50; // Reset creature's health
- inventory = []; // Reset inventory
- document.getElementById('stats-panel')?.remove();
- document.getElementById('story-panel')?.remove();
- document.getElementById('inventory-panel')?.remove(); // Close inventory if open
- showWelcomeScreen();
- }
- function resetChapters() {
- const confirmation = confirm("Are you sure you want to reset all chapters?");
- if (confirmation) {
- resetGame();
- alert("All chapters have been reset.");
- }
- }
- function saveProgress() {
- const progress = {
- collectedFruits: collectedFruits,
- moneyEarned: moneyEarned,
- experience: experience,
- currentChapter: currentChapter,
- playerHealth: playerHealth,
- creatureHealth: creatureHealth,
- inventory: inventory // Save the inventory too
- };
- const progressString = JSON.stringify(progress, null, 4);
- const blob = new Blob([progressString], { type: 'application/javascript' });
- const link = document.createElement('a');
- link.href = URL.createObjectURL(blob);
- link.download = 'eldoria_progress.js';
- link.click();
- URL.revokeObjectURL(link.href); // Clean up the URL object
- alert("Progress saved!");
- }
- function createDialogPanel() {
- const dialogPanel = document.createElement('div');
- dialogPanel.id = 'dialog-panel';
- dialogPanel.innerHTML = `
- <h2>Dialog with Creatures</h2>
- <input type="text" id="dialog-input" placeholder="Type your message here..." />
- <button onclick="sendDialog()">Send</button>
- <button onclick="closeDialog()">Close Dialog</button>
- <button onclick="attackCreature()">Attack!</button>
- <div id="response-panel"></div>
- <div id="trade-panel" style="display: none;"></div>
- `;
- document.getElementById('game-container').appendChild(dialogPanel);
- }
- function closeDialog() {
- document.getElementById('dialog-panel').remove();
- }
- function getRandomResponse(input) {
- const matchedResponses = dialogues.filter(resp => resp.pattern.test(input));
- if (matchedResponses.length === 0) {
- return { response: "What a great day to talk about fruits and adventures!", type: "bland" };
- }
- return matchedResponses[Math.floor(Math.random() * matchedResponses.length)];
- }
- function sendDialog() {
- const input = document.getElementById('dialog-input').value.trim();
- const responsePanel = document.getElementById('response-panel');
- if (input === "") {
- responsePanel.innerText = "Please type something before sending.";
- return;
- }
- const randomResponse = getRandomResponse(input);
- responsePanel.innerText = randomResponse.response;
- if (randomResponse.type === "fight") {
- attackCreature(); // Call attack creature if it's a fight type response
- } else if (randomResponse.type === "trade") {
- tradeAtChapter(); // Open the trade panel
- }
- document.getElementById('dialog-input').value = ''; // Clear input field
- }
- function attackCreature() {
- const responsePanel = document.getElementById('response-panel');
- // Simulate player attacking creature
- if (creatureHealth > 0) {
- // Player deals damage
- creatureHealth -= 20; // Player deals 20 damage
- responsePanel.innerText = `You attacked the creature! The creature now has ${creatureHealth} HP left.`;
- // Check if creature is still alive
- if (creatureHealth <= 0) {
- responsePanel.innerHTML += "<br>You defeated the creature!";
- // Reset health for next encounter
- creatureHealth = 50; // Reset creature's health after defeat
- updateStats();
- closeDialog();
- nextChapter();
- } else {
- // If the creature is still alive, it counterattacks
- playerHealth -= 10; // Creature deals 10 damage
- if (playerHealth <= 0) {
- responsePanel.innerHTML += "<br>You have been defeated! Game over.";
- closeDialog();
- resetGame(); // Reset game after defeat
- } else {
- responsePanel.innerHTML += `<br>The creature attacked back! You have ${playerHealth} HP left.`;
- }
- }
- } else {
- responsePanel.innerText = "The creature is already defeated!";
- }
- updateStats(); // Update health stats
- }
- // Show Amazon Store Functionality
- function showAmazonStore() {
- const storePanel = document.createElement('div');
- storePanel.id = 'store-panel';
- storePanel.innerHTML = `
- <h2>Amazon Store</h2>
- <p>You have $${moneyEarned}.</p>
- <input type="number" id="withdraw-amount" min="1" max="${moneyEarned}" value="1" />
- <button onclick="withdrawMoney()">Withdraw Money</button>
- <button onclick="closeAmazonStore()">Close Store</button>
- `;
- document.getElementById('game-container').appendChild(storePanel);
- }
- function withdrawMoney() {
- const withdrawAmount = parseInt(document.getElementById('withdraw-amount').value);
- if (withdrawAmount > moneyEarned) {
- alert("You don't have enough money to withdraw that amount!");
- return;
- }
- if (withdrawAmount <= 0) {
- alert("Please enter a valid amount to withdraw.");
- return;
- }
- moneyEarned -= withdrawAmount;
- // This is where we simulate adding an item to the inventory as a 'purchase'
- const itemDescription = `Purchased ${withdrawAmount} item(s)`; // Description of the item
- const itemImage = 'https://play.rosebud.ai/assets/apple_without_Shadow.png?Lzp9'; // Image link for inventory item
- inventory.push({ description: itemDescription, image: itemImage }); // Add to inventory
- alert(`You have successfully withdrawn $${withdrawAmount}! Your remaining balance is $${moneyEarned}.`);
- updateStats(); // Update stats panel after withdrawal
- closeAmazonStore();
- }
- function closeAmazonStore() {
- const storePanel = document.getElementById('store-panel');
- if (storePanel) {
- storePanel.remove();
- }
- }
- // Show inventory
- function showInventory() {
- // Create an inventory panel
- const inventoryPanel = document.createElement('div');
- inventoryPanel.id = 'inventory-panel';
- inventoryPanel.innerHTML = `<h2>Your Inventory</h2>`;
- // Display each item in the inventory
- inventory.forEach(item => {
- inventoryPanel.innerHTML += `
- <div class="item">
- <img src="${item.image}" alt="Item Image"/>
- <span>${item.description}</span>
- </div>
- `;
- });
- // Close button for inventory
- inventoryPanel.innerHTML += `<button onclick="closeInventory()">Close Inventory</button>`;
- document.getElementById('game-container').appendChild(inventoryPanel);
- }
- function closeInventory() {
- const inventoryPanel = document.getElementById('inventory-panel');
- if (inventoryPanel) {
- inventoryPanel.remove();
- }
- }
- </script>
- </body>
- </html>
Advertisement