/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Class for the main character, Hatsune Miku var Miku = Container.expand(function () { var self = Container.call(this); var mikuGraphics = self.attachAsset('miku', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Miku's update logic }; }); // Class for the notes that fall down the screen 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(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize arrays and variables var notes = []; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create Miku and position her at the bottom center of the screen var miku = game.addChild(new Miku()); miku.x = 2048 / 2; miku.y = 2732 - 200; // Function to handle note tapping function handleTap(x, y, obj) { for (var i = notes.length - 1; i >= 0; i--) { if (notes[i].intersects(miku)) { score += 1; scoreTxt.setText(score); notes[i].destroy(); notes.splice(i, 1); } } } // Game's main update loop game.update = function () { // Create new notes at regular intervals if (LK.ticks % 60 == 0) { var newNote = new Note(); newNote.x = Math.random() * 2048; newNote.y = 0; notes.push(newNote); game.addChild(newNote); } // Update all notes for (var i = 0; i < notes.length; i++) { notes[i].update(); } }; // Event listeners for tapping game.down = handleTap; game.move = function (x, y, obj) { // No move logic needed for this game }; game.up = function (x, y, obj) { // No up logic needed for this game };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Class for the main character, Hatsune Miku
var Miku = Container.expand(function () {
var self = Container.call(this);
var mikuGraphics = self.attachAsset('miku', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Miku's update logic
};
});
// Class for the notes that fall down the screen
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();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize arrays and variables
var notes = [];
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create Miku and position her at the bottom center of the screen
var miku = game.addChild(new Miku());
miku.x = 2048 / 2;
miku.y = 2732 - 200;
// Function to handle note tapping
function handleTap(x, y, obj) {
for (var i = notes.length - 1; i >= 0; i--) {
if (notes[i].intersects(miku)) {
score += 1;
scoreTxt.setText(score);
notes[i].destroy();
notes.splice(i, 1);
}
}
}
// Game's main update loop
game.update = function () {
// Create new notes at regular intervals
if (LK.ticks % 60 == 0) {
var newNote = new Note();
newNote.x = Math.random() * 2048;
newNote.y = 0;
notes.push(newNote);
game.addChild(newNote);
}
// Update all notes
for (var i = 0; i < notes.length; i++) {
notes[i].update();
}
};
// Event listeners for tapping
game.down = handleTap;
game.move = function (x, y, obj) {
// No move logic needed for this game
};
game.up = function (x, y, obj) {
// No up logic needed for this game
};