Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: LK.Button is not a constructor' in or related to this line: 'var pauseButton = new LK.Button({' Line Number: 130
User prompt
add pause button with menu
User prompt
Movement with the keyboard still doesnt work
Code edit (1 edits merged)
Please save this source code
User prompt
i want movement bound to the wasd not the mouse
User prompt
the hero movement still does not work
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'addEventListener')' in or related to this line: 'document.addEventListener('keydown', function (event) {' Line Number: 133
User prompt
map hero movement to w for forward a for left s for back d for right
User prompt
Make enemies move towards hero
User prompt
Make hero able to move
Initial prompt
Soulslike
===================================================================
--- original.js
+++ change.js
@@ -26,8 +26,16 @@
self.health = 50;
self.speed = 3;
self.update = function () {
// Update logic for enemy
+ // Move towards hero
+ var dx = hero.x - self.x;
+ var dy = hero.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 0) {
+ self.x += self.speed * dx / distance;
+ self.y += self.speed * dy / distance;
+ }
};
self.takeDamage = function (amount) {
self.health -= amount;
if (self.health <= 0) {