User prompt
Migrate to the latest version of LK
User prompt
Fix Bug: 'TypeError: requestAnimationFrame is not a function' in this line: 'requestAnimationFrame(self.update);' Line Number: 29
User prompt
improve the fps counter
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 82
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 82
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.gameInstance.removeEnemy(self);' Line Number: 82
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 82
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.gameInstance.removeEnemy(self);' Line Number: 82
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 82
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 82
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 82
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.gameInstance.removeEnemy(self);' Line Number: 82
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 82
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 85
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.gameInstance.removeEnemy(self);' Line Number: 82
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 82
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.gameInstance.removeEnemy(self);' Line Number: 82
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 82
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 81
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 80
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 79
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 79
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 79
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 80
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeEnemy')' in this line: 'self.game.removeEnemy(self);' Line Number: 80
/**** * Classes ****/ var Bullet = Container.expand(function (gameInstance) { var self = Container.call(this); self.game = gameInstance; self.game = gameInstance; var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self._move_migrated = function () { self.x += 120; if (self.x > 2048) { self.destroy(); } }; }); var Enemy = Container.expand(function (gameInstance) { var self = Container.call(this); self.game = gameInstance; var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self._move_migrated = function () { self.y += 12.8; if (self.y > 2732) { self.destroy(); } }; }); var FrameRateCounter = Container.expand(function () { var self = Container.call(this); self.lastTime = Date.now(); self.frameCount = 0; self.framerate = 0; self.display = new Text2('FPS: 0', { size: 150, fill: '#000000' }); self.display.anchor.set(1, 0); self.updateDisplay = function () { self.display.setText('FPS: ' + Math.round(self.framerate).toString()); }; self._update_migrated = function (timestamp) { if (!self.lastTime) { self.lastTime = timestamp; } var delta = timestamp - self.lastTime; self.frameCount++; if (delta >= 1000) { self.framerate = self.frameCount; self.updateDisplay(); self.frameCount = 0; self.lastTime = timestamp; } // LK engine's tick event replaces requestAnimationFrame LK.on('tick', self._update_migrated); }; }); var Plain = Container.expand(function () { var self = Container.call(this); var plainGraphics = self.attachAsset('correct_plain_asset_id', { anchorX: 0.5, anchorY: 0.5 }); plainGraphics.scale.x = 2; plainGraphics.scale.y = 2; plainGraphics.alpha = 1; 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; self.game = gameInstance; var towerGraphics = self.attachAsset('tower', { anchorX: 0.5, anchorY: 0.5 }); self.cooldown = 2.5; self.cooldownTimer = 0; self.shoot = function (enemies, bullets) { if (self.cooldownTimer <= 0 && enemies.length > 0) { self.fireBullet(bullets); } self.cooldownTimer--; }; self.fireBullet = function (bullets) { var bullet = new Bullet(self.game); bullet.x = self.x; bullet.y = self.y; gameInstance.bulletsContainer.addChild(bullet); gameInstance.bullets.push(bullet); self.cooldownTimer = self.cooldown; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ game.spawnEnemies = function () { enemiesSpawnedLastRound += 6; for (var i = 0; i < enemiesSpawnedLastRound; i++) { var newEnemy = new Enemy(); newEnemy.x = Math.random() * 2048; newEnemy.y = -50 * (i + 1); game.enemies.push(newEnemy); game.addChild(newEnemy); } game.enemyCounterTxt.setText('Enemies: ' + game.enemies.length.toString()); }; game.updateEnemyCounter = function () {}; game.score = 0; game.gold = 100; game.incrementScore = function () { this.score++; }; game.frameRateCounter = new FrameRateCounter(); LK.gui.topRight.addChild(game.frameRateCounter.display); var enemiesSpawnedLastRound = 1; game.scoreTxt = new Text2(game.score.toString(), { size: 150, fill: "#ffffff" }); game.scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(game.scoreTxt); game.goldTxt = new Text2(game.gold.toString(), { size: 150, fill: "#ffff00" }); game.goldTxt.anchor.set(0, 0); LK.gui.topLeft.addChild(game.goldTxt); game.enemies = []; game.enemyCounterTxt = new Text2('Enemies: ' + game.enemies.length.toString(), { size: 150, fill: "#ff0000" }); game.enemyCounterTxt.anchor.set(0, 1); LK.gui.bottomLeft.addChild(game.enemyCounterTxt); game.setBackgroundColor(0xFFFFFF); var towers = []; game.bullets = []; game.bulletsContainer = game.addChild(new Container()); game.enemies = []; var initialTower = new Tower(game); initialTower.x = 0 + initialTower.width / 2 - 130; initialTower.y = 500 + initialTower.height / 2 + 300; towers.push(initialTower); game.addChild(initialTower); var plain = game.addChild(new Plain()); plain.x = 2048 / 2; plain.y = 2732 / 2; game.addChild(plain); var enemy = new Enemy(); enemy.x = 2048 / 2; enemy.y = -enemy.height / 2; game.enemies.push(enemy); game.addChild(enemy); game.on('down', function (x, y, obj) { var event = obj; var pos = game.toLocal(event.global); if (game.gold >= 50) { var newTower = new Tower(game); newTower.x = pos.x; newTower.y = pos.y; game.addChild(newTower); towers.push(newTower); game.gold -= 50; game.goldTxt.setText(game.gold.toString()); } }); LK.on('tick', function () { game.frameRateCounter._update_migrated(); if (game.enemies.length === 0) { game.spawnEnemies(); } else { towers.forEach(function (tower) { tower.shoot(game.enemies, game.bullets); }); } game.enemies.forEach(function (enemy) { enemy._move_migrated(); }); game.bullets.forEach(function (bullet, index) { bullet._move_migrated(); for (var j = game.enemies.length - 1; j >= 0; j--) { if (bullet.intersects(game.enemies[j])) { game.enemies[j].destroy(); game.enemies.splice(j, 1); game.incrementScore(); game.scoreTxt.setText(game.score.toString()); game.gold += 50; bullet.destroy(); game.enemyCounterTxt.setText('Enemies: ' + game.enemies.length.toString()); break; } } if (bullet.x > 2048) { bullet.destroy(); game.bullets.splice(index, 1); } }); });
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,36 @@
/****
* Classes
-****/
+****/
+var Bullet = Container.expand(function (gameInstance) {
+ var self = Container.call(this);
+ self.game = gameInstance;
+ self.game = gameInstance;
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self._move_migrated = function () {
+ self.x += 120;
+ if (self.x > 2048) {
+ self.destroy();
+ }
+ };
+});
+var Enemy = Container.expand(function (gameInstance) {
+ var self = Container.call(this);
+ self.game = gameInstance;
+ var enemyGraphics = self.attachAsset('enemy', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self._move_migrated = function () {
+ self.y += 12.8;
+ if (self.y > 2732) {
+ self.destroy();
+ }
+ };
+});
var FrameRateCounter = Container.expand(function () {
var self = Container.call(this);
self.lastTime = Date.now();
self.frameCount = 0;
@@ -13,9 +42,9 @@
self.display.anchor.set(1, 0);
self.updateDisplay = function () {
self.display.setText('FPS: ' + Math.round(self.framerate).toString());
};
- self.update = function (timestamp) {
+ self._update_migrated = function (timestamp) {
if (!self.lastTime) {
self.lastTime = timestamp;
}
var delta = timestamp - self.lastTime;
@@ -26,14 +55,17 @@
self.frameCount = 0;
self.lastTime = timestamp;
}
// LK engine's tick event replaces requestAnimationFrame
- LK.on('tick', self.update);
+ LK.on('tick', self._update_migrated);
};
});
var Plain = Container.expand(function () {
var self = Container.call(this);
- var plainGraphics = self.createAsset('correct_plain_asset_id', 'Correct Plain Graphics Description', .5, .5);
+ var plainGraphics = self.attachAsset('correct_plain_asset_id', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
plainGraphics.scale.x = 2;
plainGraphics.scale.y = 2;
plainGraphics.alpha = 1;
self.shoot = function (enemies, bulletsContainer) {
@@ -50,9 +82,12 @@
var Tower = Container.expand(function (gameInstance) {
var self = Container.call(this);
self.game = gameInstance;
self.game = gameInstance;
- var towerGraphics = self.createAsset('tower', 'Tower Graphics', .5, .5);
+ var towerGraphics = self.attachAsset('tower', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.cooldown = 2.5;
self.cooldownTimer = 0;
self.shoot = function (enemies, bullets) {
if (self.cooldownTimer <= 0 && enemies.length > 0) {
@@ -68,42 +103,19 @@
gameInstance.bullets.push(bullet);
self.cooldownTimer = self.cooldown;
};
});
-var Enemy = Container.expand(function (gameInstance) {
- var self = Container.call(this);
- self.game = gameInstance;
- var enemyGraphics = self.createAsset('enemy', 'Enemy Graphics', .5, .5);
- self.move = function () {
- self.y += 12.8;
- if (self.y > 2732) {
- self.destroy();
- }
- };
-});
-var Bullet = Container.expand(function (gameInstance) {
- var self = Container.call(this);
- self.game = gameInstance;
- self.game = gameInstance;
- var bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5);
- self.move = function () {
- self.x += 120;
- if (self.x > 2048) {
- self.destroy();
- }
- };
-});
/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
-****/
+****/
game.spawnEnemies = function () {
enemiesSpawnedLastRound += 6;
for (var i = 0; i < enemiesSpawnedLastRound; i++) {
var newEnemy = new Enemy();
@@ -127,9 +139,9 @@
size: 150,
fill: "#ffffff"
});
game.scoreTxt.anchor.set(0.5, 0);
-LK.gui.topCenter.addChild(game.scoreTxt);
+LK.gui.top.addChild(game.scoreTxt);
game.goldTxt = new Text2(game.gold.toString(), {
size: 150,
fill: "#ffff00"
});
@@ -160,11 +172,11 @@
enemy.x = 2048 / 2;
enemy.y = -enemy.height / 2;
game.enemies.push(enemy);
game.addChild(enemy);
-game.on('down', function (obj) {
- var event = obj.event;
- var pos = event.getLocalPosition(game);
+game.on('down', function (x, y, obj) {
+ var event = obj;
+ var pos = game.toLocal(event.global);
if (game.gold >= 50) {
var newTower = new Tower(game);
newTower.x = pos.x;
newTower.y = pos.y;
@@ -174,21 +186,21 @@
game.goldTxt.setText(game.gold.toString());
}
});
LK.on('tick', function () {
- game.frameRateCounter.update();
+ game.frameRateCounter._update_migrated();
if (game.enemies.length === 0) {
game.spawnEnemies();
} else {
towers.forEach(function (tower) {
tower.shoot(game.enemies, game.bullets);
});
}
game.enemies.forEach(function (enemy) {
- enemy.move();
+ enemy._move_migrated();
});
game.bullets.forEach(function (bullet, index) {
- bullet.move();
+ bullet._move_migrated();
for (var j = game.enemies.length - 1; j >= 0; j--) {
if (bullet.intersects(game.enemies[j])) {
game.enemies[j].destroy();
game.enemies.splice(j, 1);
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.