User prompt
In the down handler, set the min y to 500 on pos
User prompt
Move up targetGraphics of targetIndicator by 30px
User prompt
When z-ordering elements make sure click target always renders below hero
User prompt
in bullet set bulletGraphics.blendMode = 1;
User prompt
Move the bullet graphics y up by 150px
User prompt
Exclude background from z-ordering
User prompt
z-order enemies, hero and bullets based on y position
User prompt
Move health bars such that they appear above the entity asset. Use height of asset to move health bar
User prompt
Anchor enemies and hero assets at .5, 1
User prompt
Use tint to color hero health bar green and enemy health bars res
User prompt
Make health bars be anchored at .5,1
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'enemyGraphics.height')' in this line: 'healthBar.y = -enemyGraphics.height / 2 - 10;' Line Number: 78
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self.healthBar.updateHealth')' in this line: 'self.healthBar.updateHealth(self.health);' Line Number: 76
User prompt
Add health bars to enemies and hero
User prompt
Add health points to enemies and hero
User prompt
Add health bar class to the game
User prompt
Make sure enemies array is passed along to findNearestEnemy
User prompt
Pass enemies to findNearestEnemy
User prompt
Fix Bug: 'ReferenceError: Can't find variable: enemies' in this line: 'var nearestEnemy = self.findNearestEnemy(enemies);' Line Number: 48
User prompt
Make hero shoot towards nearest enemy
User prompt
Make hero shoot every secound
User prompt
Make bullets move
User prompt
In tick, fire bullets every 3 seconds if the hero is standing still
User prompt
Return from the move method, if the hero moved or not
User prompt
Make target indicator have 50% opacity
var HealthBar = Container.expand(function () { var self = Container.call(this); var healthBarGraphics = XS.getAsset('healthBar', 'Health Bar', .5, 1); healthBarGraphics.tint = 0x00FF00; self.addChild(healthBarGraphics); self.updateHealth = function (health) { self.scale.x = health / 100; }; }); var TargetIndicator = Container.expand(function () { var self = Container.call(this); var targetGraphics = XS.getAsset('target', 'Target Indicator', .5, .5); targetGraphics.alpha = 0.5; targetGraphics.y -= 30; self.addChild(targetGraphics); }); var Player = Container.expand(function () { var self = Container.call(this); self.health = 100; self.findNearestEnemy = function (enemies) { var nearestEnemy = null; var nearestDistance = Infinity; for (var i = 0; i < enemies.length; i++) { var dx = enemies[i].x - self.x; var dy = enemies[i].y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < nearestDistance) { nearestDistance = distance; nearestEnemy = enemies[i]; } } return nearestEnemy; }; var playerGraphics = XS.getAsset('player', 'Player character', .5, 1); self.addChild(playerGraphics); var healthBar = new HealthBar(); healthBar.y = -playerGraphics.height; self.addChild(healthBar); self.healthBar = healthBar; self.targetX = 2048 / 2; self.targetY = 2732 / 2; self.speed = 5; self.lastShot = 0; self.move = function () { var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > self.speed) { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; self.healthBar.updateHealth(self.health); return true; } self.healthBar.updateHealth(self.health); return false; }; self.setTarget = function (x, y) { self.targetX = x; self.targetY = y; }; self.shoot = function (enemies) { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y; var nearestEnemy = self.findNearestEnemy(enemies); if (nearestEnemy) { var dx = nearestEnemy.x - self.x; var dy = nearestEnemy.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); bullet.dx = dx / distance; bullet.dy = dy / distance; } return bullet; }; }); var Enemy = Container.expand(function () { var self = Container.call(this); self.health = 100; var enemyGraphics = XS.getAsset('enemy', 'Enemy character', .5, 1); self.addChild(enemyGraphics); var healthBar = new HealthBar(); healthBar.y = -enemyGraphics.height; healthBar.children[0].tint = 0xFF0000; self.addChild(healthBar); self.healthBar = healthBar; self.healthBar.updateHealth(self.health); self.move = function () {}; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = XS.getAsset('bullet', 'Bullet', .5, .5); bulletGraphics.y -= 150; bulletGraphics.blendMode = 1; self.addChild(bulletGraphics); self.move = function () { self.x += self.dx * 5; self.y += self.dy * 5; }; }); var Game = Container.expand(function () { var self = Container.call(this); self.sortGameObjects = function () { self.children.sort(function (a, b) { if (a === background || b === background) return 0; if (a === targetIndicator) return -1; if (b === targetIndicator) return 1; return a.y - b.y; }); }; var background = XS.getAsset('background', 'Background', .5, .5); background.x = 2048 / 2; background.y = 2732 / 2; self.addChild(background); var targetIndicator = new TargetIndicator(); targetIndicator.x = 2048 / 2; targetIndicator.y = 2732 / 2; self.addChild(targetIndicator); var player = self.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2; var enemies = []; for (var i = 0; i < 5; i++) { var enemy = self.addChild(new Enemy()); enemy.x = Math.random() * (2048 - 500) + 300; enemy.y = Math.random() * (2732 - 500) + 300; enemies.push(enemy); } var bullets = []; XS.on('tick', function () { player.move(0, 0); var dx = player.targetX - player.x; var dy = player.targetY - player.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < player.speed && XS.ticks - player.lastShot >= 60) { player.lastShot = XS.ticks; var bullet = player.shoot(enemies); bullets.push(bullet); self.addChild(bullet); } if (distance < player.speed) { targetIndicator.visible = false; } for (var i = 0; i < enemies.length; i++) { enemies[i].move(); } for (var i = 0; i < bullets.length; i++) { bullets[i].move(); } self.sortGameObjects(); }); stage.on('down', function (obj) { var pos = obj.event.getLocalPosition(self); pos.y = Math.max(pos.y, 500); player.setTarget(pos.x, pos.y); targetIndicator.x = pos.x; targetIndicator.y = pos.y; targetIndicator.visible = true; }); });
===================================================================
--- original.js
+++ change.js
@@ -149,8 +149,9 @@
self.sortGameObjects();
});
stage.on('down', function (obj) {
var pos = obj.event.getLocalPosition(self);
+ pos.y = Math.max(pos.y, 500);
player.setTarget(pos.x, pos.y);
targetIndicator.x = pos.x;
targetIndicator.y = pos.y;
targetIndicator.visible = true;
giant wall Pixel art, 16 bit, isometric, SNES, top-down, no background, white background, low resolution, symmetrical
Single Short round Isometric dungeon column, simple, few stones, single column, no floor, dark room, Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Multi color chaotic noise, primary colors Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Round purple magic fireball. White core Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
enemy goblin , Pixel art, 16 bit, isometric, SNES, top-down, no background, white background, low resolution, symmetrical, seen from front. No staff.
Single fire particle Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
https://i.imgur.com/R3ZLguO.jpg Dungeon, Empty open floor, dark, fullscreen, Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. high detail. High contrast. --ar 2:3
single wizard, hooded Pixel art, 16 bit, isometric, SNES, top-down, no background, white background, low resolution, symmetrical, seen from front.
round bomb. fuse on fire Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Multi color chaotic noise, primary colors. Rays from the center. Darker center Single Game Texture. In-Game asset. 2d. Pixelart. Low detail. High contrast.