/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Character = Container.expand(function () { var self = Container.call(this); var characterGraphics = self.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); self.name = ''; self.isSelected = false; self.select = function () { self.isSelected = true; tween(characterGraphics, { scaleX: 1.3, scaleY: 1.3 }, { duration: 300, easing: tween.easeOut }); }; self.deselect = function () { self.isSelected = false; tween(characterGraphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: 300, easing: tween.easeOut }); }; self.down = function (x, y, obj) { if (gameState === 'characterSelect') { if (selectedCharacter && selectedCharacter !== self) { selectedCharacter.deselect(); } selectedCharacter = self; self.select(); // Start game after character selection LK.setTimeout(function () { startGame(); }, 500); } }; return self; }); var Sled = Container.expand(function () { var self = Container.call(this); var sledGraphics = self.attachAsset('sled', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.isMoving = false; self.onHill = true; self.update = function () { if (self.isMoving && !self.onHill) { // Apply gravity self.velocityY += 0.3; // Update position self.x += self.velocityX; self.y += self.velocityY; // Check for landing in snow pile if (self.intersects(snowPile)) { self.land(); } // Check if sled went off screen if (self.y > 2732 + 100) { self.miss(); } } }; self.launch = function (power) { self.isMoving = true; self.onHill = false; self.velocityX = power * 0.15; self.velocityY = -power * 0.1; LK.getSound('whoosh').play(); }; self.land = function () { if (self.isMoving) { self.isMoving = false; LK.getSound('landing').play(); LK.setScore(LK.getScore() + 100); scoreTxt.setText(LK.getScore()); // Flash success LK.effects.flashObject(snowPile, 0x00FF00, 1000); // Reset after delay LK.setTimeout(function () { resetGame(); }, 2000); } }; self.miss = function () { self.isMoving = false; // Flash failure LK.effects.flashScreen(0xFF0000, 500); // Reset after delay LK.setTimeout(function () { resetGame(); }, 1500); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var gameState = 'characterSelect'; // 'characterSelect', 'pullUp', 'sliding' var selectedCharacter = null; var currentCharacter = null; var sled = null; var pullPower = 0; var isPulling = false; var hill = null; var snowPile = null; var trees = []; // Create score display var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0x000000 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create instruction text var instructionTxt = new Text2('Choose your character!', { size: 60, fill: 0x000000 }); instructionTxt.anchor.set(0.5, 0.5); instructionTxt.x = 2048 / 2; instructionTxt.y = 300; game.addChild(instructionTxt); // Create power meter background var powerMeterBg = LK.getAsset('hill', { width: 300, height: 30, color: 0x666666, anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2500 }); // Create power meter fill var powerMeterFill = LK.getAsset('hill', { width: 0, height: 26, color: 0xFF0000, anchorX: 0, anchorY: 0.5, x: 2048 / 2 - 150, y: 2500 }); // Create hill hill = game.addChild(LK.getAsset('hill', { anchorX: 0, anchorY: 1, x: 0, y: 2732 })); // Create snow pile at bottom snowPile = game.addChild(new Container()); var snowPileGraphics = snowPile.attachAsset('snowPile', { anchorX: 0.5, anchorY: 0.5 }); snowPile.x = 1700; snowPile.y = 2600; // Create decorative trees for (var i = 0; i < 5; i++) { var tree = game.addChild(LK.getAsset('tree', { anchorX: 0.5, anchorY: 1 })); tree.x = Math.random() * 1800 + 100; tree.y = 2732 - Math.random() * 300; trees.push(tree); } // Create character selection var blossomBubbles = game.addChild(new Character()); blossomBubbles.name = 'Blossom Bubbles'; blossomBubbles.x = 2048 / 2 - 200; blossomBubbles.y = 2732 / 2; var buttercup = game.addChild(new Character()); buttercup.name = 'Buttercup'; buttercup.x = 2048 / 2 + 200; buttercup.y = 2732 / 2; // Change buttercup color var buttercupGraphics = buttercup.children[0]; buttercupGraphics.tint = 0xFFFF00; function startGame() { gameState = 'pullUp'; // Hide character selection blossomBubbles.visible = false; buttercup.visible = false; // Create current character on hill currentCharacter = game.addChild(new Container()); var characterGraphics = currentCharacter.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); if (selectedCharacter === buttercup) { characterGraphics.tint = 0xFFFF00; } // Create sled sled = game.addChild(new Sled()); // Position character and sled at bottom of hill currentCharacter.x = 200; currentCharacter.y = 2500; sled.x = 230; sled.y = 2510; // Show power meter game.addChild(powerMeterBg); game.addChild(powerMeterFill); // Update instructions instructionTxt.setText('Hold to pull sled up the hill!'); } function resetGame() { gameState = 'characterSelect'; // Clean up game objects if (currentCharacter) { currentCharacter.destroy(); currentCharacter = null; } if (sled) { sled.destroy(); sled = null; } // Hide power meter powerMeterBg.visible = false; powerMeterFill.visible = false; // Reset power pullPower = 0; isPulling = false; // Show character selection again blossomBubbles.visible = true; buttercup.visible = true; if (selectedCharacter) { selectedCharacter.deselect(); } selectedCharacter = null; // Update instructions instructionTxt.setText('Choose your character!'); } // Game input handling game.down = function (x, y, obj) { if (gameState === 'pullUp' && !isPulling) { isPulling = true; pullPower = 0; } }; game.up = function (x, y, obj) { if (gameState === 'pullUp' && isPulling) { isPulling = false; if (pullPower > 10) { // Launch the sled gameState = 'sliding'; sled.launch(pullPower); instructionTxt.setText('Watch the landing!'); // Hide power meter powerMeterBg.visible = false; powerMeterFill.visible = false; } else { // Not enough power, reset pullPower = 0; powerMeterFill.width = 0; } } }; game.update = function () { if (gameState === 'pullUp' && isPulling) { // Build up power pullPower += 1; if (pullPower > 100) pullPower = 100; // Update power meter powerMeterFill.width = pullPower / 100 * 296; // Update power meter color if (pullPower < 30) { powerMeterFill.tint = 0xFF0000; // Red } else if (pullPower < 70) { powerMeterFill.tint = 0xFFFF00; // Yellow } else { powerMeterFill.tint = 0x00FF00; // Green } // Move character and sled up hill based on power if (currentCharacter && sled) { var hillProgress = pullPower / 100; currentCharacter.x = 200 + hillProgress * 1400; currentCharacter.y = 2500 - hillProgress * 1200; sled.x = currentCharacter.x + 30; sled.y = currentCharacter.y + 10; } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.name = '';
self.isSelected = false;
self.select = function () {
self.isSelected = true;
tween(characterGraphics, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 300,
easing: tween.easeOut
});
};
self.deselect = function () {
self.isSelected = false;
tween(characterGraphics, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.easeOut
});
};
self.down = function (x, y, obj) {
if (gameState === 'characterSelect') {
if (selectedCharacter && selectedCharacter !== self) {
selectedCharacter.deselect();
}
selectedCharacter = self;
self.select();
// Start game after character selection
LK.setTimeout(function () {
startGame();
}, 500);
}
};
return self;
});
var Sled = Container.expand(function () {
var self = Container.call(this);
var sledGraphics = self.attachAsset('sled', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.isMoving = false;
self.onHill = true;
self.update = function () {
if (self.isMoving && !self.onHill) {
// Apply gravity
self.velocityY += 0.3;
// Update position
self.x += self.velocityX;
self.y += self.velocityY;
// Check for landing in snow pile
if (self.intersects(snowPile)) {
self.land();
}
// Check if sled went off screen
if (self.y > 2732 + 100) {
self.miss();
}
}
};
self.launch = function (power) {
self.isMoving = true;
self.onHill = false;
self.velocityX = power * 0.15;
self.velocityY = -power * 0.1;
LK.getSound('whoosh').play();
};
self.land = function () {
if (self.isMoving) {
self.isMoving = false;
LK.getSound('landing').play();
LK.setScore(LK.getScore() + 100);
scoreTxt.setText(LK.getScore());
// Flash success
LK.effects.flashObject(snowPile, 0x00FF00, 1000);
// Reset after delay
LK.setTimeout(function () {
resetGame();
}, 2000);
}
};
self.miss = function () {
self.isMoving = false;
// Flash failure
LK.effects.flashScreen(0xFF0000, 500);
// Reset after delay
LK.setTimeout(function () {
resetGame();
}, 1500);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var gameState = 'characterSelect'; // 'characterSelect', 'pullUp', 'sliding'
var selectedCharacter = null;
var currentCharacter = null;
var sled = null;
var pullPower = 0;
var isPulling = false;
var hill = null;
var snowPile = null;
var trees = [];
// Create score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0x000000
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create instruction text
var instructionTxt = new Text2('Choose your character!', {
size: 60,
fill: 0x000000
});
instructionTxt.anchor.set(0.5, 0.5);
instructionTxt.x = 2048 / 2;
instructionTxt.y = 300;
game.addChild(instructionTxt);
// Create power meter background
var powerMeterBg = LK.getAsset('hill', {
width: 300,
height: 30,
color: 0x666666,
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2500
});
// Create power meter fill
var powerMeterFill = LK.getAsset('hill', {
width: 0,
height: 26,
color: 0xFF0000,
anchorX: 0,
anchorY: 0.5,
x: 2048 / 2 - 150,
y: 2500
});
// Create hill
hill = game.addChild(LK.getAsset('hill', {
anchorX: 0,
anchorY: 1,
x: 0,
y: 2732
}));
// Create snow pile at bottom
snowPile = game.addChild(new Container());
var snowPileGraphics = snowPile.attachAsset('snowPile', {
anchorX: 0.5,
anchorY: 0.5
});
snowPile.x = 1700;
snowPile.y = 2600;
// Create decorative trees
for (var i = 0; i < 5; i++) {
var tree = game.addChild(LK.getAsset('tree', {
anchorX: 0.5,
anchorY: 1
}));
tree.x = Math.random() * 1800 + 100;
tree.y = 2732 - Math.random() * 300;
trees.push(tree);
}
// Create character selection
var blossomBubbles = game.addChild(new Character());
blossomBubbles.name = 'Blossom Bubbles';
blossomBubbles.x = 2048 / 2 - 200;
blossomBubbles.y = 2732 / 2;
var buttercup = game.addChild(new Character());
buttercup.name = 'Buttercup';
buttercup.x = 2048 / 2 + 200;
buttercup.y = 2732 / 2;
// Change buttercup color
var buttercupGraphics = buttercup.children[0];
buttercupGraphics.tint = 0xFFFF00;
function startGame() {
gameState = 'pullUp';
// Hide character selection
blossomBubbles.visible = false;
buttercup.visible = false;
// Create current character on hill
currentCharacter = game.addChild(new Container());
var characterGraphics = currentCharacter.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
if (selectedCharacter === buttercup) {
characterGraphics.tint = 0xFFFF00;
}
// Create sled
sled = game.addChild(new Sled());
// Position character and sled at bottom of hill
currentCharacter.x = 200;
currentCharacter.y = 2500;
sled.x = 230;
sled.y = 2510;
// Show power meter
game.addChild(powerMeterBg);
game.addChild(powerMeterFill);
// Update instructions
instructionTxt.setText('Hold to pull sled up the hill!');
}
function resetGame() {
gameState = 'characterSelect';
// Clean up game objects
if (currentCharacter) {
currentCharacter.destroy();
currentCharacter = null;
}
if (sled) {
sled.destroy();
sled = null;
}
// Hide power meter
powerMeterBg.visible = false;
powerMeterFill.visible = false;
// Reset power
pullPower = 0;
isPulling = false;
// Show character selection again
blossomBubbles.visible = true;
buttercup.visible = true;
if (selectedCharacter) {
selectedCharacter.deselect();
}
selectedCharacter = null;
// Update instructions
instructionTxt.setText('Choose your character!');
}
// Game input handling
game.down = function (x, y, obj) {
if (gameState === 'pullUp' && !isPulling) {
isPulling = true;
pullPower = 0;
}
};
game.up = function (x, y, obj) {
if (gameState === 'pullUp' && isPulling) {
isPulling = false;
if (pullPower > 10) {
// Launch the sled
gameState = 'sliding';
sled.launch(pullPower);
instructionTxt.setText('Watch the landing!');
// Hide power meter
powerMeterBg.visible = false;
powerMeterFill.visible = false;
} else {
// Not enough power, reset
pullPower = 0;
powerMeterFill.width = 0;
}
}
};
game.update = function () {
if (gameState === 'pullUp' && isPulling) {
// Build up power
pullPower += 1;
if (pullPower > 100) pullPower = 100;
// Update power meter
powerMeterFill.width = pullPower / 100 * 296;
// Update power meter color
if (pullPower < 30) {
powerMeterFill.tint = 0xFF0000; // Red
} else if (pullPower < 70) {
powerMeterFill.tint = 0xFFFF00; // Yellow
} else {
powerMeterFill.tint = 0x00FF00; // Green
}
// Move character and sled up hill based on power
if (currentCharacter && sled) {
var hillProgress = pullPower / 100;
currentCharacter.x = 200 + hillProgress * 1400;
currentCharacter.y = 2500 - hillProgress * 1200;
sled.x = currentCharacter.x + 30;
sled.y = currentCharacter.y + 10;
}
}
};