/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Class for the Cube var Cube = Container.expand(function () { var self = Container.call(this); var cubeGraphics = self.attachAsset('cube', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = 2; self.speedY = 2; self.update = function () { self.x += self.speedX; self.y += self.speedY; // Bounce off the edges if (self.x < 0 || self.x > 2048) { self.speedX *= -1; } if (self.y < 0 || self.y > 2732) { self.speedY *= -1; } }; }); // Class for the Sphere var Sphere = Container.expand(function () { var self = Container.call(this); var sphereGraphics = self.attachAsset('sphere', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = -2; self.speedY = -2; self.update = function () { self.x += self.speedX; self.y += self.speedY; // Bounce off the edges if (self.x < 0 || self.x > 2048) { self.speedX *= -1; } if (self.y < 0 || self.y > 2732) { self.speedY *= -1; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize the cube and sphere var cube = new Cube(); cube.x = 1024; // Start in the middle of the screen cube.y = 1366; game.addChild(cube); var sphere = new Sphere(); sphere.x = 1024; // Start in the middle of the screen sphere.y = 1366; game.addChild(sphere); // Update function for the game game.update = function () { cube.update(); sphere.update(); };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the Cube
var Cube = Container.expand(function () {
var self = Container.call(this);
var cubeGraphics = self.attachAsset('cube', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 2;
self.speedY = 2;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
// Bounce off the edges
if (self.x < 0 || self.x > 2048) {
self.speedX *= -1;
}
if (self.y < 0 || self.y > 2732) {
self.speedY *= -1;
}
};
});
// Class for the Sphere
var Sphere = Container.expand(function () {
var self = Container.call(this);
var sphereGraphics = self.attachAsset('sphere', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = -2;
self.speedY = -2;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
// Bounce off the edges
if (self.x < 0 || self.x > 2048) {
self.speedX *= -1;
}
if (self.y < 0 || self.y > 2732) {
self.speedY *= -1;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize the cube and sphere
var cube = new Cube();
cube.x = 1024; // Start in the middle of the screen
cube.y = 1366;
game.addChild(cube);
var sphere = new Sphere();
sphere.x = 1024; // Start in the middle of the screen
sphere.y = 1366;
game.addChild(sphere);
// Update function for the game
game.update = function () {
cube.update();
sphere.update();
};