User prompt
after '2:53' min stop the game and show the final score and win or lose
User prompt
Show the scores of the players in the score background when scorebutton is clicked. ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Add scorebutton beside startbutton in intro from the right side by distance of 100px
User prompt
after time of the game music is finished stop the game and show highscore and the win or lose!
User prompt
Change lines from 50x3000 to be small like 50x500. Don't play gameover if miss any blocks just don't count it so like that if player reach 2000 he win if less then that he lose.
User prompt
The music stop but blocks keep respawning and the game didn't ends to show win with score background (create score background for that)!
User prompt
The game didn't stop when the gamemusic1 finished and the blocks keep respawning! if the music finished and the player score more than 2000 do win screen with the highscore background transparent.
User prompt
when the game music is finished do the final score background and when tap again go to intro to start from there again.
User prompt
can you respawn the blocks with same rhythm of the game music.
Code edit (2 edits merged)
Please save this source code
User prompt
change lines of blocks thickness a bit to 50px
Code edit (2 edits merged)
Please save this source code
User prompt
Add gamebackground to the game when the game is start
Code edit (1 edits merged)
Please save this source code
User prompt
Add introbackground before the game start and startbutton close to the bottom by 100px.
Code edit (1 edits merged)
Please save this source code
User prompt
Add introbackground before the game start and startbutton close to the bottom by 100px.
Code edit (1 edits merged)
Please save this source code
User prompt
change the lines to be from above not bellow the blocks!
User prompt
create a thin line taller continue with the block till it get touched with player then disappears it must be with same color of that block.
User prompt
Add the colors animations assets to the blocks when get touched by the player ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var PlayerCharacter = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('playerCharacter', {
anchorX: 0.5,
anchorY: 0.5
});
// Set brown transparent color
characterGraphics.alpha = 0.7;
return self;
});
//Storage library which should be used for persistent game data
// var storage = LK.import('@upit/storage.v1');
//Library for using the camera (the background becomes the user's camera video feed) and the microphone. It can access face coordinates for interactive play, as well detect microphone volume / voice interactions
// var facekit = LK.import('@upit/facekit.v1');
//Classes can only be defined here. You cannot create inline classes in the games code.
var TerrainBlock = Container.expand(function (color, speed, noteId) {
var self = Container.call(this);
self.color = color;
self.speed = speed;
self.noteId = noteId;
var blockGraphics = self.attachAsset('terrainBlock' + self.color, {
anchorX: 0.5,
anchorY: 0.5
});
// Create vertical line extending from block
self.line = new Container();
// Get color hex value from colorMap
var lineColor = 0xFFFFFF; // Default white
if (color === 'Red') {
lineColor = 0xFF0000;
} else if (color === 'Orange') {
lineColor = 0xFFA500;
} else if (color === 'Yellow') {
lineColor = 0xFFFF00;
} else if (color === 'Green') {
lineColor = 0x008000;
} else if (color === 'Blue') {
lineColor = 0x0000FF;
} else if (color === 'Indigo') {
lineColor = 0x4B0082;
} else if (color === 'Violet') {
lineColor = 0xEE82EE;
}
// Create thin vertical line shape
var lineGraphics = LK.getAsset('line' + self.color, {
width: 50,
height: 3000,
// Very tall to reach top
color: lineColor,
shape: 'box',
anchorX: 0.5,
anchorY: 1
});
self.line.addChild(lineGraphics);
self.addChild(self.line);
self.update = function () {
self.y += self.speed;
// Keep line positioned at block center extending upward
if (self.line) {
self.line.x = 0;
self.line.y = 0;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
//Note game dimensions are 2048x2732
/*
Supported Types:
1. Shape:
- Simple geometric figures with these properties:
* width: (required) pixel width of the shape.
* height: (required) pixel height of the shape.
* color: (required) color of the shape.
* shape: (required) type of shape. Valid options: 'box', 'ellipse'.
2. Image:
- Imported images with these properties:
* width: (required) pixel resolution width.
* height: (required) pixel resolution height.
* id: (required) identifier for the image.
* flipX: (optional) horizontal flip. Valid values: 0 (no flip), 1 (flip).
* flipY: (optional) vertical flip. Valid values: 0 (no flip), 1 (flip).
* orientation: (optional) rotation in multiples of 90 degrees, clockwise. Valid values:
- 0: No rotation.
- 1: Rotate 90 degrees.
- 2: Rotate 180 degrees.
- 3: Rotate 270 degrees.
Note: Width and height remain unchanged upon flipping.
3. Sound:
- Sound effects with these properties:
* id: (required) identifier for the sound.
* volume: (optional) custom volume. Valid values are a float from 0 to 1.
4. Music:
- In contract to sound effects, only one music can be played at a time
- Music is using the same API to initilize just like sound.
- Music loops by default
- Music with these config options:
* id: (required) identifier for the sound.
* volume: (optional) custom volume. Valid values are a float from 0 to 1.
* start: (optional) a float from 0 to 1 used for cropping and indicates the start of the cropping
* end: (optional) a float from 0 to 1 used for cropping and indicates the end of the cropping
*/
// Assets are automatically created and loaded either dynamically during gameplay
// or via static code analysis based on their usage in the code.
// Initialize assets used in this game. Scale them according to what is needed for the game.
//We have access to the following plugins. (Note that the variable names used are mandetory for each plugin)
//Only include the plugins you need to create the game.
//Minimalistic tween library which should be used for animations over time, including tinting / colouring an object, scaling, rotating, or changing any game object property.
var gameState = 'intro'; // 'intro' or 'playing'
var introContainer = null;
var startButton = null;
var dragNode = null; // Centralized declaration, used by player controls
var terrainBlocks = []; // Original line
// Forward declaration for the main game initialization logic
function initializeMainGame() {
// Add game background
var gameBackground = LK.getAsset('Gamebackground', {
x: 0,
y: 0,
width: 2048,
height: 2732,
anchorX: 0,
// Optional, default is 0 for x=0, y=0
anchorY: 0 // Optional, default is 0 for x=0, y=0
});
game.addChildAt(gameBackground, 0); // Add at index 0 to ensure it's in the back
LK.playMusic('Gamemusic1');
scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.setText(LK.getScore());
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
playerCharacter = new PlayerCharacter();
// Position player character near the bottom center
playerCharacter.x = 2048 / 2;
playerCharacter.y = 2732 - playerCharacter.height - 100; // Offset from bottom
game.addChild(playerCharacter);
// Event listeners for player control
// These are assigned when the game starts, so gameState is 'playing'
game.down = function (x, y, obj) {
if (!playerCharacter) {
return;
} // Guard against playerCharacter not being ready
// Check if the touch is on the player character
dragNode = playerCharacter;
};
game.move = function (x, y, obj) {
if (!playerCharacter) {
return;
} // Guard
// Move the player character horizontally based on the cursor's x position,
// ensuring it stays within the horizontal bounds of the screen.
playerCharacter.x = Math.max(playerCharacter.width / 2, Math.min(2048 - playerCharacter.width / 2, x));
};
game.up = function (x, y, obj) {
if (!playerCharacter) {
return;
} // Guard
dragNode = null; // Stop dragging
};
lastSpawnTime = Date.now(); // Initialize block spawning timer to start spawning blocks
}
var playerCharacter = null;
var scoreTxt = null;
var spawnInterval = 1200; // Milliseconds between block spawns
var lastSpawnTime = 7;
var terrainSpeed = 9;
// Mapping colors to hex and sound IDs
var colorMap = {
'Red': '#FF0000',
'Orange': '#FFA500',
'Yellow': '#FFFF00',
'Green': '#008000',
'Blue': '#0000FF',
'Indigo': '#4B0082',
'Violet': '#EE82EE'
};
// Play background music
// Music, score, player, and event handlers are now initialized in initializeMainGame().
var colorNoteMap = {
'Red': 'noteC',
'Orange': 'noteD',
'Yellow': 'noteE',
'Green': 'noteF',
'Blue': 'noteG',
'Indigo': 'noteA',
'Violet': 'noteB'
};
game.setBackgroundColor(0x000000); // Change background color to black
// Setup Intro Screen if in 'intro' state
if (gameState === 'intro') {
introContainer = new Container();
game.addChild(introContainer);
var introBackgroundAsset = LK.getAsset('Introbackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2,
width: 2048,
// Scale to full width
height: 2732 // Scale to full height
});
introContainer.addChild(introBackgroundAsset);
// Using startButtonAsset locally for clarity, then assigning to global startButton
var startButtonAsset = LK.getAsset('Startbutton', {
anchorX: 0.5,
anchorY: 0.5
});
startButtonAsset.x = 2048 / 2;
// Position button 100px from the bottom edge. Anchor is 0.5, so use half its height in calculation.
startButtonAsset.y = 2732 - 100 - startButtonAsset.height / 2;
introContainer.addChild(startButtonAsset);
startButton = startButtonAsset; // Assign to global variable
startButton.down = function () {
// Ensure this only runs once and only if in intro state
if (gameState !== 'intro') {
return;
}
gameState = 'playing';
if (introContainer) {
introContainer.destroy(); // Clean up intro elements
introContainer = null;
}
startButton = null; // Clear reference
initializeMainGame(); // Call the function to set up and start the actual game
};
}
// The original scoreTxt, playerCharacter, and game event handlers (down, move, up)
// are removed from here as they are now part of initializeMainGame.
// The old dragNode declaration was also removed as it's now global (CB1).
game.update = function () {
if (gameState !== 'playing') {
return; // Don't run game logic if not in 'playing' state
}
var currentTime = Date.now();
// Spawn new terrain blocks
if (currentTime - lastSpawnTime > spawnInterval) {
var colors = Object.keys(colorMap);
var randomColor = colors[Math.floor(Math.random() * colors.length)];
var noteId = colorNoteMap[randomColor];
var newBlock = new TerrainBlock(randomColor, terrainSpeed, noteId);
// Position block randomly at the top within game width
newBlock.x = Math.random() * (2048 - newBlock.width) + newBlock.width / 2;
newBlock.y = -newBlock.height; // Start above the screen
terrainBlocks.push(newBlock);
game.addChild(newBlock);
lastSpawnTime = currentTime;
// Gradually increase game speed / difficulty
// spawnInterval = Math.max(500, spawnInterval - 1);
// terrainSpeed = Math.min(15, terrainSpeed + 0.05);
}
// Update and check collisions for terrain blocks
// Update and check collisions for terrain blocks
for (var i = terrainBlocks.length - 1; i >= 0; i--) {
var block = terrainBlocks[i];
if (block.lastY === undefined) {
block.lastY = block.y;
}
// Check if block is off-screen
if (block.lastY < 2732 + block.height && block.y >= 2732 + block.height) {
// Missed block - game over
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
break; // Exit loop as game is over
}
// Check for intersection with player character
var currentIntersecting = block.intersects(playerCharacter);
if (currentIntersecting) {
// Collect any color block
LK.setScore(LK.getScore() + 10);
scoreTxt.setText(LK.getScore());
// Create animation effect based on block color
var animationAsset = null;
if (block.color === 'Red') {
animationAsset = LK.getAsset('Redanimation1', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (block.color === 'Orange') {
animationAsset = LK.getAsset('Orangeanimation1', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (block.color === 'Yellow') {
animationAsset = LK.getAsset('Yellowanimation1', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (block.color === 'Green') {
animationAsset = LK.getAsset('Greenanimation1', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (block.color === 'Blue') {
animationAsset = LK.getAsset('Blueanimation1', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (block.color === 'Indigo') {
animationAsset = LK.getAsset('Purpleanimation1', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (block.color === 'Violet') {
animationAsset = LK.getAsset('Pinkanimation1', {
anchorX: 0.5,
anchorY: 0.5
});
}
if (animationAsset) {
// Position animation at block location
animationAsset.x = block.x;
animationAsset.y = block.y;
game.addChild(animationAsset);
// Animate the animation asset
tween(animationAsset, {
scaleX: 3,
scaleY: 3,
alpha: 0,
rotation: Math.PI * 2
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
animationAsset.destroy();
}
});
}
// Add visual feedback with scale animation on player
tween(playerCharacter, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(playerCharacter, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeIn
});
}
});
// Flash effect on collected block
tween(block, {
alpha: 0,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200,
easing: tween.easeOut
});
// Also fade out the line
if (block.line) {
tween(block.line, {
alpha: 0
}, {
duration: 200,
easing: tween.easeOut
});
}
// Play specific sound based on block color with smooth volume fade
var sound = null;
if (block.color === 'Red') {
sound = LK.getSound('redsound1');
} else if (block.color === 'Orange') {
sound = LK.getSound('orangesound1');
} else if (block.color === 'Yellow') {
sound = LK.getSound('yellowsound1');
} else if (block.color === 'Green') {
sound = LK.getSound('greensound1');
} else if (block.color === 'Blue') {
sound = LK.getSound('bluesound1');
} else if (block.color === 'Indigo') {
sound = LK.getSound('purplesound1');
} else if (block.color === 'Violet') {
sound = LK.getSound('pinksound1');
}
if (sound) {
// Set initial volume to 0 for fade-in effect
sound.volume = 0;
sound.play();
// Tween volume from 0 to 1 over 200ms for smooth fade-in
tween(sound, {
volume: 1
}, {
duration: 200,
easing: tween.easeOut
});
}
block.destroy();
terrainBlocks.splice(i, 1);
}
block.lastY = block.y;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -181,9 +181,9 @@
lastSpawnTime = Date.now(); // Initialize block spawning timer to start spawning blocks
}
var playerCharacter = null;
var scoreTxt = null;
-var spawnInterval = 1000; // Milliseconds between block spawns
+var spawnInterval = 1200; // Milliseconds between block spawns
var lastSpawnTime = 7;
var terrainSpeed = 9;
// Mapping colors to hex and sound IDs
var colorMap = {