User prompt
Please fix the bug: 'TypeError: self.intersectRadius is not a function' in or related to this line: 'if (self.activated) {' Line Number: 609
Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: midFrontContainer is not defined' in or related to this line: 'midFrontContainer.addChild(new ProjectileCross({' Line Number: 111
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
if a closest enemy was found, increase the baseAngle by the angle from the hero to the closestEnemy
User prompt
In the weaponCross class replace the TODO comment by finding the closest (square distance) child in the midgroundContainer, making sure that the child has tag TAG_ENEMY and not TAG_PROJECTILE
Code edit (2 edits merged)
Please save this source code
User prompt
Rename the midBackContainer to midgroundContainer
User prompt
Remove the midFrontContainer, replacing any occurrences with midBackContainer
Code edit (1 edits merged)
Please save this source code
Code edit (21 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: e is undefined' in or related to this line: 'LK.effects.flashObject(self.collision, 0xAA0000, 1000);' Line Number: 508
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: heightDifference is not defined' in or related to this line: 'var dy = hero.y + heightDifference - self.y;' Line Number: 97
Code edit (16 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self is undefined' in or related to this line: 'var updateBase = self.update;' Line Number: 117
User prompt
Please fix the bug: 'ReferenceError: WeaponFireball is not defined' in or related to this line: 'startingWeapons.push(backgroundContainer.addChild(new PickupWeapon({' Line Number: 525
Code edit (2 edits merged)
Please save this source code
User prompt
add a hero asset with anchor (0.5, 1.0) to the Hero class
Code edit (1 edits merged)
Please save this source code
/****
* Classes
****/
var ConfigContainer = Container.expand(function (config) {
var self = Container.call(this);
config = config || {};
// Private variables
var destroyCalled = false;
// Public variables
self.x = config.x || 0;
self.y = config.y || 0;
self.rotation = config.rotation || 0;
self.alpha = config.alpha !== undefined ? config.alpha : 1.0;
if (config.scale !== undefined || config.scaleX !== undefined || config.scaleY !== undefined) {
var scaleX = config.scaleX !== undefined ? config.scaleX : config.scale !== undefined ? config.scale : 1;
var scaleY = config.scaleY !== undefined ? config.scaleY : config.scale !== undefined ? config.scale : 1;
self.scale.set(scaleX, scaleY);
}
// Public functions
self.callDestroy = function () {
if (!destroyCalled) {
destroyCalled = true;
self.onDestroy();
destroy();
}
};
self.onDestroy = function () {};
// Enable inheritance
return self;
});
var ProgressBar = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var width = config.width || 100;
var height = config.height || 10;
var weight = config.weight || 4;
self.attachAsset('shapeBox', {
width: width + 2 * weight,
height: height + 2 * weight,
anchorX: 0.5,
anchorY: 0.5,
tint: 0x000000
});
var bar = self.attachAsset('shapeBox', {
x: -width,
width: width,
height: height,
anchorX: 0.5,
anchorY: 0.5,
tint: config.tint || 0xFFFFFF
});
self.updatePercentage = function (percentage) {
bar.scale.x = Math.min(1.0, Math.max(0, percentage));
};
if (config.percentage !== undefined) {
self.updatePercentage(config.percentage);
}
});
var JoystickKnob = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
self.attachAsset('shapeEllipse', {
width: config.size,
height: config.size,
anchorX: 0.5,
anchorY: 0.5,
tint: 0x808080,
alpha: 0.5
});
self.attachAsset('joystickKnob', {
width: config.size * 0.65,
height: config.size * 0.65,
anchorX: 0.5,
anchorY: 0.5,
tint: 0x000000
});
self.attachAsset('outlineSmall', {
width: config.size + 5,
height: config.size + 5,
anchorX: 0.5,
anchorY: 0.5,
tint: 0x000000
});
return self;
});
var Joystick = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var size = config.size || 100;
var maxDistance = size / 2;
var base = self.attachAsset('shapeEllipse', {
width: size,
height: size,
anchorX: 0.5,
anchorY: 0.5,
tint: 0xA0A0A0,
alpha: 0.5
});
self.attachAsset('outlineLarge', {
width: size + 5,
height: size + 5,
anchorX: 0.5,
anchorY: 0.5,
tint: 0x000000
});
var knob = self.addChild(new JoystickKnob({
size: size / 2
}));
var pressed = false;
self.magnitude = 0;
self.direction = undefined;
self.down = function (x, y, obj) {
if (x === 0 && y === 0) {
self.magnitude = 0;
self.direction = undefined;
} else {
var distance = Math.sqrt(x * x + y * y);
if (distance <= size / 2) {
pressed = true;
knob.x = x;
knob.y = y;
self.magnitude = distance / maxDistance;
self.direction = Math.atan2(y, x);
}
}
};
self.movement = function (x, y, obj) {
if (pressed) {
if (x === 0 && y === 0) {
self.magnitude = 0;
self.direction = undefined;
} else {
var distance = Math.sqrt(x * x + y * y);
var direction = Math.atan2(y, x);
if (distance > maxDistance) {
x = Math.cos(direction) * maxDistance;
y = Math.sin(direction) * maxDistance;
distance = maxDistance;
}
knob.x = x;
knob.y = y;
self.magnitude = distance / maxDistance;
self.direction = direction;
}
}
};
self.release = function (x, y, obj) {
pressed = false;
self.magnitude = 0;
self.direction = undefined;
knob.x = 0;
knob.y = 0;
};
return self;
});
var Hero = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
self.speed = HERO_SPEED_BASE;
self.healthMax = HERO_HEALTH_BASE;
self.health = self.healthMax;
var healthBar = self.addChild(new ProgressBar({
y: -self.height / 2 - 10,
tint: HERO_COLOUR
}));
self.update = function () {
if (!isPaused && joystick.direction !== undefined) {
self.rotation = joystick.direction;
var speedX = Math.cos(joystick.direction) * joystick.magnitude * self.speed;
var speedY = Math.sin(joystick.direction) * joystick.magnitude * self.speed;
self.x += speedX;
self.y += speedY;
if (self.x < HERO_BORDER) {
self.x = HERO_BORDER;
} else if (self.x > GAME_WIDTH - HERO_BORDER) {
self.x = GAME_WIDTH - HERO_BORDER;
}
if (self.y < HERO_BORDER) {
self.y = HERO_BORDER;
} else if (self.y > GAME_WIDTH - HERO_BORDER) {
self.y = GAME_WIDTH - HERO_BORDER;
}
self.scale.x = speedX < 0 ? -1 : 1;
}
};
self.takeDamage = function (amount) {
self.health = Math.max(0, self.health - amount);
healthBar.updatePercentage(self.health / self.healthMax);
LK.effects.flashObject(self.collision, 0xAA0000, 1000);
if (self.health <= 0) {
LK.effects.flashScreen(0xAA0000, 1000);
LK.showGameOver();
}
};
self.healPercentage = function (percentage) {
if (percentage > 0) {
self.health = Math.min(self.healthMax, self.health + self.healthMax * percentage);
LK.effects.flashObject(self.collision, HERO_COLOUR, 1000);
}
healthBar.updatePercentage(self.health / self.healthMax);
};
});
var SortingContainer = Container.expand(function () {
var self = Container.call(this);
self.update = function () {
self.children.sort(function (a, b) {
return a.y - b.y;
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
;
//==============================================================================
// Global constants & settings
//==============================================================================
;
var GAME_TICKS = 60;
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2732;
;
// Hero settings
var HERO_COLOUR = 0x0FA0FF;
var HERO_BORDER = 200;
var HERO_HEALTH_BASE = 100;
var HERO_HEALTH_BONUS = 30;
var HERO_SPEED_BASE = 8;
var HERO_SPEED_BONUS = 2;
var HERO_XP_REQUIRED = 20;
var HERO_XP_SCALING = 1.2;
// Enemy settings
var ENEMY_COLOUR = 0xAA0000;
var ENEMY_BORDER = 50; // Forced minimum move distance from the edge of the screen
var ENEMY_BORDER_SPAWN = -100;
var ENEMY_SPAWN_DELAY = 2 * GAME_TICKS;
var ENEMY_SPAWN_RATE_BASE = 1 * GAME_TICKS;
var ENEMY_SPAWN_RATE_SCALE = 0.75 * GAME_TICKS;
var ENEMY_SPAWN_RATE_MIN = 0.25 * GAME_TICKS;
var ENEMY_LIMIT = 40;
var ENEMY_XP_RANGE = 50;
var ENEMY_STATE_MOVE = 'move';
var ENEMY_STATE_FLEE = 'flee';
var ENEMY_STATE_ATTACK = 'attack';
var ENEMY_BASIC_SPEED = 2.5;
var ENEMY_BASIC_HEALTH_BASE = 10;
var ENEMY_BASIC_HEALTH_SCALE = 50;
var ENEMY_BASIC_HEALTH_OFFSET = 30;
var ENEMY_BASIC_ATTACK_RANGE = 100;
var ENEMY_BASIC_ATTACK_DAMAGE = 10;
var ENEMY_BASIC_ATTACK_COOLDOWN = GAME_TICKS / 6;
var ENEMY_BASIC_GRAPHICS_OFFSET = -100;
var ENEMY_BASIC_BOB_MAGNITUDE = 2;
var ENEMY_BASIC_BOB_PERIOD = 10;
var ENEMY_BASIC_XP_DROP_CHANCE = 0.3; // Per level of Luck
var ENEMY_RANGED_SPEED = 1.5;
var ENEMY_RANGED_HEALTH_BASE = 20;
var ENEMY_RANGED_HEALTH_SCALE = 60;
var ENEMY_RANGED_HEALTH_OFFSET = 20;
var ENEMY_RANGED_RANGE_MIN = 500;
var ENEMY_RANGED_RANGE_VAR = 250;
var ENEMY_RANGED_ATTACK_DAMAGE = 5;
var ENEMY_RANGED_MOVE_COOLDOWN_ADJUSTMENT = -0.5;
var ENEMY_RANGED_GRAPHICS_OFFSET = -100;
var ENEMY_RANGED_FLEE_DISTANCE_FACTOR = 0.35;
var ENEMY_RANGED_FLEE_SPEED_FACTOR = 1.5;
var ENEMY_RANGED_SCALE_PERIOD = 20;
var ENEMY_RANGED_SCALE_MAGNITUDE = 0.05;
var ENEMY_RANGED_XP_DROP_BASE = 2;
var ENEMY_RANGED_XP_DROP_CHANCE = 0.5; // Per level of Luck
var ENEMY_RANGED_DIFFICULTY = 0.2;
var ENEMY_RANGED_SPAWN_CHANCE_MIN = 0.4;
var ENEMY_RANGED_SPAWN_CHANCE_FACTOR = 0.5;
// Pickup settings
var PICKUP_HEAL_MINOR = 0.1;
var PICKUP_HEAL_MAJOR = 1.0;
var PICKUP_HEALTH_COUNT = 3;
var PICKUP_HEALTH_CHANCE = 0.02; // Per level of luck
var PICKUP_CRUCIFIX_COUNT = 1;
var PICKUP_CRUCIFIX_RANGE = 100;
var PICKUP_WEAPON_RANGE = 100;
;
//==============================================================================
// Instances & variables
//==============================================================================
;
// Variables
var isPaused = false;
var level = 1;
var experience = 0;
var levelRequirement = HERO_XP_REQUIRED;
var enemyCount = 0;
var minorBoonCount = 0;
var majorBoonCount = 0;
var pickupHealthCount = 0;
var pickupCrucifixCount = 0;
var difficultyScale = 0;
var startingWeapons = [];
var minorBoonLevels = {
'Luck': 0,
'Scale': 0,
'Range': 0,
'Damage': 0,
'Rearm': 0,
'Duration': 0,
'Health': 0,
'Speed': 0
};
var majorBoonLevels = {
'Growth': 0,
'Split': 0
};
;
// Game instances
game.attachAsset('grassTop', {
y: HERO_BORDER - 100,
x: GAME_WIDTH / 2,
anchorX: 0.5
});
game.attachAsset('grassBot', {
y: GAME_HEIGHT - HERO_BORDER + 100,
x: GAME_WIDTH / 2,
anchorX: 0.5,
anchorY: 1.0
});
var backgroundContainer = game.addChild(new Container());
var midBackContainer = game.addChild(new SortingContainer());
var hero = game.addChild(new Hero({
x: GAME_WIDTH / 2,
y: GAME_HEIGHT / 2
}));
var midFrontContainer = game.addChild(new SortingContainer());
var foregroundContainer = game.addChild(new Container());
var joystick = game.addChild(new Joystick({
size: 400,
x: GAME_WIDTH - 400,
y: GAME_HEIGHT - 400
}));
;
//==============================================================================
// Global events
//==============================================================================
;
// Add event listeners for the joystick
game.move = function (x, y, obj) {
joystick.movement(x - joystick.x, y - joystick.y, obj);
};
game.up = function (x, y, obj) {
joystick.release(x, y, obj);
};
;
//==============================================================================
// Global helper functions
//==============================================================================
;
function checkBounds(x, y) {
var borderOrBorderX = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var borderY = arguments.length > 3 ? arguments[3] : undefined;
return x < borderOrBorderX || x > 2048 - borderOrBorderX || y < (borderY || borderOrBorderX) || y > 2732 - (borderY || borderOrBorderX);
}
function addExperience(amount) {
experience += amount;
if (experience >= levelRequirement) {
level++;
experience -= levelRequirement;
levelRequirement = Math.floor(levelRequirement * 1.2);
// onLevelUp(level);
}
progressBar.setPercentage(experience / levelRequirement);
}
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