User prompt
Let's name the game a desert adventure
User prompt
It didn't work, when you change the language, the level selection part is written in both languages and they are intertwined.
User prompt
And finally, when you change the language, the animations and texts in the main menu are intertwined and it is not nice.
User prompt
When the language is changed, the text in the main menu remains, if you fix them too
User prompt
and add language option to the game either English or Turkish
User prompt
and at the beginning of each section write "enter the door if it doesn't go left"
User prompt
and if he enters the door before all the treasures are collected, restart the level
User prompt
There is a small problem, it does not go left when you go a little further.
User prompt
doesnt jump it
User prompt
Ok, let's try something else. If we press up, the jump button will be removed. In other words, the longer we press on half of the screen, the more it will jump. There will be no left or right movement at the top of the screen.
User prompt
and there is a jump button in the middle, when you press it, he jumps, the more he presses it, the higher he jumps
User prompt
When you press the stop button, it will say main menu so we can go to the main menu from there
User prompt
If they can't get all the treasures, the level won't be completed. There should also be a main menu, play there and have levels, reach the completed levels in the levels, and when you press on the character, he/she will jump and the character will be happy when the game is over. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
do a 10 level and levels are hard
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'toGlobal')' in or related to this line: 'var localPos = game.toLocal(obj.parent.toGlobal(obj.position));' Line Number: 1392
Code edit (1 edits merged)
Please save this source code
User prompt
Mario's Treasure Quest
Initial prompt
ı do a like uncharted 3 but mario stile 5 different level in the game
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Enemy = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 1.0
});
self.velocityX = -2;
self.velocityY = 0;
self.direction = -1;
self.defeated = false;
self.update = function () {
if (!self.defeated) {
// Apply gravity
self.velocityY += 1.2;
// Move horizontally
self.x += self.velocityX;
self.y += self.velocityY;
// Reset velocity Y when on ground (simplified)
if (self.y >= 2732 - 160) {
self.y = 2732 - 160;
self.velocityY = 0;
}
}
};
self.defeat = function () {
if (!self.defeated) {
self.defeated = true;
self.visible = false;
LK.setScore(LK.getScore() + 50);
LK.getSound('defeat').play();
updateUI();
}
};
self.reverseDirection = function () {
self.velocityX *= -1;
self.direction *= -1;
};
return self;
});
var Goal = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('goal', {
anchorX: 0.5,
anchorY: 1.0
});
self.reached = false;
return self;
});
var Ground = Container.expand(function (width) {
var self = Container.call(this);
var graphics = self.attachAsset('ground', {
anchorX: 0,
anchorY: 0,
width: width || 200,
height: 80
});
self.groundWidth = width || 200;
self.groundHeight = 80;
return self;
});
var Platform = Container.expand(function (width, height) {
var self = Container.call(this);
var graphics = self.attachAsset('platform', {
anchorX: 0,
anchorY: 0,
width: width || 200,
height: height || 40
});
self.platformWidth = width || 200;
self.platformHeight = height || 40;
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
self.velocityX = 0;
self.velocityY = 0;
self.speed = 8;
self.jumpPower = 25;
self.onGround = false;
self.facingRight = true;
self.invulnerable = false;
self.powerUpTimer = 0;
self.happyAnimationTimer = 0;
// Happy jump animation when touched
self.down = function (x, y, obj) {
if (gameState === 'menu') {
// Happy animation
self.happyAnimationTimer = 60; // 1 second at 60fps
tween(self, {
scaleX: 1.8,
scaleY: 1.8
}, {
duration: 200,
easing: tween.bounceOut
});
tween(graphics, {
rotation: 0.5
}, {
duration: 300,
easing: tween.elasticOut,
onFinish: function onFinish() {
tween(graphics, {
rotation: 0
}, {
duration: 300,
easing: tween.elasticOut
});
}
});
// Jump effect
if (self.onGround) {
self.velocityY = -self.jumpPower * 1.5;
self.onGround = false;
}
// Scale back to normal
LK.setTimeout(function () {
tween(self, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200,
easing: tween.bounceOut
});
}, 400);
}
};
self.update = function () {
// Apply gravity
self.velocityY += 1.2;
// Update position
self.x += self.velocityX;
self.y += self.velocityY;
// Handle power-up timer
if (self.powerUpTimer > 0) {
self.powerUpTimer--;
if (self.powerUpTimer <= 0) {
self.invulnerable = false;
graphics.tint = 0xffffff;
}
}
// Reset ground state
self.onGround = false;
// Apply friction
self.velocityX *= 0.85;
};
self.jump = function () {
if (self.onGround) {
self.velocityY = -self.jumpPower;
self.onGround = false;
LK.getSound('jump').play();
}
};
self.moveLeft = function () {
self.velocityX = -self.speed;
if (self.facingRight) {
self.facingRight = false;
graphics.scaleX = -1;
}
};
self.moveRight = function () {
self.velocityX = self.speed;
if (!self.facingRight) {
self.facingRight = true;
graphics.scaleX = 1;
}
};
self.landOnGround = function () {
self.onGround = true;
self.velocityY = 0;
};
self.collectTreasure = function () {
treasuresCollected++;
LK.setScore(LK.getScore() + 100);
LK.getSound('collect').play();
updateUI();
};
self.collectPowerUp = function () {
self.invulnerable = true;
self.powerUpTimer = 300; // 5 seconds at 60fps
graphics.tint = 0xffff00;
LK.getSound('powerup').play();
};
return self;
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('powerup', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.pulseOffset = 0;
self.update = function () {
if (!self.collected) {
self.pulseOffset += 0.15;
graphics.scaleX = 1 + Math.sin(self.pulseOffset) * 0.2;
graphics.scaleY = 1 + Math.sin(self.pulseOffset) * 0.2;
}
};
self.collect = function () {
if (!self.collected) {
self.collected = true;
self.visible = false;
return true;
}
return false;
};
return self;
});
var Treasure = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('treasure', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.bobOffset = 0;
self.update = function () {
if (!self.collected) {
self.bobOffset += 0.2;
self.y += Math.sin(self.bobOffset) * 0.5;
graphics.rotation += 0.05;
}
};
self.collect = function () {
if (!self.collected) {
self.collected = true;
self.visible = false;
return true;
}
return false;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game state variables
var currentLevel = storage.currentLevel || 1;
var maxLevel = storage.maxLevel || 1;
var treasuresCollected = 0;
var totalTreasures = 0;
var levelCompleted = false;
var gameState = 'menu'; // 'menu', 'playing', 'completed'
var gameCamera = {
x: 0,
y: 0
};
// Menu variables
var menuButtons = [];
var menuTitle;
var playButton;
var levelSelectButtons = [];
// Game objects
var player;
var platforms = [];
var grounds = [];
var treasures = [];
var enemies = [];
var powerUps = [];
var goal;
// UI elements
var scoreText;
var levelText;
var treasureText;
var instructionText;
// Level themes and colors
var levelThemes = {
1: {
name: "Desert Ruins",
bg: 0xDEB887,
groundColor: 0xD2691E
},
2: {
name: "Underground Caverns",
bg: 0x2F4F4F,
groundColor: 0x696969
},
3: {
name: "Jungle Temple",
bg: 0x228B22,
groundColor: 0x8B4513
},
4: {
name: "Icy Mountains",
bg: 0x4682B4,
groundColor: 0xE6E6FA
},
5: {
name: "Volcano Depths",
bg: 0x8B0000,
groundColor: 0x800000
},
6: {
name: "Sky Palace",
bg: 0x87CEEB,
groundColor: 0x4169E1
},
7: {
name: "Haunted Forest",
bg: 0x2F2F2F,
groundColor: 0x654321
},
8: {
name: "Crystal Caves",
bg: 0x4B0082,
groundColor: 0x9370DB
},
9: {
name: "Lava Temple",
bg: 0xFF4500,
groundColor: 0x8B0000
},
10: {
name: "Final Castle",
bg: 0x1C1C1C,
groundColor: 0x000000
}
};
// Input handling
var keys = {
left: false,
right: false,
jump: false
};
function initializeUI() {
// Clear any existing UI
if (scoreText) scoreText.destroy();
if (levelText) levelText.destroy();
if (treasureText) treasureText.destroy();
if (instructionText) instructionText.destroy();
scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
scoreText.x = 120;
scoreText.y = 20;
LK.gui.topLeft.addChild(scoreText);
levelText = new Text2('Level 1', {
size: 60,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
treasureText = new Text2('Treasures: 0/0', {
size: 60,
fill: 0xFFFFFF
});
treasureText.anchor.set(1, 0);
treasureText.x = -20;
treasureText.y = 20;
LK.gui.topRight.addChild(treasureText);
instructionText = new Text2('Collect ALL treasures to complete level!\nTap to move and jump!', {
size: 60,
fill: 0xFFFF00
});
instructionText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(instructionText);
// Hide instruction after 4 seconds
LK.setTimeout(function () {
if (instructionText) instructionText.visible = false;
}, 4000);
}
function updateUI() {
scoreText.setText('Score: ' + LK.getScore());
levelText.setText('Level ' + currentLevel + ': ' + levelThemes[currentLevel].name);
treasureText.setText('Treasures: ' + treasuresCollected + '/' + totalTreasures);
}
function createLevel(levelNum) {
// Clear existing objects
clearLevel();
// Set theme
var theme = levelThemes[levelNum];
game.setBackgroundColor(theme.bg);
// Create player
player = game.addChild(new Player());
player.x = 200;
player.y = 2732 - 200;
// Create level-specific layout
if (levelNum === 1) {
createDesertLevel();
} else if (levelNum === 2) {
createCaveLevel();
} else if (levelNum === 3) {
createJungleLevel();
} else if (levelNum === 4) {
createMountainLevel();
} else if (levelNum === 5) {
createVolcanoLevel();
} else if (levelNum === 6) {
createSkyLevel();
} else if (levelNum === 7) {
createHauntedLevel();
} else if (levelNum === 8) {
createCrystalLevel();
} else if (levelNum === 9) {
createLavaLevel();
} else if (levelNum === 10) {
createFinalCastleLevel();
}
// Create goal at the end
goal = game.addChild(new Goal());
goal.x = 4500;
goal.y = 2732 - 80;
// Reset level state
treasuresCollected = 0;
levelCompleted = false;
gameCamera.x = 0;
updateUI();
}
function createDesertLevel() {
// Ground segments
for (var i = 0; i < 25; i++) {
var ground = game.addChild(new Ground(200));
ground.x = i * 200;
ground.y = 2732 - 80;
grounds.push(ground);
}
// Platforms
var platformData = [{
x: 400,
y: 2400,
w: 200,
h: 40
}, {
x: 800,
y: 2200,
w: 150,
h: 40
}, {
x: 1200,
y: 2000,
w: 200,
h: 40
}, {
x: 1600,
y: 2300,
w: 180,
h: 40
}, {
x: 2000,
y: 2100,
w: 200,
h: 40
}, {
x: 2500,
y: 2400,
w: 150,
h: 40
}, {
x: 2900,
y: 2200,
w: 200,
h: 40
}, {
x: 3400,
y: 2000,
w: 180,
h: 40
}, {
x: 3800,
y: 2300,
w: 200,
h: 40
}, {
x: 4200,
y: 2100,
w: 150,
h: 40
}];
for (var i = 0; i < platformData.length; i++) {
var p = platformData[i];
var platform = game.addChild(new Platform(p.w, p.h));
platform.x = p.x;
platform.y = p.y;
platforms.push(platform);
}
// Treasures
var treasurePositions = [{
x: 500,
y: 2350
}, {
x: 900,
y: 2150
}, {
x: 1300,
y: 1950
}, {
x: 1700,
y: 2250
}, {
x: 2100,
y: 2050
}, {
x: 2600,
y: 2350
}, {
x: 3000,
y: 2150
}, {
x: 3500,
y: 1950
}, {
x: 3900,
y: 2250
}];
for (var i = 0; i < treasurePositions.length; i++) {
var t = treasurePositions[i];
var treasure = game.addChild(new Treasure());
treasure.x = t.x;
treasure.y = t.y;
treasures.push(treasure);
}
// Enemies
var enemyPositions = [{
x: 1000,
y: 2732 - 160
}, {
x: 1800,
y: 2732 - 160
}, {
x: 2700,
y: 2732 - 160
}, {
x: 3600,
y: 2732 - 160
}];
for (var i = 0; i < enemyPositions.length; i++) {
var e = enemyPositions[i];
var enemy = game.addChild(new Enemy());
enemy.x = e.x;
enemy.y = e.y;
enemies.push(enemy);
}
// Power-ups
var powerUp = game.addChild(new PowerUp());
powerUp.x = 1500;
powerUp.y = 1950;
powerUps.push(powerUp);
totalTreasures = treasures.length;
}
function createCaveLevel() {
// Similar structure but different layout for cave theme
for (var i = 0; i < 25; i++) {
var ground = game.addChild(new Ground(200));
ground.x = i * 200;
ground.y = 2732 - 80;
grounds.push(ground);
}
// More complex platforming for cave level
var platformData = [{
x: 300,
y: 2500,
w: 150,
h: 40
}, {
x: 600,
y: 2300,
w: 120,
h: 40
}, {
x: 900,
y: 2100,
w: 150,
h: 40
}, {
x: 1300,
y: 2400,
w: 180,
h: 40
}, {
x: 1700,
y: 2200,
w: 150,
h: 40
}, {
x: 2100,
y: 2000,
w: 200,
h: 40
}, {
x: 2600,
y: 2300,
w: 150,
h: 40
}, {
x: 3000,
y: 2100,
w: 180,
h: 40
}, {
x: 3500,
y: 2400,
w: 150,
h: 40
}, {
x: 3900,
y: 2200,
w: 200,
h: 40
}, {
x: 4300,
y: 2000,
w: 150,
h: 40
}];
for (var i = 0; i < platformData.length; i++) {
var p = platformData[i];
var platform = game.addChild(new Platform(p.w, p.h));
platform.x = p.x;
platform.y = p.y;
platforms.push(platform);
}
// More treasures in cave
var treasurePositions = [{
x: 400,
y: 2450
}, {
x: 700,
y: 2250
}, {
x: 1000,
y: 2050
}, {
x: 1400,
y: 2350
}, {
x: 1800,
y: 2150
}, {
x: 2200,
y: 1950
}, {
x: 2700,
y: 2250
}, {
x: 3100,
y: 2050
}, {
x: 3600,
y: 2350
}, {
x: 4000,
y: 2150
}, {
x: 4400,
y: 1950
}];
for (var i = 0; i < treasurePositions.length; i++) {
var t = treasurePositions[i];
var treasure = game.addChild(new Treasure());
treasure.x = t.x;
treasure.y = t.y;
treasures.push(treasure);
}
// More enemies in cave
var enemyPositions = [{
x: 800,
y: 2732 - 160
}, {
x: 1500,
y: 2732 - 160
}, {
x: 2300,
y: 2732 - 160
}, {
x: 3200,
y: 2732 - 160
}, {
x: 4100,
y: 2732 - 160
}];
for (var i = 0; i < enemyPositions.length; i++) {
var e = enemyPositions[i];
var enemy = game.addChild(new Enemy());
enemy.x = e.x;
enemy.y = e.y;
enemies.push(enemy);
}
// Multiple power-ups
var powerUpPositions = [{
x: 1200,
y: 2050
}, {
x: 2800,
y: 2050
}];
for (var i = 0; i < powerUpPositions.length; i++) {
var p = powerUpPositions[i];
var powerUp = game.addChild(new PowerUp());
powerUp.x = p.x;
powerUp.y = p.y;
powerUps.push(powerUp);
}
totalTreasures = treasures.length;
}
function createJungleLevel() {
// Ground with gaps for jungle
var groundSegments = [{
x: 0,
w: 400
}, {
x: 600,
w: 300
}, {
x: 1100,
w: 250
}, {
x: 1500,
w: 400
}, {
x: 2100,
w: 300
}, {
x: 2600,
w: 400
}, {
x: 3200,
w: 300
}, {
x: 3700,
w: 400
}, {
x: 4300,
w: 500
}];
for (var i = 0; i < groundSegments.length; i++) {
var seg = groundSegments[i];
var ground = game.addChild(new Ground(seg.w));
ground.x = seg.x;
ground.y = 2732 - 80;
grounds.push(ground);
}
// Vine-like platforms for jungle
var platformData = [{
x: 450,
y: 2400,
w: 100,
h: 40
}, {
x: 750,
y: 2300,
w: 120,
h: 40
}, {
x: 950,
y: 2500,
w: 100,
h: 40
}, {
x: 1350,
y: 2200,
w: 100,
h: 40
}, {
x: 1650,
y: 2400,
w: 120,
h: 40
}, {
x: 1950,
y: 2100,
w: 100,
h: 40
}, {
x: 2450,
y: 2300,
w: 100,
h: 40
}, {
x: 2850,
y: 2500,
w: 120,
h: 40
}, {
x: 3050,
y: 2200,
w: 100,
h: 40
}, {
x: 3550,
y: 2400,
w: 120,
h: 40
}, {
x: 3950,
y: 2100,
w: 100,
h: 40
}];
for (var i = 0; i < platformData.length; i++) {
var p = platformData[i];
var platform = game.addChild(new Platform(p.w, p.h));
platform.x = p.x;
platform.y = p.y;
platforms.push(platform);
}
// Hidden treasures in jungle
var treasurePositions = [{
x: 500,
y: 2350
}, {
x: 800,
y: 2250
}, {
x: 1000,
y: 2450
}, {
x: 1400,
y: 2150
}, {
x: 1700,
y: 2350
}, {
x: 2000,
y: 2050
}, {
x: 2500,
y: 2250
}, {
x: 2900,
y: 2450
}, {
x: 3100,
y: 2150
}, {
x: 3600,
y: 2350
}, {
x: 4000,
y: 2050
}, {
x: 4500,
y: 2600
}];
for (var i = 0; i < treasurePositions.length; i++) {
var t = treasurePositions[i];
var treasure = game.addChild(new Treasure());
treasure.x = t.x;
treasure.y = t.y;
treasures.push(treasure);
}
// Jungle enemies
var enemyPositions = [{
x: 700,
y: 2732 - 160
}, {
x: 1200,
y: 2732 - 160
}, {
x: 1800,
y: 2732 - 160
}, {
x: 2800,
y: 2732 - 160
}, {
x: 3800,
y: 2732 - 160
}];
for (var i = 0; i < enemyPositions.length; i++) {
var e = enemyPositions[i];
var enemy = game.addChild(new Enemy());
enemy.x = e.x;
enemy.y = e.y;
enemies.push(enemy);
}
// Power-ups
var powerUpPositions = [{
x: 1350,
y: 2150
}, {
x: 2900,
y: 2150
}, {
x: 3550,
y: 2150
}];
for (var i = 0; i < powerUpPositions.length; i++) {
var p = powerUpPositions[i];
var powerUp = game.addChild(new PowerUp());
powerUp.x = p.x;
powerUp.y = p.y;
powerUps.push(powerUp);
}
totalTreasures = treasures.length;
}
function createMountainLevel() {
// Icy platforms at different heights
for (var i = 0; i < 20; i++) {
var ground = game.addChild(new Ground(250));
ground.x = i * 250;
ground.y = 2732 - 80;
grounds.push(ground);
}
// Mountain-like ascending platforms
var platformData = [{
x: 300,
y: 2500,
w: 150,
h: 40
}, {
x: 600,
y: 2350,
w: 140,
h: 40
}, {
x: 900,
y: 2200,
w: 150,
h: 40
}, {
x: 1250,
y: 2050,
w: 140,
h: 40
}, {
x: 1600,
y: 1900,
w: 150,
h: 40
}, {
x: 1950,
y: 2000,
w: 140,
h: 40
}, {
x: 2300,
y: 2150,
w: 150,
h: 40
}, {
x: 2650,
y: 2000,
w: 140,
h: 40
}, {
x: 3000,
y: 1850,
w: 150,
h: 40
}, {
x: 3350,
y: 2000,
w: 140,
h: 40
}, {
x: 3700,
y: 2150,
w: 150,
h: 40
}, {
x: 4050,
y: 2000,
w: 140,
h: 40
}];
for (var i = 0; i < platformData.length; i++) {
var p = platformData[i];
var platform = game.addChild(new Platform(p.w, p.h));
platform.x = p.x;
platform.y = p.y;
platforms.push(platform);
}
// Mountain treasures
var treasurePositions = [{
x: 375,
y: 2450
}, {
x: 670,
y: 2300
}, {
x: 975,
y: 2150
}, {
x: 1320,
y: 2000
}, {
x: 1675,
y: 1850
}, {
x: 2020,
y: 1950
}, {
x: 2375,
y: 2100
}, {
x: 2720,
y: 1950
}, {
x: 3075,
y: 1800
}, {
x: 3420,
y: 1950
}, {
x: 3775,
y: 2100
}, {
x: 4120,
y: 1950
}, {
x: 4400,
y: 2600
}];
for (var i = 0; i < treasurePositions.length; i++) {
var t = treasurePositions[i];
var treasure = game.addChild(new Treasure());
treasure.x = t.x;
treasure.y = t.y;
treasures.push(treasure);
}
// Mountain enemies
var enemyPositions = [{
x: 500,
y: 2732 - 160
}, {
x: 1100,
y: 2732 - 160
}, {
x: 1700,
y: 2732 - 160
}, {
x: 2400,
y: 2732 - 160
}, {
x: 3100,
y: 2732 - 160
}, {
x: 3800,
y: 2732 - 160
}];
for (var i = 0; i < enemyPositions.length; i++) {
var e = enemyPositions[i];
var enemy = game.addChild(new Enemy());
enemy.x = e.x;
enemy.y = e.y;
enemies.push(enemy);
}
// Power-ups
var powerUpPositions = [{
x: 1320,
y: 1950
}, {
x: 2720,
y: 1900
}, {
x: 3775,
y: 1950
}];
for (var i = 0; i < powerUpPositions.length; i++) {
var p = powerUpPositions[i];
var powerUp = game.addChild(new PowerUp());
powerUp.x = p.x;
powerUp.y = p.y;
powerUps.push(powerUp);
}
totalTreasures = treasures.length;
}
function createCastleLevel() {
// Castle ground segments
for (var i = 0; i < 30; i++) {
var ground = game.addChild(new Ground(200));
ground.x = i * 200;
ground.y = 2732 - 80;
grounds.push(ground);
}
// Castle-like platform structure
var platformData = [{
x: 300,
y: 2400,
w: 200,
h: 40
}, {
x: 600,
y: 2200,
w: 150,
h: 40
}, {
x: 900,
y: 2000,
w: 180,
h: 40
}, {
x: 1200,
y: 1800,
w: 150,
h: 40
}, {
x: 1500,
y: 2300,
w: 200,
h: 40
}, {
x: 1800,
y: 2100,
w: 150,
h: 40
}, {
x: 2100,
y: 1900,
w: 180,
h: 40
}, {
x: 2400,
y: 2200,
w: 150,
h: 40
}, {
x: 2700,
y: 2000,
w: 200,
h: 40
}, {
x: 3000,
y: 1800,
w: 150,
h: 40
}, {
x: 3300,
y: 2100,
w: 180,
h: 40
}, {
x: 3600,
y: 1900,
w: 150,
h: 40
}, {
x: 3900,
y: 2200,
w: 200,
h: 40
}, {
x: 4200,
y: 2000,
w: 150,
h: 40
}, {
x: 4500,
y: 1800,
w: 180,
h: 40
}];
for (var i = 0; i < platformData.length; i++) {
var p = platformData[i];
var platform = game.addChild(new Platform(p.w, p.h));
platform.x = p.x;
platform.y = p.y;
platforms.push(platform);
}
// Final castle treasures
var treasurePositions = [{
x: 400,
y: 2350
}, {
x: 675,
y: 2150
}, {
x: 990,
y: 1950
}, {
x: 1275,
y: 1750
}, {
x: 1600,
y: 2250
}, {
x: 1875,
y: 2050
}, {
x: 2190,
y: 1850
}, {
x: 2475,
y: 2150
}, {
x: 2800,
y: 1950
}, {
x: 3075,
y: 1750
}, {
x: 3390,
y: 2050
}, {
x: 3675,
y: 1850
}, {
x: 4000,
y: 2150
}, {
x: 4275,
y: 1950
}, {
x: 4590,
y: 1750
}];
for (var i = 0; i < treasurePositions.length; i++) {
var t = treasurePositions[i];
var treasure = game.addChild(new Treasure());
treasure.x = t.x;
treasure.y = t.y;
treasures.push(treasure);
}
// Final castle enemies
var enemyPositions = [{
x: 800,
y: 2732 - 160
}, {
x: 1300,
y: 2732 - 160
}, {
x: 1900,
y: 2732 - 160
}, {
x: 2500,
y: 2732 - 160
}, {
x: 3100,
y: 2732 - 160
}, {
x: 3700,
y: 2732 - 160
}, {
x: 4300,
y: 2732 - 160
}];
for (var i = 0; i < enemyPositions.length; i++) {
var e = enemyPositions[i];
var enemy = game.addChild(new Enemy());
enemy.x = e.x;
enemy.y = e.y;
enemies.push(enemy);
}
// Multiple power-ups for final level
var powerUpPositions = [{
x: 1275,
y: 1700
}, {
x: 2190,
y: 1800
}, {
x: 3075,
y: 1700
}, {
x: 4275,
y: 1900
}];
for (var i = 0; i < powerUpPositions.length; i++) {
var p = powerUpPositions[i];
var powerUp = game.addChild(new PowerUp());
powerUp.x = p.x;
powerUp.y = p.y;
powerUps.push(powerUp);
}
totalTreasures = treasures.length;
}
function clearLevel() {
// Clear all game objects
for (var i = 0; i < platforms.length; i++) {
platforms[i].destroy();
}
platforms = [];
for (var i = 0; i < grounds.length; i++) {
grounds[i].destroy();
}
grounds = [];
for (var i = 0; i < treasures.length; i++) {
treasures[i].destroy();
}
treasures = [];
for (var i = 0; i < enemies.length; i++) {
enemies[i].destroy();
}
enemies = [];
for (var i = 0; i < powerUps.length; i++) {
powerUps[i].destroy();
}
powerUps = [];
if (goal) {
goal.destroy();
goal = null;
}
if (player) {
player.destroy();
player = null;
}
}
function checkCollisions() {
// Player vs ground collision
for (var i = 0; i < grounds.length; i++) {
var ground = grounds[i];
if (player.x + 40 > ground.x && player.x - 40 < ground.x + ground.groundWidth && player.y > ground.y - 10 && player.y < ground.y + ground.groundHeight + 10 && player.velocityY > 0) {
player.y = ground.y;
player.landOnGround();
}
}
// Player vs platform collision
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
if (player.x + 40 > platform.x && player.x - 40 < platform.x + platform.platformWidth && player.y > platform.y - 10 && player.y < platform.y + platform.platformHeight + 10 && player.velocityY > 0) {
player.y = platform.y;
player.landOnGround();
}
}
// Player vs treasure collision
for (var i = 0; i < treasures.length; i++) {
var treasure = treasures[i];
if (!treasure.collected && player.intersects(treasure)) {
if (treasure.collect()) {
player.collectTreasure();
}
}
}
// Player vs enemy collision
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
if (!enemy.defeated && player.intersects(enemy)) {
if (player.invulnerable) {
enemy.defeat();
} else {
// Player takes damage
LK.effects.flashScreen(0xff0000, 500);
player.x = 200; // Reset position
player.y = 2732 - 200;
player.velocityX = 0;
player.velocityY = 0;
}
}
}
// Player vs power-up collision
for (var i = 0; i < powerUps.length; i++) {
var powerUp = powerUps[i];
if (!powerUp.collected && player.intersects(powerUp)) {
if (powerUp.collect()) {
player.collectPowerUp();
}
}
}
// Player vs goal collision
if (goal && !goal.reached && player.intersects(goal)) {
goal.reached = true;
levelCompleted = true;
completeLevel();
}
// Enemy vs platform collision (simple AI)
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
if (!enemy.defeated) {
var onPlatform = false;
// Check if enemy is on ground
for (var j = 0; j < grounds.length; j++) {
var ground = grounds[j];
if (enemy.x + 30 > ground.x && enemy.x - 30 < ground.x + ground.groundWidth && enemy.y >= ground.y - 10 && enemy.y <= ground.y + 10) {
enemy.y = ground.y;
enemy.velocityY = 0;
onPlatform = true;
break;
}
}
// Check if enemy is on platform
if (!onPlatform) {
for (var j = 0; j < platforms.length; j++) {
var platform = platforms[j];
if (enemy.x + 30 > platform.x && enemy.x - 30 < platform.x + platform.platformWidth && enemy.y >= platform.y - 10 && enemy.y <= platform.y + 10) {
enemy.y = platform.y;
enemy.velocityY = 0;
onPlatform = true;
break;
}
}
}
// Reverse direction at edges
if (enemy.x <= 0 || enemy.x >= 5000) {
enemy.reverseDirection();
}
}
}
// Keep player in bounds
if (player.x < 0) player.x = 0;
if (player.x > 5000) player.x = 5000;
// Check if player falls off screen
if (player.y > 2732 + 200) {
player.x = 200;
player.y = 2732 - 200;
player.velocityX = 0;
player.velocityY = 0;
LK.effects.flashScreen(0xff0000, 500);
}
}
function updateCamera() {
// Follow player with camera
var targetX = -player.x + 1024; // Center player horizontally
gameCamera.x += (targetX - gameCamera.x) * 0.1; // Smooth camera movement
// Clamp camera
if (gameCamera.x > 0) gameCamera.x = 0;
if (gameCamera.x < -3500) gameCamera.x = -3500;
// Apply camera to game objects
game.x = gameCamera.x;
}
function completeLevel() {
// Check if all treasures are collected
if (treasuresCollected < totalTreasures) {
var warningText = new Text2('Collect all treasures\nto complete level!\n' + treasuresCollected + '/' + totalTreasures + ' collected', {
size: 80,
fill: 0xFFFF00
});
warningText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(warningText);
// Flash screen yellow
LK.effects.flashScreen(0xFFFF00, 1000);
// Remove warning after delay
LK.setTimeout(function () {
warningText.destroy();
}, 2000);
return; // Don't complete level
}
// All treasures collected - complete level
var completionBonus = 500;
var treasureBonus = treasuresCollected * 50;
var totalBonus = completionBonus + treasureBonus;
LK.setScore(LK.getScore() + totalBonus);
// Update storage
if (currentLevel >= maxLevel) {
maxLevel = currentLevel + 1;
storage.maxLevel = maxLevel;
}
// Show completion message
var completionText = new Text2('Level Complete!\nAll treasures collected!\nBonus: ' + totalBonus, {
size: 100,
fill: 0x00FF00
});
completionText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(completionText);
// Flash screen green
LK.effects.flashScreen(0x00ff00, 1000);
// Advance to next level after delay
LK.setTimeout(function () {
completionText.destroy();
if (currentLevel < 10) {
currentLevel++;
storage.currentLevel = currentLevel;
createLevel(currentLevel);
} else {
// Game completed - show happy animation
showGameCompleteAnimation();
}
}, 2000);
}
// Touch controls
game.down = function (x, y, obj) {
// Handle menu input
if (gameState === 'menu') {
handleMenuInput(x, y);
return;
}
// Game input
if (gameState === 'playing') {
// Use the x parameter directly as it's already in the correct coordinate space
if (x < 1024) {
keys.left = true;
} else {
keys.right = true;
}
// Jump on any touch
keys.jump = true;
}
};
game.up = function (x, y, obj) {
if (gameState === 'playing') {
keys.left = false;
keys.right = false;
keys.jump = false;
}
};
function createMainMenu() {
gameState = 'menu';
// Clear any existing level
clearLevel();
// Create menu title
menuTitle = new Text2("Mario's Treasure Quest", {
size: 120,
fill: 0xFFD700
});
menuTitle.anchor.set(0.5, 0.5);
menuTitle.x = 1024;
menuTitle.y = 400;
game.addChild(menuTitle);
// Create play button
playButton = new Text2('START GAME', {
size: 80,
fill: 0x00FF00
});
playButton.anchor.set(0.5, 0.5);
playButton.x = 1024;
playButton.y = 800;
game.addChild(playButton);
// Create level select title
var levelSelectTitle = new Text2('Select Level:', {
size: 60,
fill: 0xFFFFFF
});
levelSelectTitle.anchor.set(0.5, 0.5);
levelSelectTitle.x = 1024;
levelSelectTitle.y = 1000;
game.addChild(levelSelectTitle);
// Create level selection buttons
levelSelectButtons = [];
for (var i = 1; i <= 10; i++) {
var levelButton = new Text2(i.toString(), {
size: 60,
fill: i <= maxLevel ? 0x00FF00 : 0x888888
});
levelButton.anchor.set(0.5, 0.5);
levelButton.x = 300 + (i - 1) % 5 * 300;
levelButton.y = 1200 + Math.floor((i - 1) / 5) * 150;
levelButton.levelNumber = i;
levelButton.unlocked = i <= maxLevel;
game.addChild(levelButton);
levelSelectButtons.push(levelButton);
}
// Add animated character in menu
var menuCharacter = game.addChild(new Player());
menuCharacter.x = 1024;
menuCharacter.y = 600;
menuCharacter.scaleX = 1.5;
menuCharacter.scaleY = 1.5;
// Happy bounce animation
var bounceOffset = 0;
var menuCharacterUpdate = function menuCharacterUpdate() {
if (gameState === 'menu') {
bounceOffset += 0.1;
menuCharacter.y = 600 + Math.sin(bounceOffset) * 20;
}
};
LK.setInterval(menuCharacterUpdate, 16);
}
function handleMenuInput(x, y) {
if (gameState !== 'menu') return;
// Check play button
if (x > playButton.x - 150 && x < playButton.x + 150 && y > playButton.y - 50 && y < playButton.y + 50) {
startGame();
return;
}
// Check level buttons
for (var i = 0; i < levelSelectButtons.length; i++) {
var btn = levelSelectButtons[i];
if (btn.unlocked && x > btn.x - 50 && x < btn.x + 50 && y > btn.y - 50 && y < btn.y + 50) {
currentLevel = btn.levelNumber;
startGame();
return;
}
}
}
function startGame() {
gameState = 'playing';
// Clear menu
if (menuTitle) menuTitle.destroy();
if (playButton) playButton.destroy();
for (var i = 0; i < levelSelectButtons.length; i++) {
levelSelectButtons[i].destroy();
}
// Initialize UI and start game
initializeUI();
createLevel(currentLevel);
}
function showGameCompleteAnimation() {
gameState = 'completed';
// Create celebration character
var celebrationCharacter = game.addChild(new Player());
celebrationCharacter.x = 1024;
celebrationCharacter.y = 1300;
celebrationCharacter.scaleX = 2;
celebrationCharacter.scaleY = 2;
// Happy celebration animation
var celebrationOffset = 0;
var celebrationUpdate = function celebrationUpdate() {
if (gameState === 'completed') {
celebrationOffset += 0.15;
celebrationCharacter.y = 1300 + Math.sin(celebrationOffset) * 50;
celebrationCharacter.rotation = Math.sin(celebrationOffset * 2) * 0.3;
}
};
LK.setInterval(celebrationUpdate, 16);
// Add celebration text
var celebrationText = new Text2('CONGRATULATIONS!\nYou collected all treasures\nin all 10 levels!', {
size: 80,
fill: 0xFFD700
});
celebrationText.anchor.set(0.5, 0.5);
celebrationText.x = 1024;
celebrationText.y = 800;
game.addChild(celebrationText);
// Flash screen with rainbow colors
var rainbowColors = [0xFF0000, 0xFF8000, 0xFFFF00, 0x00FF00, 0x0080FF, 0x8000FF];
var colorIndex = 0;
LK.setInterval(function () {
if (gameState === 'completed') {
LK.effects.flashScreen(rainbowColors[colorIndex], 500);
colorIndex = (colorIndex + 1) % rainbowColors.length;
}
}, 600);
// Show final win after delay
LK.setTimeout(function () {
LK.showYouWin();
}, 5000);
}
// Initialize game with menu
createMainMenu();
LK.playMusic('bgmusic');
// Main game loop
game.update = function () {
// Only update game logic when playing
if (gameState !== 'playing' || levelCompleted) return;
// Handle input
if (keys.left) {
player.moveLeft();
}
if (keys.right) {
player.moveRight();
}
if (keys.jump) {
player.jump();
keys.jump = false; // Prevent continuous jumping
}
// Update all game objects
player.update();
for (var i = 0; i < treasures.length; i++) {
treasures[i].update();
}
for (var i = 0; i < enemies.length; i++) {
enemies[i].update();
}
for (var i = 0; i < powerUps.length; i++) {
powerUps[i].update();
}
// Check collisions
checkCollisions();
// Update camera
updateCamera();
// Check win condition (optional: complete level with all treasures)
if (treasuresCollected >= totalTreasures && goal && goal.reached) {
// Extra bonus for collecting all treasures
LK.setScore(LK.getScore() + 200);
updateUI();
}
};
function createVolcanoLevel() {
// Challenging volcanic platforms with gaps
var groundSegments = [{
x: 0,
w: 300
}, {
x: 500,
w: 250
}, {
x: 900,
w: 200
}, {
x: 1300,
w: 250
}, {
x: 1750,
w: 300
}, {
x: 2250,
w: 200
}, {
x: 2650,
w: 250
}, {
x: 3100,
w: 300
}, {
x: 3600,
w: 200
}, {
x: 4000,
w: 400
}];
for (var i = 0; i < groundSegments.length; i++) {
var seg = groundSegments[i];
var ground = game.addChild(new Ground(seg.w));
ground.x = seg.x;
ground.y = 2732 - 80;
grounds.push(ground);
}
// Floating lava platforms - more challenging spacing
var platformData = [{
x: 350,
y: 2300,
w: 100,
h: 40
}, {
x: 600,
y: 2150,
w: 80,
h: 40
}, {
x: 750,
y: 2400,
w: 100,
h: 40
}, {
x: 1000,
y: 2250,
w: 80,
h: 40
}, {
x: 1150,
y: 2100,
w: 100,
h: 40
}, {
x: 1400,
y: 2350,
w: 80,
h: 40
}, {
x: 1600,
y: 2200,
w: 100,
h: 40
}, {
x: 1900,
y: 2100,
w: 80,
h: 40
}, {
x: 2100,
y: 2350,
w: 100,
h: 40
}, {
x: 2350,
y: 2200,
w: 80,
h: 40
}, {
x: 2500,
y: 2050,
w: 100,
h: 40
}, {
x: 2750,
y: 2300,
w: 80,
h: 40
}, {
x: 2950,
y: 2150,
w: 100,
h: 40
}, {
x: 3250,
y: 2400,
w: 80,
h: 40
}, {
x: 3450,
y: 2250,
w: 100,
h: 40
}, {
x: 3750,
y: 2100,
w: 80,
h: 40
}];
for (var i = 0; i < platformData.length; i++) {
var p = platformData[i];
var platform = game.addChild(new Platform(p.w, p.h));
platform.x = p.x;
platform.y = p.y;
platforms.push(platform);
}
// More treasures requiring precision
var treasurePositions = [{
x: 400,
y: 2250
}, {
x: 650,
y: 2100
}, {
x: 800,
y: 2350
}, {
x: 1050,
y: 2200
}, {
x: 1200,
y: 2050
}, {
x: 1450,
y: 2300
}, {
x: 1650,
y: 2150
}, {
x: 1950,
y: 2050
}, {
x: 2150,
y: 2300
}, {
x: 2400,
y: 2150
}, {
x: 2550,
y: 2000
}, {
x: 2800,
y: 2250
}, {
x: 3000,
y: 2100
}, {
x: 3300,
y: 2350
}, {
x: 3500,
y: 2200
}, {
x: 3800,
y: 2050
}, {
x: 4300,
y: 2600
}];
for (var i = 0; i < treasurePositions.length; i++) {
var t = treasurePositions[i];
var treasure = game.addChild(new Treasure());
treasure.x = t.x;
treasure.y = t.y;
treasures.push(treasure);
}
// More aggressive enemies
var enemyPositions = [{
x: 400,
y: 2732 - 160
}, {
x: 800,
y: 2732 - 160
}, {
x: 1200,
y: 2732 - 160
}, {
x: 1600,
y: 2732 - 160
}, {
x: 2000,
y: 2732 - 160
}, {
x: 2400,
y: 2732 - 160
}, {
x: 2800,
y: 2732 - 160
}, {
x: 3200,
y: 2732 - 160
}, {
x: 3600,
y: 2732 - 160
}];
for (var i = 0; i < enemyPositions.length; i++) {
var e = enemyPositions[i];
var enemy = game.addChild(new Enemy());
enemy.x = e.x;
enemy.y = e.y;
enemy.velocityX = -3; // Faster enemies
enemies.push(enemy);
}
// Fewer power-ups for increased difficulty
var powerUpPositions = [{
x: 1200,
y: 2000
}, {
x: 3000,
y: 2050
}];
for (var i = 0; i < powerUpPositions.length; i++) {
var p = powerUpPositions[i];
var powerUp = game.addChild(new PowerUp());
powerUp.x = p.x;
powerUp.y = p.y;
powerUps.push(powerUp);
}
totalTreasures = treasures.length;
}
function createSkyLevel() {
// Floating sky platforms with large gaps
var groundSegments = [{
x: 0,
w: 250
}, {
x: 400,
w: 200
}, {
x: 750,
w: 150
}, {
x: 1100,
w: 200
}, {
x: 1500,
w: 250
}, {
x: 1900,
w: 150
}, {
x: 2250,
w: 200
}, {
x: 2600,
w: 250
}, {
x: 3000,
w: 150
}, {
x: 3400,
w: 200
}, {
x: 3800,
w: 300
}];
for (var i = 0; i < groundSegments.length; i++) {
var seg = groundSegments[i];
var ground = game.addChild(new Ground(seg.w));
ground.x = seg.x;
ground.y = 2732 - 80;
grounds.push(ground);
}
// Sky platforms requiring precise jumping
var platformData = [{
x: 280,
y: 2200,
w: 80,
h: 40
}, {
x: 450,
y: 2050,
w: 70,
h: 40
}, {
x: 650,
y: 2300,
w: 80,
h: 40
}, {
x: 850,
y: 2150,
w: 70,
h: 40
}, {
x: 1000,
y: 2000,
w: 80,
h: 40
}, {
x: 1250,
y: 2200,
w: 70,
h: 40
}, {
x: 1450,
y: 2350,
w: 80,
h: 40
}, {
x: 1650,
y: 2100,
w: 70,
h: 40
}, {
x: 1850,
y: 2250,
w: 80,
h: 40
}, {
x: 2050,
y: 2000,
w: 70,
h: 40
}, {
x: 2300,
y: 2150,
w: 80,
h: 40
}, {
x: 2500,
y: 2300,
w: 70,
h: 40
}, {
x: 2750,
y: 2050,
w: 80,
h: 40
}, {
x: 2950,
y: 2200,
w: 70,
h: 40
}, {
x: 3150,
y: 2350,
w: 80,
h: 40
}, {
x: 3350,
y: 2100,
w: 70,
h: 40
}, {
x: 3550,
y: 2250,
w: 80,
h: 40
}, {
x: 3750,
y: 2000,
w: 70,
h: 40
}];
for (var i = 0; i < platformData.length; i++) {
var p = platformData[i];
var platform = game.addChild(new Platform(p.w, p.h));
platform.x = p.x;
platform.y = p.y;
platforms.push(platform);
}
// High-altitude treasures
var treasurePositions = [{
x: 320,
y: 2150
}, {
x: 490,
y: 2000
}, {
x: 690,
y: 2250
}, {
x: 890,
y: 2100
}, {
x: 1040,
y: 1950
}, {
x: 1290,
y: 2150
}, {
x: 1490,
y: 2300
}, {
x: 1690,
y: 2050
}, {
x: 1890,
y: 2200
}, {
x: 2090,
y: 1950
}, {
x: 2340,
y: 2100
}, {
x: 2540,
y: 2250
}, {
x: 2790,
y: 2000
}, {
x: 2990,
y: 2150
}, {
x: 3190,
y: 2300
}, {
x: 3390,
y: 2050
}, {
x: 3590,
y: 2200
}, {
x: 3790,
y: 1950
}, {
x: 4200,
y: 2600
}];
for (var i = 0; i < treasurePositions.length; i++) {
var t = treasurePositions[i];
var treasure = game.addChild(new Treasure());
treasure.x = t.x;
treasure.y = t.y;
treasures.push(treasure);
}
// Flying enemies with different patterns
var enemyPositions = [{
x: 500,
y: 2732 - 160
}, {
x: 900,
y: 2732 - 160
}, {
x: 1300,
y: 2732 - 160
}, {
x: 1700,
y: 2732 - 160
}, {
x: 2100,
y: 2732 - 160
}, {
x: 2500,
y: 2732 - 160
}, {
x: 2900,
y: 2732 - 160
}, {
x: 3300,
y: 2732 - 160
}, {
x: 3700,
y: 2732 - 160
}];
for (var i = 0; i < enemyPositions.length; i++) {
var e = enemyPositions[i];
var enemy = game.addChild(new Enemy());
enemy.x = e.x;
enemy.y = e.y;
enemy.velocityX = -2.5;
enemies.push(enemy);
}
// Limited power-ups
var powerUpPositions = [{
x: 1040,
y: 1900
}, {
x: 2790,
y: 1950
}];
for (var i = 0; i < powerUpPositions.length; i++) {
var p = powerUpPositions[i];
var powerUp = game.addChild(new PowerUp());
powerUp.x = p.x;
powerUp.y = p.y;
powerUps.push(powerUp);
}
totalTreasures = treasures.length;
}
function createHauntedLevel() {
// Spooky broken ground segments
var groundSegments = [{
x: 0,
w: 200
}, {
x: 350,
w: 150
}, {
x: 650,
w: 100
}, {
x: 900,
w: 150
}, {
x: 1200,
w: 200
}, {
x: 1550,
w: 100
}, {
x: 1800,
w: 150
}, {
x: 2100,
w: 200
}, {
x: 2450,
w: 100
}, {
x: 2700,
w: 150
}, {
x: 3000,
w: 200
}, {
x: 3350,
w: 100
}, {
x: 3600,
w: 150
}, {
x: 3900,
w: 250
}];
for (var i = 0; i < groundSegments.length; i++) {
var seg = groundSegments[i];
var ground = game.addChild(new Ground(seg.w));
ground.x = seg.x;
ground.y = 2732 - 80;
grounds.push(ground);
}
// Narrow ghostly platforms
var platformData = [{
x: 250,
y: 2400,
w: 60,
h: 40
}, {
x: 450,
y: 2250,
w: 50,
h: 40
}, {
x: 600,
y: 2100,
w: 60,
h: 40
}, {
x: 800,
y: 2350,
w: 50,
h: 40
}, {
x: 1000,
y: 2200,
w: 60,
h: 40
}, {
x: 1350,
y: 2050,
w: 50,
h: 40
}, {
x: 1500,
y: 2300,
w: 60,
h: 40
}, {
x: 1700,
y: 2150,
w: 50,
h: 40
}, {
x: 1950,
y: 2400,
w: 60,
h: 40
}, {
x: 2200,
y: 2250,
w: 50,
h: 40
}, {
x: 2350,
y: 2100,
w: 60,
h: 40
}, {
x: 2550,
y: 2350,
w: 50,
h: 40
}, {
x: 2750,
y: 2200,
w: 60,
h: 40
}, {
x: 2950,
y: 2050,
w: 50,
h: 40
}, {
x: 3150,
y: 2300,
w: 60,
h: 40
}, {
x: 3400,
y: 2150,
w: 50,
h: 40
}, {
x: 3550,
y: 2400,
w: 60,
h: 40
}, {
x: 3750,
y: 2250,
w: 50,
h: 40
}];
for (var i = 0; i < platformData.length; i++) {
var p = platformData[i];
var platform = game.addChild(new Platform(p.w, p.h));
platform.x = p.x;
platform.y = p.y;
platforms.push(platform);
}
// Hidden treasures in dark corners
var treasurePositions = [{
x: 280,
y: 2350
}, {
x: 475,
y: 2200
}, {
x: 630,
y: 2050
}, {
x: 825,
y: 2300
}, {
x: 1030,
y: 2150
}, {
x: 1375,
y: 2000
}, {
x: 1530,
y: 2250
}, {
x: 1725,
y: 2100
}, {
x: 1980,
y: 2350
}, {
x: 2225,
y: 2200
}, {
x: 2380,
y: 2050
}, {
x: 2575,
y: 2300
}, {
x: 2780,
y: 2150
}, {
x: 2975,
y: 2000
}, {
x: 3180,
y: 2250
}, {
x: 3425,
y: 2100
}, {
x: 3580,
y: 2350
}, {
x: 3775,
y: 2200
}, {
x: 4100,
y: 2600
}];
for (var i = 0; i < treasurePositions.length; i++) {
var t = treasurePositions[i];
var treasure = game.addChild(new Treasure());
treasure.x = t.x;
treasure.y = t.y;
treasures.push(treasure);
}
// Fast ghost enemies
var enemyPositions = [{
x: 400,
y: 2732 - 160
}, {
x: 750,
y: 2732 - 160
}, {
x: 1100,
y: 2732 - 160
}, {
x: 1450,
y: 2732 - 160
}, {
x: 1800,
y: 2732 - 160
}, {
x: 2150,
y: 2732 - 160
}, {
x: 2500,
y: 2732 - 160
}, {
x: 2850,
y: 2732 - 160
}, {
x: 3200,
y: 2732 - 160
}, {
x: 3550,
y: 2732 - 160
}];
for (var i = 0; i < enemyPositions.length; i++) {
var e = enemyPositions[i];
var enemy = game.addChild(new Enemy());
enemy.x = e.x;
enemy.y = e.y;
enemy.velocityX = -3.5; // Even faster
enemies.push(enemy);
}
// Rare power-ups
var powerUpPositions = [{
x: 1375,
y: 1950
}, {
x: 2975,
y: 1950
}];
for (var i = 0; i < powerUpPositions.length; i++) {
var p = powerUpPositions[i];
var powerUp = game.addChild(new PowerUp());
powerUp.x = p.x;
powerUp.y = p.y;
powerUps.push(powerUp);
}
totalTreasures = treasures.length;
}
function createCrystalLevel() {
// Crystal formation ground segments
var groundSegments = [{
x: 0,
w: 150
}, {
x: 300,
w: 100
}, {
x: 550,
w: 120
}, {
x: 800,
w: 100
}, {
x: 1050,
w: 150
}, {
x: 1350,
w: 80
}, {
x: 1580,
w: 120
}, {
x: 1850,
w: 100
}, {
x: 2100,
w: 150
}, {
x: 2400,
w: 80
}, {
x: 2630,
w: 120
}, {
x: 2900,
w: 100
}, {
x: 3150,
w: 150
}, {
x: 3450,
w: 80
}, {
x: 3680,
w: 200
}];
for (var i = 0; i < groundSegments.length; i++) {
var seg = groundSegments[i];
var ground = game.addChild(new Ground(seg.w));
ground.x = seg.x;
ground.y = 2732 - 80;
grounds.push(ground);
}
// Sharp crystal platforms - very narrow
var platformData = [{
x: 200,
y: 2300,
w: 40,
h: 40
}, {
x: 350,
y: 2150,
w: 35,
h: 40
}, {
x: 500,
y: 2400,
w: 40,
h: 40
}, {
x: 650,
y: 2250,
w: 35,
h: 40
}, {
x: 750,
y: 2100,
w: 40,
h: 40
}, {
x: 950,
y: 2350,
w: 35,
h: 40
}, {
x: 1100,
y: 2200,
w: 40,
h: 40
}, {
x: 1300,
y: 2050,
w: 35,
h: 40
}, {
x: 1450,
y: 2300,
w: 40,
h: 40
}, {
x: 1650,
y: 2150,
w: 35,
h: 40
}, {
x: 1800,
y: 2400,
w: 40,
h: 40
}, {
x: 1950,
y: 2250,
w: 35,
h: 40
}, {
x: 2150,
y: 2100,
w: 40,
h: 40
}, {
x: 2350,
y: 2350,
w: 35,
h: 40
}, {
x: 2500,
y: 2200,
w: 40,
h: 40
}, {
x: 2700,
y: 2050,
w: 35,
h: 40
}, {
x: 2850,
y: 2300,
w: 40,
h: 40
}, {
x: 3050,
y: 2150,
w: 35,
h: 40
}, {
x: 3200,
y: 2400,
w: 40,
h: 40
}, {
x: 3400,
y: 2250,
w: 35,
h: 40
}, {
x: 3550,
y: 2100,
w: 40,
h: 40
}];
for (var i = 0; i < platformData.length; i++) {
var p = platformData[i];
var platform = game.addChild(new Platform(p.w, p.h));
platform.x = p.x;
platform.y = p.y;
platforms.push(platform);
}
// Crystal treasures requiring perfect precision
var treasurePositions = [{
x: 220,
y: 2250
}, {
x: 367,
y: 2100
}, {
x: 520,
y: 2350
}, {
x: 667,
y: 2200
}, {
x: 770,
y: 2050
}, {
x: 967,
y: 2300
}, {
x: 1120,
y: 2150
}, {
x: 1317,
y: 2000
}, {
x: 1470,
y: 2250
}, {
x: 1667,
y: 2100
}, {
x: 1820,
y: 2350
}, {
x: 1967,
y: 2200
}, {
x: 2170,
y: 2050
}, {
x: 2367,
y: 2300
}, {
x: 2520,
y: 2150
}, {
x: 2717,
y: 2000
}, {
x: 2870,
y: 2250
}, {
x: 3067,
y: 2100
}, {
x: 3220,
y: 2350
}, {
x: 3417,
y: 2200
}, {
x: 3570,
y: 2050
}, {
x: 3800,
y: 2600
}];
for (var i = 0; i < treasurePositions.length; i++) {
var t = treasurePositions[i];
var treasure = game.addChild(new Treasure());
treasure.x = t.x;
treasure.y = t.y;
treasures.push(treasure);
}
// Crystal guardians - very fast and numerous
var enemyPositions = [{
x: 250,
y: 2732 - 160
}, {
x: 450,
y: 2732 - 160
}, {
x: 650,
y: 2732 - 160
}, {
x: 850,
y: 2732 - 160
}, {
x: 1050,
y: 2732 - 160
}, {
x: 1250,
y: 2732 - 160
}, {
x: 1450,
y: 2732 - 160
}, {
x: 1650,
y: 2732 - 160
}, {
x: 1850,
y: 2732 - 160
}, {
x: 2050,
y: 2732 - 160
}, {
x: 2250,
y: 2732 - 160
}, {
x: 2450,
y: 2732 - 160
}, {
x: 2650,
y: 2732 - 160
}, {
x: 2850,
y: 2732 - 160
}, {
x: 3050,
y: 2732 - 160
}, {
x: 3250,
y: 2732 - 160
}, {
x: 3450,
y: 2732 - 160
}];
for (var i = 0; i < enemyPositions.length; i++) {
var e = enemyPositions[i];
var enemy = game.addChild(new Enemy());
enemy.x = e.x;
enemy.y = e.y;
enemy.velocityX = -4; // Very fast
enemies.push(enemy);
}
// Single power-up - make it count
var powerUpPositions = [{
x: 1850,
y: 2000
}];
for (var i = 0; i < powerUpPositions.length; i++) {
var p = powerUpPositions[i];
var powerUp = game.addChild(new PowerUp());
powerUp.x = p.x;
powerUp.y = p.y;
powerUps.push(powerUp);
}
totalTreasures = treasures.length;
}
function createLavaLevel() {
// Minimal lava stone platforms
var groundSegments = [{
x: 0,
w: 120
}, {
x: 250,
w: 80
}, {
x: 450,
w: 100
}, {
x: 700,
w: 80
}, {
x: 900,
w: 120
}, {
x: 1150,
w: 60
}, {
x: 1350,
w: 100
}, {
x: 1600,
w: 80
}, {
x: 1850,
w: 120
}, {
x: 2100,
w: 60
}, {
x: 2300,
w: 100
}, {
x: 2550,
w: 80
}, {
x: 2800,
w: 120
}, {
x: 3050,
w: 60
}, {
x: 3250,
w: 100
}, {
x: 3500,
w: 80
}, {
x: 3750,
w: 150
}];
for (var i = 0; i < groundSegments.length; i++) {
var seg = groundSegments[i];
var ground = game.addChild(new Ground(seg.w));
ground.x = seg.x;
ground.y = 2732 - 80;
grounds.push(ground);
}
// Extremely narrow lava platforms
var platformData = [{
x: 150,
y: 2350,
w: 30,
h: 40
}, {
x: 300,
y: 2200,
w: 25,
h: 40
}, {
x: 420,
y: 2450,
w: 30,
h: 40
}, {
x: 550,
y: 2300,
w: 25,
h: 40
}, {
x: 650,
y: 2150,
w: 30,
h: 40
}, {
x: 820,
y: 2400,
w: 25,
h: 40
}, {
x: 980,
y: 2250,
w: 30,
h: 40
}, {
x: 1100,
y: 2100,
w: 25,
h: 40
}, {
x: 1250,
y: 2350,
w: 30,
h: 40
}, {
x: 1400,
y: 2200,
w: 25,
h: 40
}, {
x: 1520,
y: 2450,
w: 30,
h: 40
}, {
x: 1650,
y: 2300,
w: 25,
h: 40
}, {
x: 1780,
y: 2150,
w: 30,
h: 40
}, {
x: 1920,
y: 2400,
w: 25,
h: 40
}, {
x: 2050,
y: 2250,
w: 30,
h: 40
}, {
x: 2180,
y: 2100,
w: 25,
h: 40
}, {
x: 2320,
y: 2350,
w: 30,
h: 40
}, {
x: 2450,
y: 2200,
w: 25,
h: 40
}, {
x: 2580,
y: 2450,
w: 30,
h: 40
}, {
x: 2720,
y: 2300,
w: 25,
h: 40
}, {
x: 2850,
y: 2150,
w: 30,
h: 40
}, {
x: 2980,
y: 2400,
w: 25,
h: 40
}, {
x: 3120,
y: 2250,
w: 30,
h: 40
}, {
x: 3280,
y: 2100,
w: 25,
h: 40
}, {
x: 3420,
y: 2350,
w: 30,
h: 40
}, {
x: 3550,
y: 2200,
w: 25,
h: 40
}];
for (var i = 0; i < platformData.length; i++) {
var p = platformData[i];
var platform = game.addChild(new Platform(p.w, p.h));
platform.x = p.x;
platform.y = p.y;
platforms.push(platform);
}
// Maximum treasure count for final challenge
var treasurePositions = [{
x: 165,
y: 2300
}, {
x: 312,
y: 2150
}, {
x: 435,
y: 2400
}, {
x: 562,
y: 2250
}, {
x: 665,
y: 2100
}, {
x: 832,
y: 2350
}, {
x: 995,
y: 2200
}, {
x: 1112,
y: 2050
}, {
x: 1265,
y: 2300
}, {
x: 1412,
y: 2150
}, {
x: 1535,
y: 2400
}, {
x: 1662,
y: 2250
}, {
x: 1795,
y: 2100
}, {
x: 1932,
y: 2350
}, {
x: 2065,
y: 2200
}, {
x: 2192,
y: 2050
}, {
x: 2335,
y: 2300
}, {
x: 2462,
y: 2150
}, {
x: 2595,
y: 2400
}, {
x: 2732,
y: 2250
}, {
x: 2865,
y: 2100
}, {
x: 2992,
y: 2350
}, {
x: 3135,
y: 2200
}, {
x: 3292,
y: 2050
}, {
x: 3435,
y: 2300
}, {
x: 3562,
y: 2150
}, {
x: 3900,
y: 2600
}];
for (var i = 0; i < treasurePositions.length; i++) {
var t = treasurePositions[i];
var treasure = game.addChild(new Treasure());
treasure.x = t.x;
treasure.y = t.y;
treasures.push(treasure);
}
// Massive enemy army
var enemyPositions = [{
x: 200,
y: 2732 - 160
}, {
x: 350,
y: 2732 - 160
}, {
x: 500,
y: 2732 - 160
}, {
x: 650,
y: 2732 - 160
}, {
x: 800,
y: 2732 - 160
}, {
x: 950,
y: 2732 - 160
}, {
x: 1100,
y: 2732 - 160
}, {
x: 1250,
y: 2732 - 160
}, {
x: 1400,
y: 2732 - 160
}, {
x: 1550,
y: 2732 - 160
}, {
x: 1700,
y: 2732 - 160
}, {
x: 1850,
y: 2732 - 160
}, {
x: 2000,
y: 2732 - 160
}, {
x: 2150,
y: 2732 - 160
}, {
x: 2300,
y: 2732 - 160
}, {
x: 2450,
y: 2732 - 160
}, {
x: 2600,
y: 2732 - 160
}, {
x: 2750,
y: 2732 - 160
}, {
x: 2900,
y: 2732 - 160
}, {
x: 3050,
y: 2732 - 160
}, {
x: 3200,
y: 2732 - 160
}, {
x: 3350,
y: 2732 - 160
}, {
x: 3500,
y: 2732 - 160
}];
for (var i = 0; i < enemyPositions.length; i++) {
var e = enemyPositions[i];
var enemy = game.addChild(new Enemy());
enemy.x = e.x;
enemy.y = e.y;
enemy.velocityX = -4.5; // Maximum speed
enemies.push(enemy);
}
// No power-ups - pure skill required
totalTreasures = treasures.length;
}
function createFinalCastleLevel() {
// Ultimate castle challenge - minimal ground
var groundSegments = [{
x: 0,
w: 100
}, {
x: 200,
w: 60
}, {
x: 350,
w: 80
}, {
x: 500,
w: 60
}, {
x: 650,
w: 100
}, {
x: 850,
w: 40
}, {
x: 980,
w: 80
}, {
x: 1150,
w: 60
}, {
x: 1300,
w: 100
}, {
x: 1500,
w: 40
}, {
x: 1630,
w: 80
}, {
x: 1800,
w: 60
}, {
x: 1950,
w: 100
}, {
x: 2150,
w: 40
}, {
x: 2280,
w: 80
}, {
x: 2450,
w: 60
}, {
x: 2600,
w: 100
}, {
x: 2800,
w: 40
}, {
x: 2930,
w: 80
}, {
x: 3100,
w: 60
}, {
x: 3250,
w: 100
}, {
x: 3450,
w: 40
}, {
x: 3580,
w: 80
}, {
x: 3750,
w: 120
}];
for (var i = 0; i < groundSegments.length; i++) {
var seg = groundSegments[i];
var ground = game.addChild(new Ground(seg.w));
ground.x = seg.x;
ground.y = 2732 - 80;
grounds.push(ground);
}
// Pixel-perfect platforms
var platformData = [{
x: 130,
y: 2400,
w: 20,
h: 40
}, {
x: 240,
y: 2250,
w: 20,
h: 40
}, {
x: 380,
y: 2500,
w: 20,
h: 40
}, {
x: 520,
y: 2350,
w: 20,
h: 40
}, {
x: 600,
y: 2200,
w: 20,
h: 40
}, {
x: 750,
y: 2450,
w: 20,
h: 40
}, {
x: 890,
y: 2300,
w: 20,
h: 40
}, {
x: 1020,
y: 2150,
w: 20,
h: 40
}, {
x: 1180,
y: 2400,
w: 20,
h: 40
}, {
x: 1330,
y: 2250,
w: 20,
h: 40
}, {
x: 1450,
y: 2500,
w: 20,
h: 40
}, {
x: 1580,
y: 2350,
w: 20,
h: 40
}, {
x: 1660,
y: 2200,
w: 20,
h: 40
}, {
x: 1830,
y: 2450,
w: 20,
h: 40
}, {
x: 1980,
y: 2300,
w: 20,
h: 40
}, {
x: 2100,
y: 2150,
w: 20,
h: 40
}, {
x: 2230,
y: 2400,
w: 20,
h: 40
}, {
x: 2380,
y: 2250,
w: 20,
h: 40
}, {
x: 2500,
y: 2500,
w: 20,
h: 40
}, {
x: 2630,
y: 2350,
w: 20,
h: 40
}, {
x: 2730,
y: 2200,
w: 20,
h: 40
}, {
x: 2880,
y: 2450,
w: 20,
h: 40
}, {
x: 3020,
y: 2300,
w: 20,
h: 40
}, {
x: 3130,
y: 2150,
w: 20,
h: 40
}, {
x: 3280,
y: 2400,
w: 20,
h: 40
}, {
x: 3480,
y: 2250,
w: 20,
h: 40
}, {
x: 3600,
y: 2500,
w: 20,
h: 40
}, {
x: 3720,
y: 2350,
w: 20,
h: 40
}];
for (var i = 0; i < platformData.length; i++) {
var p = platformData[i];
var platform = game.addChild(new Platform(p.w, p.h));
platform.x = p.x;
platform.y = p.y;
platforms.push(platform);
}
// Final treasure collection - master-level precision required
var treasurePositions = [{
x: 140,
y: 2350
}, {
x: 250,
y: 2200
}, {
x: 390,
y: 2450
}, {
x: 530,
y: 2300
}, {
x: 610,
y: 2150
}, {
x: 760,
y: 2400
}, {
x: 900,
y: 2250
}, {
x: 1030,
y: 2100
}, {
x: 1190,
y: 2350
}, {
x: 1340,
y: 2200
}, {
x: 1460,
y: 2450
}, {
x: 1590,
y: 2300
}, {
x: 1670,
y: 2150
}, {
x: 1840,
y: 2400
}, {
x: 1990,
y: 2250
}, {
x: 2110,
y: 2100
}, {
x: 2240,
y: 2350
}, {
x: 2390,
y: 2200
}, {
x: 2510,
y: 2450
}, {
x: 2640,
y: 2300
}, {
x: 2740,
y: 2150
}, {
x: 2890,
y: 2400
}, {
x: 3030,
y: 2250
}, {
x: 3140,
y: 2100
}, {
x: 3290,
y: 2350
}, {
x: 3490,
y: 2200
}, {
x: 3610,
y: 2450
}, {
x: 3730,
y: 2300
}, {
x: 3850,
y: 2600
}];
for (var i = 0; i < treasurePositions.length; i++) {
var t = treasurePositions[i];
var treasure = game.addChild(new Treasure());
treasure.x = t.x;
treasure.y = t.y;
treasures.push(treasure);
}
// Final boss-level enemy challenge
var enemyPositions = [{
x: 150,
y: 2732 - 160
}, {
x: 280,
y: 2732 - 160
}, {
x: 410,
y: 2732 - 160
}, {
x: 540,
y: 2732 - 160
}, {
x: 670,
y: 2732 - 160
}, {
x: 800,
y: 2732 - 160
}, {
x: 930,
y: 2732 - 160
}, {
x: 1060,
y: 2732 - 160
}, {
x: 1190,
y: 2732 - 160
}, {
x: 1320,
y: 2732 - 160
}, {
x: 1450,
y: 2732 - 160
}, {
x: 1580,
y: 2732 - 160
}, {
x: 1710,
y: 2732 - 160
}, {
x: 1840,
y: 2732 - 160
}, {
x: 1970,
y: 2732 - 160
}, {
x: 2100,
y: 2732 - 160
}, {
x: 2230,
y: 2732 - 160
}, {
x: 2360,
y: 2732 - 160
}, {
x: 2490,
y: 2732 - 160
}, {
x: 2620,
y: 2732 - 160
}, {
x: 2750,
y: 2732 - 160
}, {
x: 2880,
y: 2732 - 160
}, {
x: 3010,
y: 2732 - 160
}, {
x: 3140,
y: 2732 - 160
}, {
x: 3270,
y: 2732 - 160
}, {
x: 3400,
y: 2732 - 160
}, {
x: 3530,
y: 2732 - 160
}, {
x: 3660,
y: 2732 - 160
}];
for (var i = 0; i < enemyPositions.length; i++) {
var e = enemyPositions[i];
var enemy = game.addChild(new Enemy());
enemy.x = e.x;
enemy.y = e.y;
enemy.velocityX = -5; // Ultimate speed
enemies.push(enemy);
}
// No power-ups - ultimate skill test
totalTreasures = treasures.length;
} ===================================================================
--- original.js
+++ change.js
@@ -92,8 +92,52 @@
self.onGround = false;
self.facingRight = true;
self.invulnerable = false;
self.powerUpTimer = 0;
+ self.happyAnimationTimer = 0;
+ // Happy jump animation when touched
+ self.down = function (x, y, obj) {
+ if (gameState === 'menu') {
+ // Happy animation
+ self.happyAnimationTimer = 60; // 1 second at 60fps
+ tween(self, {
+ scaleX: 1.8,
+ scaleY: 1.8
+ }, {
+ duration: 200,
+ easing: tween.bounceOut
+ });
+ tween(graphics, {
+ rotation: 0.5
+ }, {
+ duration: 300,
+ easing: tween.elasticOut,
+ onFinish: function onFinish() {
+ tween(graphics, {
+ rotation: 0
+ }, {
+ duration: 300,
+ easing: tween.elasticOut
+ });
+ }
+ });
+ // Jump effect
+ if (self.onGround) {
+ self.velocityY = -self.jumpPower * 1.5;
+ self.onGround = false;
+ }
+ // Scale back to normal
+ LK.setTimeout(function () {
+ tween(self, {
+ scaleX: 1.5,
+ scaleY: 1.5
+ }, {
+ duration: 200,
+ easing: tween.bounceOut
+ });
+ }, 400);
+ }
+ };
self.update = function () {
// Apply gravity
self.velocityY += 1.2;
// Update position
@@ -217,12 +261,18 @@
var maxLevel = storage.maxLevel || 1;
var treasuresCollected = 0;
var totalTreasures = 0;
var levelCompleted = false;
+var gameState = 'menu'; // 'menu', 'playing', 'completed'
var gameCamera = {
x: 0,
y: 0
};
+// Menu variables
+var menuButtons = [];
+var menuTitle;
+var playButton;
+var levelSelectButtons = [];
// Game objects
var player;
var platforms = [];
var grounds = [];
@@ -294,8 +344,13 @@
right: false,
jump: false
};
function initializeUI() {
+ // Clear any existing UI
+ if (scoreText) scoreText.destroy();
+ if (levelText) levelText.destroy();
+ if (treasureText) treasureText.destroy();
+ if (instructionText) instructionText.destroy();
scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
@@ -316,18 +371,18 @@
treasureText.anchor.set(1, 0);
treasureText.x = -20;
treasureText.y = 20;
LK.gui.topRight.addChild(treasureText);
- instructionText = new Text2('Tap to move and jump!', {
- size: 80,
- fill: 0xFFFFFF
+ instructionText = new Text2('Collect ALL treasures to complete level!\nTap to move and jump!', {
+ size: 60,
+ fill: 0xFFFF00
});
instructionText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(instructionText);
- // Hide instruction after 3 seconds
+ // Hide instruction after 4 seconds
LK.setTimeout(function () {
- instructionText.visible = false;
- }, 3000);
+ if (instructionText) instructionText.visible = false;
+ }, 4000);
}
function updateUI() {
scoreText.setText('Score: ' + LK.getScore());
levelText.setText('Level ' + currentLevel + ': ' + levelThemes[currentLevel].name);
@@ -1365,9 +1420,25 @@
// Apply camera to game objects
game.x = gameCamera.x;
}
function completeLevel() {
- // Calculate completion bonus
+ // Check if all treasures are collected
+ if (treasuresCollected < totalTreasures) {
+ var warningText = new Text2('Collect all treasures\nto complete level!\n' + treasuresCollected + '/' + totalTreasures + ' collected', {
+ size: 80,
+ fill: 0xFFFF00
+ });
+ warningText.anchor.set(0.5, 0.5);
+ LK.gui.center.addChild(warningText);
+ // Flash screen yellow
+ LK.effects.flashScreen(0xFFFF00, 1000);
+ // Remove warning after delay
+ LK.setTimeout(function () {
+ warningText.destroy();
+ }, 2000);
+ return; // Don't complete level
+ }
+ // All treasures collected - complete level
var completionBonus = 500;
var treasureBonus = treasuresCollected * 50;
var totalBonus = completionBonus + treasureBonus;
LK.setScore(LK.getScore() + totalBonus);
@@ -1376,9 +1447,9 @@
maxLevel = currentLevel + 1;
storage.maxLevel = maxLevel;
}
// Show completion message
- var completionText = new Text2('Level Complete!\nBonus: ' + totalBonus, {
+ var completionText = new Text2('Level Complete!\nAll treasures collected!\nBonus: ' + totalBonus, {
size: 100,
fill: 0x00FF00
});
completionText.anchor.set(0.5, 0.5);
@@ -1392,36 +1463,178 @@
currentLevel++;
storage.currentLevel = currentLevel;
createLevel(currentLevel);
} else {
- // Game completed
- LK.showYouWin();
+ // Game completed - show happy animation
+ showGameCompleteAnimation();
}
}, 2000);
}
// Touch controls
game.down = function (x, y, obj) {
- // Use the x parameter directly as it's already in the correct coordinate space
- if (x < 1024) {
- keys.left = true;
- } else {
- keys.right = true;
+ // Handle menu input
+ if (gameState === 'menu') {
+ handleMenuInput(x, y);
+ return;
}
- // Jump on any touch
- keys.jump = true;
+ // Game input
+ if (gameState === 'playing') {
+ // Use the x parameter directly as it's already in the correct coordinate space
+ if (x < 1024) {
+ keys.left = true;
+ } else {
+ keys.right = true;
+ }
+ // Jump on any touch
+ keys.jump = true;
+ }
};
game.up = function (x, y, obj) {
- keys.left = false;
- keys.right = false;
- keys.jump = false;
+ if (gameState === 'playing') {
+ keys.left = false;
+ keys.right = false;
+ keys.jump = false;
+ }
};
-// Initialize game
-initializeUI();
-createLevel(currentLevel);
+function createMainMenu() {
+ gameState = 'menu';
+ // Clear any existing level
+ clearLevel();
+ // Create menu title
+ menuTitle = new Text2("Mario's Treasure Quest", {
+ size: 120,
+ fill: 0xFFD700
+ });
+ menuTitle.anchor.set(0.5, 0.5);
+ menuTitle.x = 1024;
+ menuTitle.y = 400;
+ game.addChild(menuTitle);
+ // Create play button
+ playButton = new Text2('START GAME', {
+ size: 80,
+ fill: 0x00FF00
+ });
+ playButton.anchor.set(0.5, 0.5);
+ playButton.x = 1024;
+ playButton.y = 800;
+ game.addChild(playButton);
+ // Create level select title
+ var levelSelectTitle = new Text2('Select Level:', {
+ size: 60,
+ fill: 0xFFFFFF
+ });
+ levelSelectTitle.anchor.set(0.5, 0.5);
+ levelSelectTitle.x = 1024;
+ levelSelectTitle.y = 1000;
+ game.addChild(levelSelectTitle);
+ // Create level selection buttons
+ levelSelectButtons = [];
+ for (var i = 1; i <= 10; i++) {
+ var levelButton = new Text2(i.toString(), {
+ size: 60,
+ fill: i <= maxLevel ? 0x00FF00 : 0x888888
+ });
+ levelButton.anchor.set(0.5, 0.5);
+ levelButton.x = 300 + (i - 1) % 5 * 300;
+ levelButton.y = 1200 + Math.floor((i - 1) / 5) * 150;
+ levelButton.levelNumber = i;
+ levelButton.unlocked = i <= maxLevel;
+ game.addChild(levelButton);
+ levelSelectButtons.push(levelButton);
+ }
+ // Add animated character in menu
+ var menuCharacter = game.addChild(new Player());
+ menuCharacter.x = 1024;
+ menuCharacter.y = 600;
+ menuCharacter.scaleX = 1.5;
+ menuCharacter.scaleY = 1.5;
+ // Happy bounce animation
+ var bounceOffset = 0;
+ var menuCharacterUpdate = function menuCharacterUpdate() {
+ if (gameState === 'menu') {
+ bounceOffset += 0.1;
+ menuCharacter.y = 600 + Math.sin(bounceOffset) * 20;
+ }
+ };
+ LK.setInterval(menuCharacterUpdate, 16);
+}
+function handleMenuInput(x, y) {
+ if (gameState !== 'menu') return;
+ // Check play button
+ if (x > playButton.x - 150 && x < playButton.x + 150 && y > playButton.y - 50 && y < playButton.y + 50) {
+ startGame();
+ return;
+ }
+ // Check level buttons
+ for (var i = 0; i < levelSelectButtons.length; i++) {
+ var btn = levelSelectButtons[i];
+ if (btn.unlocked && x > btn.x - 50 && x < btn.x + 50 && y > btn.y - 50 && y < btn.y + 50) {
+ currentLevel = btn.levelNumber;
+ startGame();
+ return;
+ }
+ }
+}
+function startGame() {
+ gameState = 'playing';
+ // Clear menu
+ if (menuTitle) menuTitle.destroy();
+ if (playButton) playButton.destroy();
+ for (var i = 0; i < levelSelectButtons.length; i++) {
+ levelSelectButtons[i].destroy();
+ }
+ // Initialize UI and start game
+ initializeUI();
+ createLevel(currentLevel);
+}
+function showGameCompleteAnimation() {
+ gameState = 'completed';
+ // Create celebration character
+ var celebrationCharacter = game.addChild(new Player());
+ celebrationCharacter.x = 1024;
+ celebrationCharacter.y = 1300;
+ celebrationCharacter.scaleX = 2;
+ celebrationCharacter.scaleY = 2;
+ // Happy celebration animation
+ var celebrationOffset = 0;
+ var celebrationUpdate = function celebrationUpdate() {
+ if (gameState === 'completed') {
+ celebrationOffset += 0.15;
+ celebrationCharacter.y = 1300 + Math.sin(celebrationOffset) * 50;
+ celebrationCharacter.rotation = Math.sin(celebrationOffset * 2) * 0.3;
+ }
+ };
+ LK.setInterval(celebrationUpdate, 16);
+ // Add celebration text
+ var celebrationText = new Text2('CONGRATULATIONS!\nYou collected all treasures\nin all 10 levels!', {
+ size: 80,
+ fill: 0xFFD700
+ });
+ celebrationText.anchor.set(0.5, 0.5);
+ celebrationText.x = 1024;
+ celebrationText.y = 800;
+ game.addChild(celebrationText);
+ // Flash screen with rainbow colors
+ var rainbowColors = [0xFF0000, 0xFF8000, 0xFFFF00, 0x00FF00, 0x0080FF, 0x8000FF];
+ var colorIndex = 0;
+ LK.setInterval(function () {
+ if (gameState === 'completed') {
+ LK.effects.flashScreen(rainbowColors[colorIndex], 500);
+ colorIndex = (colorIndex + 1) % rainbowColors.length;
+ }
+ }, 600);
+ // Show final win after delay
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 5000);
+}
+// Initialize game with menu
+createMainMenu();
LK.playMusic('bgmusic');
// Main game loop
game.update = function () {
- if (levelCompleted) return;
+ // Only update game logic when playing
+ if (gameState !== 'playing' || levelCompleted) return;
// Handle input
if (keys.left) {
player.moveLeft();
}
but like nathan drake. In-Game asset. 2d. High contrast. No shadows
silahlı çöl kıyafeti giyen bir asker. In-Game asset. 2d. High contrast. No shadows
Not a chest, just one valuable item such as a gold earring, a silver historical container or similar, but only one. In-Game asset. 2d. High contrast. No shadows
sand like a flat road. In-Game asset. 2d. High contrast. No shadows
a wall built with flat, mossy stones. In-Game asset. 2d. High contrast. No shadows
rusted iron door. In-Game asset. 2d. High contrast. No shadows