/**** * Classes ****/ // Enemy class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { if (LK.keys['w'] || LK.keys['ArrowUp']) { self.y -= 5; } if (LK.keys['s'] || LK.keys['ArrowDown']) { self.y += 5; } if (LK.keys['a'] || LK.keys['ArrowLeft']) { self.x -= 5; } if (LK.keys['d'] || LK.keys['ArrowRight']) { self.x += 5; } }; }); // VhsTape class var VhsTape = Container.expand(function () { var self = Container.call(this); var tapeGraphics = self.attachAsset('vhsTape', { anchorX: 0.5, anchorY: 0.5 }); self.collected = false; self.on('over', function () { if (!self.collected) { self.collected = true; LK.setScore(LK.getScore() + 1); } }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize assets for the game var player = game.addChild(new Player()); player.x = 1024; // Center horizontally player.y = 2500; // Position towards the bottom var vhsTapes = []; // Create vhs tapes for (var i = 0; i < 5; i++) { var tape = new VhsTape(); tape.x = Math.random() * 2048; // Random position horizontally tape.y = Math.random() * 2732; // Random position vertically vhsTapes.push(tape); game.addChild(tape); } // Touch event to move player game.on('down', function (obj) { var pos = obj.event.getLocalPosition(game); player.x = pos.x; }); // Game tick LK.on('tick', function () { // Collision detection (simplified) vhsTapes.forEach(function (tape) { if (tape.intersects(player)) { // Collect tape if (!tape.collected) { tape.collect(); // Update score LK.setScore(LK.getScore() + 1); } } }); // Check if all tapes are collected if (LK.getScore() == 5) { // Game win logic here LK.showGameOver(); } });
===================================================================
--- original.js
+++ change.js
@@ -8,9 +8,20 @@
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
- // Player update logic here
+ if (LK.keys['w'] || LK.keys['ArrowUp']) {
+ self.y -= 5;
+ }
+ if (LK.keys['s'] || LK.keys['ArrowDown']) {
+ self.y += 5;
+ }
+ if (LK.keys['a'] || LK.keys['ArrowLeft']) {
+ self.x -= 5;
+ }
+ if (LK.keys['d'] || LK.keys['ArrowRight']) {
+ self.x += 5;
+ }
};
});
// VhsTape class
var VhsTape = Container.expand(function () {
@@ -19,11 +30,14 @@
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
- self.collect = function () {
- self.collected = true;
- };
+ self.on('over', function () {
+ if (!self.collected) {
+ self.collected = true;
+ LK.setScore(LK.getScore() + 1);
+ }
+ });
});
/****
* Initialize Game