/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var BackgroundWave = Container.expand(function () {
var self = Container.call(this);
var wave = self.attachAsset('backgroundWave', {
anchorX: 0,
anchorY: 0.5,
alpha: 0.3
});
self.speed = -1;
self.amplitude = 20;
self.frequency = 0.02;
self.offset = Math.random() * Math.PI * 2;
self.update = function () {
self.x += self.speed;
self.y += Math.sin(LK.ticks * self.frequency + self.offset) * 0.5;
if (self.x < -100) {
self.x = 2148;
}
};
return self;
});
var MusicNote = Container.expand(function () {
var self = Container.call(this);
// Array of musical note symbols
var noteSymbols = ['♪', '♫', '♬', '♩', '♭', '♯'];
// Create text object with musical note
var noteText = new Text2(noteSymbols[Math.floor(Math.random() * noteSymbols.length)], {
size: 50 + Math.random() * 30,
// Varying sizes from 50-80
fill: 0x4A90E2 // Blue color
});
noteText.anchor.set(0.5, 0.5);
self.addChild(noteText);
// Movement properties - falling from top to bottom
self.speed = 1 + Math.random() * 2; // Slow downward movement
self.horizontalSpeed = (Math.random() - 0.5) * 0.5; // Slight horizontal drift
self.rotationSpeed = (Math.random() - 0.5) * 0.02; // Gentle rotation
self.fadeSpeed = 0.003 + Math.random() * 0.005;
self.changeTimer = 0;
self.changeInterval = 120 + Math.random() * 120; // Change symbol every 2-4 seconds
// Color cycling for variety
var colors = [0x4A90E2, 0x87CEEB, 0x9370DB, 0x20B2AA, 0x4169E1];
self.colorIndex = Math.floor(Math.random() * colors.length);
self.update = function () {
// Move vertically (falling down)
self.y += self.speed;
// Slight horizontal drift
self.x += self.horizontalSpeed;
// Gentle rotation
noteText.rotation += self.rotationSpeed;
// Reset position when off screen (bottom)
if (self.y > 2800) {
self.x = Math.random() * 2048;
self.y = -100;
self.alpha = 0.6 + Math.random() * 0.4;
// Reset speed for variation
self.speed = 1 + Math.random() * 2;
self.horizontalSpeed = (Math.random() - 0.5) * 0.5;
}
// Subtle fade effect
self.alpha -= self.fadeSpeed;
if (self.alpha <= 0.3) {
self.alpha = 0.6 + Math.random() * 0.4;
}
// Change note symbol periodically
self.changeTimer++;
if (self.changeTimer >= self.changeInterval) {
noteText.setText(noteSymbols[Math.floor(Math.random() * noteSymbols.length)]);
self.changeTimer = 0;
self.changeInterval = 120 + Math.random() * 120;
// Change color occasionally
if (Math.random() < 0.4) {
self.colorIndex = (self.colorIndex + 1) % colors.length;
noteText.fill = colors[self.colorIndex];
}
}
// Gentle floating animation
self.x += Math.sin(LK.ticks * 0.01 + self.y * 0.002) * 0.3;
};
return self;
});
var NoteParticle = Container.expand(function () {
var self = Container.call(this);
// Array of musical note symbols
var noteSymbols = ['♬', '♪', '♫', '♩'];
// Create text object with musical note
var noteText = new Text2(noteSymbols[Math.floor(Math.random() * noteSymbols.length)], {
size: 80 + Math.random() * 40,
// Size between 80-120
fill: 0xFFD700 // Gold color
});
noteText.anchor.set(0.5, 0.5);
self.addChild(noteText);
// Initial glow effect
noteText.alpha = 1;
noteText.scaleX = 0.5;
noteText.scaleY = 0.5;
// Animate the note particle
self.animate = function () {
// Scale up and glow
tween(noteText, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 1
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
// Float up and fade out
tween(self, {
y: self.y - 150
}, {
duration: 1000,
easing: tween.easeOut
});
tween(noteText, {
alpha: 0,
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
}
});
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 1
});
self.speed = -2;
self.update = function () {
self.x += self.speed;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var ball = self.attachAsset('ballCharacter', {
anchorX: 0.5,
anchorY: 0.5
});
self.isJumping = false;
self.jumpVelocity = 0;
self.gravity = 0.8;
self.jumpPower = -45;
self.groundY = 2532;
self.crashed = false;
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.jumpVelocity = self.jumpPower;
LK.getSound('jump').play();
// White flash effect on jump
tween(ball, {
tint: 0xFFFFFF
}, {
duration: 300,
onFinish: function onFinish() {
tween(ball, {
tint: 0xFFFF00
}, {
duration: 0
});
}
});
// Jump animation
tween(ball, {
scaleX: 1.2,
scaleY: 0.8
}, {
duration: 100,
onFinish: function onFinish() {
tween(ball, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
});
}
};
self.update = function () {
if (self.crashed) return;
if (self.isJumping) {
self.jumpVelocity += self.gravity;
self.y += self.jumpVelocity;
if (self.y >= self.groundY) {
self.y = self.groundY;
self.isJumping = false;
self.jumpVelocity = 0;
}
}
// Walking animation when on ground
if (!self.isJumping) {
// Continuous bouncing motion for walking effect
var walkBounceOffset = Math.sin(LK.ticks * 0.3) * 8;
ball.y = walkBounceOffset;
// Gentle rotation for walking effect
var walkRotation = Math.sin(LK.ticks * 0.2) * 0.15;
ball.rotation = walkRotation;
// Slight scale variation for walking rhythm
var walkScale = 1 + Math.sin(LK.ticks * 0.25) * 0.05;
ball.scaleX = walkScale;
} else {
// Reset position and rotation when jumping
ball.y = 0;
ball.rotation = 0;
}
// Subtle bounce animation when on ground (less frequent now)
if (!self.isJumping && LK.ticks % 240 === 0) {
tween(ball, {
scaleY: 0.95
}, {
duration: 200,
onFinish: function onFinish() {
tween(ball, {
scaleY: 1
}, {
duration: 200
});
}
});
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0F1A3D
});
/****
* Game Code
****/
// Create gradient background effect with dark blue
game.setBackgroundColor(0x0F1A3D);
// Game variables
var player;
var obstacles = [];
var backgroundWaves = [];
var ground;
var isGameRunning = true;
var obstacleSpawnTimer = 0;
var obstacleSpawnInterval = 180; // 3 seconds at 60fps for better spacing
var gameSpeed = 1;
var speedIncreaseTimer = 0;
var speedIncreaseInterval = 300; // 5 seconds at 60fps
// Score display
var scoreTxt = new Text2('Skor: 0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 50;
// High score display
var highScoreTxt = new Text2('En Yüksek: ' + (storage.highScore || 0), {
size: 60,
fill: 0xFFD700
});
highScoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(highScoreTxt);
highScoreTxt.y = 180;
// New record text (initially hidden)
var newRecordTxt = new Text2('Yeni Rekor!', {
size: 100,
fill: 0xFF00FF
});
newRecordTxt.anchor.set(0.5, 0.5);
newRecordTxt.x = 1024;
newRecordTxt.y = 800;
newRecordTxt.alpha = 0;
game.addChild(newRecordTxt);
// Title text
var titleTxt = new Text2('Ritimle Zıpla', {
size: 120,
fill: 0xFFFFFF
});
titleTxt.anchor.set(0.5, 0.5);
titleTxt.x = 1024;
titleTxt.y = 400;
game.addChild(titleTxt);
// Subtitle text
var subtitleTxt = new Text2('Müziği dinle, ritmi yakala!', {
size: 60,
fill: 0xCCCCCC
});
subtitleTxt.anchor.set(0.5, 0.5);
subtitleTxt.x = 1024;
subtitleTxt.y = 520;
game.addChild(subtitleTxt);
// Create ground
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 2632
}));
// Create musical notes background
var musicNotes = [];
for (var i = 0; i < 30; i++) {
var note = new MusicNote();
note.x = Math.random() * 2048;
note.y = Math.random() * 2732;
note.alpha = 0.4 + Math.random() * 0.3;
musicNotes.push(note);
game.addChild(note);
}
// Create background waves (keep some for layering effect but reduce opacity)
for (var i = 0; i < 4; i++) {
var wave = new BackgroundWave();
wave.x = Math.random() * 2048;
wave.y = 300 + i * 400;
wave.alpha = 0.1; // Much more transparent
backgroundWaves.push(wave);
game.addChild(wave);
}
// Create player
player = game.addChild(new Player());
player.x = 300;
player.y = 2532;
// Game start flag
var gameStarted = false;
// Start game function
function startGame() {
if (!gameStarted) {
gameStarted = true;
// Hide title texts
tween(titleTxt, {
alpha: 0
}, {
duration: 500
});
tween(subtitleTxt, {
alpha: 0
}, {
duration: 500
});
// Start background music
LK.playMusic('bgMusic');
// Update score display
scoreTxt.setText('Skor: ' + LK.getScore());
}
}
// Touch/click handler for jumping
game.down = function (x, y, obj) {
if (!gameStarted) {
startGame();
} else if (isGameRunning) {
player.jump();
}
};
// Collision detection function
function checkCollisions() {
var _loop = function _loop() {
obstacle = obstacles[i];
if (player.intersects(obstacle)) {
// Shake effect
var _shake = function shake() {
if (shakeCount < maxShakes) {
var offsetX = (Math.random() - 0.5) * shakeIntensity;
var offsetY = (Math.random() - 0.5) * shakeIntensity;
tween(game, {
x: originalX + offsetX,
y: originalY + offsetY
}, {
duration: 50,
onFinish: function onFinish() {
shakeCount++;
_shake();
}
});
} else {
// Return to original position and scale
tween(game, {
x: originalX,
y: originalY,
scaleX: 1,
scaleY: 1,
alpha: 1
}, {
duration: 100
});
}
};
// Game over - stop game immediately
isGameRunning = false;
player.crashed = true;
LK.getSound('hit').play();
LK.effects.flashScreen(0xFF0000, 1000);
// Flash player red
LK.effects.flashObject(player, 0xFF0000, 1000);
// Screen shake and blur effect
originalX = game.x;
originalY = game.y;
shakeIntensity = 20;
shakeCount = 0;
maxShakes = 10; // Blur effect by scaling slightly and reducing alpha
tween(game, {
scaleX: 1.05,
scaleY: 1.05,
alpha: 0.7
}, {
duration: 500
});
_shake();
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
return {
v: void 0
};
}
// Check if obstacle passed player (score point)
if (obstacle.lastX === undefined) obstacle.lastX = obstacle.x;
if (obstacle.lastX > player.x && obstacle.x <= player.x) {
LK.setScore(LK.getScore() + 100);
currentScore = LK.getScore();
currentHighScore = storage.highScore || 0;
scoreTxt.setText('Skor: ' + currentScore);
// Create glowing musical note particle
var noteParticle = new NoteParticle();
noteParticle.x = player.x;
noteParticle.y = player.y - 50;
game.addChild(noteParticle);
noteParticle.animate();
// Create particle effect when obstacle is passed
for (p = 0; p < 6; p++) {
particle = LK.getAsset('ballCharacter', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.3,
scaleY: 0.3,
tint: 0xFFD700
});
particle.x = obstacle.x;
particle.y = obstacle.y - 100;
game.addChild(particle);
// Random particle movement
randomX = (Math.random() - 0.5) * 200;
randomY = -Math.random() * 150 - 50;
randomRotation = Math.random() * Math.PI * 4;
tween(particle, {
x: particle.x + randomX,
y: particle.y + randomY,
rotation: randomRotation,
alpha: 0,
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
particle.destroy();
}
});
}
// Check if new high score
if (currentScore > currentHighScore) {
storage.highScore = currentScore;
highScoreTxt.setText('En Yüksek: ' + currentScore);
// Show new record message
newRecordTxt.alpha = 1;
tween(newRecordTxt, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 300,
onFinish: function onFinish() {
tween(newRecordTxt, {
scaleX: 1,
scaleY: 1
}, {
duration: 300,
onFinish: function onFinish() {
tween(newRecordTxt, {
alpha: 0
}, {
duration: 1000
});
}
});
}
});
}
// Increase game speed more aggressively over time
gameSpeed += 0.05;
}
obstacle.lastX = obstacle.x;
// Remove obstacles that are off screen
if (obstacle.x < -100) {
obstacle.destroy();
obstacles.splice(i, 1);
}
},
obstacle,
originalX,
originalY,
shakeIntensity,
shakeCount,
maxShakes,
currentScore,
currentHighScore,
p,
particle,
randomX,
randomY,
randomRotation,
_ret;
for (var i = obstacles.length - 1; i >= 0; i--) {
_ret = _loop();
if (_ret) return _ret.v;
}
}
// Spawn obstacle function
function spawnObstacle() {
if (gameStarted && isGameRunning) {
var obstacle = new Obstacle();
obstacle.x = 2148;
obstacle.y = 2632;
var speedMultiplier = 1 + Math.floor(LK.getScore() / 500) * 0.1;
obstacle.speed = -6.62744 * speedMultiplier; // Base speed increased by 25% with score-based multiplier
obstacles.push(obstacle);
game.addChild(obstacle);
}
}
// Main game update loop
game.update = function () {
if (!isGameRunning) return;
// Update music notes with speed boost after score 10
for (var i = 0; i < musicNotes.length; i++) {
// Increase music note speed when score >= 10
if (LK.getScore() >= 10) {
musicNotes[i].speed = (1 + Math.random() * 2) * 1.8; // 1.8x faster
}
musicNotes[i].update();
}
// Update background waves
for (var i = 0; i < backgroundWaves.length; i++) {
backgroundWaves[i].update();
}
if (gameStarted) {
// Update player
player.update();
// Calculate speed multiplier based on score (10% increase every 500 points)
var speedMultiplier = 1 + Math.floor(LK.getScore() / 500) * 0.1;
// Update obstacles
for (var j = 0; j < obstacles.length; j++) {
obstacles[j].speed = -6.62744 * speedMultiplier; // Base speed increased by 25% with score-based multiplier
obstacles[j].update();
}
// Spawn obstacles
obstacleSpawnTimer++;
if (obstacleSpawnTimer >= obstacleSpawnInterval) {
spawnObstacle();
obstacleSpawnTimer = 0;
// Gradually decrease spawn interval (increase difficulty) - less aggressive reduction for better spacing
if (obstacleSpawnInterval > 90) {
obstacleSpawnInterval -= 2;
} else if (obstacleSpawnInterval > 60) {
obstacleSpawnInterval -= 1;
}
}
// Increase speed every 5 seconds
speedIncreaseTimer++;
if (speedIncreaseTimer >= speedIncreaseInterval) {
gameSpeed *= 1.2; // Increase by 20%
speedIncreaseTimer = 0;
// Flash background to red and back on speed increase
game.setBackgroundColor(0x4a1a1a); // Reddish tint
tween(game, {}, {
duration: 300,
onFinish: function onFinish() {
// Change background color based on score
if (LK.getScore() >= 10) {
game.setBackgroundColor(0x4B0082); // Purple for energy boost
} else {
game.setBackgroundColor(0x0F1A3D); // Back to dark blue
}
}
});
}
// Background color transition when reaching score 10
if (LK.getScore() === 10) {
tween(game, {}, {
duration: 1000,
onFinish: function onFinish() {
game.setBackgroundColor(0x4B0082); // Transition to purple
}
});
}
// Background color transition when reaching score 1000
if (LK.getScore() === 1000) {
tween(game, {}, {
duration: 1000,
onFinish: function onFinish() {
game.setBackgroundColor(0x8B0000); // Transition to dark red
}
});
}
// Check collisions
checkCollisions();
// Win condition (reach score of 10,000)
if (LK.getScore() >= 10000) {
isGameRunning = false;
// Show congratulations message
var winTxt = new Text2('Tebrikler! Ritim Ustası Oldun!', {
size: 100,
fill: 0xFFD700
});
winTxt.anchor.set(0.5, 0.5);
winTxt.x = 1024;
winTxt.y = 1366;
game.addChild(winTxt);
LK.effects.flashScreen(0x00FF00, 1000);
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var BackgroundWave = Container.expand(function () {
var self = Container.call(this);
var wave = self.attachAsset('backgroundWave', {
anchorX: 0,
anchorY: 0.5,
alpha: 0.3
});
self.speed = -1;
self.amplitude = 20;
self.frequency = 0.02;
self.offset = Math.random() * Math.PI * 2;
self.update = function () {
self.x += self.speed;
self.y += Math.sin(LK.ticks * self.frequency + self.offset) * 0.5;
if (self.x < -100) {
self.x = 2148;
}
};
return self;
});
var MusicNote = Container.expand(function () {
var self = Container.call(this);
// Array of musical note symbols
var noteSymbols = ['♪', '♫', '♬', '♩', '♭', '♯'];
// Create text object with musical note
var noteText = new Text2(noteSymbols[Math.floor(Math.random() * noteSymbols.length)], {
size: 50 + Math.random() * 30,
// Varying sizes from 50-80
fill: 0x4A90E2 // Blue color
});
noteText.anchor.set(0.5, 0.5);
self.addChild(noteText);
// Movement properties - falling from top to bottom
self.speed = 1 + Math.random() * 2; // Slow downward movement
self.horizontalSpeed = (Math.random() - 0.5) * 0.5; // Slight horizontal drift
self.rotationSpeed = (Math.random() - 0.5) * 0.02; // Gentle rotation
self.fadeSpeed = 0.003 + Math.random() * 0.005;
self.changeTimer = 0;
self.changeInterval = 120 + Math.random() * 120; // Change symbol every 2-4 seconds
// Color cycling for variety
var colors = [0x4A90E2, 0x87CEEB, 0x9370DB, 0x20B2AA, 0x4169E1];
self.colorIndex = Math.floor(Math.random() * colors.length);
self.update = function () {
// Move vertically (falling down)
self.y += self.speed;
// Slight horizontal drift
self.x += self.horizontalSpeed;
// Gentle rotation
noteText.rotation += self.rotationSpeed;
// Reset position when off screen (bottom)
if (self.y > 2800) {
self.x = Math.random() * 2048;
self.y = -100;
self.alpha = 0.6 + Math.random() * 0.4;
// Reset speed for variation
self.speed = 1 + Math.random() * 2;
self.horizontalSpeed = (Math.random() - 0.5) * 0.5;
}
// Subtle fade effect
self.alpha -= self.fadeSpeed;
if (self.alpha <= 0.3) {
self.alpha = 0.6 + Math.random() * 0.4;
}
// Change note symbol periodically
self.changeTimer++;
if (self.changeTimer >= self.changeInterval) {
noteText.setText(noteSymbols[Math.floor(Math.random() * noteSymbols.length)]);
self.changeTimer = 0;
self.changeInterval = 120 + Math.random() * 120;
// Change color occasionally
if (Math.random() < 0.4) {
self.colorIndex = (self.colorIndex + 1) % colors.length;
noteText.fill = colors[self.colorIndex];
}
}
// Gentle floating animation
self.x += Math.sin(LK.ticks * 0.01 + self.y * 0.002) * 0.3;
};
return self;
});
var NoteParticle = Container.expand(function () {
var self = Container.call(this);
// Array of musical note symbols
var noteSymbols = ['♬', '♪', '♫', '♩'];
// Create text object with musical note
var noteText = new Text2(noteSymbols[Math.floor(Math.random() * noteSymbols.length)], {
size: 80 + Math.random() * 40,
// Size between 80-120
fill: 0xFFD700 // Gold color
});
noteText.anchor.set(0.5, 0.5);
self.addChild(noteText);
// Initial glow effect
noteText.alpha = 1;
noteText.scaleX = 0.5;
noteText.scaleY = 0.5;
// Animate the note particle
self.animate = function () {
// Scale up and glow
tween(noteText, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 1
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
// Float up and fade out
tween(self, {
y: self.y - 150
}, {
duration: 1000,
easing: tween.easeOut
});
tween(noteText, {
alpha: 0,
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
}
});
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 1
});
self.speed = -2;
self.update = function () {
self.x += self.speed;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var ball = self.attachAsset('ballCharacter', {
anchorX: 0.5,
anchorY: 0.5
});
self.isJumping = false;
self.jumpVelocity = 0;
self.gravity = 0.8;
self.jumpPower = -45;
self.groundY = 2532;
self.crashed = false;
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.jumpVelocity = self.jumpPower;
LK.getSound('jump').play();
// White flash effect on jump
tween(ball, {
tint: 0xFFFFFF
}, {
duration: 300,
onFinish: function onFinish() {
tween(ball, {
tint: 0xFFFF00
}, {
duration: 0
});
}
});
// Jump animation
tween(ball, {
scaleX: 1.2,
scaleY: 0.8
}, {
duration: 100,
onFinish: function onFinish() {
tween(ball, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
});
}
};
self.update = function () {
if (self.crashed) return;
if (self.isJumping) {
self.jumpVelocity += self.gravity;
self.y += self.jumpVelocity;
if (self.y >= self.groundY) {
self.y = self.groundY;
self.isJumping = false;
self.jumpVelocity = 0;
}
}
// Walking animation when on ground
if (!self.isJumping) {
// Continuous bouncing motion for walking effect
var walkBounceOffset = Math.sin(LK.ticks * 0.3) * 8;
ball.y = walkBounceOffset;
// Gentle rotation for walking effect
var walkRotation = Math.sin(LK.ticks * 0.2) * 0.15;
ball.rotation = walkRotation;
// Slight scale variation for walking rhythm
var walkScale = 1 + Math.sin(LK.ticks * 0.25) * 0.05;
ball.scaleX = walkScale;
} else {
// Reset position and rotation when jumping
ball.y = 0;
ball.rotation = 0;
}
// Subtle bounce animation when on ground (less frequent now)
if (!self.isJumping && LK.ticks % 240 === 0) {
tween(ball, {
scaleY: 0.95
}, {
duration: 200,
onFinish: function onFinish() {
tween(ball, {
scaleY: 1
}, {
duration: 200
});
}
});
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0F1A3D
});
/****
* Game Code
****/
// Create gradient background effect with dark blue
game.setBackgroundColor(0x0F1A3D);
// Game variables
var player;
var obstacles = [];
var backgroundWaves = [];
var ground;
var isGameRunning = true;
var obstacleSpawnTimer = 0;
var obstacleSpawnInterval = 180; // 3 seconds at 60fps for better spacing
var gameSpeed = 1;
var speedIncreaseTimer = 0;
var speedIncreaseInterval = 300; // 5 seconds at 60fps
// Score display
var scoreTxt = new Text2('Skor: 0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 50;
// High score display
var highScoreTxt = new Text2('En Yüksek: ' + (storage.highScore || 0), {
size: 60,
fill: 0xFFD700
});
highScoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(highScoreTxt);
highScoreTxt.y = 180;
// New record text (initially hidden)
var newRecordTxt = new Text2('Yeni Rekor!', {
size: 100,
fill: 0xFF00FF
});
newRecordTxt.anchor.set(0.5, 0.5);
newRecordTxt.x = 1024;
newRecordTxt.y = 800;
newRecordTxt.alpha = 0;
game.addChild(newRecordTxt);
// Title text
var titleTxt = new Text2('Ritimle Zıpla', {
size: 120,
fill: 0xFFFFFF
});
titleTxt.anchor.set(0.5, 0.5);
titleTxt.x = 1024;
titleTxt.y = 400;
game.addChild(titleTxt);
// Subtitle text
var subtitleTxt = new Text2('Müziği dinle, ritmi yakala!', {
size: 60,
fill: 0xCCCCCC
});
subtitleTxt.anchor.set(0.5, 0.5);
subtitleTxt.x = 1024;
subtitleTxt.y = 520;
game.addChild(subtitleTxt);
// Create ground
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 2632
}));
// Create musical notes background
var musicNotes = [];
for (var i = 0; i < 30; i++) {
var note = new MusicNote();
note.x = Math.random() * 2048;
note.y = Math.random() * 2732;
note.alpha = 0.4 + Math.random() * 0.3;
musicNotes.push(note);
game.addChild(note);
}
// Create background waves (keep some for layering effect but reduce opacity)
for (var i = 0; i < 4; i++) {
var wave = new BackgroundWave();
wave.x = Math.random() * 2048;
wave.y = 300 + i * 400;
wave.alpha = 0.1; // Much more transparent
backgroundWaves.push(wave);
game.addChild(wave);
}
// Create player
player = game.addChild(new Player());
player.x = 300;
player.y = 2532;
// Game start flag
var gameStarted = false;
// Start game function
function startGame() {
if (!gameStarted) {
gameStarted = true;
// Hide title texts
tween(titleTxt, {
alpha: 0
}, {
duration: 500
});
tween(subtitleTxt, {
alpha: 0
}, {
duration: 500
});
// Start background music
LK.playMusic('bgMusic');
// Update score display
scoreTxt.setText('Skor: ' + LK.getScore());
}
}
// Touch/click handler for jumping
game.down = function (x, y, obj) {
if (!gameStarted) {
startGame();
} else if (isGameRunning) {
player.jump();
}
};
// Collision detection function
function checkCollisions() {
var _loop = function _loop() {
obstacle = obstacles[i];
if (player.intersects(obstacle)) {
// Shake effect
var _shake = function shake() {
if (shakeCount < maxShakes) {
var offsetX = (Math.random() - 0.5) * shakeIntensity;
var offsetY = (Math.random() - 0.5) * shakeIntensity;
tween(game, {
x: originalX + offsetX,
y: originalY + offsetY
}, {
duration: 50,
onFinish: function onFinish() {
shakeCount++;
_shake();
}
});
} else {
// Return to original position and scale
tween(game, {
x: originalX,
y: originalY,
scaleX: 1,
scaleY: 1,
alpha: 1
}, {
duration: 100
});
}
};
// Game over - stop game immediately
isGameRunning = false;
player.crashed = true;
LK.getSound('hit').play();
LK.effects.flashScreen(0xFF0000, 1000);
// Flash player red
LK.effects.flashObject(player, 0xFF0000, 1000);
// Screen shake and blur effect
originalX = game.x;
originalY = game.y;
shakeIntensity = 20;
shakeCount = 0;
maxShakes = 10; // Blur effect by scaling slightly and reducing alpha
tween(game, {
scaleX: 1.05,
scaleY: 1.05,
alpha: 0.7
}, {
duration: 500
});
_shake();
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
return {
v: void 0
};
}
// Check if obstacle passed player (score point)
if (obstacle.lastX === undefined) obstacle.lastX = obstacle.x;
if (obstacle.lastX > player.x && obstacle.x <= player.x) {
LK.setScore(LK.getScore() + 100);
currentScore = LK.getScore();
currentHighScore = storage.highScore || 0;
scoreTxt.setText('Skor: ' + currentScore);
// Create glowing musical note particle
var noteParticle = new NoteParticle();
noteParticle.x = player.x;
noteParticle.y = player.y - 50;
game.addChild(noteParticle);
noteParticle.animate();
// Create particle effect when obstacle is passed
for (p = 0; p < 6; p++) {
particle = LK.getAsset('ballCharacter', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.3,
scaleY: 0.3,
tint: 0xFFD700
});
particle.x = obstacle.x;
particle.y = obstacle.y - 100;
game.addChild(particle);
// Random particle movement
randomX = (Math.random() - 0.5) * 200;
randomY = -Math.random() * 150 - 50;
randomRotation = Math.random() * Math.PI * 4;
tween(particle, {
x: particle.x + randomX,
y: particle.y + randomY,
rotation: randomRotation,
alpha: 0,
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
particle.destroy();
}
});
}
// Check if new high score
if (currentScore > currentHighScore) {
storage.highScore = currentScore;
highScoreTxt.setText('En Yüksek: ' + currentScore);
// Show new record message
newRecordTxt.alpha = 1;
tween(newRecordTxt, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 300,
onFinish: function onFinish() {
tween(newRecordTxt, {
scaleX: 1,
scaleY: 1
}, {
duration: 300,
onFinish: function onFinish() {
tween(newRecordTxt, {
alpha: 0
}, {
duration: 1000
});
}
});
}
});
}
// Increase game speed more aggressively over time
gameSpeed += 0.05;
}
obstacle.lastX = obstacle.x;
// Remove obstacles that are off screen
if (obstacle.x < -100) {
obstacle.destroy();
obstacles.splice(i, 1);
}
},
obstacle,
originalX,
originalY,
shakeIntensity,
shakeCount,
maxShakes,
currentScore,
currentHighScore,
p,
particle,
randomX,
randomY,
randomRotation,
_ret;
for (var i = obstacles.length - 1; i >= 0; i--) {
_ret = _loop();
if (_ret) return _ret.v;
}
}
// Spawn obstacle function
function spawnObstacle() {
if (gameStarted && isGameRunning) {
var obstacle = new Obstacle();
obstacle.x = 2148;
obstacle.y = 2632;
var speedMultiplier = 1 + Math.floor(LK.getScore() / 500) * 0.1;
obstacle.speed = -6.62744 * speedMultiplier; // Base speed increased by 25% with score-based multiplier
obstacles.push(obstacle);
game.addChild(obstacle);
}
}
// Main game update loop
game.update = function () {
if (!isGameRunning) return;
// Update music notes with speed boost after score 10
for (var i = 0; i < musicNotes.length; i++) {
// Increase music note speed when score >= 10
if (LK.getScore() >= 10) {
musicNotes[i].speed = (1 + Math.random() * 2) * 1.8; // 1.8x faster
}
musicNotes[i].update();
}
// Update background waves
for (var i = 0; i < backgroundWaves.length; i++) {
backgroundWaves[i].update();
}
if (gameStarted) {
// Update player
player.update();
// Calculate speed multiplier based on score (10% increase every 500 points)
var speedMultiplier = 1 + Math.floor(LK.getScore() / 500) * 0.1;
// Update obstacles
for (var j = 0; j < obstacles.length; j++) {
obstacles[j].speed = -6.62744 * speedMultiplier; // Base speed increased by 25% with score-based multiplier
obstacles[j].update();
}
// Spawn obstacles
obstacleSpawnTimer++;
if (obstacleSpawnTimer >= obstacleSpawnInterval) {
spawnObstacle();
obstacleSpawnTimer = 0;
// Gradually decrease spawn interval (increase difficulty) - less aggressive reduction for better spacing
if (obstacleSpawnInterval > 90) {
obstacleSpawnInterval -= 2;
} else if (obstacleSpawnInterval > 60) {
obstacleSpawnInterval -= 1;
}
}
// Increase speed every 5 seconds
speedIncreaseTimer++;
if (speedIncreaseTimer >= speedIncreaseInterval) {
gameSpeed *= 1.2; // Increase by 20%
speedIncreaseTimer = 0;
// Flash background to red and back on speed increase
game.setBackgroundColor(0x4a1a1a); // Reddish tint
tween(game, {}, {
duration: 300,
onFinish: function onFinish() {
// Change background color based on score
if (LK.getScore() >= 10) {
game.setBackgroundColor(0x4B0082); // Purple for energy boost
} else {
game.setBackgroundColor(0x0F1A3D); // Back to dark blue
}
}
});
}
// Background color transition when reaching score 10
if (LK.getScore() === 10) {
tween(game, {}, {
duration: 1000,
onFinish: function onFinish() {
game.setBackgroundColor(0x4B0082); // Transition to purple
}
});
}
// Background color transition when reaching score 1000
if (LK.getScore() === 1000) {
tween(game, {}, {
duration: 1000,
onFinish: function onFinish() {
game.setBackgroundColor(0x8B0000); // Transition to dark red
}
});
}
// Check collisions
checkCollisions();
// Win condition (reach score of 10,000)
if (LK.getScore() >= 10000) {
isGameRunning = false;
// Show congratulations message
var winTxt = new Text2('Tebrikler! Ritim Ustası Oldun!', {
size: 100,
fill: 0xFFD700
});
winTxt.anchor.set(0.5, 0.5);
winTxt.x = 1024;
winTxt.y = 1366;
game.addChild(winTxt);
LK.effects.flashScreen(0x00FF00, 1000);
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}
}
};