User prompt
when updating score text also call LK.setScore
User prompt
Give me a point each time I kill a zombie
User prompt
As the game progresses zombies should spawn faster
User prompt
make zombies spawn 30% faster
Code edit (1 edits merged)
Please save this source code
User prompt
Flash screen red every time you take damage
User prompt
use the zombies[I] version when setting puff x and y
User prompt
tick all elements in the effects array in game
User prompt
puff should have a tick method
User prompt
make puff's it's own class
User prompt
create an effects array in game, add puff's to this array
User prompt
In game, when zombie merge returns true, insert a cloud puff element
User prompt
When merging zombies set the x,y of the merged zombie to the average of the two merged zombies
User prompt
when merging zombies multiply the max health and current health with .8
User prompt
Increase hero bullet fire speed by 50%
User prompt
remove all console.logs
User prompt
Change impact of close zombies from .5 to 1
Code edit (2 edits merged)
Please save this source code
User prompt
reverse the x,y medication when zombies are close to each other
User prompt
Zombies seem to push either other away rather than attacking
Code edit (1 edits merged)
Please save this source code
User prompt
Decrease zombie damage by 1/20
Code edit (1 edits merged)
Please save this source code
User prompt
set score text font size to 120
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,13 @@
+/****
+* Classes
+****/
var Puff = Container.expand(function () {
var self = Container.call(this);
- var puffGraphics = self.createAsset('puff', 'Puff effect', .5, .5);
+ var puffGraphics = self.attachAsset('puff', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.tick = function () {
self.scale.x += 0.05;
self.scale.y += 0.05;
self.alpha -= 0.05;
@@ -11,9 +17,12 @@
};
});
var ClickTarget = Container.expand(function () {
var self = Container.call(this);
- var targetGraphics = self.createAsset('clickTarget', 'Click Target', 0.5, 0.5);
+ var targetGraphics = self.attachAsset('clickTarget', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
targetGraphics.alpha = 0.4;
self.x = 0;
self.y = 0;
self.setVisible = function (isVisible) {
@@ -23,10 +32,16 @@
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);
+ var background = self.attachAsset('healthBarBackground', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ var foreground = self.attachAsset('healthBarForeground', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
foreground.y -= 5;
self.updateHealth = function (newHealth) {
self.currentHealth = newHealth;
var healthRatio = self.currentHealth / self.maxHealth;
@@ -50,13 +65,19 @@
return nearestZombie;
};
self.targetX = 2048 / 2;
self.targetY = 2732 / 2;
- var heroShadow = self.createAsset('heroShadow', 'Hero Shadow', .5, .5);
+ var heroShadow = self.attachAsset('heroShadow', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
heroShadow.alpha = 0.3;
heroShadow.zIndex = -1;
self.addChild(heroShadow);
- var heroGraphics = self.createAsset('hero', 'Hero character', .4, .3);
+ var heroGraphics = self.attachAsset('hero', {
+ anchorX: 0.4,
+ anchorY: 0.3
+ });
self.addChild(heroGraphics);
var initialHeroRotation = -0.0872665 - 35 * (Math.PI / 180);
heroGraphics.rotation = initialHeroRotation;
self.healthBar = self.addChild(new HealthBar(100, 100));
@@ -101,9 +122,12 @@
};
});
var Zombie = Container.expand(function (hero) {
var self = Container.call(this);
- var zombieGraphics = self.createAsset('zombie', 'Zombie character', .5, .5);
+ var zombieGraphics = self.attachAsset('zombie', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
zombieGraphics.rotation = -Math.PI / 2;
self.target = hero;
self.healthBar = self.addChild(new HealthBar(100, 100));
self.healthBar.y = -125;
@@ -152,9 +176,11 @@
}
};
self.removed = false;
self.merge = function (otherZombie) {
- if (otherZombie.removed) return false;
+ if (otherZombie.removed) {
+ return false;
+ }
var newMaxHealth = self.healthBar.maxHealth + otherZombie.healthBar.maxHealth;
self.x = (self.x + otherZombie.x) / 2;
self.y = (self.y + otherZombie.y) / 2;
self.healthBar.maxHealth = newMaxHealth * 0.8;
@@ -166,14 +192,19 @@
};
self.hit = function () {
var newHealth = self.healthBar.currentHealth - 10;
self.healthBar.updateHealth(newHealth);
- if (newHealth <= 0) return true;
+ if (newHealth <= 0) {
+ return true;
+ }
};
});
var Bullet = Container.expand(function (shooter, direction) {
var self = Container.call(this);
- var bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.speed = 10;
self.x = shooter.x - Math.cos(direction - .5) * 55;
self.y = shooter.y - Math.sin(direction - .5) * 55;
self.direction = direction;
@@ -183,118 +214,135 @@
self.y += Math.sin(self.direction) * self.speed;
bulletGraphics.rotation = self.direction + 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 = .4;
- var hero, zombies = [], bullets = [], effects = [];
- var scoreTxt, timer, score = 0;
- hero = self.addChild(new Hero());
- hero.x = 2048 / 2;
- hero.y = 2732 / 2;
- scoreTxt = new Text2('0', {
- size: 120,
- fill: "#ffffff",
- font: 'Impact',
- dropShadow: true,
- dropShadowColor: '#000000',
- dropShadowBlur: 4,
- dropShadowAngle: Math.PI / 6,
- dropShadowDistance: 6
- });
- scoreTxt.anchor.set(.5, 0);
- LK.gui.topCenter.addChild(scoreTxt);
- LK.on('tick', function () {
- if (hero.move() && self.clickTarget) {
- self.clickTarget.setVisible(false);
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+var background = game.attachAsset('background', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+background.x = 2048 / 2 - 80;
+background.y = 2732 / 2;
+background.alpha = .4;
+var hero,
+ zombies = [],
+ bullets = [],
+ effects = [];
+var scoreTxt,
+ timer,
+ score = 0;
+hero = game.addChild(new Hero());
+hero.x = 2048 / 2;
+hero.y = 2732 / 2;
+scoreTxt = new Text2('0', {
+ size: 120,
+ fill: "#ffffff",
+ font: 'Impact',
+ dropShadow: true,
+ dropShadowColor: '#000000',
+ dropShadowBlur: 4,
+ dropShadowAngle: Math.PI / 6,
+ dropShadowDistance: 6
+});
+scoreTxt.anchor.set(.5, 0);
+LK.gui.topCenter.addChild(scoreTxt);
+LK.on('tick', function () {
+ if (hero.move() && game.clickTarget) {
+ game.clickTarget.setVisible(false);
+ }
+ if (hero.shootDelay <= 0) {
+ var newBullet = hero.shoot(zombies);
+ if (newBullet) {
+ bullets.push(newBullet);
+ game.addChildAt(newBullet, game.getChildIndex(hero));
}
- if (hero.shootDelay <= 0) {
- var newBullet = hero.shoot(zombies);
- if (newBullet) {
- bullets.push(newBullet);
- self.addChildAt(newBullet, self.getChildIndex(hero));
- }
+ }
+ hero.shootDelay--;
+ for (var i = 0; i < zombies.length; i++) {
+ zombies[i].move(zombies);
+ }
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ bullets[i].move();
+ if (bullets[i].x < 0 || bullets[i].x > 2048 || bullets[i].y < 0 || bullets[i].y > 2732) {
+ bullets[i].destroy();
+ bullets.splice(i, 1);
}
- hero.shootDelay--;
- for (var i = 0; i < zombies.length; i++) {
- zombies[i].move(zombies);
- }
- for (var i = bullets.length - 1; i >= 0; i--) {
- bullets[i].move();
- if (bullets[i].x < 0 || bullets[i].x > 2048 || bullets[i].y < 0 || bullets[i].y > 2732) {
- bullets[i].destroy();
- bullets.splice(i, 1);
+ }
+ 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);
+ score++;
+ LK.setScore(score);
+ scoreTxt.setText(score);
+ }
+ bullets[j].destroy();
+ bullets.splice(j, 1);
}
}
- 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);
- score++;
- scoreTxt.setText(score);
- }
- bullets[j].destroy();
- bullets.splice(j, 1);
+ for (var k = 0; k < zombies.length; k++) {
+ if (zombies[i] !== zombies[k] && zombies[i] && zombies[k] && zombies[i].intersects(zombies[k])) {
+ if (zombies[i].merge(zombies[k])) {
+ var puff = new Puff();
+ puff.x = zombies[i].x;
+ puff.y = zombies[i].y;
+ effects.push(puff);
+ game.addChild(puff);
+ zombies[k].destroy();
+ zombies.splice(k, 1);
}
}
- for (var k = 0; k < zombies.length; k++) {
- if (zombies[i] !== zombies[k] && zombies[i] && zombies[k] && zombies[i].intersects(zombies[k])) {
- if (zombies[i].merge(zombies[k])) {
- var puff = new Puff();
- puff.x = zombies[i].x;
- puff.y = zombies[i].y;
- effects.push(puff);
- self.addChild(puff);
- zombies[k].destroy();
- zombies.splice(k, 1);
- }
- }
- }
}
- for (var i = 0; i < zombies.length; i++) {
- if (hero.intersects(zombies[i])) {
- hero.healthBar.updateHealth(hero.healthBar.currentHealth - 0.5);
- }
+ }
+ for (var i = 0; i < zombies.length; i++) {
+ if (hero.intersects(zombies[i])) {
+ hero.healthBar.updateHealth(hero.healthBar.currentHealth - 0.5);
}
- for (var i = effects.length - 1; i >= 0; i--) {
- effects[i].tick();
- if (effects[i].alpha <= 0) {
- effects.splice(i, 1);
- }
+ }
+ for (var i = effects.length - 1; i >= 0; i--) {
+ effects[i].tick();
+ if (effects[i].alpha <= 0) {
+ effects.splice(i, 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;
- if (!self.clickTarget) {
- self.clickTarget = self.addChildAt(new ClickTarget(), self.getChildIndex(background) + 1);
- }
- self.clickTarget.x = pos.x;
- self.clickTarget.y = pos.y;
- self.clickTarget.setVisible(true);
- });
- var spawnInterval = 2100;
- timer = LK.setInterval(function () {
- var zombie = new Zombie(hero);
- zombie.spawn();
- zombies.push(zombie);
- self.addChild(zombie);
- spawnInterval = Math.max(500, spawnInterval - 10);
- LK.clearInterval(timer);
- timer = LK.setInterval(arguments.callee, spawnInterval);
- }, spawnInterval);
- function isGameOver() {
- return hero.healthBar.currentHealth <= 0;
}
+ if (isGameOver()) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
});
+game.on('down', function (obj) {
+ var pos = obj.event.getLocalPosition(game);
+ hero.targetX = pos.x;
+ hero.targetY = pos.y;
+ if (!game.clickTarget) {
+ game.clickTarget = game.addChildAt(new ClickTarget(), game.getChildIndex(background) + 1);
+ }
+ game.clickTarget.x = pos.x;
+ game.clickTarget.y = pos.y;
+ game.clickTarget.setVisible(true);
+});
+var spawnInterval = 2100;
+timer = LK.setInterval(function () {
+ var zombie = new Zombie(hero);
+ zombie.spawn();
+ zombies.push(zombie);
+ game.addChild(zombie);
+ spawnInterval = Math.max(500, spawnInterval - 10);
+ LK.clearInterval(timer);
+ timer = LK.setInterval(arguments.callee, spawnInterval);
+}, spawnInterval);
+function isGameOver() {
+ return hero.healthBar.currentHealth <= 0;
+}
\ No newline at end of file
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.