Code edit (1 edits merged)
Please save this source code
User prompt
when merging zombies make scale 1.2 x larger than the average of the scale of the two input zombies
User prompt
modify background alpha to .4
Code edit (1 edits merged)
Please save this source code
User prompt
change hero shadow to .3
User prompt
Set player shadow alpha to .5
User prompt
set hero shadow anchor to .5,.5
User prompt
add a shadow to player, with a smaller z-index than the player graphics
User prompt
Spawn zombies slower
User prompt
zombies does not have a self.maxHealth, which makes the marge code break, update code to use the variables on zombie.healthBar
User prompt
when merging also update the max health to the sum of the two merged zombies
User prompt
When merging zombies, set an attribute that indicates zombies[k] has been removed. Don't allow removed zombies to be merged
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'zombies[i].intersects')' in this line: 'if (zombies[i] !== zombies[k] && zombies[i].intersects(zombies[k])) {' Line Number: 189
User prompt
in tick when merging zombies, if merge return true, destroy the zombies[k] and remove it from the array
User prompt
In the merge function don't destroy the other zombie, simply return true
Code edit (1 edits merged)
Please save this source code
User prompt
Move the zombie to zombie intersection code to game class
User prompt
If two zombies touch each other, merge them together into a larger zombie
User prompt
Remove bullets that fly off screen
User prompt
On bullets don’t set a target, just set a direction
User prompt
When attaching a bullet, attach it with a z-index lower than the hero
User prompt
Remove the code that attaches bullets in fire, the in game, attach the bullet there instead
User prompt
Only allow the hero to fire bullets if the hero is standing still
User prompt
When shooting a bullet rotate the hero to the direction of fire
User prompt
Rotate bullets by 90deg clockwise in the bullet move method
var HealthBar = Container.expand(function (maxHealth, currentHealth) {
var self = Container.call(this);
self.maxHealth = maxHealth;
self.currentHealth = currentHealth;
var background = self.createAsset('healthBarBackground', 'Health Bar Background', .5, 1);
var foreground = self.createAsset('healthBarForeground', 'Health Bar Foreground', .5, 1);
foreground.y -= 5;
self.updateHealth = function (newHealth) {
self.currentHealth = newHealth;
var healthRatio = self.currentHealth / self.maxHealth;
foreground.scale.x = healthRatio;
};
});
var Hero = Container.expand(function () {
var self = Container.call(this);
self.findNearestZombie = function (zombies) {
var nearestZombie = null;
var nearestDistance = Infinity;
for (var i = 0; i < zombies.length; i++) {
var dx = zombies[i].x - self.x;
var dy = zombies[i].y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < nearestDistance) {
nearestZombie = zombies[i];
nearestDistance = distance;
}
}
return nearestZombie;
};
self.targetX = 2048 / 2;
self.targetY = 2732 / 2;
var heroGraphics = self.createAsset('hero', 'Hero character', .4, .3);
var initialHeroRotation = -0.0872665 - 35 * (Math.PI / 180);
heroGraphics.rotation = initialHeroRotation;
self.healthBar = self.addChild(new HealthBar(100, 100));
self.healthBar.y = -125;
self.move = function () {
if (self.targetX !== undefined && self.targetY !== undefined) {
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
var speed = 5;
self.x += dx / distance * speed;
self.y += dy / distance * speed;
var angle = Math.atan2(dy, dx);
heroGraphics.rotation = angle + initialHeroRotation;
} else {
self.x = self.targetX;
self.y = self.targetY;
}
}
};
self.shootDelay = 0;
self.shoot = function (zombies) {
if (self.shootDelay <= 0) {
var nearestZombie = self.findNearestZombie(zombies);
if (nearestZombie) {
var bullet = new Bullet(self, nearestZombie);
self.parent.addChild(bullet);
self.shootDelay = 30;
return bullet;
}
}
self.shootDelay--;
return null;
};
});
var Zombie = Container.expand(function (hero) {
var self = Container.call(this);
var zombieGraphics = self.createAsset('zombie', 'Zombie character', .5, .5);
zombieGraphics.rotation = -Math.PI / 2;
self.target = hero;
self.healthBar = self.addChild(new HealthBar(100, 100));
self.healthBar.y = -125;
self.spawn = function () {
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0:
self.x = Math.random() * 2048;
self.y = -50;
break;
case 1:
self.x = 2048 + 50;
self.y = Math.random() * 2732;
break;
case 2:
self.x = Math.random() * 2048;
self.y = 2732 + 50;
break;
case 3:
self.x = -50;
self.y = Math.random() * 2732;
break;
}
};
self.move = function () {
var dx = self.target.x - self.x;
var dy = self.target.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
var speed = 2;
self.x += dx / distance * speed;
self.y += dy / distance * speed;
var angle = Math.atan2(dy, dx);
zombieGraphics.rotation = angle - Math.PI / 2;
}
};
self.hit = function () {
var newHealth = self.healthBar.currentHealth - 10;
self.healthBar.updateHealth(newHealth);
if (newHealth <= 0) return true;
};
});
var Bullet = Container.expand(function (shooter, target) {
var self = Container.call(this);
var bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5);
self.speed = 10;
self.x = shooter.x;
self.y = shooter.y;
self.target = target;
self.hit = false;
self.move = function () {
var dx = self.target.x - self.x;
var dy = self.target.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
var angle = Math.atan2(dy, dx);
bulletGraphics.rotation = angle + Math.PI / 2;
}
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var background = self.createAsset('background', 'Game Background', .5, .5);
background.x = 2048 / 2 - 80;
background.y = 2732 / 2;
background.alpha = .2;
var hero, zombies = [], bullets = [];
var scoreTxt, timer;
hero = self.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 / 2;
scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(.5, 0);
LK.gui.topCenter.addChild(scoreTxt);
LK.on('tick', function () {
hero.move();
if (hero.shootDelay <= 0) {
var newBullet = hero.shoot(zombies);
if (newBullet) {
bullets.push(newBullet);
}
}
hero.shootDelay--;
for (var i = 0; i < zombies.length; i++) {
zombies[i].move();
}
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].move();
}
for (var i = zombies.length - 1; i >= 0; i--) {
for (var j = bullets.length - 1; j >= 0; j--) {
if (bullets[j].intersects(zombies[i]) && !bullets[j].hit) {
bullets[j].hit = true;
if (zombies[i].hit()) {
zombies[i].destroy();
zombies.splice(i, 1);
}
bullets[j].destroy();
bullets.splice(j, 1);
}
}
}
if (isGameOver()) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
});
stage.on('down', function (obj) {
var pos = obj.event.getLocalPosition(self);
hero.targetX = pos.x;
hero.targetY = pos.y;
});
timer = LK.setInterval(function () {
var zombie = new Zombie(hero);
zombie.spawn();
zombies.push(zombie);
self.addChild(zombie);
}, 2000);
function isGameOver() {}
});
Soldier with gun seen from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
empty abandoned city street background seen from the top. Zoomed in. Top down. Street only
Zombie seen from above. Arms in front of it Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Fired Bullet tip, no case, grayscale Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Simple circular click target, showing where the hero needs to walk to. Grayscale. No shadows Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cloud puff explosion, grayscale, seen from topdown. Circular. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.