/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var PinballGame = Container.expand(function () { var self = Container.call(this); self.isActive = false; self.ball = null; self.paddles = []; self.score = 0; self.ballSpeed = { x: 5, y: 5 }; self.start = function () { self.isActive = true; // Create ball self.ball = self.addChild(LK.getAsset('Balls', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.5, scaleY: 0.5 })); self.ball.x = 1024; self.ball.y = 1366; // Create single paddle var paddle = self.addChild(LK.getAsset('A', { anchorX: 0.5, anchorY: 0.5, scaleX: 4, scaleY: 1 })); paddle.x = 1024; paddle.y = 2200; self.paddles.push(paddle); // Update title to show pinball mode titleText.setText('Game Time!'); }; self.update = function () { if (!self.isActive || !self.ball) return; // Move ball self.ball.x += self.ballSpeed.x; self.ball.y += self.ballSpeed.y; // Bounce off walls if (self.ball.x <= 50 || self.ball.x >= 1998) { self.ballSpeed.x = -self.ballSpeed.x; } if (self.ball.y <= 50) { self.ballSpeed.y = -self.ballSpeed.y; } // Check paddle collisions for (var i = 0; i < self.paddles.length; i++) { if (self.ball.intersects(self.paddles[i])) { self.ballSpeed.y = -Math.abs(self.ballSpeed.y); // Always bounce up self.score += 10; // Play bounce sound LK.getSound('Sound').play(); } } // Ball falls off bottom - game over if (self.ball.y > 2732) { self.stop(); } }; self.move = function (x, y, obj) { if (self.isActive && self.paddles.length > 0) { // Move paddle to follow finger position self.paddles[0].x = x; // Keep paddle within screen bounds if (self.paddles[0].x < 100) self.paddles[0].x = 100; if (self.paddles[0].x > 1948) self.paddles[0].x = 1948; } }; self.stop = function () { self.isActive = false; if (self.ball) { self.removeChild(self.ball); self.ball = null; } for (var i = 0; i < self.paddles.length; i++) { self.removeChild(self.paddles[i]); } self.paddles = []; titleText.setText('Johnathan T. Mantleholder'); }; return self; }); var TransformButton = Container.expand(function () { var self = Container.call(this); // Array of button states self.buttonStates = ['button1']; self.soundStates = ['Sound']; self.currentState = 0; // Create initial button graphics self.buttonGraphics = self.attachAsset(self.buttonStates[0], { anchorX: 0.5, anchorY: 0.5, scaleX: 2.0, scaleY: 2.0 }); self.transformToNext = function () { // Add shrinking animation tween(self.buttonGraphics, { scaleX: 1.5, scaleY: 1.5 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { // Return to full size tween(self.buttonGraphics, { scaleX: 2.0, scaleY: 2.0 }, { duration: 100, easing: tween.easeOut }); } }); // Cycle to next state self.currentState = (self.currentState + 1) % self.buttonStates.length; // Remove current graphics self.removeChild(self.buttonGraphics); // Add new graphics self.buttonGraphics = self.attachAsset(self.buttonStates[self.currentState], { anchorX: 0.5, anchorY: 0.5, scaleX: 2.0, scaleY: 2.0 }); // Play corresponding sound LK.getSound(self.soundStates[self.currentState]).play(); }; self.down = function (x, y, obj) { // Track click time var currentTime = Date.now(); clickTimes.push(currentTime); // Keep only clicks from the last second clickTimes = clickTimes.filter(function (time) { return currentTime - time <= 1000; }); // Check if we have 7 clicks in the last second if (clickTimes.length >= 7 && !hasTriggeredSpecialMode) { hasTriggeredSpecialMode = true; // Play music LK.playMusic('Music'); // Change text to "Johnathan T. Mantleholder" titleText.setText('Johnathan T. Mantleholder'); } // Pattern detection logic (only active after special mode is triggered) if (hasTriggeredSpecialMode) { // Check if enough time has passed since last click to consider this a new pattern step var timeSinceLastClick = currentTime - lastClickTime; var expectedClicks = patternSequence[currentPatternStep]; var isRapidClickStep = currentPatternStep === 3; // Last step requires rapid clicks if (timeSinceLastClick > waitThreshold && patternClickCount > 0) { // We've waited long enough, check if previous step was completed correctly if (patternClickCount === expectedClicks) { currentPatternStep++; patternClickCount = 0; if (currentPatternStep >= patternSequence.length) { // Pattern completed! Start pinball game with 1 second delay LK.setTimeout(function () { startPinballGame(); }, 1000); // Reset pattern tracking currentPatternStep = 0; patternClickCount = 0; } } else { // Wrong number of clicks, reset pattern currentPatternStep = 0; patternClickCount = 0; } } // Count this click for current pattern step patternClickCount++; lastClickTime = currentTime; // For rapid click step, check timing between clicks if (isRapidClickStep && patternClickCount > 1) { if (timeSinceLastClick > rapidClickThreshold) { // Too slow between rapid clicks, reset pattern currentPatternStep = 0; patternClickCount = 0; } } } self.transformToNext(); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c3e50 }); /**** * Game Code ****/ // Add background var background = game.addChild(LK.getAsset('Background', { anchorX: 0, anchorY: 0, scaleX: 20.48, scaleY: 27.32 })); background.x = 0; background.y = 0; // Start continuous floating animation for background function startBackgroundFloatingAnimation() { tween(background, { x: -50 }, { duration: 4000, easing: tween.easeInOut, onFinish: function onFinish() { tween(background, { x: 0 }, { duration: 4000, easing: tween.easeInOut, onFinish: startBackgroundFloatingAnimation }); } }); } // Start the background floating animation startBackgroundFloatingAnimation(); // Click tracking variables var clickTimes = []; var hasTriggeredSpecialMode = false; // Pattern tracking variables for pinball sequence var patternSequence = [1, 2, 2, 5]; // Expected pattern: 1 click, wait, 2 clicks, wait, 2 clicks, wait, 5 clicks var currentPatternStep = 0; var patternClickCount = 0; var lastClickTime = 0; var waitThreshold = 500; // 0.5 second wait between pattern steps var rapidClickThreshold = 500; // Max time between rapid clicks (for the "5 quickly" part) // Create title text var titleText = new Text2('John Mantle', { size: 120, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0.5); titleText.x = 2048 / 2; titleText.y = 2732 / 2 - 400; game.addChild(titleText); // Create the transform button var transformButton = game.addChild(new TransformButton()); // Position button at center of screen transformButton.x = 2048 / 2; transformButton.y = 2732 / 2; // Start continuous up and down movement animation function startFloatingAnimation() { tween(transformButton, { y: transformButton.y - 50 }, { duration: 800, easing: tween.easeInOut, onFinish: function onFinish() { tween(transformButton, { y: transformButton.y + 50 }, { duration: 800, easing: tween.easeInOut, onFinish: startFloatingAnimation }); } }); } // Start the floating animation startFloatingAnimation(); // Create pinball game instance var pinballGame = game.addChild(new PinballGame()); // Function to start pinball game function startPinballGame() { pinballGame.start(); } game.move = function (x, y, obj) { // Delegate move events to pinball game pinballGame.move(x, y, obj); }; game.update = function () { // Update pinball game if active pinballGame.update(); };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var PinballGame = Container.expand(function () {
var self = Container.call(this);
self.isActive = false;
self.ball = null;
self.paddles = [];
self.score = 0;
self.ballSpeed = {
x: 5,
y: 5
};
self.start = function () {
self.isActive = true;
// Create ball
self.ball = self.addChild(LK.getAsset('Balls', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.5,
scaleY: 0.5
}));
self.ball.x = 1024;
self.ball.y = 1366;
// Create single paddle
var paddle = self.addChild(LK.getAsset('A', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1
}));
paddle.x = 1024;
paddle.y = 2200;
self.paddles.push(paddle);
// Update title to show pinball mode
titleText.setText('Game Time!');
};
self.update = function () {
if (!self.isActive || !self.ball) return;
// Move ball
self.ball.x += self.ballSpeed.x;
self.ball.y += self.ballSpeed.y;
// Bounce off walls
if (self.ball.x <= 50 || self.ball.x >= 1998) {
self.ballSpeed.x = -self.ballSpeed.x;
}
if (self.ball.y <= 50) {
self.ballSpeed.y = -self.ballSpeed.y;
}
// Check paddle collisions
for (var i = 0; i < self.paddles.length; i++) {
if (self.ball.intersects(self.paddles[i])) {
self.ballSpeed.y = -Math.abs(self.ballSpeed.y); // Always bounce up
self.score += 10;
// Play bounce sound
LK.getSound('Sound').play();
}
}
// Ball falls off bottom - game over
if (self.ball.y > 2732) {
self.stop();
}
};
self.move = function (x, y, obj) {
if (self.isActive && self.paddles.length > 0) {
// Move paddle to follow finger position
self.paddles[0].x = x;
// Keep paddle within screen bounds
if (self.paddles[0].x < 100) self.paddles[0].x = 100;
if (self.paddles[0].x > 1948) self.paddles[0].x = 1948;
}
};
self.stop = function () {
self.isActive = false;
if (self.ball) {
self.removeChild(self.ball);
self.ball = null;
}
for (var i = 0; i < self.paddles.length; i++) {
self.removeChild(self.paddles[i]);
}
self.paddles = [];
titleText.setText('Johnathan T. Mantleholder');
};
return self;
});
var TransformButton = Container.expand(function () {
var self = Container.call(this);
// Array of button states
self.buttonStates = ['button1'];
self.soundStates = ['Sound'];
self.currentState = 0;
// Create initial button graphics
self.buttonGraphics = self.attachAsset(self.buttonStates[0], {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2.0,
scaleY: 2.0
});
self.transformToNext = function () {
// Add shrinking animation
tween(self.buttonGraphics, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
// Return to full size
tween(self.buttonGraphics, {
scaleX: 2.0,
scaleY: 2.0
}, {
duration: 100,
easing: tween.easeOut
});
}
});
// Cycle to next state
self.currentState = (self.currentState + 1) % self.buttonStates.length;
// Remove current graphics
self.removeChild(self.buttonGraphics);
// Add new graphics
self.buttonGraphics = self.attachAsset(self.buttonStates[self.currentState], {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2.0,
scaleY: 2.0
});
// Play corresponding sound
LK.getSound(self.soundStates[self.currentState]).play();
};
self.down = function (x, y, obj) {
// Track click time
var currentTime = Date.now();
clickTimes.push(currentTime);
// Keep only clicks from the last second
clickTimes = clickTimes.filter(function (time) {
return currentTime - time <= 1000;
});
// Check if we have 7 clicks in the last second
if (clickTimes.length >= 7 && !hasTriggeredSpecialMode) {
hasTriggeredSpecialMode = true;
// Play music
LK.playMusic('Music');
// Change text to "Johnathan T. Mantleholder"
titleText.setText('Johnathan T. Mantleholder');
}
// Pattern detection logic (only active after special mode is triggered)
if (hasTriggeredSpecialMode) {
// Check if enough time has passed since last click to consider this a new pattern step
var timeSinceLastClick = currentTime - lastClickTime;
var expectedClicks = patternSequence[currentPatternStep];
var isRapidClickStep = currentPatternStep === 3; // Last step requires rapid clicks
if (timeSinceLastClick > waitThreshold && patternClickCount > 0) {
// We've waited long enough, check if previous step was completed correctly
if (patternClickCount === expectedClicks) {
currentPatternStep++;
patternClickCount = 0;
if (currentPatternStep >= patternSequence.length) {
// Pattern completed! Start pinball game with 1 second delay
LK.setTimeout(function () {
startPinballGame();
}, 1000);
// Reset pattern tracking
currentPatternStep = 0;
patternClickCount = 0;
}
} else {
// Wrong number of clicks, reset pattern
currentPatternStep = 0;
patternClickCount = 0;
}
}
// Count this click for current pattern step
patternClickCount++;
lastClickTime = currentTime;
// For rapid click step, check timing between clicks
if (isRapidClickStep && patternClickCount > 1) {
if (timeSinceLastClick > rapidClickThreshold) {
// Too slow between rapid clicks, reset pattern
currentPatternStep = 0;
patternClickCount = 0;
}
}
}
self.transformToNext();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Add background
var background = game.addChild(LK.getAsset('Background', {
anchorX: 0,
anchorY: 0,
scaleX: 20.48,
scaleY: 27.32
}));
background.x = 0;
background.y = 0;
// Start continuous floating animation for background
function startBackgroundFloatingAnimation() {
tween(background, {
x: -50
}, {
duration: 4000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(background, {
x: 0
}, {
duration: 4000,
easing: tween.easeInOut,
onFinish: startBackgroundFloatingAnimation
});
}
});
}
// Start the background floating animation
startBackgroundFloatingAnimation();
// Click tracking variables
var clickTimes = [];
var hasTriggeredSpecialMode = false;
// Pattern tracking variables for pinball sequence
var patternSequence = [1, 2, 2, 5]; // Expected pattern: 1 click, wait, 2 clicks, wait, 2 clicks, wait, 5 clicks
var currentPatternStep = 0;
var patternClickCount = 0;
var lastClickTime = 0;
var waitThreshold = 500; // 0.5 second wait between pattern steps
var rapidClickThreshold = 500; // Max time between rapid clicks (for the "5 quickly" part)
// Create title text
var titleText = new Text2('John Mantle', {
size: 120,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 2732 / 2 - 400;
game.addChild(titleText);
// Create the transform button
var transformButton = game.addChild(new TransformButton());
// Position button at center of screen
transformButton.x = 2048 / 2;
transformButton.y = 2732 / 2;
// Start continuous up and down movement animation
function startFloatingAnimation() {
tween(transformButton, {
y: transformButton.y - 50
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(transformButton, {
y: transformButton.y + 50
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: startFloatingAnimation
});
}
});
}
// Start the floating animation
startFloatingAnimation();
// Create pinball game instance
var pinballGame = game.addChild(new PinballGame());
// Function to start pinball game
function startPinballGame() {
pinballGame.start();
}
game.move = function (x, y, obj) {
// Delegate move events to pinball game
pinballGame.move(x, y, obj);
};
game.update = function () {
// Update pinball game if active
pinballGame.update();
};