/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Character class for Michele and John var Character = Container.expand(function () { var self = Container.call(this); self.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Character update logic }; self.move = function (x, y) { self.x = x; self.y = y; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize characters var michele = new Character(); var john = new Character(); // Position characters at the start of the game michele.x = 500; michele.y = 2000; john.x = 1500; john.y = 2000; // Add characters to the game game.addChild(michele); game.addChild(john); // Handle dragging of characters var dragNode = null; function handleMove(x, y, obj) { if (dragNode) { dragNode.move(x, y); } } game.move = handleMove; game.down = function (x, y, obj) { if (michele.intersects(obj)) { dragNode = michele; } else if (john.intersects(obj)) { dragNode = john; } handleMove(x, y, obj); }; game.up = function (x, y, obj) { dragNode = null; }; // Update game logic game.update = function () { michele.update(); john.update(); };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Character class for Michele and John
var Character = Container.expand(function () {
var self = Container.call(this);
self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Character update logic
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize characters
var michele = new Character();
var john = new Character();
// Position characters at the start of the game
michele.x = 500;
michele.y = 2000;
john.x = 1500;
john.y = 2000;
// Add characters to the game
game.addChild(michele);
game.addChild(john);
// Handle dragging of characters
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.move(x, y);
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
if (michele.intersects(obj)) {
dragNode = michele;
} else if (john.intersects(obj)) {
dragNode = john;
}
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Update game logic
game.update = function () {
michele.update();
john.update();
};