User prompt
fireballprojectiles should check in their update function if they collide with an enemy, and deal damage to it and destroy itself
Code edit (5 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: hero is undefined' in this line: 'hero.rotation += rotationSpeed;' Line Number: 82
User prompt
add a new weapon type called FireballWeapon that slowly rotates, firing FireballProjectiles in the direction it's facing.
Code edit (13 edits merged)
Please save this source code
User prompt
RangedEnemies scale back and forth slightly during their update
User prompt
ranged enemies flash black when they attack
Code edit (1 edits merged)
Please save this source code
Code edit (7 edits merged)
Please save this source code
User prompt
Add a RangedEnemy class which moves towards the hero, periodically shooting EnemyProjectiles towards the hero when it's within 500 range
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: midgroundContainer is not defined' in this line: 'var enemy = new BasicEnemy(midgroundContainer, x, y, {' Line Number: 95
User prompt
make an EnemySpawner class that handles the spawning of enemies instead of the tick event
Code edit (1 edits merged)
Please save this source code
User prompt
countdown timer should continue counting down even after reaching zero
User prompt
when the countdowntimer reaches zero, perform a once-off update that changes the text to red
Code edit (8 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: bool is not defined' in this line: 'if (bool === 'Health') {' Line Number: 862
Code edit (5 edits merged)
Please save this source code
User prompt
healing pickups first check if the hero is at max health already before applying the heal and destroying itself
User prompt
Fix Bug: 'ReferenceError: health is not defined' in this line: 'if (health <= 0) {' Line Number: 684
User prompt
change the hero's `var health` and `var healthMax` to `self.health` and `self.healthMax` and update any references to these variables found within the hero class
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: sqrt is not defined' in this line: 'var distance = sqrt(distance);' Line Number: 317
Code edit (6 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -397,69 +397,85 @@
parent.addChild(self);
self.x = x;
self.y = y;
self.collisionPoint = new Point(self);
- var projectileAsset = self.createAsset('enemyProjectile', 'Enemy Projectile', .5, .5);
- var speed = 5;
- var target = args.target;
+ var direction = args.direction;
var damage = args.damage;
+ var projectileAsset = self.createAsset('enemyProjectile', 'Enemy Projectile', .5, .5);
+ var speed = 10;
+ var speedFactorX = Math.cos(direction);
+ var speedFactorY = Math.sin(direction);
+ projectileAsset.rotation = direction - 135 / 180 * Math.PI;
self.update = update;
- function update() {
- var dx = target.x - self.x;
- var dy = target.y - self.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance > 0) {
- self.x += dx / distance * speed;
- self.y += dy / distance * speed;
- }
- if (target.collision.intersects(self.collisionPoint)) {
- target.onTakeDamage(damage);
+ function update(args) {
+ var hero = args.hero;
+ self.x += speed * speedFactorX;
+ self.y += speed * speedFactorY;
+ if (hero.collision.intersects(self.collisionPoint)) {
+ hero.onTakeDamage(damage);
return true;
}
+ if (LK.tick % 5) {
+ self.scale.y *= -1;
+ }
return self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732;
}
});
var RangedEnemy = Container.expand(function (parent, x, y, args) {
var self = Container.call(this);
parent.addChild(self);
- self.collision = self.createAsset('rangedEnemy', 'Ranged Enemy', .5, .5);
+ self.collision = self.createAsset('rangedEnemy', 'Ranged Enemy', .6, .5);
+ self.collision.scale.y = -1;
self.id = args.id;
self.x = x;
self.y = y;
var healthBar = null;
- var attackRange = 500;
- var heightDifference = 25;
+ var attackRange = 1000 + Math.random() * 500;
+ var attackRangeSqr = attackRange * attackRange;
+ var scaredRange = attackRange / 3;
+ var scaredRangeSqr = scaredRange * scaredRange;
var speed = 1.5;
var damage = 5;
- var initialCooldown = 120;
+ var initialCooldown = 240;
var cooldown = initialCooldown;
- var healthMax = 20 + 30 * args.difficultyScale;
+ var healthMax = 20 + 60 * args.difficultyScale;
var health = healthMax;
self.update = update;
self.onTakeDamage = onTakeDamage;
function update(args) {
if (health <= 0) {
kill(args);
return true;
}
+ var foregroundContainer = args.foregroundContainer;
+ var midgroundContainer = args.midgroundContainer;
var hero = args.hero;
var dx = hero.x - self.x;
- var dy = hero.y + heightDifference - self.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance < attackRange) {
- cooldown--;
+ var dy = hero.y - self.y;
+ var distanceSqr = dx * dx + dy * dy;
+ if (distanceSqr <= attackRangeSqr && distanceSqr >= scaredRangeSqr) {
+ cooldown -= 2;
if (cooldown <= 0) {
cooldown = initialCooldown;
- args.enemyProjectiles.push(new EnemyProjectile(args.midgroundContainer, self.x, self.y, {
- target: hero,
- damage: damage
+ args.projectiles.push(new EnemyProjectile(foregroundContainer, self.x, self.y, {
+ direction: Math.atan2(dy, dx),
+ damage
}));
}
} else {
- self.x += dx / distance * speed;
- self.y += dy / distance * speed;
+ if (distanceSqr < scaredRangeSqr) {
+ var distance = Math.sqrt(distanceSqr);
+ self.x += dx / distance * -speed;
+ self.y += dy / distance * -speed;
+ cooldown = initialCooldown;
+ } else {
+ var distance = Math.sqrt(distanceSqr);
+ self.x += dx / distance * speed;
+ self.y += dy / distance * speed;
+ cooldown--;
+ }
}
- var newParent = distance <= hero.y + heightDifference ? args.midgroundContainer : args.foregroundContainer;
+ var newParent = self.y <= hero.y ? midgroundContainer : foregroundContainer;
if (parent !== newParent) {
newParent.addChild(self);
parent = newParent;
}
@@ -470,9 +486,9 @@
function onTakeDamage(takenDamage) {
health -= takenDamage;
if (health > 0) {
if (!healthBar) {
- healthBar = new HealthBar(self, 0, -self.collision.height / 2 - 50, {
+ healthBar = new HealthBar(self, 0, -self.collision.height / 2 - 20, {
tint: 0xaa0000
});
}
healthBar.updatePercentage(health / healthMax);
@@ -523,14 +539,9 @@
cooldown = initialCooldown;
hero.onTakeDamage(damage);
}
}
- var newParent;
- if (self.y <= hero.y + heightDifference) {
- newParent = midgroundContainer;
- } else {
- newParent = foregroundContainer;
- }
+ var newParent = self.y <= hero.y + heightDifference ? args.midgroundContainer : args.foregroundContainer;
if (parent !== newParent) {
newParent.addChild(self);
parent = newParent;
}
@@ -571,9 +582,9 @@
function onTakeDamage(takenDamage) {
health -= takenDamage;
if (health > 0) {
if (!healthBar) {
- healthBar = new HealthBar(self, 0, -self.collision.height / 2 - 50, {
+ healthBar = new HealthBar(self, 0, -self.collision.height / 2 - 30, {
tint: 0xaa0000
});
}
healthBar.updatePercentage(health / healthMax);
@@ -585,21 +596,22 @@
var self = Container.call(this);
parent.addChild(self);
var enemyIdCounter = -1;
var spawnRate = 60;
- var spawnLimit = 50;
+ var spawnLimit = 40;
var spawnTimer = spawnRate;
self.update = update;
function update(args) {
if (args.enemies.length < spawnLimit) {
spawnTimer--;
if (spawnTimer <= 0) {
- spawnTimer = Math.max(10, spawnRate - Math.floor(50 * args.difficultyScale));
+ spawnTimer = Math.max(15, spawnRate - Math.floor(45 * args.difficultyScale));
spawnEnemy(args);
}
}
}
function spawnEnemy(args) {
+ var difficultyScale = args.difficultyScale;
var side = Math.floor(Math.random() * 4);
var distance = Math.random();
var x, y;
switch (side) {
@@ -619,36 +631,38 @@
x = 0;
y = 2732 * distance;
break;
}
- var enemy = new BasicEnemy(args.midgroundContainer, x, y, {
+ var enemyType = difficultyScale >= 0.2 && Math.random() < Math.min(0.4, difficultyScale / 2) ? RangedEnemy : BasicEnemy;
+ args.enemies.push(new enemyType(args.midgroundContainer, x, y, {
id: (++enemyIdCounter).toString(),
- difficultyScale: args.difficultyScale
- });
- args.enemies.push(enemy);
+ difficultyScale
+ }));
}
});
var CrossProjectile = Container.expand(function (parent, x, y, args) {
var self = Container.call(this);
parent.addChild(self);
self.x = x;
self.y = y;
self.collisionPoint = new Point(self);
+ var direction = args.direction;
+ var damage = args.damage;
+ var linger = args.linger;
+ var range = args.range;
var projectileAsset = self.createAsset('crossProjectile', 'Projectile Asset', .5, .5);
var hitMap = {};
var initialSpeed = 30;
var speed = initialSpeed;
+ var speedFactorX = Math.cos(direction);
+ var speedFactorY = Math.sin(direction);
var speedDecrement = 1;
var destroyRange = -1200;
var growth = 1;
var growthRate = args.growthRate;
var initialScale = args.scale;
var currentScale = initialScale;
var scaleDamageFactor = 0.1;
- var range = args.range;
- var damage = args.damage;
- var linger = args.linger;
- var angle = args.angle;
self.rotation = Math.random() * Math.PI * 2;
self.scale = {
x: currentScale,
y: currentScale
@@ -656,10 +670,10 @@
self.update = update;
function update(args) {
var hero = args.hero;
var enemies = args.enemies;
- self.x += speed * Math.cos(angle);
- self.y += speed * Math.sin(angle);
+ self.x += speed * speedFactorX;
+ self.y += speed * speedFactorY;
self.rotation += 0.2;
if (growthRate > 0) {
growth += growthRate;
currentScale = initialScale * growth;
@@ -727,15 +741,15 @@
var dy = hero.shootPos.y - hero.y;
var baseAngle = Math.atan2(dy, dx) - spreadCount * spreadIncrement / 2;
for (var i = 0; i < spreadCount; i++) {
var spreadAngle = spreadIncrement / 2 * (spreadCount <= 1 ? 1 : Math.random() - 0.5);
- var angle = baseAngle + i * spreadIncrement + spreadAngle;
+ var direction = baseAngle + i * spreadIncrement + spreadAngle;
projectiles.push(new CrossProjectile(game, hero.x, hero.y, {
linger: linger + Math.floor(10 * Math.random()),
range: range * (0.9 + 0.2 * Math.random()),
growthRate,
+ direction,
damage,
- angle,
scale
}));
}
}
@@ -921,15 +935,18 @@
updateIteration(heroProjectiles, {
enemies,
hero
});
- updateIteration(enemyProjectiles);
+ updateIteration(enemyProjectiles, {
+ hero
+ });
enemySpawner.update({
midgroundContainer,
difficultyScale,
enemies
});
updateIteration(enemies, {
+ projectiles: enemyProjectiles,
backgroundContainer,
midgroundContainer,
foregroundContainer,
experiencePickups,
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