/****
* Classes
****/
// Note class to represent each note in the rhythm game
var Note = Container.expand(function () {
var self = Container.call(this);
var noteGraphics = self.attachAsset('note', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
notes.splice(notes.indexOf(self), 1);
}
};
});
//<Assets used in the game will automatically appear here>
// ZodiacSign class to represent each zodiac sign
var ZodiacSign = Container.expand(function () {
var self = Container.call(this);
var zodiacGraphics = self.attachAsset('zodiac', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for zodiac signs
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var background = LK.getAsset('Background', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2048 / 1920,
scaleY: 2732 / 1920,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(background);
// Initialize arrays and variables
var zodiacSigns = [];
var notes = [];
var score = 0;
var maxNotesOnScreen = 20;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to spawn a new note
function spawnNote() {
var newNote = new Note();
newNote.speed += speedIncrement + Math.random() * 2 + Math.random() * 2;
if (notes.length < maxNotesOnScreen) {
speedIncrement += 0.3;
}
newNote.x = Math.random() * 2048;
newNote.y = -Math.random() * 500 - (notes.length > 0 ? notes[notes.length - 1].y + 200 + Math.random() * 200 : 0);
if (notes.length > 0) {
newNote.y = Math.min(newNote.y, notes[notes.length - 1].y - 200 - Math.random() * 100);
}
notes.push(newNote);
game.addChild(newNote);
speedIncrement += 0.5;
}
// Function to update the score
function updateScore() {
score += 1;
scoreTxt.setText(score);
}
// Function to handle note hit
function handleNoteHit(note) {
updateScore();
note.destroy();
notes.splice(notes.indexOf(note), 1);
// Play spark sound
LK.getSound('spark').play();
}
// Initialize a single zodiac sign
var zodiac = new ZodiacSign();
zodiac.x = 2048 / 2;
zodiac.y = 2732 * 5.5 / 6;
zodiacSigns.push(zodiac);
game.addChild(zodiac);
// Game update function
game.update = function () {
// Update notes
for (var i = notes.length - 1; i >= 0; i--) {
notes[i].update();
// Check for note hit
for (var j = 0; j < zodiacSigns.length; j++) {
if (notes[i] && notes[i].intersects(zodiacSigns[j])) {
handleNoteHit(notes[i]);
break;
}
}
}
// Increase the time since the last note was spawned
timeSinceLastNote++;
// Spawn a new note every 2 seconds (120 ticks), and decrease the spawn frequency by 0.2 seconds every 10 seconds
// Increment the game duration every tick
gameDuration++;
// End the game after 90 seconds (5400 ticks)
if (gameDuration >= 5400) {
var gameOverText = new Text2('Game Over! Your score: ' + score, {
size: 100,
fill: "#ffffff"
});
gameOverText.anchor.set(0.5, 0.5);
gameOverText.x = 2048 / 2;
gameOverText.y = 2732 / 2;
LK.gui.center.addChild(gameOverText);
LK.showGameOver();
}
if (timeSinceLastNote >= 120 - Math.floor(LK.ticks / 600) * 12) {
if (notes.length < maxNotesOnScreen) {
spawnNote();
timeSinceLastNote = 0;
}
}
};
// Event listeners for touch events
game.down = function (x, y, obj) {
// Handle touch down event
zodiac.x = x;
};
game.move = function (x, y, obj) {
// Handle touch move event
zodiac.x = x;
};
game.up = function (x, y, obj) {
// Handle touch up event
// No additional logic needed for now
};
var speedIncrement = 0.5;
var timeSinceLastNote = 0;
var gameDuration = 0;
// Play the 'starrysky' music track and loop it
LK.playMusic('starrysky', {
loop: true
});
// Play the 'starrysky' music track and loop it
LK.playMusic('starrysky', {
loop: true
});