/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Block = Container.expand(function () { var self = Container.call(this); var blockGraphics = self.attachAsset('block', { anchorX: 0.5, anchorY: 0.5 }); return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.inventory = []; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Initialize assets used in this game. Scale them according to what is needed for the game. game.setBackgroundColor(0x87CEEB); // Set background color to sky blue var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2; var blocks = []; var isPlacingBlock = false; // Function to place a block function placeBlock(x, y) { var newBlock = new Block(); newBlock.x = Math.floor(x / 100) * 100; newBlock.y = Math.floor(y / 100) * 100; blocks.push(newBlock); game.addChild(newBlock); LK.getSound('placeBlock').play(); } // Function to mine a block function mineBlock(block) { block.destroy(); blocks.splice(blocks.indexOf(block), 1); LK.getSound('mineBlock').play(); } // Handle game move events game.move = function (x, y, obj) { if (isPlacingBlock) { placeBlock(x, y); } }; // Handle game down events game.down = function (x, y, obj) { isPlacingBlock = true; placeBlock(x, y); }; // Handle game up events game.up = function (x, y, obj) { isPlacingBlock = false; }; // Update game every tick game.update = function () { // Check for block mining for (var i = blocks.length - 1; i >= 0; i--) { if (player.intersects(blocks[i])) { mineBlock(blocks[i]); } } }; // Play background music LK.playMusic('bgMusic');
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,85 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var Block = Container.expand(function () {
+ var self = Container.call(this);
+ var blockGraphics = self.attachAsset('block', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ return self;
+});
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.inventory = [];
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB // Sky blue background
+});
+
+/****
+* Game Code
+****/
+// Initialize assets used in this game. Scale them according to what is needed for the game.
+game.setBackgroundColor(0x87CEEB); // Set background color to sky blue
+var player = game.addChild(new Player());
+player.x = 2048 / 2;
+player.y = 2732 / 2;
+var blocks = [];
+var isPlacingBlock = false;
+// Function to place a block
+function placeBlock(x, y) {
+ var newBlock = new Block();
+ newBlock.x = Math.floor(x / 100) * 100;
+ newBlock.y = Math.floor(y / 100) * 100;
+ blocks.push(newBlock);
+ game.addChild(newBlock);
+ LK.getSound('placeBlock').play();
+}
+// Function to mine a block
+function mineBlock(block) {
+ block.destroy();
+ blocks.splice(blocks.indexOf(block), 1);
+ LK.getSound('mineBlock').play();
+}
+// Handle game move events
+game.move = function (x, y, obj) {
+ if (isPlacingBlock) {
+ placeBlock(x, y);
+ }
+};
+// Handle game down events
+game.down = function (x, y, obj) {
+ isPlacingBlock = true;
+ placeBlock(x, y);
+};
+// Handle game up events
+game.up = function (x, y, obj) {
+ isPlacingBlock = false;
+};
+// Update game every tick
+game.update = function () {
+ // Check for block mining
+ for (var i = blocks.length - 1; i >= 0; i--) {
+ if (player.intersects(blocks[i])) {
+ mineBlock(blocks[i]);
+ }
+ }
+};
+// Play background music
+LK.playMusic('bgMusic');
\ No newline at end of file