/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Goat = Container.expand(function (color) {
var self = Container.call(this);
var goatGraphics = self.attachAsset('goat', {
anchorX: 0.5,
anchorY: 0.5,
tint: color || 0xffffff
});
self.moveToPosition = function (x, y, duration) {
tween(self, {
x: x,
y: y
}, {
duration: duration || 1000,
easing: tween.easeOut
});
};
self.bounce = function () {
tween(self, {
y: self.y - 50
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
y: self.y + 50
}, {
duration: 300,
easing: tween.easeIn
});
}
});
};
return self;
});
var Scene = Container.expand(function (sceneNumber) {
var self = Container.call(this);
self.sceneNumber = sceneNumber;
self.isActive = false;
self.completed = false;
self.activate = function () {
self.isActive = true;
self.alpha = 0;
self.visible = true;
tween(self, {
alpha: 1
}, {
duration: 500
});
};
self.deactivate = function () {
self.isActive = false;
tween(self, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
self.visible = false;
}
});
};
return self;
});
var ThemeParkScene = Scene.expand(function () {
var self = Scene.call(this, 7);
var bg = self.attachAsset('themepark', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
var goat1 = self.addChild(new Goat(0xffffff));
var goat2 = self.addChild(new Goat(0xf0f0f0));
var goat3 = self.addChild(new Goat(0xe0e0e0));
goat1.x = 400;
goat1.y = 1400;
goat2.x = 1024;
goat2.y = 1400;
goat3.x = 1600;
goat3.y = 1400;
self.activate = function () {
Scene.prototype.activate.call(self);
LK.setTimeout(function () {
goat1.moveToPosition(600, 1200, 1000);
goat2.moveToPosition(1024, 1100, 1000);
goat3.moveToPosition(1400, 1200, 1000);
}, 500);
LK.setTimeout(function () {
self.completed = true;
}, 2500);
};
return self;
});
var TVScene = Scene.expand(function () {
var self = Scene.call(this, 1);
var bg = self.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
var tv = self.attachAsset('tv', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1200
});
var tvScreen = self.attachAsset('tvScreen', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1200
});
var playButton = self.attachAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1200
});
self.down = function (x, y, obj) {
var localPos = self.toLocal(obj.parent.toGlobal(obj.position));
var distance = Math.sqrt(Math.pow(localPos.x - playButton.x, 2) + Math.pow(localPos.y - playButton.y, 2));
if (distance < 100) {
LK.getSound('tap').play();
tween(playButton, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 100,
onFinish: function onFinish() {
tween(playButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
self.completed = true;
}
};
return self;
});
var SlideScene = Scene.expand(function () {
var self = Scene.call(this, 4);
var bg = self.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
tint: 0x87ceeb
});
var slide = self.attachAsset('slide', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
rotation: 0.3
});
var goat1 = self.addChild(new Goat(0xffffff));
var goat2 = self.addChild(new Goat(0xf0f0f0));
var goat3 = self.addChild(new Goat(0xe0e0e0));
goat1.x = 200;
goat1.y = 1000;
goat2.x = 400;
goat2.y = 1100;
goat3.x = 600;
goat3.y = 1200;
self.activate = function () {
Scene.prototype.activate.call(self);
LK.setTimeout(function () {
LK.getSound('whoosh').play();
goat1.moveToPosition(1400, 1800, 2000);
goat2.moveToPosition(1600, 1900, 2200);
goat3.moveToPosition(1800, 2000, 2400);
}, 500);
LK.setTimeout(function () {
self.completed = true;
}, 3000);
};
return self;
});
var SkyScene = Scene.expand(function () {
var self = Scene.call(this, 5);
var bg = self.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
tint: 0x87ceeb
});
var cloud1 = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
x: 300,
y: 800
});
var cloud2 = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 600
});
var cloud3 = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
x: 1700,
y: 900
});
var goat1 = self.addChild(new Goat(0xffffff));
var goat2 = self.addChild(new Goat(0xf0f0f0));
var goat3 = self.addChild(new Goat(0xe0e0e0));
goat1.x = 100;
goat1.y = 1400;
goat2.x = 1024;
goat2.y = 1400;
goat3.x = 1900;
goat3.y = 1400;
self.activate = function () {
Scene.prototype.activate.call(self);
LK.setTimeout(function () {
LK.getSound('whoosh').play();
goat1.moveToPosition(300, 800, 2000);
goat2.moveToPosition(1024, 600, 2000);
goat3.moveToPosition(1700, 900, 2000);
}, 500);
LK.setTimeout(function () {
self.completed = true;
}, 3000);
};
return self;
});
var MusicScene = Scene.expand(function () {
var self = Scene.call(this, 8);
var bg = self.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
tint: 0xffd700
});
var goat1 = self.addChild(new Goat(0xffffff));
var goat2 = self.addChild(new Goat(0xf0f0f0));
var goat3 = self.addChild(new Goat(0xe0e0e0));
goat1.x = 400;
goat1.y = 1400;
goat2.x = 1024;
goat2.y = 1400;
goat3.x = 1600;
goat3.y = 1400;
var musicNotes = [];
self.activate = function () {
Scene.prototype.activate.call(self);
for (var i = 0; i < 12; i++) {
var note = self.attachAsset('musicNote', {
anchorX: 0.5,
anchorY: 0.5,
x: Math.random() * 2048,
y: Math.random() * 1000 + 500
});
musicNotes.push(note);
tween(note, {
y: note.y - 200,
rotation: Math.PI * 2
}, {
duration: 3000 + Math.random() * 2000,
easing: tween.easeOut
});
}
LK.setTimeout(function () {
goat1.bounce();
goat2.bounce();
goat3.bounce();
}, 500);
LK.setTimeout(function () {
self.completed = true;
}, 4000);
};
return self;
});
var HillScene = Scene.expand(function () {
var self = Scene.call(this, 3);
var bg = self.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
tint: 0x87ceeb
});
var hill = self.attachAsset('hill', {
anchorX: 0.5,
anchorY: 1,
x: 1024,
y: 2732
});
var goat1 = self.addChild(new Goat(0xffffff));
var goat2 = self.addChild(new Goat(0xf0f0f0));
var goat3 = self.addChild(new Goat(0xe0e0e0));
goat1.x = 400;
goat1.y = 1800;
goat2.x = 1024;
goat2.y = 1700;
goat3.x = 1600;
goat3.y = 1800;
self.activate = function () {
Scene.prototype.activate.call(self);
LK.setTimeout(function () {
LK.getSound('whoosh').play();
goat1.moveToPosition(600, 2400, 2000);
goat2.moveToPosition(1024, 2300, 2000);
goat3.moveToPosition(1400, 2400, 2000);
}, 500);
LK.setTimeout(function () {
self.completed = true;
}, 3000);
};
return self;
});
var GoatsScene = Scene.expand(function () {
var self = Scene.call(this, 2);
var bg = self.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
tint: 0x87ceeb
});
var goat1 = self.addChild(new Goat(0xffffff));
var goat2 = self.addChild(new Goat(0xf0f0f0));
var goat3 = self.addChild(new Goat(0xe0e0e0));
goat1.x = 200;
goat1.y = 1400;
goat2.x = 1024;
goat2.y = 1400;
goat3.x = 1800;
goat3.y = 1400;
self.activate = function () {
Scene.prototype.activate.call(self);
LK.setTimeout(function () {
goat1.bounce();
}, 500);
LK.setTimeout(function () {
goat2.bounce();
}, 700);
LK.setTimeout(function () {
goat3.bounce();
}, 900);
LK.setTimeout(function () {
self.completed = true;
}, 2000);
};
return self;
});
var BattleScene = Scene.expand(function () {
var self = Scene.call(this, 6);
var bg = self.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
tint: 0x4a4a4a
});
var goblin = self.attachAsset('goblin', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1200
});
var goat1 = self.addChild(new Goat(0xffffff));
var goat2 = self.addChild(new Goat(0xf0f0f0));
var goat3 = self.addChild(new Goat(0xe0e0e0));
goat1.x = 400;
goat1.y = 1800;
goat2.x = 1024;
goat2.y = 1800;
goat3.x = 1600;
goat3.y = 1800;
self.activate = function () {
Scene.prototype.activate.call(self);
LK.setTimeout(function () {
LK.getSound('battle').play();
tween(goblin, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 500,
onFinish: function onFinish() {
tween(goblin, {
alpha: 0
}, {
duration: 1000
});
}
});
goat1.bounce();
goat2.bounce();
goat3.bounce();
}, 500);
LK.setTimeout(function () {
self.completed = true;
}, 3000);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var currentSceneIndex = 0;
var scenes = [];
var transitionDelay = 1000;
var lastSceneComplete = false;
// Create all scenes
scenes.push(new TVScene());
scenes.push(new GoatsScene());
scenes.push(new HillScene());
scenes.push(new SlideScene());
scenes.push(new SkyScene());
scenes.push(new BattleScene());
scenes.push(new ThemeParkScene());
scenes.push(new MusicScene());
// Add all scenes to game
for (var i = 0; i < scenes.length; i++) {
game.addChild(scenes[i]);
scenes[i].visible = false;
}
// Activate first scene
scenes[currentSceneIndex].activate();
// Progress text
var progressText = new Text2('Tap to continue...', {
size: 60,
fill: 0xFFFFFF
});
progressText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(progressText);
// Scene title text
var titleText = new Text2('Troll Bridge Adventure', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
function updateSceneTitle() {
var titles = ['Hotel TV Room', 'Three Goats Meet', 'Sliding Down the Hill', 'Big Slide Navigation', 'Sky Journey', 'Final Goblin Battle', 'Theme Park Adventure', 'Musical Finale'];
titleText.setText(titles[currentSceneIndex] || 'Troll Bridge Adventure');
}
function nextScene() {
if (currentSceneIndex < scenes.length - 1) {
scenes[currentSceneIndex].deactivate();
currentSceneIndex++;
LK.setTimeout(function () {
scenes[currentSceneIndex].activate();
updateSceneTitle();
}, transitionDelay);
} else {
// Game complete
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}
}
game.down = function (x, y, obj) {
var currentScene = scenes[currentSceneIndex];
// Pass tap to current scene
if (currentScene && currentScene.down) {
currentScene.down(x, y, obj);
}
// Check if we can advance to next scene
if (currentScene && currentScene.completed && !lastSceneComplete) {
LK.getSound('tap').play();
nextScene();
}
};
game.update = function () {
var currentScene = scenes[currentSceneIndex];
// Track scene completion state
if (currentScene) {
var wasComplete = lastSceneComplete;
lastSceneComplete = currentScene.completed;
// Update progress text visibility
if (currentScene.completed) {
progressText.alpha = 0.7 + 0.3 * Math.sin(LK.ticks * 0.1);
} else {
progressText.alpha = 0.3;
}
}
};
// Initialize scene title
updateSceneTitle();
// Start background music
LK.playMusic('storyMusic'); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Goat = Container.expand(function (color) {
var self = Container.call(this);
var goatGraphics = self.attachAsset('goat', {
anchorX: 0.5,
anchorY: 0.5,
tint: color || 0xffffff
});
self.moveToPosition = function (x, y, duration) {
tween(self, {
x: x,
y: y
}, {
duration: duration || 1000,
easing: tween.easeOut
});
};
self.bounce = function () {
tween(self, {
y: self.y - 50
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
y: self.y + 50
}, {
duration: 300,
easing: tween.easeIn
});
}
});
};
return self;
});
var Scene = Container.expand(function (sceneNumber) {
var self = Container.call(this);
self.sceneNumber = sceneNumber;
self.isActive = false;
self.completed = false;
self.activate = function () {
self.isActive = true;
self.alpha = 0;
self.visible = true;
tween(self, {
alpha: 1
}, {
duration: 500
});
};
self.deactivate = function () {
self.isActive = false;
tween(self, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
self.visible = false;
}
});
};
return self;
});
var ThemeParkScene = Scene.expand(function () {
var self = Scene.call(this, 7);
var bg = self.attachAsset('themepark', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
var goat1 = self.addChild(new Goat(0xffffff));
var goat2 = self.addChild(new Goat(0xf0f0f0));
var goat3 = self.addChild(new Goat(0xe0e0e0));
goat1.x = 400;
goat1.y = 1400;
goat2.x = 1024;
goat2.y = 1400;
goat3.x = 1600;
goat3.y = 1400;
self.activate = function () {
Scene.prototype.activate.call(self);
LK.setTimeout(function () {
goat1.moveToPosition(600, 1200, 1000);
goat2.moveToPosition(1024, 1100, 1000);
goat3.moveToPosition(1400, 1200, 1000);
}, 500);
LK.setTimeout(function () {
self.completed = true;
}, 2500);
};
return self;
});
var TVScene = Scene.expand(function () {
var self = Scene.call(this, 1);
var bg = self.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
var tv = self.attachAsset('tv', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1200
});
var tvScreen = self.attachAsset('tvScreen', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1200
});
var playButton = self.attachAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1200
});
self.down = function (x, y, obj) {
var localPos = self.toLocal(obj.parent.toGlobal(obj.position));
var distance = Math.sqrt(Math.pow(localPos.x - playButton.x, 2) + Math.pow(localPos.y - playButton.y, 2));
if (distance < 100) {
LK.getSound('tap').play();
tween(playButton, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 100,
onFinish: function onFinish() {
tween(playButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
self.completed = true;
}
};
return self;
});
var SlideScene = Scene.expand(function () {
var self = Scene.call(this, 4);
var bg = self.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
tint: 0x87ceeb
});
var slide = self.attachAsset('slide', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
rotation: 0.3
});
var goat1 = self.addChild(new Goat(0xffffff));
var goat2 = self.addChild(new Goat(0xf0f0f0));
var goat3 = self.addChild(new Goat(0xe0e0e0));
goat1.x = 200;
goat1.y = 1000;
goat2.x = 400;
goat2.y = 1100;
goat3.x = 600;
goat3.y = 1200;
self.activate = function () {
Scene.prototype.activate.call(self);
LK.setTimeout(function () {
LK.getSound('whoosh').play();
goat1.moveToPosition(1400, 1800, 2000);
goat2.moveToPosition(1600, 1900, 2200);
goat3.moveToPosition(1800, 2000, 2400);
}, 500);
LK.setTimeout(function () {
self.completed = true;
}, 3000);
};
return self;
});
var SkyScene = Scene.expand(function () {
var self = Scene.call(this, 5);
var bg = self.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
tint: 0x87ceeb
});
var cloud1 = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
x: 300,
y: 800
});
var cloud2 = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 600
});
var cloud3 = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
x: 1700,
y: 900
});
var goat1 = self.addChild(new Goat(0xffffff));
var goat2 = self.addChild(new Goat(0xf0f0f0));
var goat3 = self.addChild(new Goat(0xe0e0e0));
goat1.x = 100;
goat1.y = 1400;
goat2.x = 1024;
goat2.y = 1400;
goat3.x = 1900;
goat3.y = 1400;
self.activate = function () {
Scene.prototype.activate.call(self);
LK.setTimeout(function () {
LK.getSound('whoosh').play();
goat1.moveToPosition(300, 800, 2000);
goat2.moveToPosition(1024, 600, 2000);
goat3.moveToPosition(1700, 900, 2000);
}, 500);
LK.setTimeout(function () {
self.completed = true;
}, 3000);
};
return self;
});
var MusicScene = Scene.expand(function () {
var self = Scene.call(this, 8);
var bg = self.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
tint: 0xffd700
});
var goat1 = self.addChild(new Goat(0xffffff));
var goat2 = self.addChild(new Goat(0xf0f0f0));
var goat3 = self.addChild(new Goat(0xe0e0e0));
goat1.x = 400;
goat1.y = 1400;
goat2.x = 1024;
goat2.y = 1400;
goat3.x = 1600;
goat3.y = 1400;
var musicNotes = [];
self.activate = function () {
Scene.prototype.activate.call(self);
for (var i = 0; i < 12; i++) {
var note = self.attachAsset('musicNote', {
anchorX: 0.5,
anchorY: 0.5,
x: Math.random() * 2048,
y: Math.random() * 1000 + 500
});
musicNotes.push(note);
tween(note, {
y: note.y - 200,
rotation: Math.PI * 2
}, {
duration: 3000 + Math.random() * 2000,
easing: tween.easeOut
});
}
LK.setTimeout(function () {
goat1.bounce();
goat2.bounce();
goat3.bounce();
}, 500);
LK.setTimeout(function () {
self.completed = true;
}, 4000);
};
return self;
});
var HillScene = Scene.expand(function () {
var self = Scene.call(this, 3);
var bg = self.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
tint: 0x87ceeb
});
var hill = self.attachAsset('hill', {
anchorX: 0.5,
anchorY: 1,
x: 1024,
y: 2732
});
var goat1 = self.addChild(new Goat(0xffffff));
var goat2 = self.addChild(new Goat(0xf0f0f0));
var goat3 = self.addChild(new Goat(0xe0e0e0));
goat1.x = 400;
goat1.y = 1800;
goat2.x = 1024;
goat2.y = 1700;
goat3.x = 1600;
goat3.y = 1800;
self.activate = function () {
Scene.prototype.activate.call(self);
LK.setTimeout(function () {
LK.getSound('whoosh').play();
goat1.moveToPosition(600, 2400, 2000);
goat2.moveToPosition(1024, 2300, 2000);
goat3.moveToPosition(1400, 2400, 2000);
}, 500);
LK.setTimeout(function () {
self.completed = true;
}, 3000);
};
return self;
});
var GoatsScene = Scene.expand(function () {
var self = Scene.call(this, 2);
var bg = self.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
tint: 0x87ceeb
});
var goat1 = self.addChild(new Goat(0xffffff));
var goat2 = self.addChild(new Goat(0xf0f0f0));
var goat3 = self.addChild(new Goat(0xe0e0e0));
goat1.x = 200;
goat1.y = 1400;
goat2.x = 1024;
goat2.y = 1400;
goat3.x = 1800;
goat3.y = 1400;
self.activate = function () {
Scene.prototype.activate.call(self);
LK.setTimeout(function () {
goat1.bounce();
}, 500);
LK.setTimeout(function () {
goat2.bounce();
}, 700);
LK.setTimeout(function () {
goat3.bounce();
}, 900);
LK.setTimeout(function () {
self.completed = true;
}, 2000);
};
return self;
});
var BattleScene = Scene.expand(function () {
var self = Scene.call(this, 6);
var bg = self.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
tint: 0x4a4a4a
});
var goblin = self.attachAsset('goblin', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1200
});
var goat1 = self.addChild(new Goat(0xffffff));
var goat2 = self.addChild(new Goat(0xf0f0f0));
var goat3 = self.addChild(new Goat(0xe0e0e0));
goat1.x = 400;
goat1.y = 1800;
goat2.x = 1024;
goat2.y = 1800;
goat3.x = 1600;
goat3.y = 1800;
self.activate = function () {
Scene.prototype.activate.call(self);
LK.setTimeout(function () {
LK.getSound('battle').play();
tween(goblin, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 500,
onFinish: function onFinish() {
tween(goblin, {
alpha: 0
}, {
duration: 1000
});
}
});
goat1.bounce();
goat2.bounce();
goat3.bounce();
}, 500);
LK.setTimeout(function () {
self.completed = true;
}, 3000);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var currentSceneIndex = 0;
var scenes = [];
var transitionDelay = 1000;
var lastSceneComplete = false;
// Create all scenes
scenes.push(new TVScene());
scenes.push(new GoatsScene());
scenes.push(new HillScene());
scenes.push(new SlideScene());
scenes.push(new SkyScene());
scenes.push(new BattleScene());
scenes.push(new ThemeParkScene());
scenes.push(new MusicScene());
// Add all scenes to game
for (var i = 0; i < scenes.length; i++) {
game.addChild(scenes[i]);
scenes[i].visible = false;
}
// Activate first scene
scenes[currentSceneIndex].activate();
// Progress text
var progressText = new Text2('Tap to continue...', {
size: 60,
fill: 0xFFFFFF
});
progressText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(progressText);
// Scene title text
var titleText = new Text2('Troll Bridge Adventure', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
function updateSceneTitle() {
var titles = ['Hotel TV Room', 'Three Goats Meet', 'Sliding Down the Hill', 'Big Slide Navigation', 'Sky Journey', 'Final Goblin Battle', 'Theme Park Adventure', 'Musical Finale'];
titleText.setText(titles[currentSceneIndex] || 'Troll Bridge Adventure');
}
function nextScene() {
if (currentSceneIndex < scenes.length - 1) {
scenes[currentSceneIndex].deactivate();
currentSceneIndex++;
LK.setTimeout(function () {
scenes[currentSceneIndex].activate();
updateSceneTitle();
}, transitionDelay);
} else {
// Game complete
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}
}
game.down = function (x, y, obj) {
var currentScene = scenes[currentSceneIndex];
// Pass tap to current scene
if (currentScene && currentScene.down) {
currentScene.down(x, y, obj);
}
// Check if we can advance to next scene
if (currentScene && currentScene.completed && !lastSceneComplete) {
LK.getSound('tap').play();
nextScene();
}
};
game.update = function () {
var currentScene = scenes[currentSceneIndex];
// Track scene completion state
if (currentScene) {
var wasComplete = lastSceneComplete;
lastSceneComplete = currentScene.completed;
// Update progress text visibility
if (currentScene.completed) {
progressText.alpha = 0.7 + 0.3 * Math.sin(LK.ticks * 0.1);
} else {
progressText.alpha = 0.3;
}
}
};
// Initialize scene title
updateSceneTitle();
// Start background music
LK.playMusic('storyMusic');