User prompt
Rix the bad fluidity
User prompt
Add only two more enemy by round
User prompt
Fix the bad fluidity
User prompt
Improve the fluidity of the game
User prompt
Improve the fluidity of the game
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'length')' in this line: 'self.enemyCounterTxt = new Text2('Enemies: ' + self.enemies.length.toString(), {' Line Number: 103
User prompt
Optimise
User prompt
Improve the fluidity of the game
User prompt
Improve the framerate
User prompt
Fix Bug: 'TypeError: bulletsContainer.addChild is not a function' in this line: 'bulletsContainer.addChild(bullet);' Line Number: 54
User prompt
Fix Bug: 'TypeError: bulletsContainer.addChild is not a function' in this line: 'bulletsContainer.addChild(bullet);' Line Number: 54
User prompt
Improve the code 10 time
User prompt
Fix Bug: 'TypeError: fragment.appendChild is not a function' in this line: 'fragment.appendChild(newEnemy);' Line Number: 128
User prompt
Optmise the code 3 time
User prompt
Fix Bug: 'TypeError: DocumentFragment is not a constructor' in this line: 'var fragment = new DocumentFragment();' Line Number: 120
User prompt
Optimise the game 3 time
User prompt
Optimise
User prompt
make the tower fire bullet at the start
User prompt
move the tower 30 pixel to the right
User prompt
make the tower fire bullet
User prompt
make the tower fire bullet
User prompt
fix the fire
User prompt
optimise the code 3 time
User prompt
optimise the code two time
User prompt
optimise
===================================================================
--- original.js
+++ change.js
@@ -13,10 +13,11 @@
};
self.update = function () {
var currentTime = Date.now();
self.frameCount++;
- if (currentTime - self.lastTime >= 1000) {
- self.framerate = self.frameCount;
+ var elapsedTime = (currentTime - self.lastTime) / 1000;
+ if (elapsedTime >= 1) {
+ self.framerate = self.frameCount / elapsedTime;
self.updateDisplay();
self.frameCount = 0;
self.lastTime = currentTime;
}
@@ -27,8 +28,18 @@
var plainGraphics = self.createAsset('correct_plain_asset_id', 'Correct Plain Graphics Description', .5, .5);
plainGraphics.scale.x = 2;
plainGraphics.scale.y = 2;
plainGraphics.alpha = 0;
+ self.shoot = function (enemies, bulletsContainer) {
+ if (self.cooldownTimer <= 0 && enemies.length > 0) {
+ var bullet = new Bullet(self);
+ bullet.x = self.x;
+ bullet.y = self.y;
+ bulletsContainer.addChild(bullet);
+ self.cooldownTimer = self.cooldown;
+ }
+ self.cooldownTimer--;
+ };
});
var Tower = Container.expand(function (gameInstance) {
var self = Container.call(this);
self.game = gameInstance;
@@ -59,33 +70,17 @@
var enemyGraphics = self.createAsset('enemy', 'Enemy Graphics', .5, .5);
var enemySpeed = 25.6 * 0.7 * 0.6;
self.move = function () {
self.y += enemySpeed;
- if (self.y > LK.stageContainer.height - 50) {
- self.checkBounds();
- }
};
- self.checkBounds = function () {
- if (self.y > LK.stageContainer.height) {
- self.destroy();
- }
- };
});
var Bullet = Container.expand(function (gameInstance) {
var self = Container.call(this);
self.game = gameInstance;
var bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5);
self.move = function () {
self.x += 240;
- if (self.x > LK.stageContainer.width - 50) {
- self.checkBounds();
- }
};
- self.checkBounds = function () {
- if (self.x > LK.stageContainer.width) {
- self.destroy();
- }
- };
});
var Game = Container.expand(function () {
var self = Container.call(this);
self.incrementScore = function () {
@@ -94,9 +89,9 @@
self.spawnEnemies = function () {
this.generateEnemies();
};
self.generateEnemies = function () {
- enemiesSpawnedLastRound += 2;
+ enemiesSpawnedLastRound += 10;
for (var i = 0; i < enemiesSpawnedLastRound; i++) {
var newEnemy = new Enemy();
newEnemy.x = Math.random() * 2048;
newEnemy.y = -25 * (i + 1);
@@ -148,36 +143,31 @@
LK.on('tick', function () {
self.frameRateCounter.update(enemiesSpawnedLastRound);
if (self.enemies.length === 0) {
self.spawnEnemies();
+ } else {
+ towers.forEach(function (tower) {
+ tower.shoot(self.enemies, self.bullets);
+ });
}
- towers.forEach(function (tower) {
- tower.shoot(self.enemies, self.bullets);
- });
- self.enemies.forEach(function (enemy, i) {
+ self.enemies.forEach(function (enemy) {
enemy.move();
- if (enemy.y > LK.stageContainer.height) {
- enemy.destroy();
- self.enemies.splice(i, 1);
- }
});
- self.bullets.forEach(function (bullet, i) {
+ self.bullets.forEach(function (bullet, index) {
bullet.move();
- if (bullet.x > LK.stageContainer.width) {
+ for (var j = self.enemies.length - 1; j >= 0; j--) {
+ if (bullet.intersects(self.enemies[j])) {
+ self.enemies[j].destroy();
+ self.enemies.splice(j, 1);
+ self.incrementScore();
+ bullet.destroy();
+ self.enemyCounterTxt.setText('Enemies: ' + self.enemies.length.toString());
+ break;
+ }
+ }
+ if (bullet.x > 2048) {
bullet.destroy();
- self.bullets.splice(i, 1);
- } else {
- self.enemies.forEach(function (enemy, j) {
- if (bullet.intersects(enemy)) {
- enemy.destroy();
- self.enemies.splice(j, 1);
- self.incrementScore();
- bullet.destroy();
- self.bullets.splice(i, 1);
- return;
- }
- });
+ self.bullets.splice(index, 1);
}
});
- self.enemyCounterTxt.setText('Enemies: ' + self.enemies.length.toString());
});
});
A plain in a comic style with a dirt road with 4 turn staring to top to the botom see from a top and 50 meter high view Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A tower shooting at enemy in a modern style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A single soldat walking downard in a 16 bit style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.