Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: availableBoonsTxt.anchor is undefined' in this line: 'availableBoonsTxt.anchor.set(.5, .5);' Line Number: 389
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: setting is not defined' in this line: 'if (setting.anchor) {' Line Number: 55
Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: setting is not defined' in this line: 'text.anchor.set(settings.anchor.x, setting.anchor.y);' Line Number: 51
Code edit (4 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: countdownTxt.anchor is undefined' in this line: 'countdownTxt.anchor.set(.5, 0);' Line Number: 18
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: countdown is not defined' in this line: 'LK.gui.topCenter.addChild(countdown);' Line Number: 377
Code edit (19 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: this.children is undefined' in this line: 'LK.gui.topCenter.addChild(countdown);' Line Number: 377
User prompt
Fix Bug: 'TypeError: this.children is undefined' in this line: 'LK.gui.topCenter.addChild(countdown);' Line Number: 377
Code edit (1 edits merged)
Please save this source code
User prompt
in the cross weapon's launch function, create a new hero bullet in the direction from the hero to the hero's targetPos
User prompt
move the shootPos variable to the hero class, making sure to update all used references
User prompt
in the cross weapon class there's a `initialCooldown` variable set to 120, and a `cooldown` variable set to that. In the update function, reduce the cooldown by 1 until it reaches zero, at which point call a `launch` function and reset the `cooldown` back to the initial variable
User prompt
Fix Bug: 'TypeError: self.weapons[i].update is not a function' in this line: 'self.weapons[i].update();' Line Number: 141
User prompt
when the hero updates, update all weapons in the array
Code edit (1 edits merged)
Please save this source code
User prompt
when creating the hero's weapon, pass through the hero reference
===================================================================
--- original.js
+++ change.js
@@ -1,43 +1,17 @@
function updateIteration(container, vars) {
for (var i = 0; i < container.length; i++) {
if (container[i].update(vars)) {
+ container[i].destroy();
container.splice(i, 1);
i--;
}
}
}
-var CountdownTimer = Container.expand(function (initialCountdown) {
+var SectionalContainer = Container.expand(function (parent, x, y, difficultyScale) {
var self = Container.call(this);
- var countdown = initialCountdown;
- var ticker = 60;
- var countdownTxt = new BorderedText('', {
- size: 60,
- anchor: {
- x: .5,
- y: 0
- }
- });
- self.addChild(countdownTxt);
- adjustLabel();
- function update() {
- ticker -= 1;
- if (ticker <= 0) {
- ticker = 60;
- countdown--;
- if (countdown >= 0) {
- adjustLabel();
- }
- }
- return 1 - countdown / initialCountdown;
- }
- function adjustLabel() {
- var minutes = Math.floor(countdown / 60);
- var seconds = countdown % 60;
- var minutesString = (minutes < 10 ? '0' : '') + minutes;
- var secondsString = (seconds < 10 ? '0' : '') + seconds;
- countdownTxt.setText(minutesString + ':' + secondsString);
- }
+ self.x = 0;
+ self.y = 0;
});
var BorderedText = Container.expand(function (string, settings) {
var self = Container.call(this);
var textList = [];
@@ -75,8 +49,41 @@
textList[i].setText(string);
}
};
});
+var CountdownTimer = Container.expand(function (initialCountdown) {
+ var self = Container.call(this);
+ var countdown = initialCountdown;
+ var ticker = 60;
+ var countdownTxt = new BorderedText('', {
+ size: 60,
+ anchor: {
+ x: .5,
+ y: 0
+ }
+ });
+ self.update = update;
+ self.addChild(countdownTxt);
+ adjustLabel();
+ function update() {
+ ticker -= 1;
+ if (ticker <= 0) {
+ ticker = 60;
+ countdown--;
+ if (countdown >= 0) {
+ adjustLabel();
+ }
+ }
+ return 1 - countdown / initialCountdown;
+ }
+ function adjustLabel() {
+ var minutes = Math.floor(countdown / 60);
+ var seconds = countdown % 60;
+ var minutesString = (minutes < 10 ? '0' : '') + minutes;
+ var secondsString = (seconds < 10 ? '0' : '') + seconds;
+ countdownTxt.setText(minutesString + ':' + secondsString);
+ }
+});
var ExperiencePickup = Container.expand(function (experience) {
var self = Container.call(this);
var pickupGraphics = self.createAsset('experiencePickup', 'Experience Pickup', .5, .5);
var active = false;
@@ -102,14 +109,15 @@
var CrucifixPickup = Container.expand(function () {
var self = Container.call(this);
var pickupGraphics = self.createAsset('crucifixPickup', 'Crucifix Pickup', .5, .5);
});
-var HealingPickup = Container.expand(function (hero) {
+var HealingPickup = Container.expand(function () {
var self = Container.call(this);
var pickupGraphics = self.createAsset('healingPickup', 'Healing Pickup', .5, .5);
var healPercentage = 0.1;
self.update = update;
- function update() {
+ function update(args) {
+ var hero = args.hero;
if (self.intersects(hero)) {
hero.health = Math.min(hero.healthMax, hero.health + hero.healthMax * healPercentage);
return true;
}
@@ -135,15 +143,12 @@
self.destroy();
}
}, 0);
});
-var SectionalContainer = Container.expand(function (parent, x, y, difficultyScale) {
- var self = Container.call(this);
-});
var BasicEnemy = Container.expand(function (parent, x, y, difficultyScale) {
var self = Container.call(this);
var enemyGraphics = self.createAsset('enemy', 'Enemy character', .5, .5);
- var damageDistance = 100;
+ var damageDistance = 120;
var speed = 1.8;
var damage = 5;
var initialCooldown = 20;
var cooldown = initialCooldown;
@@ -162,39 +167,52 @@
var game = vars.game;
var healthPickups = vars.healthPickups;
var crucifixPickups = vars.crucifixPickups;
var projectiles = vars.projectiles;
+ var backgroundContainer = vars.backgroundContainer;
+ var foregroundContainer = vars.foregroundContainer;
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > damageDistance) {
self.x += dx / distance * speed;
self.y += dy / distance * speed + Math.sin((LK.ticks - creationTick) / bobPeriod) * bobMagnitude;
+ cooldown = initialCooldown;
} else {
cooldown -= 1;
if (cooldown <= 0) {
- cooldown = cooldownInitial;
+ cooldown = initialCooldown;
hero.health -= damage;
}
}
+ var newParent;
+ if (self.y <= hero.y) {
+ newParent = backgroundContainer;
+ } else {
+ newParent = foregroundContainer;
+ }
+ if (parent !== newParent) {
+ newParent.addChild(self);
+ parent = newParent;
+ }
for (var j = 0; j < projectiles.length; j++) {
var projectile = hero.projectiles[j];
if (self.intersects(projectile)) {
- self.health -= 10 + 5 * hero.minorBoonLevels['Damage'];
+ self.health -= projectile.damage;
if (self.health.health <= 0) {
if (crucifixPickups.length < 1 && Math.random() < Math.sqrt(hero.minorBoonLevels['Luck']) / 100) {
var crucifixPickup = new CrucifixPickup();
crucifixPickup.x = self.x;
crucifixPickup.y = self.y;
- self.addChild(crucifixPickup);
+ game.addChild(crucifixPickup);
crucifixPickups.push(crucifixPickup);
} else if (healthPickups.length < 5) {
for (var k = 0; k <= hero.minorBoonLevels['Luck']; k++) {
- if (Math.random() < 0.05) {
+ if (Math.random() < 0.02) {
var pickup = new HealingPickup();
pickup.x = self.x;
pickup.y = self.y;
- self.addChild(pickup);
+ game.addChild(pickup);
healthPickups.push(pickup);
break;
}
}
@@ -218,60 +236,69 @@
}
}
}
});
-var CrossProjectile = Container.expand(function () {
+var CrossProjectile = Container.expand(function (parent, x, y) {
var self = Container.call(this);
- var bulletGraphics = self.createAsset('crossProjectile', 'Bullet Graphics', .5, .5);
+ var projectileAsset = self.createAsset('crossProjectile', 'Projectile Asset', .5, .5);
self.speed = 30;
self.range = null;
+ self.damage = null;
self.destroyRange = -1200;
self.travelDistance = 200;
- self.update = function (vars) {
- var hero = vars.hero;
+ self.targetPos = {
+ x,
+ y
+ };
+ self.update = function (args) {
+ var hero = args.hero;
self.x += self.speed * Math.cos(self.angle);
self.y += self.speed * Math.sin(self.angle);
self.rotation += 0.2;
self.travelDistance -= Math.abs(self.speed);
if (self.travelDistance <= 0 && self.speed > -30) {
self.speed -= 1;
}
- return (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) && self.travelDistance < -self.destroyRange || self.intersects(hero) && projectile.speed < 0;
+ return (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) && self.travelDistance < self.destroyRange || self.intersects(hero) && self.speed < 0;
};
});
var CrossWeapon = Container.expand(function (hero) {
var self = Container.call(this);
self.initialCooldown = 120;
self.cooldown = self.initialCooldown;
- self.launch = function () {
- var bullet = new Bullet(hero);
- var scale = 1 + 0.25 * hero.minorBoonLevels['Scale'];
- var range = 200 + 50 * hero.minorBoonLevels['Range'];
- var dx = hero.targetPos.x - hero.x;
- var dy = hero.targetPos.y - hero.y;
- bullet.x = hero.x;
- bullet.y = hero.y;
- bullet.angle = Math.atan2(dy, dx);
- bullet.range = range;
- bullet.initialRange = range;
- hero.projectiles.push(bullet);
- self.addChild(bullet);
- };
- self.update = function () {
+ self.update = update;
+ self.launch = launch;
+ function update(args) {
if (self.cooldown > 0) {
self.cooldown--;
} else {
- self.launch();
+ self.launch(args);
var attackSpeed = 1 + 0.25 * hero.minorBoonLevels['Rearm'];
self.cooldown = self.initialCooldown / attackSpeed;
}
- };
+ }
+ function launch(args) {
+ var game = args.game;
+ var projectile = new CrossProjectile(hero);
+ var scale = 1 + 0.25 * hero.minorBoonLevels['Scale'];
+ var range = 200 + 50 * hero.minorBoonLevels['Range'];
+ var damage = 10 + 5 * hero.minorBoonLevels['Damage'];
+ var dx = hero.shootPos.x - hero.x;
+ var dy = hero.shootPos.y - hero.y;
+ projectile.x = hero.x;
+ projectile.y = hero.y;
+ projectile.angle = Math.atan2(dy, dx);
+ projectile.range = range;
+ projectile.initialRange = range;
+ hero.projectiles.push(projectile);
+ game.addChild(projectile);
+ }
});
-var Hero = Container.expand(function (consts) {
+var Hero = Container.expand(function (parent, x, y, args) {
var self = Container.call(this);
var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
- var progressBar = consts.progressBar;
- var onLevelUp = consts.onLevelUp;
+ var progressBar = args.progressBar;
+ var onLevelUp = args.onLevelUp;
var experience = 0;
var level = 1;
var levelRequirement = 20;
self.minorBoonLevels = {
@@ -285,11 +312,13 @@
'Split': 0,
'Multi': 0
};
self.shootPos = {
- x: 2048 / 2,
- y: 2732 / 2
+ x,
+ y
};
+ self.x = x;
+ self.y = y;
self.weapons = [];
self.projectiles = [];
self.crossWeapon = new CrossWeapon(self);
self.weapons.push(self.crossWeapon);
@@ -302,9 +331,11 @@
self.healthBarBorder.x = self.healthBar.x;
self.healthBarBorder.width = self.healthBar.width + 10;
self.healthBarBorder.height = self.healthBar.height + 10;
self.update = update;
- function update(enemies) {
+ parent.addChild(self);
+ function update(args) {
+ var game = args.game;
self.healthBar.scale.x = Math.max(0, self.health / self.healthMax);
if (self.health <= 0) {
LK.showGameOver();
}
@@ -325,9 +356,14 @@
self.scale.x = -1;
} else {
self.scale.x = 1;
}
- iterateContainer(self.weapons);
+ updateIteration(self.weapons, {
+ game
+ });
+ updateIteration(self.projectiles, {
+ hero: self
+ });
}
function addExperience(amount) {
if (experience >= levelRequirement) {
level++;
@@ -402,9 +438,9 @@
}
});
var Game = Container.expand(function () {
var self = Container.call(this);
- var isPaused = true;
+ var isPaused = false;
var minorBoonCount = 0;
var majorBoonCount = 0;
var grass = self.createAsset('grass', 'Grass Background', 0, 0);
var canMove = false;
@@ -421,9 +457,8 @@
var updateButton = LK.gui.topRight.createAsset('updateButton', 'Update Button', 0.5, 0.5);
LK.gui.topRight.addChild(availableBoonsTxt);
grass.width = 2048;
grass.height = 2732;
- self.addChild(grass);
updateButton.x = -70;
updateButton.y = 70;
updateButton.on('down', function () {
if (minorBoonCount + majorBoonCount > 0) {
@@ -436,8 +471,10 @@
y: 0
},
size: 80
});
+ var foregroundContainer = new SectionalContainer();
+ var backgroundContainer = new SectionalContainer();
var selectingBoon = false;
var progressBarBorder = LK.getAsset('progressBarBorder', 'Progress Bar Border', 0, .5);
var progressBar = LK.getAsset('progressBar', 'Progress Bar', 0, .5);
var enemyProjectiles = [];
@@ -445,12 +482,8 @@
var healthPickups = [];
var crucifixPickups = [];
var experiencePickups = [];
var countdownTimer = new CountdownTimer(300);
- var hero = new Hero({
- progressBar,
- onLevelUp
- });
LK.gui.topCenter.addChild(countdownTimer);
LK.gui.topCenter.addChild(progressBarBorder);
LK.gui.topCenter.addChild(progressBar);
LK.gui.topCenter.addChild(levelTxt);
@@ -459,12 +492,16 @@
progressBarBorder.y = levelTxt.y + levelTxt.height / 2;
progressBar.x = 24;
progressBar.y = levelTxt.y + levelTxt.height / 2;
progressBar.scale.x = 0;
- hero.x = 2048 / 2;
- hero.y = 2732 / 2;
self.targetPos = null;
- self.addChild(hero);
+ self.addChild(grass);
+ self.addChild(backgroundContainer);
+ var hero = new Hero(self, 2048 / 2, 2732 / 2, {
+ progressBar,
+ onLevelUp
+ });
+ self.addChild(foregroundContainer);
refreshBoonUpgradeButton();
stage.on('down', function (obj) {
canMove = true;
hero.targetPos = obj.event.getLocalPosition(self);
@@ -488,27 +525,37 @@
});
LK.on('tick', function () {
if (!isPaused) {
difficultyScale = countdownTimer.update();
- hero.update();
- updateContainer(healthPickups);
- updateContainer(enemyProjectiles);
- updateContainer(enemies, {
- projectiles: hero.projectiles
+ hero.update({
+ game: self
});
- updateContainer(experiencePickups, {
- hero: hero
+ updateIteration(healthPickups, {
+ hero
});
+ updateIteration(enemyProjectiles);
+ updateIteration(enemies, {
+ hero,
+ game: self,
+ healthPickups,
+ crucifixPickups,
+ projectiles: hero.projectiles,
+ backgroundContainer,
+ foregroundContainer
+ });
+ updateIteration(experiencePickups, {
+ hero
+ });
for (var i = 0; i < crucifixPickups.length; i++) {
if (hero.intersects(crucifixPickups[i])) {
for (var j = 0; j < enemies.length; j++) {
enemies[j].destroy();
}
enemies = [];
- for (var j = 0; j < enemyBullets.length; j++) {
- enemyBullets[j].destroy();
+ for (var j = 0; j < enemyProjectiles.length; j++) {
+ enemyProjectiles[j].destroy();
}
- enemyBullets = [];
+ enemyProjectiles = [];
for (var j = 0; j < healthPickups.length; j++) {
healthPickups[j].destroy();
}
healthPickups = [];
@@ -569,29 +616,30 @@
}
}
function spawnEnemy() {
var side = Math.floor(Math.random() * 4);
- var enemy = new Enemy(hero);
+ var distance = Math.random();
+ var x, y;
switch (side) {
case 0:
- enemy.x = Math.random() * 2048;
- enemy.y = 0;
+ x = distance * 2048;
+ y = 0;
break;
case 1:
- enemy.x = 2048;
- enemy.y = Math.random() * 2732;
+ x = 2048;
+ y = distance * 2732;
break;
case 2:
- enemy.x = Math.random() * 2048;
- enemy.y = 2732;
+ x = distance * 2048;
+ y = 2732;
break;
case 3:
- enemy.x = 0;
- enemy.y = Math.random() * 2732;
+ x = 0;
+ y = distance * 2732;
break;
}
+ var enemy = new BasicEnemy(self, x, y, difficultyScale);
enemies.push(enemy);
- self.addChild(enemy);
}
function onLevelUp(level) {
levelTxt.setText('Level ' + level + ' • XP');
if (level % 5) {
pixel art cross with blue accents Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a white orb. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a white orb with a halo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a pulsating white heart with a halo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a dark goo projectile with red highlights. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art tall blue fireball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of an evil fantasy sword facing downward. Minor red details. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
backgroundAmbient
Sound effect
heroHealed
Sound effect
pickupExperience
Sound effect
heroLeveled
Sound effect
weaponCrossImpact
Sound effect
heroImpact
Sound effect
enemyDeath
Sound effect
pickupWeapon
Sound effect
pickupCrucifix
Sound effect
weaponCrossLaunch
Sound effect
heroDeath
Sound effect
enemyRoar
Sound effect
clockChime
Sound effect