User prompt
the soldiers move faster and a bit randomly
User prompt
add 10 soldiers of each team in random position at start of the game
User prompt
red soldiers shoot toward blue soldiers
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'forEach')' in this line: 'bullets[i].targetTeam.forEach(function (target, index) {' Line Number: 163
User prompt
Fix Bug: 'Timeout.tick error: opposingTeam is not defined' in this line: 'bullet.targetTeam = opposingTeam;' Line Number: 56
User prompt
Fix Bug: 'Timeout.tick error: opposingTeam is not defined' in this line: 'bullet.targetTeam = opposingTeam;' Line Number: 56
User prompt
when the battle start the soldiers move toward each other and shoot at the other team soldiers
User prompt
when the battle start the soldiers start shooting at each other
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
User prompt
Fix Bug: 'TypeError: Cannot set properties of undefined (setting 'color')' in this line: 'self.color = 'red';' Line Number: 15
===================================================================
--- original.js
+++ change.js
@@ -5,74 +5,59 @@
self.move = function () {
self.x += self.speed;
};
});
-var Soldier = Container.expand(function () {
+var RedSoldier = Container.expand(function () {
var self = Container.call(this);
+ var self = Soldier.call(this, 'red');
});
-var RedSoldier = Soldier.expand(function () {
+var Soldier = Container.expand(function (color) {
var self = Container.call(this);
- Soldier.call(this);
- self.color = 'red';
- var soldierGraphics = self.createAsset(self.color + 'Soldier', self.color.charAt(0).toUpperCase() + self.color.slice(1) + ' Soldier Graphics', .5, .5);
- self.move = function (opposingTeam) {
- if (!this.isFighting) return;
- for (var i = 0; i < opposingTeam.length; i++) {
- var target = opposingTeam[i];
- if (Math.abs(this.y - target.y) <= 50) {
- this.shoot(target, opposingTeam);
- }
+ self.destroy = function () {
+ if (self.shootInterval) {
+ LK.clearInterval(self.shootInterval);
}
+ Container.prototype.destroy.call(self);
};
- self.shoot = function (target, opposingTeam) {
- var bullet = new Bullet();
- bullet.x = this.x;
- bullet.y = this.y;
- bullet.targetTeam = opposingTeam;
- LK.emit('bulletFired', {
- detail: bullet
- });
+ self.startFighting = function (opposingTeam) {
+ self.isFighting = true;
+ self.shootInterval = LK.setInterval(function () {
+ self.shoot(opposingTeam);
+ }, 1400);
};
-});
-var BlueSoldier = Soldier.expand(function () {
- var self = Container.call(this);
- Soldier.call(this);
- self.color = 'blue';
- var soldierGraphics = self.createAsset(self.color + 'Soldier', self.color.charAt(0).toUpperCase() + self.color.slice(1) + ' Soldier Graphics', .5, .5);
+ var soldierGraphics = self.createAsset(color + 'Soldier', color.charAt(0).toUpperCase() + color.slice(1) + ' Soldier Graphics', .5, .5);
self.move = function (opposingTeam) {
- if (!this.isFighting) return;
- this.x += this.speed;
- for (var i = 0; i < opposingTeam.length; i++) {
- var target = opposingTeam[i];
- if (this.intersects(target)) {
- this.shoot(target, opposingTeam);
- }
+ if (self.isFighting && opposingTeam.length > 0) {
+ var target = opposingTeam[0];
+ var directionX = target.x > self.x ? 1 : -1;
+ var directionY = target.y > self.y ? 1 : -1;
+ self.x += 1.04 * directionX;
+ self.y += 1.04 * directionY;
}
};
- self.shoot = function (target, opposingTeam) {
+ self.shoot = function (targetTeam) {
var bullet = new Bullet();
- bullet.x = this.x;
- bullet.y = this.y;
- bullet.targetTeam = opposingTeam;
+ if (color === 'red') {
+ bullet.x = self.x + self.width / 2;
+ bullet.speed = -Math.abs(bullet.speed);
+ } else {
+ bullet.x = self.x - self.width / 2;
+ }
+ bullet.y = self.y;
+ bullet.targetTeam = targetTeam;
+ if (color === 'blue') {
+ bullet.speed = Math.abs(bullet.speed);
+ }
+ self.parent.addChild(bullet);
LK.emit('bulletFired', {
detail: bullet
});
};
});
-Soldier.prototype.destroy = function () {
- if (this.shootInterval) {
- LK.clearInterval(this.shootInterval);
- }
- Container.prototype.destroy.call(this);
-};
-Soldier.prototype.startFighting = function (opposingTeam) {
- this.isFighting = true;
- this.shootInterval = LK.setInterval((function () {
- this.shoot(opposingTeam);
- }).bind(this), 1400);
-};
-Soldier.prototype.move = function (opposingTeam) {};
-Soldier.prototype.shoot = function (targetTeam) {};
+var BlueSoldier = Container.expand(function () {
+ var self = Container.call(this);
+ var self = Soldier.call(this, 'blue');
+});
var Game = Container.expand(function () {
var self = Container.call(this);
var frameRateText = new Text2('FPS: Calculating...', {
size: 100,
@@ -94,18 +79,18 @@
lastTick = now;
}
});
LK.on('soldierHit', function (event) {
- var soldier = event.detail.soldier;
- var target = event.detail.target;
- var targetIndex = target.team.indexOf(target);
+ var bulletIndex = bullets.indexOf(event.detail.bullet);
+ var targetIndex = event.detail.targetTeam ? event.detail.targetTeam.indexOf(event.detail.target) : -1;
+ if (bulletIndex !== -1) {
+ bullets.splice(bulletIndex, 1);
+ }
if (targetIndex !== -1) {
- target.team.splice(targetIndex, 1);
+ event.detail.target.team.splice(targetIndex, 1);
}
- target.destroy();
- if (soldier) {
- soldier.destroy();
- }
+ event.detail.target.destroy();
+ event.detail.bullet.destroy();
});
LK.on('bulletFired', function (event) {
bullets.push(event.detail);
self.addChild(event.detail);
@@ -133,9 +118,23 @@
});
}
});
var soldiers = [];
+ for (var i = 0; i < 10; i++) {
+ var soldier = new BlueSoldier();
+ soldier.x = Math.random() * 1024;
+ soldier.y = Math.random() * 2732;
+ soldiers.push(soldier);
+ self.addChild(soldier);
+ }
var enemies = [];
+ for (var i = 0; i < 10; i++) {
+ var enemy = new RedSoldier();
+ enemy.x = 1024 + Math.random() * 1024;
+ enemy.y = Math.random() * 2732;
+ enemies.push(enemy);
+ self.addChild(enemy);
+ }
var bullets = [];
var spawnSoldier = function (position) {
var soldier = new BlueSoldier();
soldier.x = position.x;
@@ -158,23 +157,23 @@
enemies[i].move(soldiers);
}
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].move();
- if (bullets[i] && bullets[i].targetTeam) {
- bullets[i].targetTeam.forEach(function (target, index) {
- if (bullets[i].intersects(target)) {
- LK.emit('soldierHit', {
- detail: {
- bullet: bullets[i],
- target: target
- }
- });
- target.destroy();
+ bullets[i].targetTeam.forEach(function (target, index) {
+ if (bullets[i] && bullets[i].intersects(target)) {
+ LK.emit('soldierHit', {
+ detail: {
+ bullet: bullets[i],
+ target: target
+ }
+ });
+ target.destroy();
+ if (bullets[i]) {
bullets[i].destroy();
- bullets.splice(i, 1);
}
- });
- }
+ bullets.splice(i, 1);
+ }
+ });
if (bullets[i] && bullets[i].y < 0) {
bullets[i].destroy();
bullets.splice(i, 1);
}
a big plain show from the top with a line right at the center of the plain to the top from the botom Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a blue toy soldier Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a red toy soldier Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A start Battle button Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A blue soldier toy Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A red soldier toy Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a bullet in an anime style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.