User prompt
create a function to make a text element pulse ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (5 edits merged)
Please save this source code
User prompt
center the text
User prompt
put the phase instruction text on 2 lines
User prompt
put a black outline to the hitzone labels
User prompt
put a black outline to the text of the phase instructions
User prompt
make the phase instructions bigger
User prompt
use arial black font
User prompt
use glowworm font
User prompt
lower it again
User prompt
lower the volume of the electronic beat, rock anthem, jazz fusion, hip hop and 8 bit
User prompt
remove the auto end game, only triger end game after phase 3
User prompt
display the final score after phase 3
User prompt
why is the ai phase not working anymore?
User prompt
lower the volume of the music during the phases 1-2-3 by about half
User prompt
why does it still not animate
Code edit (1 edits merged)
Please save this source code
User prompt
make it pulse ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
a bit higher, centered between the title and the first button
User prompt
lower
User prompt
lower the song selection instruction
User prompt
increase the space between the buttons and the titel
User prompt
add some space between the select song instruction and the tittle and buttons
User prompt
import tween module ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
make the instructions pulse ↪💡 Consider importing and using the following plugins: @upit/tween.v1
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Note = Container.expand(function (beat, track) { var self = Container.call(this); var noteGraphics = self.attachAsset('note', { anchorX: 0.5, anchorY: 0.5 }); self.beat = beat; self.track = track; self.speed = 4; self.hit = false; self.missed = false; self.scaledUp = false; self.update = function () { self.y += self.speed; // Check if note is entering hit zone (scale up) if (!self.scaledUp && self.y >= hitZoneY - 150 && self.y <= hitZoneY + 150) { self.scaledUp = true; tween(noteGraphics, { scaleX: 1.5, scaleY: 1.5 }, { duration: 300, easing: tween.easeOut }); } // Check if note passed hit zone without being hit if (!self.hit && !self.missed && self.y > hitZoneY + 100) { self.missed = true; missedNotes++; } }; return self; }); var SongButton = Container.expand(function (songId, songName, yPos) { var self = Container.call(this); var buttonBg = self.attachAsset('songButton', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.875, scaleY: 1.875 }); var buttonText = new Text2(songName, { size: 50, fill: '#e4f4f5', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma", stroke: '#000000', strokeThickness: 3 }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.songId = songId; self.x = 1024; self.y = yPos; self.down = function (x, y, obj) { selectSong(self.songId); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1A1A2E }); /**** * Game Code ****/ // Game states var GAME_STATE = { SONG_SELECT: 0, PATTERN_CREATE: 1, PATTERN_RECREATE: 2, AI_CHALLENGE: 3, GAME_OVER: 4 }; var currentState = GAME_STATE.SONG_SELECT; var selectedSong = null; var currentMusic = null; // Pattern data var playerPattern = []; var currentPattern = []; var patternStartTime = 0; var passNumber = 1; // Timing variables var bpm = 120; var beatDuration = 60000 / bpm; // milliseconds per beat var songStartTime = 0; var lastBeatTime = 0; // Game objects var notes = []; var tracks = []; var hitZones = []; var uiElements = []; // Scoring var score = 0; var hitNotes = 0; var missedNotes = 0; // Track positions - spaced wider to prevent hit zone overlap var trackPositions = [350, 650, 950, 1250, 1550]; var hitZoneY = 2200; // UI Title elements var titleText = LK.getAsset('Title', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 550 }); var instructionText = new Text2('Select a Song', { size: 80, fill: '#ECFF86', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); instructionText.anchor.set(0.5, 0.5); instructionText.x = 1024; instructionText.y = 750; // Add pulsing animation to instruction text tween(instructionText, { scaleX: 1.1, scaleY: 1.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(instructionText, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { // Restart the pulse cycle if (instructionText.parent) { tween(instructionText, { scaleX: 1.1, scaleY: 1.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: arguments.callee }); } } }); } }); var scoreText = new Text2('Score: 0', { size: 60, fill: '#FFFFFF', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); scoreText.anchor.set(0.5, 0); var passText = new Text2('Pass 1/3', { size: 40, fill: '#FFFFFF', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); passText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); LK.gui.topRight.addChild(passText); passText.x = -150; passText.y = 20; // Initialize game elements function initializeGame() { // Create background var bg = game.addChild(LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 })); // Create tracks for (var i = 0; i < trackPositions.length; i++) { var track = game.addChild(LK.getAsset('trackLine', { anchorX: 0.5, anchorY: 0, x: trackPositions[i], y: 0 })); track.alpha = 0.3; tracks.push(track); } // Create hit zones var hitZoneLabels = ['Sound', 'Cymbal', 'Drumkick', 'Base', 'Shaker']; for (var i = 0; i < trackPositions.length; i++) { var hitZone = game.addChild(LK.getAsset('hitZone', { anchorX: 0.5, anchorY: 0.5, x: trackPositions[i], y: hitZoneY })); hitZone.alpha = 0; hitZones.push(hitZone); // Add text label for each hit zone var hitZoneText = new Text2(hitZoneLabels[i], { size: 48, fill: '#FFFFFF', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); hitZoneText.anchor.set(0.5, 0.5); hitZoneText.x = trackPositions[i]; hitZoneText.y = hitZoneY + 80; hitZoneText.alpha = 0; game.addChild(hitZoneText); hitZones.push(hitZoneText); } showSongSelection(); } function showSongSelection() { currentState = GAME_STATE.SONG_SELECT; game.addChild(titleText); game.addChild(instructionText); // Play menu music LK.playMusic('menu_music'); // Create song buttons with much increased spacing var songButton1 = game.addChild(new SongButton('song1', 'Electronic Beat', 900)); var songButton2 = game.addChild(new SongButton('song2', 'Rock Anthem', 1200)); var songButton3 = game.addChild(new SongButton('song3', 'Jazz Fusion', 1500)); var songButton4 = game.addChild(new SongButton('song4', 'Hip Hop', 1800)); var songButton5 = game.addChild(new SongButton('song5', '8-Bit', 2100)); uiElements.push(songButton1, songButton2, songButton3, songButton4, songButton5); } function selectSong(songId) { // Stop menu music LK.stopMusic(); // Map song IDs to actual music asset names var songMapping = { 'song1': 'electronic_beat', 'song2': 'rock_anthem', 'song3': 'jazz', 'song4': 'hip_hop', 'song5': 'eight_bit' }; selectedSong = songMapping[songId]; // Animate hit zones to visible for (var i = 0; i < hitZones.length; i++) { tween(hitZones[i], { alpha: 1 }, { duration: 500, easing: tween.easeOut }); } // Clear UI elements for (var i = 0; i < uiElements.length; i++) { uiElements[i].destroy(); } uiElements = []; titleText.destroy(); instructionText.destroy(); startPatternCreation(); } function startPatternCreation() { currentState = GAME_STATE.PATTERN_CREATE; passNumber = 1; updatePassText(); var createText = new Text2('Tap to create your rhythm pattern!', { size: 70, fill: '#ECFF86', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); createText.anchor.set(0.5, 0.5); createText.x = 1024; createText.y = 400; game.addChild(createText); uiElements.push(createText); // Add pulsing animation to instruction text tween(createText, { scaleX: 1.1, scaleY: 1.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(createText, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { // Restart the pulse cycle if (createText.parent) { tween(createText, { scaleX: 1.1, scaleY: 1.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: arguments.callee }); } } }); } }); showCountdown(function () { // Start music currentMusic = selectedSong; LK.playMusic(selectedSong); songStartTime = Date.now(); patternStartTime = songStartTime; playerPattern = []; // Auto advance after 30 seconds LK.setTimeout(function () { if (currentState === GAME_STATE.PATTERN_CREATE) { startPatternRecreation(); } }, 30000); }); } function startPatternRecreation() { currentState = GAME_STATE.PATTERN_RECREATE; passNumber = 2; updatePassText(); // Clear UI for (var i = 0; i < uiElements.length; i++) { uiElements[i].destroy(); } uiElements = []; var recreateText = new Text2('Recreate your pattern!', { size: 70, fill: '#ECFF86', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); recreateText.anchor.set(0.5, 0.5); recreateText.x = 1024; recreateText.y = 400; game.addChild(recreateText); uiElements.push(recreateText); // Add pulsing animation to instruction text tween(recreateText, { scaleX: 1.1, scaleY: 1.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(recreateText, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { // Restart the pulse cycle if (recreateText.parent) { tween(recreateText, { scaleX: 1.1, scaleY: 1.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: arguments.callee }); } } }); } }); showCountdown(function () { // Restart music and prepare pattern LK.stopMusic(); LK.setTimeout(function () { LK.playMusic(selectedSong); songStartTime = Date.now(); currentPattern = playerPattern.slice(); spawnNotesForPattern(); }, 100); // Auto advance after pattern completion + buffer LK.setTimeout(function () { if (currentState === GAME_STATE.PATTERN_RECREATE) { startAIChallenge(); } }, 35000); }); } function startAIChallenge() { currentState = GAME_STATE.AI_CHALLENGE; passNumber = 3; updatePassText(); // Clear UI for (var i = 0; i < uiElements.length; i++) { uiElements[i].destroy(); } uiElements = []; var challengeText = new Text2('AI Enhanced Challenge!', { size: 70, fill: '#FF6B6B', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); challengeText.anchor.set(0.5, 0.5); challengeText.x = 1024; challengeText.y = 400; game.addChild(challengeText); uiElements.push(challengeText); // Add pulsing animation to instruction text tween(challengeText, { scaleX: 1.1, scaleY: 1.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(challengeText, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { // Restart the pulse cycle if (challengeText.parent) { tween(challengeText, { scaleX: 1.1, scaleY: 1.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: arguments.callee }); } } }); } }); // Add AI beats to pattern var enhancedPattern = playerPattern.slice(); var aiPercentage = Math.random() * 0.10 + 0.10; // Random between 10% and 20% var aiBeats = Math.floor(playerPattern.length * aiPercentage); for (var i = 0; i < aiBeats; i++) { var randomTime = Math.random() * 30000; // Random time within 30 seconds var randomTrack = Math.floor(Math.random() * trackPositions.length); enhancedPattern.push({ time: randomTime, track: randomTrack, isAI: true }); } // Sort by time enhancedPattern.sort(function (a, b) { return a.time - b.time; }); showCountdown(function () { // Restart music LK.stopMusic(); LK.setTimeout(function () { LK.playMusic(selectedSong); songStartTime = Date.now(); currentPattern = enhancedPattern; spawnNotesForPattern(); }, 100); // Auto end after completion LK.setTimeout(function () { if (currentState === GAME_STATE.AI_CHALLENGE) { endGame(); } }, 40000); }); } function spawnNotesForPattern() { for (var i = 0; i < currentPattern.length; i++) { var beat = currentPattern[i]; var spawnTime = beat.time - 2000; // Spawn 2 seconds before hit time LK.setTimeout(function (beatData) { return function () { if (currentState === GAME_STATE.PATTERN_RECREATE || currentState === GAME_STATE.AI_CHALLENGE) { var note = new Note(beatData, beatData.track); note.x = trackPositions[beatData.track]; note.y = -50; if (beatData.isAI) { note.attachAsset('note', {}).tint = 0xFF6B6B; // Red for AI beats } game.addChild(note); notes.push(note); } }; }(beat), Math.max(0, spawnTime)); } } function updatePassText() { passText.setText('Pass ' + passNumber + '/3'); } function showCountdown(callback) { var countdownText = new Text2('3', { size: 200, fill: '#FF6B6B', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); countdownText.anchor.set(0.5, 0.5); countdownText.x = 1024; countdownText.y = 1366; countdownText.alpha = 0; game.addChild(countdownText); // Animate countdown from 3 to 1 var count = 3; function animateCount() { countdownText.setText(count.toString()); countdownText.alpha = 1; countdownText.scaleX = 2; countdownText.scaleY = 2; tween(countdownText, { scaleX: 1, scaleY: 1, alpha: 0 }, { duration: 800, easing: tween.easeOut, onFinish: function onFinish() { count--; if (count > 0) { animateCount(); } else { // Show "GO!" for final countdown countdownText.setText('GO!'); countdownText.alpha = 1; countdownText.scaleX = 2; countdownText.scaleY = 2; tween(countdownText, { scaleX: 1, scaleY: 1, alpha: 0 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { countdownText.destroy(); callback(); } }); } } }); } animateCount(); } function updateScore(points) { score += points; scoreText.setText('Score: ' + score); } function endGame() { currentState = GAME_STATE.GAME_OVER; LK.stopMusic(); var accuracy = hitNotes > 0 ? Math.round(hitNotes / (hitNotes + missedNotes) * 100) : 0; LK.setScore(score); // Show final score and return to main menu var finalScoreText = new Text2('Final Score: ' + score + '\nAccuracy: ' + accuracy + '%', { size: 60, fill: '#FFFFFF', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); finalScoreText.anchor.set(0.5, 0.5); finalScoreText.x = 1024; finalScoreText.y = 1200; game.addChild(finalScoreText); // Remove final score after 5 seconds and then show menu LK.setTimeout(function () { if (finalScoreText && finalScoreText.parent) { tween(finalScoreText, { alpha: 0 }, { duration: 500, onFinish: function onFinish() { finalScoreText.destroy(); // Show menu after final score disappears resetGame(); } }); } }, 5000); } function resetGame() { // Clear all game objects for (var i = notes.length - 1; i >= 0; i--) { notes[i].destroy(); } notes = []; for (var i = 0; i < uiElements.length; i++) { uiElements[i].destroy(); } uiElements = []; // Reset hit zones to invisible for (var i = 0; i < hitZones.length; i++) { tween(hitZones[i], { alpha: 0 }, { duration: 300, easing: tween.easeOut }); } // Reset game variables playerPattern = []; currentPattern = []; passNumber = 1; score = 0; hitNotes = 0; missedNotes = 0; selectedSong = null; currentMusic = null; // Clear score display scoreText.setText('Score: 0'); // Return to song selection showSongSelection(); } function handleTap(x, y) { var currentTime = Date.now(); if (currentState === GAME_STATE.PATTERN_CREATE) { // Record tap in pattern var relativeTime = currentTime - patternStartTime; var nearestTrack = findNearestTrack(x); playerPattern.push({ time: relativeTime, track: nearestTrack, isAI: false }); LK.getSound('hit_track' + nearestTrack).play(); // Visual feedback var hitZone = hitZones[nearestTrack]; tween(hitZone, { scaleX: 1.2, scaleY: 1.2 }, { duration: 100 }); tween(hitZone, { scaleX: 1, scaleY: 1 }, { duration: 100 }); } else if (currentState === GAME_STATE.PATTERN_RECREATE || currentState === GAME_STATE.AI_CHALLENGE) { // Check for note hits var nearestTrack = findNearestTrack(x); var hitNote = null; var minDistance = Infinity; for (var i = 0; i < notes.length; i++) { var note = notes[i]; if (!note.hit && !note.missed && note.track === nearestTrack) { var distance = Math.abs(note.y - hitZoneY); if (distance < minDistance && distance < 100) { minDistance = distance; hitNote = note; } } } if (hitNote) { hitNote.hit = true; hitNotes++; var points = Math.max(10, 100 - Math.floor(minDistance)); updateScore(points); LK.getSound('hit_track' + nearestTrack).play(); // Visual feedback tween(hitNote, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 200 }); LK.setTimeout(function () { if (hitNote && hitNote.parent) { hitNote.destroy(); var index = notes.indexOf(hitNote); if (index > -1) notes.splice(index, 1); } }, 200); } else { LK.getSound('miss').play(); } } } function findNearestTrack(x) { var minDistance = Infinity; var nearestTrack = 0; for (var i = 0; i < trackPositions.length; i++) { var distance = Math.abs(x - trackPositions[i]); if (distance < minDistance) { minDistance = distance; nearestTrack = i; } } return nearestTrack; } // Event handlers game.down = function (x, y, obj) { handleTap(x, y); }; game.update = function () { // Update notes for (var i = notes.length - 1; i >= 0; i--) { var note = notes[i]; // Remove notes that are off screen if (note.y > 2800) { note.destroy(); notes.splice(i, 1); } } // Check if song is finished and all notes are cleared if ((currentState === GAME_STATE.PATTERN_RECREATE || currentState === GAME_STATE.AI_CHALLENGE) && notes.length === 0 && currentPattern.length > 0 && Date.now() - songStartTime > 35000) { endGame(); } // Check for missed notes and update score display if (LK.ticks % 60 === 0) { // Update every second scoreText.setText('Score: ' + score); } }; // Initialize the game initializeGame();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Note = Container.expand(function (beat, track) {
var self = Container.call(this);
var noteGraphics = self.attachAsset('note', {
anchorX: 0.5,
anchorY: 0.5
});
self.beat = beat;
self.track = track;
self.speed = 4;
self.hit = false;
self.missed = false;
self.scaledUp = false;
self.update = function () {
self.y += self.speed;
// Check if note is entering hit zone (scale up)
if (!self.scaledUp && self.y >= hitZoneY - 150 && self.y <= hitZoneY + 150) {
self.scaledUp = true;
tween(noteGraphics, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 300,
easing: tween.easeOut
});
}
// Check if note passed hit zone without being hit
if (!self.hit && !self.missed && self.y > hitZoneY + 100) {
self.missed = true;
missedNotes++;
}
};
return self;
});
var SongButton = Container.expand(function (songId, songName, yPos) {
var self = Container.call(this);
var buttonBg = self.attachAsset('songButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.875,
scaleY: 1.875
});
var buttonText = new Text2(songName, {
size: 50,
fill: '#e4f4f5',
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
stroke: '#000000',
strokeThickness: 3
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.songId = songId;
self.x = 1024;
self.y = yPos;
self.down = function (x, y, obj) {
selectSong(self.songId);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1A1A2E
});
/****
* Game Code
****/
// Game states
var GAME_STATE = {
SONG_SELECT: 0,
PATTERN_CREATE: 1,
PATTERN_RECREATE: 2,
AI_CHALLENGE: 3,
GAME_OVER: 4
};
var currentState = GAME_STATE.SONG_SELECT;
var selectedSong = null;
var currentMusic = null;
// Pattern data
var playerPattern = [];
var currentPattern = [];
var patternStartTime = 0;
var passNumber = 1;
// Timing variables
var bpm = 120;
var beatDuration = 60000 / bpm; // milliseconds per beat
var songStartTime = 0;
var lastBeatTime = 0;
// Game objects
var notes = [];
var tracks = [];
var hitZones = [];
var uiElements = [];
// Scoring
var score = 0;
var hitNotes = 0;
var missedNotes = 0;
// Track positions - spaced wider to prevent hit zone overlap
var trackPositions = [350, 650, 950, 1250, 1550];
var hitZoneY = 2200;
// UI Title elements
var titleText = LK.getAsset('Title', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 550
});
var instructionText = new Text2('Select a Song', {
size: 80,
fill: '#ECFF86',
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 750;
// Add pulsing animation to instruction text
tween(instructionText, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(instructionText, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Restart the pulse cycle
if (instructionText.parent) {
tween(instructionText, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: arguments.callee
});
}
}
});
}
});
var scoreText = new Text2('Score: 0', {
size: 60,
fill: '#FFFFFF',
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
scoreText.anchor.set(0.5, 0);
var passText = new Text2('Pass 1/3', {
size: 40,
fill: '#FFFFFF',
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
passText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
LK.gui.topRight.addChild(passText);
passText.x = -150;
passText.y = 20;
// Initialize game elements
function initializeGame() {
// Create background
var bg = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Create tracks
for (var i = 0; i < trackPositions.length; i++) {
var track = game.addChild(LK.getAsset('trackLine', {
anchorX: 0.5,
anchorY: 0,
x: trackPositions[i],
y: 0
}));
track.alpha = 0.3;
tracks.push(track);
}
// Create hit zones
var hitZoneLabels = ['Sound', 'Cymbal', 'Drumkick', 'Base', 'Shaker'];
for (var i = 0; i < trackPositions.length; i++) {
var hitZone = game.addChild(LK.getAsset('hitZone', {
anchorX: 0.5,
anchorY: 0.5,
x: trackPositions[i],
y: hitZoneY
}));
hitZone.alpha = 0;
hitZones.push(hitZone);
// Add text label for each hit zone
var hitZoneText = new Text2(hitZoneLabels[i], {
size: 48,
fill: '#FFFFFF',
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
hitZoneText.anchor.set(0.5, 0.5);
hitZoneText.x = trackPositions[i];
hitZoneText.y = hitZoneY + 80;
hitZoneText.alpha = 0;
game.addChild(hitZoneText);
hitZones.push(hitZoneText);
}
showSongSelection();
}
function showSongSelection() {
currentState = GAME_STATE.SONG_SELECT;
game.addChild(titleText);
game.addChild(instructionText);
// Play menu music
LK.playMusic('menu_music');
// Create song buttons with much increased spacing
var songButton1 = game.addChild(new SongButton('song1', 'Electronic Beat', 900));
var songButton2 = game.addChild(new SongButton('song2', 'Rock Anthem', 1200));
var songButton3 = game.addChild(new SongButton('song3', 'Jazz Fusion', 1500));
var songButton4 = game.addChild(new SongButton('song4', 'Hip Hop', 1800));
var songButton5 = game.addChild(new SongButton('song5', '8-Bit', 2100));
uiElements.push(songButton1, songButton2, songButton3, songButton4, songButton5);
}
function selectSong(songId) {
// Stop menu music
LK.stopMusic();
// Map song IDs to actual music asset names
var songMapping = {
'song1': 'electronic_beat',
'song2': 'rock_anthem',
'song3': 'jazz',
'song4': 'hip_hop',
'song5': 'eight_bit'
};
selectedSong = songMapping[songId];
// Animate hit zones to visible
for (var i = 0; i < hitZones.length; i++) {
tween(hitZones[i], {
alpha: 1
}, {
duration: 500,
easing: tween.easeOut
});
}
// Clear UI elements
for (var i = 0; i < uiElements.length; i++) {
uiElements[i].destroy();
}
uiElements = [];
titleText.destroy();
instructionText.destroy();
startPatternCreation();
}
function startPatternCreation() {
currentState = GAME_STATE.PATTERN_CREATE;
passNumber = 1;
updatePassText();
var createText = new Text2('Tap to create your rhythm pattern!', {
size: 70,
fill: '#ECFF86',
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
createText.anchor.set(0.5, 0.5);
createText.x = 1024;
createText.y = 400;
game.addChild(createText);
uiElements.push(createText);
// Add pulsing animation to instruction text
tween(createText, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(createText, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Restart the pulse cycle
if (createText.parent) {
tween(createText, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: arguments.callee
});
}
}
});
}
});
showCountdown(function () {
// Start music
currentMusic = selectedSong;
LK.playMusic(selectedSong);
songStartTime = Date.now();
patternStartTime = songStartTime;
playerPattern = [];
// Auto advance after 30 seconds
LK.setTimeout(function () {
if (currentState === GAME_STATE.PATTERN_CREATE) {
startPatternRecreation();
}
}, 30000);
});
}
function startPatternRecreation() {
currentState = GAME_STATE.PATTERN_RECREATE;
passNumber = 2;
updatePassText();
// Clear UI
for (var i = 0; i < uiElements.length; i++) {
uiElements[i].destroy();
}
uiElements = [];
var recreateText = new Text2('Recreate your pattern!', {
size: 70,
fill: '#ECFF86',
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
recreateText.anchor.set(0.5, 0.5);
recreateText.x = 1024;
recreateText.y = 400;
game.addChild(recreateText);
uiElements.push(recreateText);
// Add pulsing animation to instruction text
tween(recreateText, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(recreateText, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Restart the pulse cycle
if (recreateText.parent) {
tween(recreateText, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: arguments.callee
});
}
}
});
}
});
showCountdown(function () {
// Restart music and prepare pattern
LK.stopMusic();
LK.setTimeout(function () {
LK.playMusic(selectedSong);
songStartTime = Date.now();
currentPattern = playerPattern.slice();
spawnNotesForPattern();
}, 100);
// Auto advance after pattern completion + buffer
LK.setTimeout(function () {
if (currentState === GAME_STATE.PATTERN_RECREATE) {
startAIChallenge();
}
}, 35000);
});
}
function startAIChallenge() {
currentState = GAME_STATE.AI_CHALLENGE;
passNumber = 3;
updatePassText();
// Clear UI
for (var i = 0; i < uiElements.length; i++) {
uiElements[i].destroy();
}
uiElements = [];
var challengeText = new Text2('AI Enhanced Challenge!', {
size: 70,
fill: '#FF6B6B',
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
challengeText.anchor.set(0.5, 0.5);
challengeText.x = 1024;
challengeText.y = 400;
game.addChild(challengeText);
uiElements.push(challengeText);
// Add pulsing animation to instruction text
tween(challengeText, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(challengeText, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Restart the pulse cycle
if (challengeText.parent) {
tween(challengeText, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: arguments.callee
});
}
}
});
}
});
// Add AI beats to pattern
var enhancedPattern = playerPattern.slice();
var aiPercentage = Math.random() * 0.10 + 0.10; // Random between 10% and 20%
var aiBeats = Math.floor(playerPattern.length * aiPercentage);
for (var i = 0; i < aiBeats; i++) {
var randomTime = Math.random() * 30000; // Random time within 30 seconds
var randomTrack = Math.floor(Math.random() * trackPositions.length);
enhancedPattern.push({
time: randomTime,
track: randomTrack,
isAI: true
});
}
// Sort by time
enhancedPattern.sort(function (a, b) {
return a.time - b.time;
});
showCountdown(function () {
// Restart music
LK.stopMusic();
LK.setTimeout(function () {
LK.playMusic(selectedSong);
songStartTime = Date.now();
currentPattern = enhancedPattern;
spawnNotesForPattern();
}, 100);
// Auto end after completion
LK.setTimeout(function () {
if (currentState === GAME_STATE.AI_CHALLENGE) {
endGame();
}
}, 40000);
});
}
function spawnNotesForPattern() {
for (var i = 0; i < currentPattern.length; i++) {
var beat = currentPattern[i];
var spawnTime = beat.time - 2000; // Spawn 2 seconds before hit time
LK.setTimeout(function (beatData) {
return function () {
if (currentState === GAME_STATE.PATTERN_RECREATE || currentState === GAME_STATE.AI_CHALLENGE) {
var note = new Note(beatData, beatData.track);
note.x = trackPositions[beatData.track];
note.y = -50;
if (beatData.isAI) {
note.attachAsset('note', {}).tint = 0xFF6B6B; // Red for AI beats
}
game.addChild(note);
notes.push(note);
}
};
}(beat), Math.max(0, spawnTime));
}
}
function updatePassText() {
passText.setText('Pass ' + passNumber + '/3');
}
function showCountdown(callback) {
var countdownText = new Text2('3', {
size: 200,
fill: '#FF6B6B',
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
countdownText.anchor.set(0.5, 0.5);
countdownText.x = 1024;
countdownText.y = 1366;
countdownText.alpha = 0;
game.addChild(countdownText);
// Animate countdown from 3 to 1
var count = 3;
function animateCount() {
countdownText.setText(count.toString());
countdownText.alpha = 1;
countdownText.scaleX = 2;
countdownText.scaleY = 2;
tween(countdownText, {
scaleX: 1,
scaleY: 1,
alpha: 0
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
count--;
if (count > 0) {
animateCount();
} else {
// Show "GO!" for final countdown
countdownText.setText('GO!');
countdownText.alpha = 1;
countdownText.scaleX = 2;
countdownText.scaleY = 2;
tween(countdownText, {
scaleX: 1,
scaleY: 1,
alpha: 0
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
countdownText.destroy();
callback();
}
});
}
}
});
}
animateCount();
}
function updateScore(points) {
score += points;
scoreText.setText('Score: ' + score);
}
function endGame() {
currentState = GAME_STATE.GAME_OVER;
LK.stopMusic();
var accuracy = hitNotes > 0 ? Math.round(hitNotes / (hitNotes + missedNotes) * 100) : 0;
LK.setScore(score);
// Show final score and return to main menu
var finalScoreText = new Text2('Final Score: ' + score + '\nAccuracy: ' + accuracy + '%', {
size: 60,
fill: '#FFFFFF',
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
finalScoreText.anchor.set(0.5, 0.5);
finalScoreText.x = 1024;
finalScoreText.y = 1200;
game.addChild(finalScoreText);
// Remove final score after 5 seconds and then show menu
LK.setTimeout(function () {
if (finalScoreText && finalScoreText.parent) {
tween(finalScoreText, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
finalScoreText.destroy();
// Show menu after final score disappears
resetGame();
}
});
}
}, 5000);
}
function resetGame() {
// Clear all game objects
for (var i = notes.length - 1; i >= 0; i--) {
notes[i].destroy();
}
notes = [];
for (var i = 0; i < uiElements.length; i++) {
uiElements[i].destroy();
}
uiElements = [];
// Reset hit zones to invisible
for (var i = 0; i < hitZones.length; i++) {
tween(hitZones[i], {
alpha: 0
}, {
duration: 300,
easing: tween.easeOut
});
}
// Reset game variables
playerPattern = [];
currentPattern = [];
passNumber = 1;
score = 0;
hitNotes = 0;
missedNotes = 0;
selectedSong = null;
currentMusic = null;
// Clear score display
scoreText.setText('Score: 0');
// Return to song selection
showSongSelection();
}
function handleTap(x, y) {
var currentTime = Date.now();
if (currentState === GAME_STATE.PATTERN_CREATE) {
// Record tap in pattern
var relativeTime = currentTime - patternStartTime;
var nearestTrack = findNearestTrack(x);
playerPattern.push({
time: relativeTime,
track: nearestTrack,
isAI: false
});
LK.getSound('hit_track' + nearestTrack).play();
// Visual feedback
var hitZone = hitZones[nearestTrack];
tween(hitZone, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100
});
tween(hitZone, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
} else if (currentState === GAME_STATE.PATTERN_RECREATE || currentState === GAME_STATE.AI_CHALLENGE) {
// Check for note hits
var nearestTrack = findNearestTrack(x);
var hitNote = null;
var minDistance = Infinity;
for (var i = 0; i < notes.length; i++) {
var note = notes[i];
if (!note.hit && !note.missed && note.track === nearestTrack) {
var distance = Math.abs(note.y - hitZoneY);
if (distance < minDistance && distance < 100) {
minDistance = distance;
hitNote = note;
}
}
}
if (hitNote) {
hitNote.hit = true;
hitNotes++;
var points = Math.max(10, 100 - Math.floor(minDistance));
updateScore(points);
LK.getSound('hit_track' + nearestTrack).play();
// Visual feedback
tween(hitNote, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 200
});
LK.setTimeout(function () {
if (hitNote && hitNote.parent) {
hitNote.destroy();
var index = notes.indexOf(hitNote);
if (index > -1) notes.splice(index, 1);
}
}, 200);
} else {
LK.getSound('miss').play();
}
}
}
function findNearestTrack(x) {
var minDistance = Infinity;
var nearestTrack = 0;
for (var i = 0; i < trackPositions.length; i++) {
var distance = Math.abs(x - trackPositions[i]);
if (distance < minDistance) {
minDistance = distance;
nearestTrack = i;
}
}
return nearestTrack;
}
// Event handlers
game.down = function (x, y, obj) {
handleTap(x, y);
};
game.update = function () {
// Update notes
for (var i = notes.length - 1; i >= 0; i--) {
var note = notes[i];
// Remove notes that are off screen
if (note.y > 2800) {
note.destroy();
notes.splice(i, 1);
}
}
// Check if song is finished and all notes are cleared
if ((currentState === GAME_STATE.PATTERN_RECREATE || currentState === GAME_STATE.AI_CHALLENGE) && notes.length === 0 && currentPattern.length > 0 && Date.now() - songStartTime > 35000) {
endGame();
}
// Check for missed notes and update score display
if (LK.ticks % 60 === 0) {
// Update every second
scoreText.setText('Score: ' + score);
}
};
// Initialize the game
initializeGame();
dark neon lit background in the tints of green orange yellow and blue. In-Game asset. 2d. High contrast. No shadows
light neon orange yellow green and blue line. In-Game asset. 2d. High contrast. No shadows
text in neon outline no background that says "Rhythm Echo Challenge". In-Game asset. 2d. High contrast. No shadows
neon pink purple red orange oval filled in blue nuaces. In-Game asset. 2d. High contrast. No shadows