/****
* Classes
****/
var MusicalNote = Container.expand(function (noteType) {
var self = Container.call(this);
self.noteType = noteType;
self.speed = 3;
self.hitZone = 150;
self.wasInHitZone = false;
self.isHit = false;
var noteNames = ['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Si'];
var noteAssets = ['noteDo', 'noteRe', 'noteMi', 'noteFa', 'noteSol', 'noteLa', 'noteSi'];
var noteSounds = ['soundDo', 'soundRe', 'soundMi', 'soundFa', 'soundSol', 'soundLa', 'soundSi'];
self.noteName = noteNames[noteType];
self.soundId = noteSounds[noteType];
var noteGraphics = self.attachAsset(noteAssets[noteType], {
anchorX: 0.5,
anchorY: 0.5
});
var noteText = new Text2(self.noteName, {
size: 40,
fill: 0x000000
});
noteText.anchor.set(0.5, 0.5);
self.addChild(noteText);
self.update = function () {
self.y += self.speed;
};
self.checkHit = function (touchY) {
var distance = Math.abs(self.y - touchY);
return distance < self.hitZone;
};
self.playSound = function () {
LK.getSound(self.soundId).play();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var targetLineY = 2200;
var targetLine = game.attachAsset('targetLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: targetLineY
});
var notes = [];
var lives = 3;
var spawnTimer = 0;
var spawnInterval = 120;
var gameSpeed = 1;
var scoreText = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var livesText = new Text2('Vidas: 3', {
size: 60,
fill: 0xFF4444
});
livesText.anchor.set(0, 0);
livesText.x = 150;
livesText.y = 50;
LK.gui.topLeft.addChild(livesText);
function spawnNote() {
var noteType = Math.floor(Math.random() * 7);
var note = new MusicalNote(noteType);
note.x = Math.random() * (2048 - 200) + 100;
note.y = -100;
note.speed = 2 + gameSpeed;
notes.push(note);
game.addChild(note);
}
function updateScore() {
scoreText.setText(LK.getScore().toString());
}
function updateLives() {
livesText.setText('Vidas: ' + lives);
}
function hitNote(note) {
if (!note.isHit) {
note.isHit = true;
note.playSound();
LK.getSound('hitSound').play();
LK.setScore(LK.getScore() + 10);
updateScore();
LK.effects.flashObject(note, 0xffffff, 200);
var index = notes.indexOf(note);
if (index > -1) {
notes.splice(index, 1);
}
note.destroy();
}
}
function missNote() {
lives--;
updateLives();
LK.getSound('missSound').play();
LK.effects.flashScreen(0xff0000, 300);
if (lives <= 0) {
LK.showGameOver();
}
}
game.down = function (x, y, obj) {
var hitAnyNote = false;
for (var i = notes.length - 1; i >= 0; i--) {
var note = notes[i];
if (!note.isHit) {
var distance = Math.sqrt((note.x - x) * (note.x - x) + (note.y - y) * (note.y - y));
if (distance < 80) {
if (note.checkHit(targetLineY)) {
hitNote(note);
hitAnyNote = true;
break;
} else {
missNote();
hitAnyNote = true;
break;
}
}
}
}
};
game.update = function () {
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnNote();
spawnTimer = 0;
if (LK.getScore() > 0 && LK.getScore() % 50 == 0) {
gameSpeed += 0.2;
spawnInterval = Math.max(60, spawnInterval - 5);
}
}
for (var i = notes.length - 1; i >= 0; i--) {
var note = notes[i];
var currentInHitZone = Math.abs(note.y - targetLineY) < note.hitZone;
if (!note.wasInHitZone && currentInHitZone) {
note.wasInHitZone = true;
} else if (note.wasInHitZone && !currentInHitZone && !note.isHit) {
if (note.y > targetLineY + note.hitZone) {
missNote();
notes.splice(i, 1);
note.destroy();
continue;
}
}
if (note.y > 2800) {
if (!note.isHit) {
missNote();
}
notes.splice(i, 1);
note.destroy();
}
}
}; /****
* Classes
****/
var MusicalNote = Container.expand(function (noteType) {
var self = Container.call(this);
self.noteType = noteType;
self.speed = 3;
self.hitZone = 150;
self.wasInHitZone = false;
self.isHit = false;
var noteNames = ['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Si'];
var noteAssets = ['noteDo', 'noteRe', 'noteMi', 'noteFa', 'noteSol', 'noteLa', 'noteSi'];
var noteSounds = ['soundDo', 'soundRe', 'soundMi', 'soundFa', 'soundSol', 'soundLa', 'soundSi'];
self.noteName = noteNames[noteType];
self.soundId = noteSounds[noteType];
var noteGraphics = self.attachAsset(noteAssets[noteType], {
anchorX: 0.5,
anchorY: 0.5
});
var noteText = new Text2(self.noteName, {
size: 40,
fill: 0x000000
});
noteText.anchor.set(0.5, 0.5);
self.addChild(noteText);
self.update = function () {
self.y += self.speed;
};
self.checkHit = function (touchY) {
var distance = Math.abs(self.y - touchY);
return distance < self.hitZone;
};
self.playSound = function () {
LK.getSound(self.soundId).play();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var targetLineY = 2200;
var targetLine = game.attachAsset('targetLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: targetLineY
});
var notes = [];
var lives = 3;
var spawnTimer = 0;
var spawnInterval = 120;
var gameSpeed = 1;
var scoreText = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var livesText = new Text2('Vidas: 3', {
size: 60,
fill: 0xFF4444
});
livesText.anchor.set(0, 0);
livesText.x = 150;
livesText.y = 50;
LK.gui.topLeft.addChild(livesText);
function spawnNote() {
var noteType = Math.floor(Math.random() * 7);
var note = new MusicalNote(noteType);
note.x = Math.random() * (2048 - 200) + 100;
note.y = -100;
note.speed = 2 + gameSpeed;
notes.push(note);
game.addChild(note);
}
function updateScore() {
scoreText.setText(LK.getScore().toString());
}
function updateLives() {
livesText.setText('Vidas: ' + lives);
}
function hitNote(note) {
if (!note.isHit) {
note.isHit = true;
note.playSound();
LK.getSound('hitSound').play();
LK.setScore(LK.getScore() + 10);
updateScore();
LK.effects.flashObject(note, 0xffffff, 200);
var index = notes.indexOf(note);
if (index > -1) {
notes.splice(index, 1);
}
note.destroy();
}
}
function missNote() {
lives--;
updateLives();
LK.getSound('missSound').play();
LK.effects.flashScreen(0xff0000, 300);
if (lives <= 0) {
LK.showGameOver();
}
}
game.down = function (x, y, obj) {
var hitAnyNote = false;
for (var i = notes.length - 1; i >= 0; i--) {
var note = notes[i];
if (!note.isHit) {
var distance = Math.sqrt((note.x - x) * (note.x - x) + (note.y - y) * (note.y - y));
if (distance < 80) {
if (note.checkHit(targetLineY)) {
hitNote(note);
hitAnyNote = true;
break;
} else {
missNote();
hitAnyNote = true;
break;
}
}
}
}
};
game.update = function () {
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnNote();
spawnTimer = 0;
if (LK.getScore() > 0 && LK.getScore() % 50 == 0) {
gameSpeed += 0.2;
spawnInterval = Math.max(60, spawnInterval - 5);
}
}
for (var i = notes.length - 1; i >= 0; i--) {
var note = notes[i];
var currentInHitZone = Math.abs(note.y - targetLineY) < note.hitZone;
if (!note.wasInHitZone && currentInHitZone) {
note.wasInHitZone = true;
} else if (note.wasInHitZone && !currentInHitZone && !note.isHit) {
if (note.y > targetLineY + note.hitZone) {
missNote();
notes.splice(i, 1);
note.destroy();
continue;
}
}
if (note.y > 2800) {
if (!note.isHit) {
missNote();
}
notes.splice(i, 1);
note.destroy();
}
}
};