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
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -11,9 +11,8 @@
var countdown = initialCountdown;
var ticker = 60;
var countdownTxt = new BorderedText('', {
size: 60,
- font: 'bold monospace',
anchor: {
x: .5,
y: 0
}
@@ -41,25 +40,31 @@
});
var BorderedText = Container.expand(function (string, settings) {
var self = Container.call(this);
var textList = [];
- var border = 2;
- var offsets = [[-border, -border], [-border, border], [border, border], [border, -border], [0, 0]];
+ var defaultFill = '#ffffff';
+ var defaultBorder = '#000000';
+ var defaultFont = 'bold monospace';
+ var defaultSize = 50;
+ var defaultWeight = 2;
+ var offsets = [[-1, -1], [-1, 1], [1, 1], [1, -1], [0, 0]];
var borderSettings = {
- fill: settings.border || '#000000',
- font: settings.font,
- size: settings.size
+ fill: settings.border || defaultBorder,
+ font: settings.font || defaultFont,
+ size: settings.size || defaultSize
};
var textSettings = {
- fill: settings.fill || '#ffffff',
- font: settings.font,
- size: settings.size
+ fill: settings.fill || defaultFill,
+ font: settings.font || defaultFont,
+ size: settings.size || defaultSize
};
+ self.x = settings.x;
+ self.y = settings.y;
for (var i = 0; i < offsets.length; i++) {
var localSettings = i === offsets.length - 1 ? textSettings : borderSettings;
var text = new Text2(string, localSettings);
- text.x += offsets[i][0];
- text.y += offsets[i][1];
+ text.x += offsets[i][0] * defaultWeight;
+ text.y += offsets[i][1] * defaultWeight;
if (settings.anchor) {
text.anchor.set(settings.anchor.x, settings.anchor.y);
}
textList.push(text);
@@ -70,24 +75,30 @@
textList[i].setText(string);
}
};
});
-var ExperiencePickup = Container.expand(function (hero) {
+var ExperiencePickup = Container.expand(function (experience) {
var self = Container.call(this);
var pickupGraphics = self.createAsset('experiencePickup', 'Experience Pickup', .5, .5);
- self.active = false;
- self.move = function () {
+ var active = false;
+ self.update = update;
+ function update(vars) {
+ var hero = vars.hero;
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 400) {
self.active = true;
+ if (self.intersects(hero)) {
+ hero.addExperience(experience);
+ return true;
+ }
}
if (self.active) {
self.x += dx / distance * 20;
self.y += dy / distance * 20;
}
- };
+ }
});
var CrucifixPickup = Container.expand(function () {
var self = Container.call(this);
var pickupGraphics = self.createAsset('crucifixPickup', 'Crucifix Pickup', .5, .5);
@@ -103,13 +114,16 @@
return true;
}
}
});
-var BasicBloodSplatter = Container.expand(function () {
+var BasicBloodSplatter = Container.expand(function (parent, x, y) {
var self = Container.call(this);
var splatterGraphics = self.createAsset('bloodSplatter', 'Blood Splatter', .5, .5);
var initialLifetime = Math.floor(0.2 * 60);
var remainingLifetime = initialLifetime;
+ parent.addChild(self);
+ self.x = x;
+ self.y = y;
LK.setInterval(function () {
remainingLifetime -= 1;
var lifetime = remainingLifetime / initialLifetime;
splatterGraphics.alpha = lifetime;
@@ -121,10 +135,13 @@
self.destroy();
}
}, 0);
});
-var BasicEnemy = Container.expand(function (difficultyScale) {
+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 speed = 1.8;
var damage = 5;
@@ -133,11 +150,19 @@
var bobMagnitude = 2;
var bobPeriod = 10;
var creationTick = LK.ticks;
var health = 5 + 25 * difficultyScale;
- self.update = function (vars) {
+ var parent = parent;
+ self.x = x;
+ self.y = x;
+ self.update = update;
+ parent.addChild(self);
+ function update(vars) {
if (health <= 0) {}
var hero = vars.hero;
+ var game = vars.game;
+ var healthPickups = vars.healthPickups;
+ var crucifixPickups = vars.crucifixPickups;
var projectiles = vars.projectiles;
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
@@ -157,67 +182,61 @@
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;
+ crucifixPickup.x = self.x;
+ crucifixPickup.y = self.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;
+ pickup.x = self.x;
+ pickup.y = self.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 experience = 0;
+ for (var k = 0; k <= hero.minorBoonLevels['Luck'] + 1; k++) {
+ if (Math.random() < 0.3) {
+ experience++;
}
}
- 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;
+ if (experience > 0) {
+ var experiencePickup = new ExperiencePickup(experience);
+ experiencePickup.x = enemies[i].x + Math.random() * 100 - 50;
+ experiencePickup.y = enemies[i].y + Math.random() * 100 - 50;
+ self.addChild(experiencePickup);
+ experiencePickups.push(experiencePickup);
+ }
+ var bloodSplatter = new BloodSplatter(game, self.x, self.y);
+ return true;
}
}
}
- };
+ }
});
-var CrossProjectile = Container.expand(function (hero) {
+var CrossProjectile = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('crossProjectile', 'Bullet Graphics', .5, .5);
self.speed = 30;
self.range = null;
self.destroyRange = -1200;
self.travelDistance = 200;
- self.update = function () {
+ self.update = function (vars) {
+ var hero = vars.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;
}
- 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--;
- }
+ return (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) && self.travelDistance < -self.destroyRange || self.intersects(hero) && projectile.speed < 0;
};
});
var CrossWeapon = Container.expand(function (hero) {
var self = Container.call(this);
@@ -246,11 +265,16 @@
self.cooldown = self.initialCooldown / attackSpeed;
}
};
});
-var Hero = Container.expand(function () {
+var Hero = Container.expand(function (consts) {
var self = Container.call(this);
var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
+ var progressBar = consts.progressBar;
+ var onLevelUp = consts.onLevelUp;
+ var experience = 0;
+ var level = 1;
+ var levelRequirement = 20;
self.minorBoonLevels = {
'Luck': 0,
'Scale': 0,
'Range': 0,
@@ -277,9 +301,10 @@
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 (enemies) {
+ self.update = update;
+ function update(enemies) {
self.healthBar.scale.x = Math.max(0, self.health / self.healthMax);
if (self.health <= 0) {
LK.showGameOver();
}
@@ -301,9 +326,18 @@
} else {
self.scale.x = 1;
}
iterateContainer(self.weapons);
- };
+ }
+ function addExperience(amount) {
+ if (experience >= levelRequirement) {
+ level++;
+ experience -= levelRequirement;
+ levelRequirement = Math.floor(levelRequirement * 1.2);
+ onLevelUp(level);
+ }
+ progressBar.scale.x = hero.experience / hero.levelRequirement;
+ }
});
var BoonSelection = Container.expand(function (boons, type, count, callback) {
var self = Container.call(this);
var availableBoons = Object.keys(boons).filter(function (boon) {
@@ -319,27 +353,24 @@
selectedBoons.push(availableBoons.splice(boonIndex, 1)[0]);
}
var background = self.createAsset('boonBackground', 'Boon Selection Popup', 0.5, 0.5);
var boonMessageTitle = new BorderedText('Choose ' + count, {
+ y: -220,
size: 60,
- font: 'bold monospace',
anchor: {
x: .5,
y: 0
}
});
background.y = 50;
- boonMessageTitle.y = -220;
self.addChild(boonMessageTitle);
var boonMessageSubtitle = new BorderedText(type + ' Boon', {
- size: 50,
- font: 'bold monospace',
+ y: -160,
anchor: {
y: .5,
y: 0
}
});
- boonMessageSubtitle.y = -160;
self.addChild(boonMessageSubtitle);
for (var i = 0; i < selectedBoons.length; i++) {
var boon = selectedBoons[i];
var boonButton = self.createAsset('boonButton', boon + ' Boon Button', 0.5, 0.5);
@@ -352,20 +383,16 @@
});
var boonLevel = new BorderedText(boons[boon], {
x: boonButton.x,
y: boonButton.y,
- size: 50,
- font: 'bold monospace',
anchor: {
x: .5,
y: .5
}
});
var boonName = new BorderedText(boon, {
x: boonButton.x + 60,
y: boonButton.y,
- size: 50,
- font: 'bold monospace',
anchor: {
x: 0,
y: .5
}
@@ -376,41 +403,40 @@
});
var Game = Container.expand(function () {
var self = Container.call(this);
var isPaused = true;
+ var minorBoonCount = 0;
+ var majorBoonCount = 0;
var grass = self.createAsset('grass', 'Grass Background', 0, 0);
- var hero = new Hero();
var canMove = false;
var difficultyScale = 0;
- var experience = 0;
- var level = 1;
- var levelRequirement = 20;
- var minorBoonCount = 0;
- var majorBoonCount = 0;
var availableBoonsTxt = new BorderedText('0', {
- size: 50,
+ x: -70,
+ y: 70,
fill: '#ff0000',
- font: 'bold monospace'
+ anchor: {
+ x: .5,
+ y: .5
+ }
});
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;
- availableBoonsTxt.y = 70;
updateButton.on('down', function () {
if (minorBoonCount + majorBoonCount > 0) {
showBoonSelection();
}
});
- var levelTxt = new BorderedText('Level ' + level + ' • XP', {
- size: 80,
- fill: '#ffffff',
- font: 'bold monospace'
+ var levelTxt = new BorderedText('Level 1 • XP', {
+ anchor: {
+ x: 1.0,
+ y: 0
+ },
+ size: 80
});
var selectingBoon = false;
var progressBarBorder = LK.getAsset('progressBarBorder', 'Progress Bar Border', 0, .5);
var progressBar = LK.getAsset('progressBar', 'Progress Bar', 0, .5);
@@ -419,8 +445,12 @@
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);
@@ -429,9 +459,8 @@
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);
hero.x = 2048 / 2;
hero.y = 2732 / 2;
self.targetPos = null;
self.addChild(hero);
@@ -465,8 +494,11 @@
updateContainer(enemyProjectiles);
updateContainer(enemies, {
projectiles: hero.projectiles
});
+ updateContainer(experiencePickups, {
+ hero: 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();
@@ -490,31 +522,8 @@
LK.effects.flashScreen(0xffffff, 1000);
break;
}
}
- for (var i = 0; i < experiencePickups.length; i++) {
- var experiencePickup = experiencePickups[i];
- experiencePickup.move();
- if (experiencePickup.intersects(hero)) {
- experiencePickup.destroy();
- experiencePickups.splice(i, 1);
- experience++;
- if (experience >= levelRequirement) {
- level++;
- experience -= levelRequirement;
- levelRequirement = Math.floor(levelRequirement * 1.2);
- levelTxt.setText('Level ' + level + ' • XP');
- if (level % 5) {
- minorBoonCount++;
- } else {
- majorBoonCount++;
- }
- refreshBoonUpgradeButton();
- }
- progressBar.scale.x = experience / levelRequirement;
- i--;
- }
- }
if (LK.ticks % (60 - Math.floor(55 * difficultyScale)) === 0) {
spawnEnemy();
}
}
@@ -582,5 +591,14 @@
}
enemies.push(enemy);
self.addChild(enemy);
}
+ function onLevelUp(level) {
+ levelTxt.setText('Level ' + level + ' • XP');
+ if (level % 5) {
+ minorBoonCount++;
+ } else {
+ majorBoonCount++;
+ }
+ refreshBoonUpgradeButton();
+ }
});
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