User prompt
remove old healthbar. add more enemys after every 10 seconds
User prompt
make epic background. make helathbar bigger and high quality. make bullets disappear after 5 seconds
User prompt
make bullets facing taget. make enemys dont die in one hit
User prompt
make bullets spawns not only if player moves, but every 1 sec
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'intersects')' in this line: 'if (enemies[i].intersects(heroBullets[j])) {' Line Number: 122
User prompt
make bullets destroy after 1 sec or if they hit the enemy. add hp to enemy
User prompt
make hero fire to nearest enemy
User prompt
add delay to bullet spawning
User prompt
Fix Bug: 'TypeError: heroBullets[i].update is not a function' in this line: 'heroBullets[i].update();' Line Number: 105
User prompt
Fix Bug: 'TypeError: Reduce of empty array with no initial value' in this line: 'var nearestEnemy = enemies.reduce((prev, curr) => {' Line Number: 65
User prompt
move healthbar to top of the player. make player auto-fire to nearest enemy
User prompt
add more delay between enemy attacks. move health bar to the top of the screen
User prompt
move health bar to top, make him red. Add delay to enemy damage
User prompt
add healthbar and damage when enemy hit the player
User prompt
spawn enemys every 5 seconds. enemys follow the player
User prompt
player follow the mouse without swipe
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: hero.moveLeft is not a function' in this line: 'hero.moveLeft();' Line Number: 86
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'event')' in this line: 'var mouseX = obj.event.getLocalPosition(self).x;' Line Number: 43
User prompt
make character follow the mouse
User prompt
add swipe character control
User prompt
Fix Bug: 'TypeError: hero.move is not a function' in this line: 'hero.move();' Line Number: 74
User prompt
Fix Bug: 'Uncaught TypeError: window.addEventListener is not a function' in this line: 'window.addEventListener('keydown', function (event) {' Line Number: 54
var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5); self.speed = 20; self.jump = function () {}; self.shoot = function () {}; self.moveLeft = function () { self.x -= self.speed; }; self.moveRight = function () { self.x += self.speed; }; self.healthBar = self.createAsset('highQualityHealthBar', 'High Quality Health Bar', 0, 0); self.healthBar.width = 200; self.healthBar.height = 20; self.healthBar.x = 0; self.healthBar.y = -self.height / 2 - self.healthBar.height / 2; self.health = 100; self.update = function (mouseX) { if (self.x < mouseX) { self.moveRight(); } else if (self.x > mouseX) { self.moveLeft(); } }; }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.createAsset('enemy', 'Enemy character', .5, .5); self.speed = 3; self.health = 100; self.move = function (targetX, targetY) { if (self.x < targetX) { self.x += self.speed; } else if (self.x > targetX) { self.x -= self.speed; } if (self.y < targetY) { self.y += self.speed; } else if (self.y > targetY) { self.y -= self.speed; } }; self.attack = function () {}; }); var HeroBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.createAsset('heroBullet', 'Hero Bullet', .5, .5); self.speed = 10; self.target = null; LK.setTimeout(function () { self.destroy(); }, 5000); self.move = function () { if (self.target) { var dx = self.target.x - self.x; var dy = self.target.y - self.y; var angle = Math.atan2(dy, dx); self.x += Math.cos(angle) * self.speed; self.y += Math.sin(angle) * self.speed; bulletGraphics.rotation = angle; } else { self.x += self.speed; } }; }); var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.createAsset('enemyBullet', 'Enemy Bullet', .5, .5); self.speed = 7; self.move = function () {}; }); var Game = Container.expand(function () { var self = Container.call(this); var background = self.createAsset('epicBackground', 'Epic Background', 0, 0); background.width = 2048; background.height = 2732; self.on('move', function (obj) { var event = obj.event; var pos = event.getLocalPosition(self); hero.x = pos.x; hero.y = pos.y; }); var bulletSpawnInterval = LK.setInterval(function () { var nearestEnemy = enemies.length > 0 ? enemies.reduce((prev, curr) => { var d1 = Math.hypot(hero.x - prev.x, hero.y - prev.y); var d2 = Math.hypot(hero.x - curr.x, hero.y - curr.y); return d1 < d2 ? prev : curr; }) : null; var bullet = new HeroBullet(); bullet.x = hero.x; bullet.y = hero.y; bullet.target = nearestEnemy; heroBullets.push(bullet); self.addChild(bullet); }, 1000); var hero = self.addChild(new Hero()); var enemies = []; var enemySpawnInterval = LK.setInterval(function () { for (var i = 0; i < 5; i++) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = Math.random() * 2732; enemies.push(enemy); self.addChild(enemy); } }, 10000); var heroBullets = []; var enemyBullets = []; hero.x = 724; hero.y = 1366; LK.on('tick', function () { hero.update(); for (var i = 0; i < enemies.length; i++) { enemies[i].move(hero.x, hero.y); if (enemies[i].intersects(hero)) { LK.setTimeout(function () { hero.health -= 10; hero.healthBar.width = hero.health; if (hero.health <= 0) { LK.showGameOver(); } }, 1000); } for (var j = 0; j < heroBullets.length; j++) { if (enemies[i] && heroBullets[j] && enemies[i].intersects(heroBullets[j])) { enemies[i].health -= 10; heroBullets[j].destroy(); if (enemies[i].health <= 0) { enemies[i].destroy(); enemies.splice(i, 1); } else { enemies[i].tint = 0xFF0000 + 0x00FF00 * (enemies[i].health / 100); } } } } for (var i = 0; i < heroBullets.length; i++) { heroBullets[i].move(); } for (var i = 0; i < enemyBullets.length; i++) { enemyBullets[i].update(); } }); LK.on('keydown', function (event) { switch (event.key) { case 'ArrowLeft': hero.moveLeft(); break; case 'ArrowRight': hero.moveRight(); break; case 'Space': hero.jump(); break; case 'Control': hero.shoot(); break; } }); });
===================================================================
--- original.js
+++ change.js
@@ -9,9 +9,8 @@
};
self.moveRight = function () {
self.x += self.speed;
};
- self.healthBar = self.createAsset('healthBar', 'Hero Health Bar', 0, 0);
self.healthBar = self.createAsset('highQualityHealthBar', 'High Quality Health Bar', 0, 0);
self.healthBar.width = 200;
self.healthBar.height = 20;
self.healthBar.x = 0;
@@ -97,13 +96,15 @@
}, 1000);
var hero = self.addChild(new Hero());
var enemies = [];
var enemySpawnInterval = LK.setInterval(function () {
- var enemy = new Enemy();
- enemy.x = Math.random() * 2048;
- enemy.y = Math.random() * 2732;
- enemies.push(enemy);
- self.addChild(enemy);
+ for (var i = 0; i < 5; i++) {
+ var enemy = new Enemy();
+ enemy.x = Math.random() * 2048;
+ enemy.y = Math.random() * 2732;
+ enemies.push(enemy);
+ self.addChild(enemy);
+ }
}, 10000);
var heroBullets = [];
var enemyBullets = [];
hero.x = 724;
Hero Character for platformer game Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Enemy turtle for survival game Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Bullet from bullethell Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
healthbar Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Epic brawl stars styled Background Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.