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
===================================================================
--- 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