/**** * Classes ****/ //<Assets used in the game will automatically appear here> // PianoKey class to represent each key on the pizza piano var PianoKey = Container.expand(function () { var self = Container.call(this); var keyGraphics = self.attachAsset('key', { anchorX: 0.5, anchorY: 0.5 }); self.playNote = function () { // Play the specific note assigned to this key LK.getSound(self.note).play(); }; self.down = function (x, y, obj) { self.playNote(); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xFFA500 //Init game with orange background }); /**** * Game Code ****/ // Add text saying Pizza Piano var pizzaPianoText = new Text2('Pizza Piano', { size: 200, fill: "#ffffff" }); pizzaPianoText.anchor.set(0.5, 0.5); pizzaPianoText.x = 2048 / 2; pizzaPianoText.y = 200; game.addChild(pizzaPianoText); // Initialize arrays and variables var keys = []; var notes = ['C', 'D', 'E', 'F', 'G', 'A', 'B']; var brickWall = LK.getAsset('brickWall', { anchorX: 0.5, anchorY: 0.5, scaleX: 3, scaleY: 3 }); brickWall.x = 2048 / 2; brickWall.y = 2732 / 2 - 600; game.addChild(brickWall); // Copy and paste the brick asset to down var brickWallCopy = LK.getAsset('brickWall', { anchorX: 0.5, anchorY: 0.5, scaleX: 3, scaleY: 3 }); brickWallCopy.x = 2048 / 2; brickWallCopy.y = 2732 / 2 + 600; game.addChild(brickWallCopy); // Create piano keys for (var i = 0; i < notes.length; i++) { var key = new PianoKey(); key.note = notes[i]; key.x = 2048 / 2 - notes.length / 2 * 300 + i * 300 + 200; // Adjusted spacing to place keys even closer to each other and moved more to the right key.y = 2732 / 2; keys.push(key); game.addChild(key); } // Update function to handle game logic game.update = function () { // No specific update logic needed for this simple game }; // Add event listeners for touch interactions game.down = function (x, y, obj) { for (var i = 0; i < keys.length; i++) { if (keys[i].intersects(obj)) { keys[i].down(x, y, obj); } } };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// PianoKey class to represent each key on the pizza piano
var PianoKey = Container.expand(function () {
var self = Container.call(this);
var keyGraphics = self.attachAsset('key', {
anchorX: 0.5,
anchorY: 0.5
});
self.playNote = function () {
// Play the specific note assigned to this key
LK.getSound(self.note).play();
};
self.down = function (x, y, obj) {
self.playNote();
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFA500 //Init game with orange background
});
/****
* Game Code
****/
// Add text saying Pizza Piano
var pizzaPianoText = new Text2('Pizza Piano', {
size: 200,
fill: "#ffffff"
});
pizzaPianoText.anchor.set(0.5, 0.5);
pizzaPianoText.x = 2048 / 2;
pizzaPianoText.y = 200;
game.addChild(pizzaPianoText);
// Initialize arrays and variables
var keys = [];
var notes = ['C', 'D', 'E', 'F', 'G', 'A', 'B'];
var brickWall = LK.getAsset('brickWall', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 3
});
brickWall.x = 2048 / 2;
brickWall.y = 2732 / 2 - 600;
game.addChild(brickWall);
// Copy and paste the brick asset to down
var brickWallCopy = LK.getAsset('brickWall', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 3
});
brickWallCopy.x = 2048 / 2;
brickWallCopy.y = 2732 / 2 + 600;
game.addChild(brickWallCopy);
// Create piano keys
for (var i = 0; i < notes.length; i++) {
var key = new PianoKey();
key.note = notes[i];
key.x = 2048 / 2 - notes.length / 2 * 300 + i * 300 + 200; // Adjusted spacing to place keys even closer to each other and moved more to the right
key.y = 2732 / 2;
keys.push(key);
game.addChild(key);
}
// Update function to handle game logic
game.update = function () {
// No specific update logic needed for this simple game
};
// Add event listeners for touch interactions
game.down = function (x, y, obj) {
for (var i = 0; i < keys.length; i++) {
if (keys[i].intersects(obj)) {
keys[i].down(x, y, obj);
}
}
};