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
Code edit (1 edits merged)
Please save this source code
User prompt
Rename the hero's `move` function to `update`
User prompt
create a weapons array in the hero and put the crossWeapon reference in it
User prompt
create a CrossWeapon container (without any graphics) and add it to the hero
User prompt
create a CrossWeapon container and add it to the hero
Code edit (2 edits merged)
Please save this source code
User prompt
Make sure that all minorBoonLevels and majorBoonLevels usage is referenced from the hero
User prompt
Fix Bug: 'ReferenceError: minorBoonLevels is not defined' in this line: 'for (var k = 0; k <= minorBoonLevels['Luck']; k++) {' Line Number: 340
User prompt
Fix Bug: 'ReferenceError: minorBoonLevels is not defined' in this line: 'for (var k = 0; k <= minorBoonLevels['Luck']; k++) {' Line Number: 329
User prompt
Fix Bug: 'ReferenceError: minorBoonLevels is not defined' in this line: 'if (crucifixPickups.length < 1 && Math.random() < Math.sqrt(minorBoonLevels['Luck']) / 100) {' Line Number: 322
User prompt
Fix Bug: 'ReferenceError: minorBoonLevels is not defined' in this line: 'enemies[i].health -= 10 + 5 * minorBoonLevels['Damage'];' Line Number: 320
User prompt
Fix Bug: 'ReferenceError: minorBoonLevels is not defined' in this line: 'if (LK.ticks % Math.floor(120 / (1 + 0.25 * minorBoonLevels['Rearm'])) === 0) {' Line Number: 421
===================================================================
--- original.js
+++ change.js
@@ -1,4 +1,22 @@
+function updateIteration(container, vars) {
+ for (var i = 0; i < container.length; i++) {
+ if (container[i].update(vars)) {
+ container.splice(i, 1);
+ i--;
+ }
+ }
+}
+var Countdown = Container.expand(function () {
+ var initialCountdown = 300;
+ var countdown = initialCountdown;
+ var countdownTxt = new Text2('05:00', {
+ size: 60,
+ fill: '#ffffff',
+ font: 'bold monospace'
+ });
+ countdownTxt.anchor.set(.5, 0);
+});
var BorderedText = Container.expand(function (string, settings) {
var self = Container.call(this);
var textList = [];
var offsets = [[-2, -2], [-2, 2], [2, 2], [2, -2], [0, 0]];
@@ -35,10 +53,22 @@
var CrucifixPickup = Container.expand(function () {
var self = Container.call(this);
var pickupGraphics = self.createAsset('crucifixPickup', 'Crucifix Pickup', .5, .5);
});
-var BloodSplatter = Container.expand(function () {
+var HealingPickup = Container.expand(function (hero) {
var self = Container.call(this);
+ var pickupGraphics = self.createAsset('healingPickup', 'Healing Pickup', .5, .5);
+ var healPercentage = 0.1;
+ self.update = update;
+ function update() {
+ if (self.intersects(hero)) {
+ hero.health = Math.min(hero.healthMax, hero.health + hero.healthMax * healPercentage);
+ return true;
+ }
+ }
+});
+var BasicBloodSplatter = Container.expand(function () {
+ var self = Container.call(this);
var splatterGraphics = self.createAsset('bloodSplatter', 'Blood Splatter', .5, .5);
var initialLifetime = Math.floor(0.2 * 60);
var remainingLifetime = initialLifetime;
LK.setInterval(function () {
@@ -53,102 +83,169 @@
self.destroy();
}
}, 0);
});
-var HealingPickup = Container.expand(function () {
+var BasicEnemy = Container.expand(function (difficultyScale) {
var self = Container.call(this);
- var pickupGraphics = self.createAsset('healingPickup', 'Healing Pickup', .5, .5);
+ var enemyGraphics = self.createAsset('enemy', 'Enemy character', .5, .5);
+ var damageDistance = 100;
+ var speed = 1.8;
+ var damage = 5;
+ var initialCooldown = 20;
+ var cooldown = initialCooldown;
+ var bobMagnitude = 2;
+ var bobPeriod = 10;
+ var creationTick = LK.ticks;
+ var health = 5 + 25 * difficultyScale;
+ self.update = function (vars) {
+ if (health <= 0) {}
+ var hero = vars.hero;
+ var projectiles = vars.projectiles;
+ 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;
+ } else {
+ cooldown -= 1;
+ if (cooldown <= 0) {
+ cooldown = cooldownInitial;
+ hero.health -= damage;
+ }
+ }
+ for (var j = 0; j < projectiles.length; j++) {
+ var projectile = hero.projectiles[j];
+ if (self.intersects(projectile)) {
+ self.health -= 10 + 5 * hero.minorBoonLevels['Damage'];
+ if (self.health.health <= 0) {
+ if (crucifixPickups.length < 1 && Math.random() < Math.sqrt(hero.minorBoonLevels['Luck']) / 100) {
+ var crucifixPickup = new CrucifixPickup();
+ crucifixPickup.x = enemies[i].x;
+ crucifixPickup.y = enemies[i].y;
+ self.addChild(crucifixPickup);
+ crucifixPickups.push(crucifixPickup);
+ } else if (healthPickups.length < 5) {
+ for (var k = 0; k <= hero.minorBoonLevels['Luck']; k++) {
+ if (Math.random() < 0.05) {
+ var pickup = new HealingPickup();
+ pickup.x = enemies[i].x;
+ pickup.y = enemies[i].y;
+ self.addChild(pickup);
+ healthPickups.push(pickup);
+ break;
+ }
+ }
+ }
+ for (var k = 0; k <= hero.minorBoonLevels['Luck']; k++) {
+ if (Math.random() < 0.5) {
+ var experiencePickup = new ExperiencePickup(hero);
+ experiencePickup.x = enemies[i].x + Math.random() * 100 - 50;
+ experiencePickup.y = enemies[i].y + Math.random() * 100 - 50;
+ self.addChild(experiencePickup);
+ experiencePickups.push(experiencePickup);
+ break;
+ }
+ }
+ var bloodSplatter = new BloodSplatter();
+ bloodSplatter.x = enemies[i].x;
+ bloodSplatter.y = enemies[i].y;
+ self.addChild(bloodSplatter);
+ enemies[i].destroy();
+ enemies.splice(i, 1);
+ i--;
+ break;
+ }
+ }
+ }
+ };
});
-var Bullet = Container.expand(function () {
+var CrossProjectile = Container.expand(function (hero) {
var self = Container.call(this);
- var bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5);
+ var bulletGraphics = self.createAsset('crossProjectile', 'Bullet Graphics', .5, .5);
self.speed = 30;
+ self.range = null;
+ self.destroyRange = -1200;
self.travelDistance = 200;
- self.move = function () {
+ self.update = function () {
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;
}
- };
-});
-var Enemy = Container.expand(function (hero) {
- var self = Container.call(this);
- var enemyGraphics = self.createAsset('enemy', 'Enemy character', .5, .5);
- self.creationTick = LK.ticks;
- self.health = 1;
- self.move = function () {
- var dx = hero.x - self.x;
- var dy = hero.y - self.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance > 100) {
- self.x += dx / distance * 1.8;
- self.y += dy / distance * 1.8 + Math.sin((LK.ticks - self.creationTick) / 10) * 2;
- } else {
- hero.health -= 1;
- if (hero.health <= 0) {
- LK.showGameOver();
- }
+ if ((self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) && self.travelDistance < -self.destroyRange || self.intersects(hero) && projectile.speed < 0) {
+ heroBullet.destroy();
+ hero.projectiles.splice(index, 1);
+ i--;
}
};
});
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();
+ 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);
- heroBullets.push(bullet);
+ bullet.range = range;
+ bullet.initialRange = range;
+ hero.projectiles.push(bullet);
self.addChild(bullet);
};
self.update = function () {
if (self.cooldown > 0) {
self.cooldown--;
} else {
self.launch();
- self.cooldown = self.initialCooldown;
+ var attackSpeed = 1 + 0.25 * hero.minorBoonLevels['Rearm'];
+ self.cooldown = self.initialCooldown / attackSpeed;
}
};
});
var Hero = Container.expand(function () {
var self = Container.call(this);
- self.shootPos = {
- x: 2048 / 2,
- y: 2732 / 2
- };
+ var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
self.minorBoonLevels = {
'Luck': 0,
'Scale': 0,
'Range': 0,
'Damage': 0,
'Rearm': 0
};
- self.weapons = [];
- self.crossWeapon = new CrossWeapon(self);
- self.weapons.push(self.crossWeapon);
- self.addChild(self.crossWeapon);
self.majorBoonLevels = {
'Split': 0,
'Multi': 0
};
- var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
+ self.shootPos = {
+ x: 2048 / 2,
+ y: 2732 / 2
+ };
+ self.weapons = [];
+ self.projectiles = [];
+ self.crossWeapon = new CrossWeapon(self);
+ self.weapons.push(self.crossWeapon);
+ self.addChild(self.crossWeapon);
self.health = 100;
self.healthBarBorder = self.createAsset('healthBarBorder', 'Health Bar Border', 0.5, 1);
self.healthBarBorder.y = -115;
self.healthBar = self.createAsset('healthBar', 'Health Bar', 0.5, 1);
self.healthBar.y = -120;
self.healthBarBorder.x = self.healthBar.x;
self.healthBarBorder.width = self.healthBar.width + 10;
self.healthBarBorder.height = self.healthBar.height + 10;
- self.update = function () {
- self.healthBar.scale.x = self.health / 100;
+ self.update = function (enemies) {
+ self.healthBar.scale.x = Math.max(0, self.health / self.healthMax);
+ if (self.health <= 0) {
+ LK.showGameOver();
+ }
if (self.targetPos) {
var dx = self.targetPos.x - self.x;
var dy = self.targetPos.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
@@ -165,11 +262,9 @@
self.scale.x = -1;
} else {
self.scale.x = 1;
}
- for (var i = 0; i < self.weapons.length; i++) {
- self.weapons[i].update();
- }
+ iterateContainer(self.weapons);
};
});
var BoonSelection = Container.expand(function (boons, type, count, callback) {
var self = Container.call(this);
@@ -236,37 +331,26 @@
var Game = Container.expand(function () {
var self = Container.call(this);
var isPaused = true;
var grass = self.createAsset('grass', 'Grass Background', 0, 0);
- grass.width = 2048;
- grass.height = 2732;
- self.addChild(grass);
var hero = new Hero();
var canMove = false;
- var shootPos = {
- x: 2048 / 2,
- y: 2732 / 2
- };
+ var difficultyScale = 0;
var experience = 0;
var level = 1;
var levelRequirement = 20;
- var initialCountdown = 300;
- var countdown = initialCountdown;
- var difficultyScale = 0;
var minorBoonCount = 0;
var majorBoonCount = 0;
- var countdownTxt = new Text2('05:00', {
- size: 60,
- fill: '#ffffff',
- font: 'bold monospace'
- });
var availableBoonsTxt = new Text2('0', {
size: 50,
fill: '#ff0000',
font: 'bold monospace'
});
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;
availableBoonsTxt.anchor.set(.5, .5);
availableBoonsTxt.x = -70;
@@ -283,26 +367,25 @@
});
var selectingBoon = false;
var progressBarBorder = LK.getAsset('progressBarBorder', 'Progress Bar Border', 0, .5);
var progressBar = LK.getAsset('progressBar', 'Progress Bar', 0, .5);
- var heroBullets = [];
- var enemyBullets = [];
+ var enemyProjectiles = [];
var enemies = [];
var healthPickups = [];
var crucifixPickups = [];
var experiencePickups = [];
+ var countdown = new Countdown();
+ self.addChild(countdown);
LK.gui.topCenter.addChild(progressBarBorder);
LK.gui.topCenter.addChild(progressBar);
LK.gui.topCenter.addChild(levelTxt);
- LK.gui.topCenter.addChild(countdownTxt);
+ countdown.y = levelTxt.height + 10;
progressBarBorder.x = 20;
progressBarBorder.y = levelTxt.y + levelTxt.height / 2;
progressBar.x = 24;
progressBar.y = levelTxt.y + levelTxt.height / 2;
progressBar.scale.x = 0;
levelTxt.anchor.set(1.0, 0);
- countdownTxt.y = levelTxt.height + 10;
- countdownTxt.anchor.set(.5, 0);
hero.x = 2048 / 2;
hero.y = 2732 / 2;
self.targetPos = null;
self.addChild(hero);
@@ -339,74 +422,13 @@
var secondsString = (seconds < 10 ? '0' : '') + seconds;
countdownTxt.setText(minutesString + ':' + secondsString);
}
hero.update();
- for (var i = 0; i < heroBullets.length; i++) {
- var heroBullet = heroBullets[i];
- heroBullet.move();
- if ((heroBullet.x < 0 || heroBullet.x > 2048 || heroBullet.y < 0 || heroBullet.y > 2732) && heroBullet.travelDistance < -1200 || heroBullet.intersects(hero) && heroBullet.speed < 0) {
- heroBullet.destroy();
- heroBullets.splice(i, 1);
- i--;
- }
- }
- for (var i = 0; i < enemyBullets.length; i++) {
- enemyBullets[i].move();
- }
- for (var i = 0; i < enemies.length; i++) {
- enemies[i].move();
- for (var j = 0; j < heroBullets.length; j++) {
- if (heroBullets[j].intersects(enemies[i])) {
- enemies[i].health -= 10 + 5 * hero.minorBoonLevels['Damage'];
- if (enemies[i].health <= 0) {
- if (crucifixPickups.length < 1 && Math.random() < Math.sqrt(hero.minorBoonLevels['Luck']) / 100) {
- var crucifixPickup = new CrucifixPickup();
- crucifixPickup.x = enemies[i].x;
- crucifixPickup.y = enemies[i].y;
- self.addChild(crucifixPickup);
- crucifixPickups.push(crucifixPickup);
- } else if (healthPickups.length < 5) {
- for (var k = 0; k <= hero.minorBoonLevels['Luck']; k++) {
- if (Math.random() < 0.05) {
- var pickup = new HealingPickup();
- pickup.x = enemies[i].x;
- pickup.y = enemies[i].y;
- self.addChild(pickup);
- healthPickups.push(pickup);
- break;
- }
- }
- }
- for (var k = 0; k <= hero.minorBoonLevels['Luck']; k++) {
- if (Math.random() < 0.5) {
- var experiencePickup = new ExperiencePickup(hero);
- experiencePickup.x = enemies[i].x + Math.random() * 100 - 50;
- experiencePickup.y = enemies[i].y + Math.random() * 100 - 50;
- self.addChild(experiencePickup);
- experiencePickups.push(experiencePickup);
- break;
- }
- }
- var bloodSplatter = new BloodSplatter();
- bloodSplatter.x = enemies[i].x;
- bloodSplatter.y = enemies[i].y;
- self.addChild(bloodSplatter);
- enemies[i].destroy();
- enemies.splice(i, 1);
- i--;
- break;
- }
- }
- }
- }
- for (var i = 0; i < healthPickups.length; i++) {
- if (hero.intersects(healthPickups[i])) {
- hero.health = Math.min(100, hero.health + 10);
- healthPickups[i].destroy();
- healthPickups.splice(i, 1);
- i--;
- }
- }
+ updateContainer(healthPickups);
+ updateContainer(enemyProjectiles);
+ updateContainer(enemies, {
+ projectiles: hero.projectiles
+ });
for (var i = 0; i < crucifixPickups.length; i++) {
if (hero.intersects(crucifixPickups[i])) {
for (var j = 0; j < enemies.length; j++) {
enemies[j].destroy();
@@ -456,18 +478,8 @@
}
if (LK.ticks % (60 - Math.floor(55 * difficultyScale)) === 0) {
spawnEnemy();
}
- if (LK.ticks % Math.floor(120 / (1 + 0.25 * hero.minorBoonLevels['Rearm'])) === 0) {
- var bullet = new Bullet();
- var dx = hero.shootPos.x - hero.x;
- var dy = hero.shootPos.y - hero.y;
- bullet.x = hero.x;
- bullet.y = hero.y;
- bullet.angle = Math.atan2(dy, dx);
- heroBullets.push(bullet);
- self.addChild(bullet);
- }
}
});
function refreshBoonUpgradeButton() {
var bool = minorBoonCount + majorBoonCount > 0;
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