User prompt
Green icon go to up and exit to down return
User prompt
Green icon return come a down
User prompt
Green icon go to up
User prompt
Player tap to screen move to icon
User prompt
Please fix the bug: 'TypeError: LK.isKeyDown is not a function' in or related to this line: 'if (LK.isKeyDown('ArrowLeft')) {' Line Number: 37
User prompt
Left right move to all icon
Initial prompt
Adventure time
/****
* Classes
****/
// Create an Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
// Move enemy left and right
self.x += self.speed;
if (self.x > 2048 || self.x < 0) {
self.speed *= -1; // Reverse direction when hitting screen edge
}
};
});
// The assets will be automatically created and loaded by the LK engine
// Create a Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Move player left and right
// Move player based on touch input
self.move = function (x, y, obj) {
if (x < self.x) {
self.x -= self.speed;
} else if (x > self.x) {
self.x += self.speed;
}
};
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize player and enemy
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
var enemies = [];
for (var i = 0; i < 10; i++) {
var enemy = game.addChild(new Enemy());
enemy.x = Math.random() * 2048;
enemy.y = Math.random() * 2732;
enemies.push(enemy);
}
// Game update function
game.update = function () {
// Player and enemy update logic goes here
for (var i = 0; i < enemies.length; i++) {
if (player.intersects(enemies[i])) {
// Game over logic goes here
LK.showGameOver();
}
}
};
// Game touch events
game.down = function (x, y, obj) {
player.move(x, y, obj);
};
game.move = function (x, y, obj) {
player.move(x, y, obj);
};
game.up = function (x, y, obj) {
// Touch up logic goes here
}; ===================================================================
--- original.js
+++ change.js
@@ -71,9 +71,9 @@
}
};
// Game touch events
game.down = function (x, y, obj) {
- // Touch down logic goes here
+ player.move(x, y, obj);
};
game.move = function (x, y, obj) {
player.move(x, y, obj);
};