Code edit (2 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
change deadbody meterbar to -300 y position
User prompt
change y position of deadbody meterbar to -100
User prompt
change y position of deadbody meterbar to -300
User prompt
Add a meterbar to the dead body
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'scale')' in this line: 'self.meterBar.scale.x = Math.min(2, self.timeSpentNearDeadBody / timeNeededNearDeadBody);' Line Number: 130
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'scale')' in this line: 'self.meterBar.scale.x = Math.min(2, self.timeSpentNearDeadBody / timeNeededNearDeadBody);' Line Number: 128
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'parent')' in this line: 'if (!self.meterBar.parent && self.parent) {' Line Number: 122
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'parent')' in this line: 'if (!self.meterBar.parent && self.parent) {' Line Number: 122
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'parent')' in this line: 'if (!self.meterBar.parent && self.parent) {' Line Number: 122
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'addChild')' in this line: 'self.parent.addChild(minionCreationVFX);' Line Number: 107
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'addChild')' in this line: 'self.parent.addChild(minionCreationVFX);' Line Number: 107
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'parent')' in this line: 'if (!self.meterBar.parent) {' Line Number: 120
User prompt
Call update on the deadbody every frame
User prompt
In the dead body class update, only increase timeSpentNearDeadBody when the player is near to it
User prompt
Move the player's meter bar to the dead body class
User prompt
Move the logic of creating a minion from the player class to the dead body class
User prompt
Move the logic for timeSpentNearDeadBody from the player class to the dead body class
Code edit (1 edits merged)
Please save this source code
User prompt
Change the enemy spawn time to every 5 seconds
User prompt
Enemies that are created on the left and right side of the screen cannot have a Y position of less than 1200
User prompt
Enemies cannot be created on the top edge of the scren
User prompt
Enemies can only be created from the edges of the screen
var timeNeededNearDeadBody = 1;
var Enemy = Container.expand(function () {
var self = Container.call(this);
self.health = 100;
var shadowGraphics = self.createAsset('shadow', 'Shadow Graphics', .5, .5);
shadowGraphics.scale.x = 2;
shadowGraphics.scale.y = 0.66;
var enemyGraphics = self.createAsset('enemy', 'Enemy Graphics', .5, 1);
self.healthBar = new MeterBar();
self.addChild(self.healthBar);
self.healthBar.x = -50;
self.healthBar.y = 30;
self.healthBar.scale.y = 20 / self.healthBar.height;
self.updateHealthBar = function () {
self.healthBar.scale.x = self.health / 100;
};
self.updateHealthBar();
self.speed = 5;
self.movedDistance = 0;
self.pauseTicks = 0;
self.isPaused = false;
self.move = function (player) {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance <= 150) {
if (player instanceof Minion) {
player.health -= 10;
player.updateHealthBar();
} else {
self.health = Math.max(self.health - 0.7, 0);
self.updateHealthBar();
if (self.health <= 0) {
var deadBody = new DeadBody();
deadBody.x = self.x;
deadBody.y = self.y;
if (self.parent) {
self.parent.deadBodies.push(deadBody);
self.parent.addChild(deadBody);
var enemyIndex = self.parent.enemies.indexOf(self);
if (enemyIndex > -1) {
self.parent.enemies.splice(enemyIndex, 1);
}
}
self.destroy();
}
}
} else if (distance > 60 && !self.isPaused && !(player instanceof Minion)) {
var moveX = dx / distance * self.speed;
var moveY = dy / distance * self.speed;
self.x += moveX;
self.y += moveY;
if (moveX < 0) {
enemyGraphics.scale.x = -1;
} else {
enemyGraphics.scale.x = 1;
}
self.movedDistance += Math.sqrt(moveX * moveX + moveY * moveY);
if (self.movedDistance >= 300) {
self.isPaused = true;
self.movedDistance = 0;
}
} else if (self.isPaused) {
self.pauseTicks++;
if (self.pauseTicks >= 45) {
self.isPaused = false;
self.pauseTicks = 0;
}
}
};
});
var MinionCreationVFX = Container.expand(function () {
var self = Container.call(this);
var minionCreationVFXGraphics = self.createAsset('minionCreationVFX', 'Minion Creation VFX', .5, 1);
self.scale.x = 0;
self.scale.y = 0;
self.ticksToScale = 15;
self.currentScaleTick = 0;
self.scaleVFX = function () {
if (self.currentScaleTick < self.ticksToScale) {
var scaleAmount = 1 / self.ticksToScale;
self.scale.x += scaleAmount;
self.scale.y += scaleAmount;
self.currentScaleTick++;
} else if (self.currentScaleTick === self.ticksToScale) {
self.destroy();
}
};
});
var MeterBar = Container.expand(function () {
var self = Container.call(this);
var meterBarBackgroundGraphics = self.createAsset('meterBarBackground', 'MeterBar Background Image', 0, 0.5);
var meterBarGraphics = self.createAsset('meterBar', 'MeterBar Graphics', 0, 0.5);
});
var DeadBody = Container.expand(function () {
var self = Container.call(this);
var deadBodyGraphics = self.createAsset('deadBody', 'Dead Body Graphics', .5, 1);
});
var Player = Container.expand(function () {
var self = Container.call(this);
var shadowGraphics = self.createAsset('shadow', 'Shadow Graphics', .5, .5);
shadowGraphics.scale.x = 2;
shadowGraphics.scale.y = 0.66;
var playerGraphics = self.createAsset('player', 'Player Graphics', .5, 1);
self.meterBar = new MeterBar();
self.meterBar.scale.y = 0.2;
self.targetPosition = null;
self.speed = 8;
self.move = function (deadBodies, enemies) {
if (self.targetPosition) {
var dx = self.targetPosition.x - self.x;
var dy = self.targetPosition.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < self.speed) {
self.x = self.targetPosition.x;
self.y = Math.min(self.targetPosition.y, 2732);
self.targetPosition = null;
if (dx < 0) {
playerGraphics.scale.x = -1;
} else {
playerGraphics.scale.x = 1;
}
} else {
self.x += dx / distance * self.speed;
self.y = Math.max(Math.min(self.y + dy / distance * self.speed, 2732), 1200);
if (dx < 0) {
playerGraphics.scale.x = -1;
} else {
playerGraphics.scale.x = 1;
}
}
}
for (var i = 0; i < deadBodies.length; i++) {
var deadBody = deadBodies[i];
var distanceToDeadBody = Math.sqrt(Math.pow(self.x - deadBody.x, 2) + Math.pow(self.y - deadBody.y, 2));
if (distanceToDeadBody < 200) {
if (!self.meterBar.parent) {
self.addChild(self.meterBar);
self.meterBar.y = -430;
self.meterBar.x = -100;
self.meterBar.scale.x = 0;
self.timeSpentNearDeadBody = 0;
self.startTick = null;
}
if (!self.startTick && !self.targetPosition) {
self.startTick = LK.ticks;
}
if (!self.targetPosition) {
self.timeSpentNearDeadBody += 1 / 60;
self.meterBar.scale.x = Math.min(2, self.timeSpentNearDeadBody / timeNeededNearDeadBody);
if (self.meterBar.scale.x >= 2) {
var newMinion = new Minion();
newMinion.x = deadBody.x;
newMinion.y = deadBody.y;
self.parent.minions.push(newMinion);
self.parent.addChild(newMinion);
self.removeChild(self.meterBar);
self.timeSpentNearDeadBody = 0;
self.meterBar.scale.x = 0;
deadBody.destroy();
var minionCreationVFX = new MinionCreationVFX();
minionCreationVFX.x = newMinion.x;
minionCreationVFX.y = newMinion.y;
self.parent.addChild(minionCreationVFX);
}
}
} else if (self.meterBar.parent) {
self.meterBar.parent.removeChild(self.meterBar);
self.timeSpentNearDeadBody = 0;
}
}
};
});
var Minion = Container.expand(function () {
var self = Container.call(this);
var shadowGraphics = self.createAsset('shadow', 'Shadow Graphics', .5, .5);
shadowGraphics.scale.x = 2;
shadowGraphics.scale.y = 0.66;
var minionGraphics = self.createAsset('minion', 'Minion Graphics', .5, 1);
self.healthBar = new MeterBar();
self.addChild(self.healthBar);
self.healthBar.y = 30;
self.healthBar.x = -50;
self.healthBar.scale.y = 20 / self.healthBar.height;
self.updateHealthBar = function () {
self.healthBar.scale.x = self.health / 100;
};
self.updateHealthBar();
self.health = 100;
self.speed = 5;
self.scale.x = 0;
self.scale.y = 0;
self.ticksToScale = 15;
self.currentScaleTick = 0;
self.move = function (player) {
self.updateHealthBar();
if (self.health <= 0) {
var minionIndex = self.parent.minions.indexOf(self);
if (minionIndex > -1) {
self.parent.minions.splice(minionIndex, 1);
}
self.destroy();
} else {
self.updateHealthBar();
}
var target = player;
var minDistance = 500;
if (self.parent && self.parent.enemies) {
for (var i = 0; i < self.parent.enemies.length; i++) {
var enemy = self.parent.enemies[i];
var dx = enemy.x - self.x;
var dy = enemy.y - self.y;
var distanceToEnemy = Math.sqrt(dx * dx + dy * dy);
if (distanceToEnemy < minDistance) {
minDistance = distanceToEnemy;
target = enemy;
}
}
}
if (target === player && minDistance >= 500) {
target = player;
}
if (target) {
var dx = target.x - self.x;
var dy = target.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
}
if (distance <= 150 && target instanceof Enemy) {
self.health = Math.max(self.health - 1, 0);
target.health = Math.max(target.health - 0.7, 0);
self.updateHealthBar();
target.updateHealthBar();
} else if (distance > 60) {
self.x += dx / distance * self.speed;
if (dx > 0) {
minionGraphics.scale.x = -1;
} else {
minionGraphics.scale.x = 1;
}
self.y += dy / distance * self.speed;
}
};
self.attack = function () {};
self.scaleMinion = function () {
if (self.currentScaleTick < self.ticksToScale) {
var scaleAmount = 1 / self.ticksToScale;
self.scale.x += scaleAmount;
self.scale.y += scaleAmount;
self.currentScaleTick++;
}
};
});
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('heroBullet', 'Hero Bullet Graphics', .5, .5);
self.speed = 10;
self.move = function () {};
});
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('enemyBullet', 'Enemy Bullet Graphics', .5, .5);
self.speed = -10;
self.move = function () {};
});
var Background = Container.expand(function () {
var bgSelf = Container.call(this);
var backgroundGraphics = bgSelf.createAsset('background', 'Background Image', 0, 0);
bgSelf.addChild(backgroundGraphics);
});
var Game = Container.expand(function () {
var self = Container.call(this);
var background = self.addChild(new Background());
background.x = LK.stage.width / 2 - background.width / 2;
background.y = LK.stage.height - background.height;
var player = self.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 200;
self.deadBodies = [];
var deadBody = new DeadBody();
deadBody.x = 2048 / 2;
deadBody.y = 1750;
self.deadBodies.push(deadBody);
self.addChild(deadBody);
self.minions = [];
self.enemies = [];
var heroBullets = [];
var enemyBullets = [];
LK.on('tick', function () {
player.move(self.deadBodies, self.enemies);
self.children.sort(function (a, b) {
return a.y - b.y;
});
self.deadBodies = self.deadBodies.filter(function (deadBody) {
return deadBody.parent;
});
for (var i = 0; i < self.minions.length; i++) {
self.minions[i].scaleMinion();
self.minions[i].move(player);
}
for (var i = 0; i < self.enemies.length; i++) {
self.enemies[i].move(player);
}
for (var i = 0; i < self.children.length; i++) {
if (self.children[i] instanceof MinionCreationVFX) {
self.children[i].scaleVFX();
}
}
});
var enemyCreationInterval = LK.setInterval(function () {
var newEnemy = new Enemy();
var edge = Math.floor(Math.random() * 4);
switch (edge) {
case 0:
newEnemy.x = 0;
newEnemy.y = Math.random() * 2732;
break;
case 1:
newEnemy.x = Math.random() * 2048;
newEnemy.y = 0;
break;
case 2:
newEnemy.x = 2048;
newEnemy.y = Math.random() * 2732;
break;
case 3:
newEnemy.x = Math.random() * 2048;
newEnemy.y = 2732;
break;
}
self.enemies.push(newEnemy);
self.addChild(newEnemy);
}, 2000);
LK.stage.on('down', function (obj) {
var pos = obj.event.getLocalPosition(self);
player.targetPosition = pos;
});
});
A pixel art sprite in a Super Nintendo, Super Castlevania style where it looks a little gothic/vampire hunter like Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A pixel art large background in a Super Nintendo, Super Castlevania style with an open world like cemetery, 3/4 viewpoint Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. A pixel art sprite in a Super Nintendo, Super Castlevania style that looks like a small pile of bones
Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. A pixel art sprite in a Super Nintendo, Super Castlevania style that looks like a skeleton zombie that is haunched over
Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Pixel art in a SNES style that looks like something from castlevania. A ground explosion effect like something is coming out of the ground
Pixel art in SNES Castlevania style. Red goblin Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Pixel art in SNES Castlevania style. Red goblin