User prompt
Only the road gets moved not the buildings
User prompt
Make it lower
User prompt
Make a road rectangle
User prompt
Add more buildings
User prompt
Make an animation of building being reconstructed by making a fade in effect
User prompt
Make a sound when it explodes
User prompt
Make a little road with cars driving on it
User prompt
Please fix the bug: 'Timeout.tick error: LK.effects.shakeScreen is not a function' in or related to this line: 'LK.effects.shakeScreen(500);' Line Number: 26
User prompt
Make it shake the screen when it explodes
User prompt
It didnt flasht eh screen
User prompt
Add a animation of buildings being reconstructed
User prompt
Make the bomb wait for 1 second, And then explodes
User prompt
The bomb isnt shown, Which makes it unused
User prompt
When all buildings are destroyed, add new ones, Also add a explosion effect
Initial prompt
Demolishin'
/****
* Classes
****/
// Bomb class
var Bomb = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.attachAsset('bomb', {
anchorX: 0.5,
anchorY: 0.5
});
self.explode = function () {
// Create explosion effect
var explosion = new Explosion();
explosion.x = self.x;
explosion.y = self.y;
game.addChild(explosion);
explosion.init();
// Flash the screen
LK.effects.flashScreen(0xff0000, 500);
// Damage nearby buildings
for (var i = 0; i < buildings.length; i++) {
if (self.intersects(buildings[i])) {
buildings[i].takeDamage(50);
}
}
LK.getSound('explosion').play();
self.destroy();
};
});
//<Assets used in the game will automatically appear here>
// Building class
var Building = Container.expand(function () {
var self = Container.call(this);
var buildingGraphics = self.attachAsset('building', {
anchorX: 0.5,
anchorY: 0.5
});
// Create reconstruction animation
var reconstruction = new BuildingReconstruction();
reconstruction.x = self.x;
reconstruction.y = self.y;
game.addChild(reconstruction);
reconstruction.init();
self.health = 100;
self.update = function () {
if (self.health <= 0) {
self.destroy();
}
};
self.takeDamage = function (damage) {
self.health -= damage;
};
});
// BuildingReconstruction class
var BuildingReconstruction = Container.expand(function () {
var self = Container.call(this);
self.init = function () {
// Create reconstruction effect
LK.effects.flashObject(self, 0x00ff00, 500);
};
});
// Explosion class
var Explosion = Container.expand(function () {
var self = Container.call(this);
self.init = function () {
// Create explosion effect
LK.effects.flashObject(self, 0xff0000, 500);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize buildings array
var buildings = [];
// Create buildings
for (var i = 0; i < 5; i++) {
var building = new Building();
building.x = 400 * (i + 1);
building.y = 1366;
buildings.push(building);
game.addChild(building);
}
// Initialize bombs array
var bombs = [];
// Handle touch down event to place bombs
game.down = function (x, y, obj) {
var bomb = new Bomb();
bomb.x = x;
bomb.y = y;
bombs.push(bomb);
game.addChild(bomb);
LK.setTimeout(function () {
bomb.explode();
}, 1000);
};
// Update game state
game.update = function () {
for (var i = buildings.length - 1; i >= 0; i--) {
buildings[i].update();
if (buildings[i].health <= 0) {
buildings.splice(i, 1);
}
}
for (var j = bombs.length - 1; j >= 0; j--) {
if (bombs[j].destroyed) {
bombs.splice(j, 1);
}
}
// Add new buildings when all are destroyed
if (buildings.length === 0) {
LK.setTimeout(function () {
for (var i = 0; i < 5; i++) {
var building = new Building();
building.x = 400 * (i + 1);
building.y = 1366;
buildings.push(building);
game.addChild(building);
}
}, 1000);
}
}; ===================================================================
--- original.js
+++ change.js
@@ -22,8 +22,9 @@
if (self.intersects(buildings[i])) {
buildings[i].takeDamage(50);
}
}
+ LK.getSound('explosion').play();
self.destroy();
};
});
//<Assets used in the game will automatically appear here>
@@ -57,23 +58,8 @@
// Create reconstruction effect
LK.effects.flashObject(self, 0x00ff00, 500);
};
});
-// Car class
-var Car = Container.expand(function () {
- var self = Container.call(this);
- var carGraphics = self.attachAsset('car', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 5;
- self.update = function () {
- self.x += self.speed;
- if (self.x > 2048) {
- self.x = -100;
- }
- };
-});
// Explosion class
var Explosion = Container.expand(function () {
var self = Container.call(this);
self.init = function () {
@@ -91,23 +77,17 @@
/****
* Game Code
****/
-// Initialize cars array
-var cars = [];
-// Create road
-var road = new Graphics();
-road.beginFill(0x808080);
-road.drawRect(0, 1366 - 100, 2048, 100);
-road.endFill();
-game.addChild(road);
-// Create cars
+// Initialize buildings array
+var buildings = [];
+// Create buildings
for (var i = 0; i < 5; i++) {
- var car = new Car();
- car.x = 400 * i;
- car.y = 1366 - 75;
- cars.push(car);
- game.addChild(car);
+ var building = new Building();
+ building.x = 400 * (i + 1);
+ building.y = 1366;
+ buildings.push(building);
+ game.addChild(building);
}
// Initialize bombs array
var bombs = [];
// Handle touch down event to place bombs
@@ -122,10 +102,13 @@
}, 1000);
};
// Update game state
game.update = function () {
- for (var i = 0; i < cars.length; i++) {
- cars[i].update();
+ for (var i = buildings.length - 1; i >= 0; i--) {
+ buildings[i].update();
+ if (buildings[i].health <= 0) {
+ buildings.splice(i, 1);
+ }
}
for (var j = bombs.length - 1; j >= 0; j--) {
if (bombs[j].destroyed) {
bombs.splice(j, 1);