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
User prompt
Please fix the bug: 'ReferenceError: tint is not defined' in or related to this line: 'var bar = self.attachAsset('shapeBox', {' Line Number: 73
Code edit (7 edits merged)
Please save this source code
User prompt
add an outlineSmall asset to the joystickKnob and an outlineLarge asset to the joystick
Code edit (2 edits merged)
Please save this source code
User prompt
add a new sorting container (inheriting from Container) that has an update function that sorts it's children array by their ascending y value
Code edit (3 edits merged)
Please save this source code
User prompt
Replace all usages of the 'blank' asset with the 'shapeBox' asset
User prompt
Migrate to the latest version of LK
Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
flash the CrossWeapon's aimArrow and the FireballWeapon's projectileLaunchers white during the launch function
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: tryUpdateLaunchers is not defined' in this line: 'tryUpdateLaunchers(args);' Line Number: 1024
Code edit (14 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: existingEffect.refresh is not a function' in this line: 'existingEffect.refresh({' Line Number: 803
/**** * Classes ****/ var ConfigContainer = Container.expand(function (config) { var self = Container.call(this); config = config || {}; // Private variables var destroyCalled = false; // Public variables self.tags = {}; 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(); self.destroy(); } }; self.onDestroy = function () {}; // Enable inheritance return self; }); var UiCountdownTimer = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); var countdown = config.countdown; var ticker = 60; var countdownTxt = self.addChild(new BorderedText('', { size: 80, anchorX: .5, anchorY: 0 })); self.update = function () { if (countdown > 0 && --ticker <= 0) { ticker = 60; if (--countdown === 0) { countdownTxt.setFill('#AA0000'); // TODO: Spawn boss } adjustLabel(); } difficultyScale = 1 - countdown / config.countdown; }; function adjustLabel() { var minutes = Math.floor(countdown / 60); var seconds = Math.abs(countdown) % 60; var minutesString = (minutes < 10 ? '0' : '') + minutes; var secondsString = (seconds < 10 ? '0' : '') + seconds; countdownTxt.setText(minutesString + ':' + secondsString); } adjustLabel(); // Enable inheritance return self; }); var UiBoonUpgradeButton = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); var hidden = false; var count = 0; var button = self.attachAsset('uiBoonButton', { anchorX: 0.5, anchorY: 0.4 }); var countTxt = self.addChild(new BorderedText('0', { fill: config.fill, anchorX: .5, anchorY: .5 })); button.on('down', function (x, y, obj) { obj.event = obj; config.callback(obj); }); self.visible = false; self.setHidden = function (newHidden) { hidden = newHidden; self.checkHidden(); }; self.setCount = function (newCount) { count = newCount; countTxt.setText(newCount); self.checkHidden(); }; self.checkHidden = function () { self.visible = !hidden && count > 0; }; // Enable inheritance return self; }); var UiBoonSelection = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); var availableBoons = Object.keys(config.boons).filter(function (boon) { return config.boons[boon] < 3; }); var selectedBoons = []; if (availableBoons.length <= 3) { selectedBoons = availableBoons; } else { while (selectedBoons.length < 3 && availableBoons.length > 0) { var boonIndex = Math.floor(Math.random() * availableBoons.length); selectedBoons.push(availableBoons.splice(boonIndex, 1)[0]); } } if (selectedBoons.length < 3) { selectedBoons.push(config.type === 'Minor' ? 'Minor Heal' : 'Full Heal'); } self.attachAsset('uiBoonBackground', { y: 50, anchorX: 0.5, anchorY: 0.5 }); self.addChild(new BorderedText('Choose ' + config.count, { y: -220, size: 60, anchorX: .5, anchorY: 0 })); self.addChild(new BorderedText(config.type + ' Boon' + (config.count === 1 ? '' : 's'), { y: -150, anchorX: .5, anchorY: 0 })); for (var i = 0; i < selectedBoons.length; i++) { var boon = selectedBoons[i]; var boonButton = self.attachAsset('uiBoonButton', { y: i * 120, x: -120, anchorX: 0.5, anchorY: 0.4 }); boonButton.boon = boon; boonButton.on('down', function () { self.destroy(); config.callback(this.boon); }); var boonLevel = self.addChild(new BorderedText(config.boons[boon] !== undefined ? config.boons[boon] : '∞', { x: boonButton.x, y: boonButton.y, anchor: { x: .5, y: .5 } })); var boonName = self.addChild(new BorderedText(boon, { x: boonButton.x + 60, y: boonButton.y, anchorX: 0, anchorY: .5 })); } // Enable inheritance return self; }); var ProgressBar = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); var width = config.width || 120; var height = config.height || 15; var weight = config.weight || 6; 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 / 2, width: width, height: height, 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); } // Enable inheritance return self; }); var Pickup = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); self.tags[TAG_PICKUP] = true; self.activated = false; self.pickupRange = 0; self.update = function () { if (!isPaused && !self.activated) { var dx = hero.x - self.x; var dy = hero.y - self.y; var distanceSqr = dx * dx + dy * dy; if (distanceSqr <= self.pickupRange * self.pickupRange) { self.activated = true; self.onActivate(); } } }; self.onActivate = function () {}; // Enable inheritance return self; }); var PickupWeapon = Pickup.expand(function (config) { var self = Pickup.call(this, config); var updateBase = self.update; var scaleBase = self.scale; self.pickupRange = PICKUP_WEAPON_RANGE; var graphics = self.attachAsset(config.graphics, { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { updateBase(); var scaleFactor = 1 + Math.sin(LK.ticks / 10) * 0.1; graphics.scale.x = scaleBase.x * scaleFactor; graphics.scale.y = scaleBase.y * scaleFactor; }; self.onActivate = function () { // hero.addChild(new config.weaponClass()); for (var i = backgroundContainer.children.length - 1; i >= 0; i--) { var child = backgroundContainer.children[i]; if (child.tags[TAG_PICKUP] && child.tags[TAG_WEAPON]) { child.callDestroy(); } } self.callDestroy(); }; // Enable inheritance return self; }); var PickupHealing = Pickup.expand(function (config) { var self = Pickup.call(this, config); var updateBase = self.update; self.attachAsset('pickupHealing', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { if (hero.health < hero.healthMax) { updateBase(); } }; self.onActivate = function () { hero.healPercentage(PICKUP_HEAL_MINOR); }; self.onDestroy = function () { pickupHealthCount--; }; pickupHealthCount++; // Enable inheritance return self; }); var PickupCrucifix = Pickup.expand(function (config) { var self = Pickup.call(this, config); self.tags[TAG_CRUCIFIX] = true; self.pickupRange = PICKUP_CRUCIFIX_RANGE; self.attachAsset('pickupCrucifix', { anchorX: 0.5, anchorY: 0.5 }); self.onActivate = function () { for (var i = midBackContainer.children.length - 1; i >= 0; i--) { var child = midBackContainer.children[i]; if (child.tags[TAG_ENEMY]) { child.callDestroy(); } } for (var i = midFrontContainer.children.length - 1; i >= 0; i--) { var child = midFrontContainer.children[i]; if (child.tags[TAG_ENEMY]) { child.callDestroy(); } } for (var i = backgroundContainer.children.length - 1; i >= 0; i--) { var child = backgroundContainer.children[i]; if (child.tags[TAG_PICKUP] && child.tags[TAG_EXPERIENCE]) { child.callActivate(); } } }; self.onDestroy = function () { pickupCrucifixCount--; }; pickupCrucifixCount++; // Enable inheritance return self; }); 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 }); // Enable inheritance 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; }; // Enable inheritance return self; }); var Hero = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); // Private variables var level = 1; var experience = 0; var levelRequirement = HERO_XP_REQUIRED; // Public variables self.speed = HERO_SPEED_BASE; self.healthMax = HERO_HEALTH_BASE; self.health = self.healthMax; // Graphics self.attachAsset('shapeEllipse', { width: 150, height: 15, anchorX: 0.5, anchorY: 0.5, tint: 0x000000, alpha: 0.75 }); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 1.0 }); var experienceBar = self.addChild(new ProgressBar({ y: -heroGraphics.height - 25 // percentage: 0 })); var healthBar = self.addChild(new ProgressBar({ y: -heroGraphics.height - 35, tint: HERO_COLOUR })); var levelTxt = self.addChild(new BorderedText('1', { y: -heroGraphics.height - 30, anchorX: 0.5, anchorY: 0.5, size: 60 })); // Public functions self.update = function () { if (!isPaused && joystick.direction !== undefined) { 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_HEIGHT - HERO_BORDER) { self.y = GAME_HEIGHT - HERO_BORDER; } heroGraphics.scale.x = speedX < 0 ? -1 : 1; } }; self.addExperience = function (amount) { experience += amount; if (experience >= levelRequirement) { level++; experience -= levelRequirement; levelRequirement = Math.floor(levelRequirement * 1.2); // onLevelUp(level); } experienceBar.setPercentage(experience / levelRequirement); }; 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); }; // Enable inheritance return self; }); /** * config { * x : Number || 0, // See: ConfigContainer * y : Number || 0, // See: ConfigContainer * rotation : Number || 0, // See: ConfigContainer * anchorX : Number || 0, * anchorY : Number || 1, * size : Number || TEXT_DEFAULT_SIZE, * weight : Number || TEXT_DEFAULT_WEIGHT, * font : String || TEXT_DEFAULT_FONT, * fill : String || TEXT_DEFAULT_FILL, * border : String || TEXT_DEFAULT_BORDER, * } **/ var BorderedText = ConfigContainer.expand(function (text, config) { var self = ConfigContainer.call(this, config); config = config || {}; ; var anchorX = config.anchorX !== undefined ? config.anchorX : 0; var anchorY = config.anchorY !== undefined ? config.anchorY : 1; var size = config.size !== undefined ? config.size : TEXT_DEFAULT_SIZE; var weight = config.weight !== undefined ? config.weight : TEXT_DEFAULT_WEIGHT; var font = config.font !== undefined ? config.font : TEXT_DEFAULT_FONT; var textFill = config.fill !== undefined ? config.fill : TEXT_DEFAULT_FILL; var borderFill = config.border !== undefined ? config.border : TEXT_DEFAULT_BORDER; var textAssets = []; var mainAsset; ; self.setText = setText; self.setFill = setFill; ; function setText(newText) { for (var i = 0; i < textAssets.length; i++) { textAssets[i].setText(newText); } } function setFill(newFill) { textFill = newFill; mainAsset.fill = newFill; } function buildTextAssets(newText) { for (var i = 0; i < TEXT_OFFSETS.length; i++) { var main = i === TEXT_OFFSETS.length - 1; var fill = main ? textFill : borderFill; var textAsset = textAssets[i]; if (textAsset) { textAsset.destroy(); } textAsset = self.addChild(new Text2(newText, { fill: fill, font: font, size: size })); textAsset.anchor = { x: anchorX, y: anchorY }; // NOTE: Cannot be set in config textAsset.x = TEXT_OFFSETS[i][0] * weight; // NOTE: Cannot be set in config textAsset.y = TEXT_OFFSETS[i][1] * weight; // NOTE: Cannot be set in config textAssets[i] = textAsset; } mainAsset = textAssets[TEXT_OFFSETS.length - 1]; } ; buildTextAssets(text); // Enable inheritance return self; }); var SortingContainer = Container.expand(function () { var self = Container.call(this); self.update = function () { self.children.sort(function (a, b) { return a.y - b.y; }); }; // Enable inheritance return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ ; //============================================================================== // Global constants & settings //============================================================================== ; // Math constants / pre-calculations var MATH_2_PI = Math.PI * 2; var MATH_HALF_PI = Math.PI / 2; var MATH_QUARTER_PI = Math.PI / 4; var MATH_HALF_ROOT_3 = Math.sqrt(3) / 2; // Required by: TEXT_OFFSETS, BorderedText, BorderedSymbol, BorderedShape, SymbolText var MATH_APPROX_ZERO = 0.0000001; ; // Text settings var TEXT_OFFSETS = [[0, 1], [MATH_HALF_ROOT_3, 0.5], [MATH_HALF_ROOT_3, -0.5], [0, -1], [-MATH_HALF_ROOT_3, -0.5], [-MATH_HALF_ROOT_3, 0.5], [0, 0]]; // Required by: BorderedText, BorderedSymbol, BorderedShape, SymbolText var TEXT_DEFAULT_WEIGHT = 4; // Required by: BorderedText, BorderedSymbol, BorderedShape, SymbolText var TEXT_DEFAULT_BORDER = '#000000'; // Required by: BorderedText, BorderedSymbol, BorderedShape, SymbolText var TEXT_DEFAULT_FILL = '#FFFFFF'; // Required by: BorderedText, SymbolText var TEXT_DEFAULT_FONT = 'Arial'; // Required by: BorderedText, SymbolText var TEXT_DEFAULT_SIZE = 50; // Required by: BorderedText, SymbolText ; // Game constants var GAME_TICKS = 60; var GAME_WIDTH = 2048; var GAME_HEIGHT = 2732; ; // Tags var TAG_ENEMY = 'Enemy'; var TAG_PROJECTILE = 'Projectile'; var TAG_PICKUP = 'Pickup'; var TAG_EXPERIENCE = 'Experience'; var TAG_CRUCIFIX = 'Crucifix'; var TAG_WEAPON = 'Weapon'; // Hero settings var HERO_COLOUR = 0x0FA0FF; var HERO_BORDER = 250; 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 = 200; var PICKUP_WEAPON_RANGE = 200; ; //============================================================================== // Instances & variables //============================================================================== ; // Variables var isPaused = false; 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 }; ; // Interface instances var upgradeButton = LK.gui.topRight.addChild(new UiBoonUpgradeButton({ x: -80, y: 60, fill: '#ff0000', callback: function callback() { if (minorBoonCount + majorBoonCount > 0) { showBoonSelection(); } } })); var countdownTimer = LK.gui.top.addChild(new UiCountdownTimer({ y: 10, countdown: 300 })); ; // 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 })); backgroundContainer.addChild(new PickupWeapon({ x: GAME_WIDTH / 4 * 2, y: GAME_HEIGHT / 4, scale: 1.25, graphics: 'weaponFireball' // weaponClass: WeaponFireball })); backgroundContainer.addChild(new PickupWeapon({ x: GAME_WIDTH / 4 * 2, y: GAME_HEIGHT / 4 * 3, scale: 1.25, rotation: -Math.PI / 8, graphics: 'weaponCross' // weaponClass: WeaponCross })); ; //============================================================================== // 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); }
===================================================================
--- original.js
+++ change.js
@@ -6,8 +6,9 @@
config = config || {};
// Private variables
var destroyCalled = false;
// Public variables
+ self.tags = {};
self.x = config.x || 0;
self.y = config.y || 0;
self.rotation = config.rotation || 0;
self.alpha = config.alpha !== undefined ? config.alpha : 1.0;
@@ -20,15 +21,143 @@
self.callDestroy = function () {
if (!destroyCalled) {
destroyCalled = true;
self.onDestroy();
- destroy();
+ self.destroy();
}
};
self.onDestroy = function () {};
// Enable inheritance
return self;
});
+var UiCountdownTimer = ConfigContainer.expand(function (config) {
+ var self = ConfigContainer.call(this, config);
+ var countdown = config.countdown;
+ var ticker = 60;
+ var countdownTxt = self.addChild(new BorderedText('', {
+ size: 80,
+ anchorX: .5,
+ anchorY: 0
+ }));
+ self.update = function () {
+ if (countdown > 0 && --ticker <= 0) {
+ ticker = 60;
+ if (--countdown === 0) {
+ countdownTxt.setFill('#AA0000');
+ // TODO: Spawn boss
+ }
+ adjustLabel();
+ }
+ difficultyScale = 1 - countdown / config.countdown;
+ };
+ function adjustLabel() {
+ var minutes = Math.floor(countdown / 60);
+ var seconds = Math.abs(countdown) % 60;
+ var minutesString = (minutes < 10 ? '0' : '') + minutes;
+ var secondsString = (seconds < 10 ? '0' : '') + seconds;
+ countdownTxt.setText(minutesString + ':' + secondsString);
+ }
+ adjustLabel();
+ // Enable inheritance
+ return self;
+});
+var UiBoonUpgradeButton = ConfigContainer.expand(function (config) {
+ var self = ConfigContainer.call(this, config);
+ var hidden = false;
+ var count = 0;
+ var button = self.attachAsset('uiBoonButton', {
+ anchorX: 0.5,
+ anchorY: 0.4
+ });
+ var countTxt = self.addChild(new BorderedText('0', {
+ fill: config.fill,
+ anchorX: .5,
+ anchorY: .5
+ }));
+ button.on('down', function (x, y, obj) {
+ obj.event = obj;
+ config.callback(obj);
+ });
+ self.visible = false;
+ self.setHidden = function (newHidden) {
+ hidden = newHidden;
+ self.checkHidden();
+ };
+ self.setCount = function (newCount) {
+ count = newCount;
+ countTxt.setText(newCount);
+ self.checkHidden();
+ };
+ self.checkHidden = function () {
+ self.visible = !hidden && count > 0;
+ };
+ // Enable inheritance
+ return self;
+});
+var UiBoonSelection = ConfigContainer.expand(function (config) {
+ var self = ConfigContainer.call(this, config);
+ var availableBoons = Object.keys(config.boons).filter(function (boon) {
+ return config.boons[boon] < 3;
+ });
+ var selectedBoons = [];
+ if (availableBoons.length <= 3) {
+ selectedBoons = availableBoons;
+ } else {
+ while (selectedBoons.length < 3 && availableBoons.length > 0) {
+ var boonIndex = Math.floor(Math.random() * availableBoons.length);
+ selectedBoons.push(availableBoons.splice(boonIndex, 1)[0]);
+ }
+ }
+ if (selectedBoons.length < 3) {
+ selectedBoons.push(config.type === 'Minor' ? 'Minor Heal' : 'Full Heal');
+ }
+ self.attachAsset('uiBoonBackground', {
+ y: 50,
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(new BorderedText('Choose ' + config.count, {
+ y: -220,
+ size: 60,
+ anchorX: .5,
+ anchorY: 0
+ }));
+ self.addChild(new BorderedText(config.type + ' Boon' + (config.count === 1 ? '' : 's'), {
+ y: -150,
+ anchorX: .5,
+ anchorY: 0
+ }));
+ for (var i = 0; i < selectedBoons.length; i++) {
+ var boon = selectedBoons[i];
+ var boonButton = self.attachAsset('uiBoonButton', {
+ y: i * 120,
+ x: -120,
+ anchorX: 0.5,
+ anchorY: 0.4
+ });
+ boonButton.boon = boon;
+ boonButton.on('down', function () {
+ self.destroy();
+ config.callback(this.boon);
+ });
+ var boonLevel = self.addChild(new BorderedText(config.boons[boon] !== undefined ? config.boons[boon] : '∞', {
+ x: boonButton.x,
+ y: boonButton.y,
+ anchor: {
+ x: .5,
+ y: .5
+ }
+ }));
+ var boonName = self.addChild(new BorderedText(boon, {
+ x: boonButton.x + 60,
+ y: boonButton.y,
+ anchorX: 0,
+ anchorY: .5
+ }));
+ }
+ // Enable inheritance
+ return self;
+});
var ProgressBar = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var width = config.width || 120;
var height = config.height || 15;
@@ -57,8 +186,9 @@
return self;
});
var Pickup = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
+ self.tags[TAG_PICKUP] = true;
self.activated = false;
self.pickupRange = 0;
self.update = function () {
if (!isPaused && !self.activated) {
@@ -91,12 +221,15 @@
graphics.scale.y = scaleBase.y * scaleFactor;
};
self.onActivate = function () {
// hero.addChild(new config.weaponClass());
- for (var i = startingWeapons.length - 1; i >= 0; i--) {
- startingWeapons[i].callDestroy();
+ for (var i = backgroundContainer.children.length - 1; i >= 0; i--) {
+ var child = backgroundContainer.children[i];
+ if (child.tags[TAG_PICKUP] && child.tags[TAG_WEAPON]) {
+ child.callDestroy();
+ }
}
- callDestroy();
+ self.callDestroy();
};
// Enable inheritance
return self;
});
@@ -114,38 +247,49 @@
};
self.onActivate = function () {
hero.healPercentage(PICKUP_HEAL_MINOR);
};
+ self.onDestroy = function () {
+ pickupHealthCount--;
+ };
+ pickupHealthCount++;
// Enable inheritance
return self;
});
var PickupCrucifix = Pickup.expand(function (config) {
var self = Pickup.call(this, config);
+ self.tags[TAG_CRUCIFIX] = true;
self.pickupRange = PICKUP_CRUCIFIX_RANGE;
self.attachAsset('pickupCrucifix', {
anchorX: 0.5,
anchorY: 0.5
});
self.onActivate = function () {
- for (var i = midBackContainer.children.length; i >= 0; --i) {
+ for (var i = midBackContainer.children.length - 1; i >= 0; i--) {
var child = midBackContainer.children[i];
- if (child && child.clearable) {
- child.destroy();
+ if (child.tags[TAG_ENEMY]) {
+ child.callDestroy();
}
}
- for (var i = midFrontContainer.children.length; i >= 0; --i) {
+ for (var i = midFrontContainer.children.length - 1; i >= 0; i--) {
var child = midFrontContainer.children[i];
- if (child && child.clearable) {
- child.destroy();
+ if (child.tags[TAG_ENEMY]) {
+ child.callDestroy();
}
}
- for (var i = backgroundContainer.children.length; i >= 0; --i) {
+ for (var i = backgroundContainer.children.length - 1; i >= 0; i--) {
var child = backgroundContainer.children[i];
- if (child && child.onActivate) {
- child.onActivate();
+ if (child.tags[TAG_PICKUP] && child.tags[TAG_EXPERIENCE]) {
+ child.callActivate();
}
}
};
+ self.onDestroy = function () {
+ pickupCrucifixCount--;
+ };
+ pickupCrucifixCount++;
+ // Enable inheritance
+ return self;
});
var JoystickKnob = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
self.attachAsset('shapeEllipse', {
@@ -169,8 +313,9 @@
anchorX: 0.5,
anchorY: 0.5,
tint: 0x000000
});
+ // Enable inheritance
return self;
});
var Joystick = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
@@ -238,15 +383,22 @@
self.direction = undefined;
knob.x = 0;
knob.y = 0;
};
+ // Enable inheritance
return self;
});
var Hero = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
+ // Private variables
+ var level = 1;
+ var experience = 0;
+ var levelRequirement = HERO_XP_REQUIRED;
+ // Public variables
self.speed = HERO_SPEED_BASE;
self.healthMax = HERO_HEALTH_BASE;
self.health = self.healthMax;
+ // Graphics
self.attachAsset('shapeEllipse', {
width: 150,
height: 15,
anchorX: 0.5,
@@ -257,12 +409,23 @@
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 1.0
});
+ var experienceBar = self.addChild(new ProgressBar({
+ y: -heroGraphics.height - 25
+ // percentage: 0
+ }));
var healthBar = self.addChild(new ProgressBar({
- y: -heroGraphics.height - 30,
+ y: -heroGraphics.height - 35,
tint: HERO_COLOUR
}));
+ var levelTxt = self.addChild(new BorderedText('1', {
+ y: -heroGraphics.height - 30,
+ anchorX: 0.5,
+ anchorY: 0.5,
+ size: 60
+ }));
+ // Public functions
self.update = function () {
if (!isPaused && joystick.direction !== undefined) {
var speedX = Math.cos(joystick.direction) * joystick.magnitude * self.speed;
var speedY = Math.sin(joystick.direction) * joystick.magnitude * self.speed;
@@ -280,8 +443,18 @@
}
heroGraphics.scale.x = speedX < 0 ? -1 : 1;
}
};
+ self.addExperience = function (amount) {
+ experience += amount;
+ if (experience >= levelRequirement) {
+ level++;
+ experience -= levelRequirement;
+ levelRequirement = Math.floor(levelRequirement * 1.2);
+ // onLevelUp(level);
+ }
+ experienceBar.setPercentage(experience / levelRequirement);
+ };
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);
@@ -296,16 +469,87 @@
LK.effects.flashObject(self.collision, HERO_COLOUR, 1000);
}
healthBar.updatePercentage(self.health / self.healthMax);
};
+ // Enable inheritance
+ return self;
});
+/**
+* config {
+* x : Number || 0, // See: ConfigContainer
+* y : Number || 0, // See: ConfigContainer
+* rotation : Number || 0, // See: ConfigContainer
+* anchorX : Number || 0,
+* anchorY : Number || 1,
+* size : Number || TEXT_DEFAULT_SIZE,
+* weight : Number || TEXT_DEFAULT_WEIGHT,
+* font : String || TEXT_DEFAULT_FONT,
+* fill : String || TEXT_DEFAULT_FILL,
+* border : String || TEXT_DEFAULT_BORDER,
+* }
+**/
+var BorderedText = ConfigContainer.expand(function (text, config) {
+ var self = ConfigContainer.call(this, config);
+ config = config || {};
+ ;
+ var anchorX = config.anchorX !== undefined ? config.anchorX : 0;
+ var anchorY = config.anchorY !== undefined ? config.anchorY : 1;
+ var size = config.size !== undefined ? config.size : TEXT_DEFAULT_SIZE;
+ var weight = config.weight !== undefined ? config.weight : TEXT_DEFAULT_WEIGHT;
+ var font = config.font !== undefined ? config.font : TEXT_DEFAULT_FONT;
+ var textFill = config.fill !== undefined ? config.fill : TEXT_DEFAULT_FILL;
+ var borderFill = config.border !== undefined ? config.border : TEXT_DEFAULT_BORDER;
+ var textAssets = [];
+ var mainAsset;
+ ;
+ self.setText = setText;
+ self.setFill = setFill;
+ ;
+ function setText(newText) {
+ for (var i = 0; i < textAssets.length; i++) {
+ textAssets[i].setText(newText);
+ }
+ }
+ function setFill(newFill) {
+ textFill = newFill;
+ mainAsset.fill = newFill;
+ }
+ function buildTextAssets(newText) {
+ for (var i = 0; i < TEXT_OFFSETS.length; i++) {
+ var main = i === TEXT_OFFSETS.length - 1;
+ var fill = main ? textFill : borderFill;
+ var textAsset = textAssets[i];
+ if (textAsset) {
+ textAsset.destroy();
+ }
+ textAsset = self.addChild(new Text2(newText, {
+ fill: fill,
+ font: font,
+ size: size
+ }));
+ textAsset.anchor = {
+ x: anchorX,
+ y: anchorY
+ }; // NOTE: Cannot be set in config
+ textAsset.x = TEXT_OFFSETS[i][0] * weight; // NOTE: Cannot be set in config
+ textAsset.y = TEXT_OFFSETS[i][1] * weight; // NOTE: Cannot be set in config
+ textAssets[i] = textAsset;
+ }
+ mainAsset = textAssets[TEXT_OFFSETS.length - 1];
+ }
+ ;
+ buildTextAssets(text);
+ // Enable inheritance
+ return self;
+});
var SortingContainer = Container.expand(function () {
var self = Container.call(this);
self.update = function () {
self.children.sort(function (a, b) {
return a.y - b.y;
});
};
+ // Enable inheritance
return self;
});
/****
@@ -322,12 +566,35 @@
//==============================================================================
// Global constants & settings
//==============================================================================
;
+// Math constants / pre-calculations
+var MATH_2_PI = Math.PI * 2;
+var MATH_HALF_PI = Math.PI / 2;
+var MATH_QUARTER_PI = Math.PI / 4;
+var MATH_HALF_ROOT_3 = Math.sqrt(3) / 2; // Required by: TEXT_OFFSETS, BorderedText, BorderedSymbol, BorderedShape, SymbolText
+var MATH_APPROX_ZERO = 0.0000001;
+;
+// Text settings
+var TEXT_OFFSETS = [[0, 1], [MATH_HALF_ROOT_3, 0.5], [MATH_HALF_ROOT_3, -0.5], [0, -1], [-MATH_HALF_ROOT_3, -0.5], [-MATH_HALF_ROOT_3, 0.5], [0, 0]]; // Required by: BorderedText, BorderedSymbol, BorderedShape, SymbolText
+var TEXT_DEFAULT_WEIGHT = 4; // Required by: BorderedText, BorderedSymbol, BorderedShape, SymbolText
+var TEXT_DEFAULT_BORDER = '#000000'; // Required by: BorderedText, BorderedSymbol, BorderedShape, SymbolText
+var TEXT_DEFAULT_FILL = '#FFFFFF'; // Required by: BorderedText, SymbolText
+var TEXT_DEFAULT_FONT = 'Arial'; // Required by: BorderedText, SymbolText
+var TEXT_DEFAULT_SIZE = 50; // Required by: BorderedText, SymbolText
+;
+// Game constants
var GAME_TICKS = 60;
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2732;
;
+// Tags
+var TAG_ENEMY = 'Enemy';
+var TAG_PROJECTILE = 'Projectile';
+var TAG_PICKUP = 'Pickup';
+var TAG_EXPERIENCE = 'Experience';
+var TAG_CRUCIFIX = 'Crucifix';
+var TAG_WEAPON = 'Weapon';
// Hero settings
var HERO_COLOUR = 0x0FA0FF;
var HERO_BORDER = 250;
var HERO_HEALTH_BASE = 100;
@@ -345,11 +612,11 @@
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_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;
@@ -383,20 +650,17 @@
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;
+var PICKUP_CRUCIFIX_RANGE = 200;
+var PICKUP_WEAPON_RANGE = 200;
;
//==============================================================================
// 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;
@@ -417,8 +681,24 @@
'Growth': 0,
'Split': 0
};
;
+// Interface instances
+var upgradeButton = LK.gui.topRight.addChild(new UiBoonUpgradeButton({
+ x: -80,
+ y: 60,
+ fill: '#ff0000',
+ callback: function callback() {
+ if (minorBoonCount + majorBoonCount > 0) {
+ showBoonSelection();
+ }
+ }
+}));
+var countdownTimer = LK.gui.top.addChild(new UiCountdownTimer({
+ y: 10,
+ countdown: 300
+}));
+;
// Game instances
game.attachAsset('grassTop', {
y: HERO_BORDER - 100,
x: GAME_WIDTH / 2,
@@ -442,20 +722,23 @@
size: 400,
x: GAME_WIDTH - 400,
y: GAME_HEIGHT - 400
}));
-startingWeapons.push(backgroundContainer.addChild(new PickupWeapon({
+backgroundContainer.addChild(new PickupWeapon({
x: GAME_WIDTH / 4 * 2,
y: GAME_HEIGHT / 4,
+ scale: 1.25,
graphics: 'weaponFireball'
// weaponClass: WeaponFireball
-})));
-startingWeapons.push(backgroundContainer.addChild(new PickupWeapon({
+}));
+backgroundContainer.addChild(new PickupWeapon({
x: GAME_WIDTH / 4 * 2,
y: GAME_HEIGHT / 4 * 3,
+ scale: 1.25,
+ rotation: -Math.PI / 8,
graphics: 'weaponCross'
// weaponClass: WeaponCross
-})));
+}));
;
//==============================================================================
// Global events
//==============================================================================
@@ -475,15 +758,5 @@
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);
}
\ No newline at end of file
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