Code edit (1 edits merged)
Please save this source code
User prompt
Fruitsies TV Show: Character Collection Adventure
Initial prompt
Fruitsies TV Show The Game With Cast(Milly The Strawberry Monkey Joy The Green Apple Dog(You Need 1 Level To Unlock) Simone The Grape Frog(You Need 2 Level To Unlock) Jane The Banana Cat(Coming Soon...) And Plex The Passion Fruit Tiger(Coming Soon...) And 5 House(Strawberry House & Green Apple House & Grape House & Sale Sign Comic Soon... Is: Banana House & Sale Sign Comic Soon... Is: Passion Fruit House) And 4 Buildings(Food Shop & Cloths Shop & Hospital(Coming Soon...) & Gardens(Coming Soon...) Cilck 5 Houses To See The 5 Rooms Like(Strawberry Room & Green Apple Room & Grape Room & Banana Room(Coming Soon..) & Passion Fruit Room(Coming Soon...)
/**** * Plugins ****/ var storage = LK.import("@upit/storage.v1", { level: 0, unlockedCharacters: ["milly"] }); /**** * Classes ****/ var Building = Container.expand(function (buildingType, isAvailable) { var self = Container.call(this); var buildingGraphic = self.attachAsset(buildingType, { anchorX: 0.5, anchorY: 0.5 }); self.buildingType = buildingType; self.isAvailable = isAvailable; if (!self.isAvailable) { buildingGraphic.alpha = 0.5; } // Add building label var labelText = buildingType === 'foodShop' ? 'Food Shop' : buildingType === 'clothesShop' ? 'Clothes Shop' : buildingType === 'hospital' ? 'Hospital' : 'Gardens'; self.label = new Text2(labelText, { size: 35, fill: 0xFFFFFF }); self.label.anchor.set(0.5, 0.5); self.label.y = 20; self.addChild(self.label); if (!self.isAvailable) { self.comingSoonText = new Text2('Coming Soon', { size: 25, fill: 0xFFFF00 }); self.comingSoonText.anchor.set(0.5, 0.5); self.comingSoonText.y = 50; self.addChild(self.comingSoonText); } self.down = function (x, y, obj) { if (self.isAvailable) { LK.getSound('click').play(); showBuildingContent(self.buildingType); } }; return self; }); var Character = Container.expand(function (characterType) { var self = Container.call(this); var characterGraphic = self.attachAsset(characterType + 'Character', { anchorX: 0.5, anchorY: 0.5 }); self.characterType = characterType; self.isUnlocked = storage.unlockedCharacters.indexOf(characterType) !== -1; if (!self.isUnlocked) { characterGraphic.alpha = 0.3; } self.down = function (x, y, obj) { if (self.isUnlocked) { LK.getSound('click').play(); showCharacterDetail(self.characterType); } }; return self; }); var House = Container.expand(function (houseType, isAvailable) { var self = Container.call(this); var houseGraphic = self.attachAsset(houseType + 'House', { anchorX: 0.5, anchorY: 0.5 }); self.houseType = houseType; self.isAvailable = isAvailable; if (!self.isAvailable) { houseGraphic.alpha = 0.5; } // Add house label self.label = new Text2(houseType.charAt(0).toUpperCase() + houseType.slice(1), { size: 40, fill: 0xFFFFFF }); self.label.anchor.set(0.5, 0.5); self.label.y = 20; self.addChild(self.label); if (!self.isAvailable) { self.comingSoonText = new Text2('Coming Soon', { size: 30, fill: 0xFFFF00 }); self.comingSoonText.anchor.set(0.5, 0.5); self.comingSoonText.y = 60; self.addChild(self.comingSoonText); } self.down = function (x, y, obj) { if (self.isAvailable) { LK.getSound('click').play(); showHouseRooms(self.houseType); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ // UI elements // Room asset // Building assets // House assets // Character assets // Game state variables var currentScreen = 'main'; var characters = []; var houses = []; var buildings = []; // UI elements var levelText; var backButton; // Initialize level and character unlocking function checkUnlocks() { var currentLevel = storage.level; var unlockedChars = storage.unlockedCharacters.slice(); if (currentLevel >= 1 && unlockedChars.indexOf('joy') === -1) { unlockedChars.push('joy'); LK.getSound('unlock').play(); } if (currentLevel >= 2 && unlockedChars.indexOf('simone') === -1) { unlockedChars.push('simone'); LK.getSound('unlock').play(); } storage.unlockedCharacters = unlockedChars; } // Create main menu screen function createMainScreen() { clearScreen(); currentScreen = 'main'; // Level display levelText = new Text2('Level ' + storage.level, { size: 60, fill: 0xFFFFFF }); levelText.anchor.set(0.5, 0); LK.gui.top.addChild(levelText); levelText.y = 150; // Title var titleText = new Text2('Fruitsies TV Show', { size: 80, fill: 0xFF1493 }); titleText.anchor.set(0.5, 0.5); titleText.x = 1024; titleText.y = 300; game.addChild(titleText); // Create characters section var charSectionTitle = new Text2('Characters', { size: 50, fill: 0xFFFFFF }); charSectionTitle.anchor.set(0.5, 0.5); charSectionTitle.x = 1024; charSectionTitle.y = 450; game.addChild(charSectionTitle); // Add characters var milly = new Character('milly'); milly.x = 700; milly.y = 550; game.addChild(milly); characters.push(milly); var joy = new Character('joy'); joy.x = 1024; joy.y = 550; game.addChild(joy); characters.push(joy); var simone = new Character('simone'); simone.x = 1348; simone.y = 550; game.addChild(simone); characters.push(simone); // Create houses section var houseSectionTitle = new Text2('Houses', { size: 50, fill: 0xFFFFFF }); houseSectionTitle.anchor.set(0.5, 0.5); houseSectionTitle.x = 1024; houseSectionTitle.y = 750; game.addChild(houseSectionTitle); // Add houses var strawberryHouse = new House('strawberry', true); strawberryHouse.x = 400; strawberryHouse.y = 950; game.addChild(strawberryHouse); houses.push(strawberryHouse); var greenAppleHouse = new House('greenApple', true); greenAppleHouse.x = 750; greenAppleHouse.y = 950; game.addChild(greenAppleHouse); houses.push(greenAppleHouse); var grapeHouse = new House('grape', true); grapeHouse.x = 1100; grapeHouse.y = 950; game.addChild(grapeHouse); houses.push(grapeHouse); var bananaHouse = new House('banana', false); bananaHouse.x = 1450; bananaHouse.y = 950; game.addChild(bananaHouse); houses.push(bananaHouse); var passionFruitHouse = new House('passionFruit', false); passionFruitHouse.x = 1024; passionFruitHouse.y = 1200; game.addChild(passionFruitHouse); houses.push(passionFruitHouse); // Create buildings section var buildingSectionTitle = new Text2('Buildings', { size: 50, fill: 0xFFFFFF }); buildingSectionTitle.anchor.set(0.5, 0.5); buildingSectionTitle.x = 1024; buildingSectionTitle.y = 1450; game.addChild(buildingSectionTitle); // Add buildings var foodShop = new Building('foodShop', true); foodShop.x = 500; foodShop.y = 1600; game.addChild(foodShop); buildings.push(foodShop); var clothesShop = new Building('clothesShop', true); clothesShop.x = 900; clothesShop.y = 1600; game.addChild(clothesShop); buildings.push(clothesShop); var hospital = new Building('hospital', false); hospital.x = 1300; hospital.y = 1600; game.addChild(hospital); buildings.push(hospital); var gardens = new Building('gardens', false); gardens.x = 1024; gardens.y = 1800; game.addChild(gardens); buildings.push(gardens); // Level up button (for testing) var levelUpButton = new Text2('Level Up!', { size: 40, fill: 0x00FF00 }); levelUpButton.anchor.set(0.5, 0.5); levelUpButton.x = 1024; levelUpButton.y = 2000; game.addChild(levelUpButton); levelUpButton.down = function (x, y, obj) { storage.level++; checkUnlocks(); createMainScreen(); }; } // Show character detail screen function showCharacterDetail(characterType) { clearScreen(); currentScreen = 'character'; var characterNames = { 'milly': 'Milly The Strawberry Monkey', 'joy': 'Joy The Green Apple Dog', 'simone': 'Simone The Grape Frog' }; var characterName = new Text2(characterNames[characterType], { size: 60, fill: 0xFFFFFF }); characterName.anchor.set(0.5, 0.5); characterName.x = 1024; characterName.y = 400; game.addChild(characterName); var character = new Character(characterType); character.x = 1024; character.y = 600; game.addChild(character); createBackButton(); } // Show house rooms function showHouseRooms(houseType) { clearScreen(); currentScreen = 'house'; var houseTitle = new Text2(houseType.charAt(0).toUpperCase() + houseType.slice(1) + ' House', { size: 60, fill: 0xFFFFFF }); houseTitle.anchor.set(0.5, 0.5); houseTitle.x = 1024; houseTitle.y = 300; game.addChild(houseTitle); // Character room var characterRoom = LK.getAsset('characterRoom', { anchorX: 0.5, anchorY: 0.5 }); characterRoom.x = 1024; characterRoom.y = 800; game.addChild(characterRoom); var roomText = new Text2('Character Room', { size: 40, fill: 0x000000 }); roomText.anchor.set(0.5, 0.5); roomText.x = 1024; roomText.y = 800; game.addChild(roomText); characterRoom.down = function (x, y, obj) { LK.getSound('click').play(); // Show room contents would go here }; createBackButton(); } // Show building content function showBuildingContent(buildingType) { clearScreen(); currentScreen = 'building'; var buildingNames = { 'foodShop': 'Food Shop', 'clothesShop': 'Clothes Shop' }; var buildingTitle = new Text2(buildingNames[buildingType], { size: 60, fill: 0xFFFFFF }); buildingTitle.anchor.set(0.5, 0.5); buildingTitle.x = 1024; buildingTitle.y = 400; game.addChild(buildingTitle); var contentText = new Text2('Welcome to the ' + buildingNames[buildingType] + '!', { size: 40, fill: 0xFFFFFF }); contentText.anchor.set(0.5, 0.5); contentText.x = 1024; contentText.y = 600; game.addChild(contentText); createBackButton(); } // Create back button function createBackButton() { backButton = LK.getAsset('backButton', { anchorX: 0.5, anchorY: 0.5 }); backButton.x = 200; backButton.y = 200; game.addChild(backButton); var backText = new Text2('Back', { size: 30, fill: 0xFFFFFF }); backText.anchor.set(0.5, 0.5); backText.x = 200; backText.y = 200; game.addChild(backText); backButton.down = function (x, y, obj) { LK.getSound('click').play(); createMainScreen(); }; } // Clear screen function clearScreen() { // Remove all children from game while (game.children.length > 0) { var child = game.children[0]; child.destroy(); } // Clear GUI while (LK.gui.top.children.length > 0) { var guiChild = LK.gui.top.children[0]; guiChild.destroy(); } // Reset arrays characters = []; houses = []; buildings = []; } // Initialize game checkUnlocks(); createMainScreen();
/****
* Plugins
****/
var storage = LK.import("@upit/storage.v1", {
level: 0,
unlockedCharacters: ["milly"]
});
/****
* Classes
****/
var Building = Container.expand(function (buildingType, isAvailable) {
var self = Container.call(this);
var buildingGraphic = self.attachAsset(buildingType, {
anchorX: 0.5,
anchorY: 0.5
});
self.buildingType = buildingType;
self.isAvailable = isAvailable;
if (!self.isAvailable) {
buildingGraphic.alpha = 0.5;
}
// Add building label
var labelText = buildingType === 'foodShop' ? 'Food Shop' : buildingType === 'clothesShop' ? 'Clothes Shop' : buildingType === 'hospital' ? 'Hospital' : 'Gardens';
self.label = new Text2(labelText, {
size: 35,
fill: 0xFFFFFF
});
self.label.anchor.set(0.5, 0.5);
self.label.y = 20;
self.addChild(self.label);
if (!self.isAvailable) {
self.comingSoonText = new Text2('Coming Soon', {
size: 25,
fill: 0xFFFF00
});
self.comingSoonText.anchor.set(0.5, 0.5);
self.comingSoonText.y = 50;
self.addChild(self.comingSoonText);
}
self.down = function (x, y, obj) {
if (self.isAvailable) {
LK.getSound('click').play();
showBuildingContent(self.buildingType);
}
};
return self;
});
var Character = Container.expand(function (characterType) {
var self = Container.call(this);
var characterGraphic = self.attachAsset(characterType + 'Character', {
anchorX: 0.5,
anchorY: 0.5
});
self.characterType = characterType;
self.isUnlocked = storage.unlockedCharacters.indexOf(characterType) !== -1;
if (!self.isUnlocked) {
characterGraphic.alpha = 0.3;
}
self.down = function (x, y, obj) {
if (self.isUnlocked) {
LK.getSound('click').play();
showCharacterDetail(self.characterType);
}
};
return self;
});
var House = Container.expand(function (houseType, isAvailable) {
var self = Container.call(this);
var houseGraphic = self.attachAsset(houseType + 'House', {
anchorX: 0.5,
anchorY: 0.5
});
self.houseType = houseType;
self.isAvailable = isAvailable;
if (!self.isAvailable) {
houseGraphic.alpha = 0.5;
}
// Add house label
self.label = new Text2(houseType.charAt(0).toUpperCase() + houseType.slice(1), {
size: 40,
fill: 0xFFFFFF
});
self.label.anchor.set(0.5, 0.5);
self.label.y = 20;
self.addChild(self.label);
if (!self.isAvailable) {
self.comingSoonText = new Text2('Coming Soon', {
size: 30,
fill: 0xFFFF00
});
self.comingSoonText.anchor.set(0.5, 0.5);
self.comingSoonText.y = 60;
self.addChild(self.comingSoonText);
}
self.down = function (x, y, obj) {
if (self.isAvailable) {
LK.getSound('click').play();
showHouseRooms(self.houseType);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// UI elements
// Room asset
// Building assets
// House assets
// Character assets
// Game state variables
var currentScreen = 'main';
var characters = [];
var houses = [];
var buildings = [];
// UI elements
var levelText;
var backButton;
// Initialize level and character unlocking
function checkUnlocks() {
var currentLevel = storage.level;
var unlockedChars = storage.unlockedCharacters.slice();
if (currentLevel >= 1 && unlockedChars.indexOf('joy') === -1) {
unlockedChars.push('joy');
LK.getSound('unlock').play();
}
if (currentLevel >= 2 && unlockedChars.indexOf('simone') === -1) {
unlockedChars.push('simone');
LK.getSound('unlock').play();
}
storage.unlockedCharacters = unlockedChars;
}
// Create main menu screen
function createMainScreen() {
clearScreen();
currentScreen = 'main';
// Level display
levelText = new Text2('Level ' + storage.level, {
size: 60,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
levelText.y = 150;
// Title
var titleText = new Text2('Fruitsies TV Show', {
size: 80,
fill: 0xFF1493
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 300;
game.addChild(titleText);
// Create characters section
var charSectionTitle = new Text2('Characters', {
size: 50,
fill: 0xFFFFFF
});
charSectionTitle.anchor.set(0.5, 0.5);
charSectionTitle.x = 1024;
charSectionTitle.y = 450;
game.addChild(charSectionTitle);
// Add characters
var milly = new Character('milly');
milly.x = 700;
milly.y = 550;
game.addChild(milly);
characters.push(milly);
var joy = new Character('joy');
joy.x = 1024;
joy.y = 550;
game.addChild(joy);
characters.push(joy);
var simone = new Character('simone');
simone.x = 1348;
simone.y = 550;
game.addChild(simone);
characters.push(simone);
// Create houses section
var houseSectionTitle = new Text2('Houses', {
size: 50,
fill: 0xFFFFFF
});
houseSectionTitle.anchor.set(0.5, 0.5);
houseSectionTitle.x = 1024;
houseSectionTitle.y = 750;
game.addChild(houseSectionTitle);
// Add houses
var strawberryHouse = new House('strawberry', true);
strawberryHouse.x = 400;
strawberryHouse.y = 950;
game.addChild(strawberryHouse);
houses.push(strawberryHouse);
var greenAppleHouse = new House('greenApple', true);
greenAppleHouse.x = 750;
greenAppleHouse.y = 950;
game.addChild(greenAppleHouse);
houses.push(greenAppleHouse);
var grapeHouse = new House('grape', true);
grapeHouse.x = 1100;
grapeHouse.y = 950;
game.addChild(grapeHouse);
houses.push(grapeHouse);
var bananaHouse = new House('banana', false);
bananaHouse.x = 1450;
bananaHouse.y = 950;
game.addChild(bananaHouse);
houses.push(bananaHouse);
var passionFruitHouse = new House('passionFruit', false);
passionFruitHouse.x = 1024;
passionFruitHouse.y = 1200;
game.addChild(passionFruitHouse);
houses.push(passionFruitHouse);
// Create buildings section
var buildingSectionTitle = new Text2('Buildings', {
size: 50,
fill: 0xFFFFFF
});
buildingSectionTitle.anchor.set(0.5, 0.5);
buildingSectionTitle.x = 1024;
buildingSectionTitle.y = 1450;
game.addChild(buildingSectionTitle);
// Add buildings
var foodShop = new Building('foodShop', true);
foodShop.x = 500;
foodShop.y = 1600;
game.addChild(foodShop);
buildings.push(foodShop);
var clothesShop = new Building('clothesShop', true);
clothesShop.x = 900;
clothesShop.y = 1600;
game.addChild(clothesShop);
buildings.push(clothesShop);
var hospital = new Building('hospital', false);
hospital.x = 1300;
hospital.y = 1600;
game.addChild(hospital);
buildings.push(hospital);
var gardens = new Building('gardens', false);
gardens.x = 1024;
gardens.y = 1800;
game.addChild(gardens);
buildings.push(gardens);
// Level up button (for testing)
var levelUpButton = new Text2('Level Up!', {
size: 40,
fill: 0x00FF00
});
levelUpButton.anchor.set(0.5, 0.5);
levelUpButton.x = 1024;
levelUpButton.y = 2000;
game.addChild(levelUpButton);
levelUpButton.down = function (x, y, obj) {
storage.level++;
checkUnlocks();
createMainScreen();
};
}
// Show character detail screen
function showCharacterDetail(characterType) {
clearScreen();
currentScreen = 'character';
var characterNames = {
'milly': 'Milly The Strawberry Monkey',
'joy': 'Joy The Green Apple Dog',
'simone': 'Simone The Grape Frog'
};
var characterName = new Text2(characterNames[characterType], {
size: 60,
fill: 0xFFFFFF
});
characterName.anchor.set(0.5, 0.5);
characterName.x = 1024;
characterName.y = 400;
game.addChild(characterName);
var character = new Character(characterType);
character.x = 1024;
character.y = 600;
game.addChild(character);
createBackButton();
}
// Show house rooms
function showHouseRooms(houseType) {
clearScreen();
currentScreen = 'house';
var houseTitle = new Text2(houseType.charAt(0).toUpperCase() + houseType.slice(1) + ' House', {
size: 60,
fill: 0xFFFFFF
});
houseTitle.anchor.set(0.5, 0.5);
houseTitle.x = 1024;
houseTitle.y = 300;
game.addChild(houseTitle);
// Character room
var characterRoom = LK.getAsset('characterRoom', {
anchorX: 0.5,
anchorY: 0.5
});
characterRoom.x = 1024;
characterRoom.y = 800;
game.addChild(characterRoom);
var roomText = new Text2('Character Room', {
size: 40,
fill: 0x000000
});
roomText.anchor.set(0.5, 0.5);
roomText.x = 1024;
roomText.y = 800;
game.addChild(roomText);
characterRoom.down = function (x, y, obj) {
LK.getSound('click').play();
// Show room contents would go here
};
createBackButton();
}
// Show building content
function showBuildingContent(buildingType) {
clearScreen();
currentScreen = 'building';
var buildingNames = {
'foodShop': 'Food Shop',
'clothesShop': 'Clothes Shop'
};
var buildingTitle = new Text2(buildingNames[buildingType], {
size: 60,
fill: 0xFFFFFF
});
buildingTitle.anchor.set(0.5, 0.5);
buildingTitle.x = 1024;
buildingTitle.y = 400;
game.addChild(buildingTitle);
var contentText = new Text2('Welcome to the ' + buildingNames[buildingType] + '!', {
size: 40,
fill: 0xFFFFFF
});
contentText.anchor.set(0.5, 0.5);
contentText.x = 1024;
contentText.y = 600;
game.addChild(contentText);
createBackButton();
}
// Create back button
function createBackButton() {
backButton = LK.getAsset('backButton', {
anchorX: 0.5,
anchorY: 0.5
});
backButton.x = 200;
backButton.y = 200;
game.addChild(backButton);
var backText = new Text2('Back', {
size: 30,
fill: 0xFFFFFF
});
backText.anchor.set(0.5, 0.5);
backText.x = 200;
backText.y = 200;
game.addChild(backText);
backButton.down = function (x, y, obj) {
LK.getSound('click').play();
createMainScreen();
};
}
// Clear screen
function clearScreen() {
// Remove all children from game
while (game.children.length > 0) {
var child = game.children[0];
child.destroy();
}
// Clear GUI
while (LK.gui.top.children.length > 0) {
var guiChild = LK.gui.top.children[0];
guiChild.destroy();
}
// Reset arrays
characters = [];
houses = [];
buildings = [];
}
// Initialize game
checkUnlocks();
createMainScreen();