/**** * Classes ****/ // Building class to manage buildings var Building = Container.expand(function () { var self = Container.call(this); self.level = 1; self.update = function () { // Update building logic }; }); // Enemy class to manage enemies var Enemy = Container.expand(function () { var self = Container.call(this); self.health = 100; self.update = function () { // Update enemy logic }; }); // Hero class to manage the player's hero var Hero = Container.expand(function () { var self = Container.call(this); self.health = 100; self.update = function () { // Update hero logic }; }); // Kingdom class to manage the player's kingdom var Kingdom = Container.expand(function () { var self = Container.call(this); self.resources = { wood: new Resource(), stone: new Resource(), food: new Resource() }; self.buildings = []; self.update = function () { // Update kingdom logic }; }); //<Assets used in the game will automatically appear here> // Resource class to manage resources var Resource = Container.expand(function () { var self = Container.call(this); self.amount = 0; self.update = function () { // Update resource logic }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Handle touch events game.down = function (x, y, obj) { // Handle touch down event }; game.move = function (x, y, obj) { // Handle touch move event }; game.up = function (x, y, obj) { // Handle touch up event }; // Initialize kingdom var kingdom = new Kingdom(); kingdom.x = 2048 / 2; kingdom.y = 2732 / 2; game.addChild(kingdom); // Initialize resources var woodResource = LK.getAsset('wood', { anchorX: 0.5, anchorY: 0.5 }); var stoneResource = LK.getAsset('stone', { anchorX: 0.5, anchorY: 0.5 }); var foodResource = LK.getAsset('food', { anchorX: 0.5, anchorY: 0.5 }); kingdom.resources.wood.addChild(woodResource); kingdom.resources.stone.addChild(stoneResource); kingdom.resources.food.addChild(foodResource); // Initialize buildings var castle = new Building(); castle.x = 2048 / 2; castle.y = 2732 / 2; kingdom.buildings.push(castle); game.addChild(castle); // Initialize hero var hero = new Hero(); hero.x = 2048 / 2; hero.y = 2732 / 2; game.addChild(hero); // Initialize enemies var enemies = []; for (var i = 0; i < 5; i++) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = Math.random() * 2732; enemies.push(enemy); game.addChild(enemy); } // Initialize kingdom var kingdom = new Kingdom(); kingdom.x = 2048 / 2; kingdom.y = 2732 / 2; game.addChild(kingdom); // Initialize resources var woodResource = LK.getAsset('wood', { anchorX: 0.5, anchorY: 0.5 }); var stoneResource = LK.getAsset('stone', { anchorX: 0.5, anchorY: 0.5 }); var foodResource = LK.getAsset('food', { anchorX: 0.5, anchorY: 0.5 }); kingdom.resources.wood.addChild(woodResource); kingdom.resources.stone.addChild(stoneResource); kingdom.resources.food.addChild(foodResource); // Initialize buildings var castle = new Building(); castle.x = 2048 / 2; castle.y = 2732 / 2; kingdom.buildings.push(castle); game.addChild(castle); // Initialize hero var hero = new Hero(); hero.x = 2048 / 2; hero.y = 2732 / 2; game.addChild(hero); // Initialize enemies var enemies = []; for (var i = 0; i < 5; i++) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = Math.random() * 2732; enemies.push(enemy); game.addChild(enemy); } // Update game logic game.update = function () { kingdom.update(); hero.update(); for (var i = 0; i < kingdom.buildings.length; i++) { kingdom.buildings[i].update(); } for (var i = 0; i < enemies.length; i++) { enemies[i].update(); } }; // Handle touch events game.down = function (x, y, obj) { // Handle touch down event }; game.move = function (x, y, obj) { // Handle touch move event }; game.up = function (x, y, obj) { // Handle touch up event }; game.update = function () { kingdom.update(); hero.update(); for (var i = 0; i < kingdom.buildings.length; i++) { kingdom.buildings[i].update(); } for (var i = 0; i < enemies.length; i++) { enemies[i].update(); } };
===================================================================
--- original.js
+++ change.js
@@ -57,8 +57,18 @@
/****
* Game Code
****/
+// Handle touch events
+game.down = function (x, y, obj) {
+ // Handle touch down event
+};
+game.move = function (x, y, obj) {
+ // Handle touch move event
+};
+game.up = function (x, y, obj) {
+ // Handle touch up event
+};
// Initialize kingdom
var kingdom = new Kingdom();
kingdom.x = 2048 / 2;
kingdom.y = 2732 / 2;
@@ -98,8 +108,49 @@
enemy.y = Math.random() * 2732;
enemies.push(enemy);
game.addChild(enemy);
}
+// Initialize kingdom
+var kingdom = new Kingdom();
+kingdom.x = 2048 / 2;
+kingdom.y = 2732 / 2;
+game.addChild(kingdom);
+// Initialize resources
+var woodResource = LK.getAsset('wood', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+var stoneResource = LK.getAsset('stone', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+var foodResource = LK.getAsset('food', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+kingdom.resources.wood.addChild(woodResource);
+kingdom.resources.stone.addChild(stoneResource);
+kingdom.resources.food.addChild(foodResource);
+// Initialize buildings
+var castle = new Building();
+castle.x = 2048 / 2;
+castle.y = 2732 / 2;
+kingdom.buildings.push(castle);
+game.addChild(castle);
+// Initialize hero
+var hero = new Hero();
+hero.x = 2048 / 2;
+hero.y = 2732 / 2;
+game.addChild(hero);
+// Initialize enemies
+var enemies = [];
+for (var i = 0; i < 5; i++) {
+ var enemy = new Enemy();
+ enemy.x = Math.random() * 2048;
+ enemy.y = Math.random() * 2732;
+ enemies.push(enemy);
+ game.addChild(enemy);
+}
// Update game logic
game.update = function () {
kingdom.update();
hero.update();
@@ -118,5 +169,15 @@
// Handle touch move event
};
game.up = function (x, y, obj) {
// Handle touch up event
+};
+game.update = function () {
+ kingdom.update();
+ hero.update();
+ for (var i = 0; i < kingdom.buildings.length; i++) {
+ kingdom.buildings[i].update();
+ }
+ for (var i = 0; i < enemies.length; i++) {
+ enemies[i].update();
+ }
};
\ No newline at end of file