User prompt
Make background darker
User prompt
Make background grass colored green
User prompt
Enemies should spawn faster the longer the hero is alive
User prompt
Be game over if enemy touches the hero
User prompt
Add score to game
User prompt
Make hero shoot half as fast
User prompt
Rotate enemy asset 90 degrees counter clockwise
User prompt
Rotate the enemies based on what direction they are moving
User prompt
Enemies should only spawn outside the playable area
User prompt
Enemies should keep spawning
User prompt
Enemies should spawn from all directions
User prompt
Make enemies respawn outside the playable area
User prompt
Rotate the tank asset 90 degrees to the left
User prompt
Make hero shoot 3x as fast
User prompt
Hero bullets should be removed if they hit an enemy
User prompt
Enemies should die if hit by hero bullets
User prompt
Make enemies move towards the hero
User prompt
When shooting rotate the hero in the direction he is shooting
User prompt
While running rotate the hero so he points in the direction he is running
User prompt
Fix Bug: 'TypeError: hero.findNearestEnemy is not a function. (In 'hero.findNearestEnemy(enemies)', 'hero.findNearestEnemy' is undefined)' in this line: 'var nearestEnemy = hero.findNearestEnemy(enemies);' Line Number: 97
User prompt
Fix Bug: 'TypeError: hero.findNearestEnemy is not a function. (In 'hero.findNearestEnemy(enemies)', 'hero.findNearestEnemy' is undefined)' in this line: 'var nearestEnemy = hero.findNearestEnemy(enemies);' Line Number: 97
User prompt
Fix Bug: 'TypeError: hero.findNearestEnemy is not a function. (In 'hero.findNearestEnemy(enemies)', 'hero.findNearestEnemy' is undefined)' in this line: 'var nearestEnemy = hero.findNearestEnemy(enemies);' Line Number: 97
User prompt
Make hero shoot in the direction of the nearest enemy
User prompt
The target indicator does not always hide
User prompt
The hero does not seem to always stop moving when it reaches the target. I think it’s because the the test uses a to small variable. Please fix this
var TargetIndicator = Container.expand(function () { var self = Container.call(this); var indicatorGraphics = XS.getAsset('indicator', 'Target Indicator', .5, .5); self.addChild(indicatorGraphics); }); var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = XS.getAsset('hero', 'Hero character', .5, .5); heroGraphics.rotation = -Math.PI / 2; self.addChild(heroGraphics); self.target = { x: 2048 / 2, y: 2732 / 2 }; self.isMoving = false; self.move = function () { var dx = self.target.x - self.x; var dy = self.target.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 5) { self.x += 5 * (dx / distance); self.y += 5 * (dy / distance); self.rotation = Math.atan2(dy, dx); self.isMoving = true; } else { self.isMoving = false; } }; self.shoot = function (target) { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y; var dx = target.x - self.x; var dy = target.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); bullet.direction.x = dx / distance; bullet.direction.y = dy / distance; return bullet; }; self.findNearestEnemy = function (enemies) { var nearestDistance = Infinity; var nearestEnemy = null; 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 Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = XS.getAsset('enemy', 'Enemy character', .5, .5); enemyGraphics.rotation = -Math.PI / 2; self.addChild(enemyGraphics); self.speed = 2; self.move = function (hero) { var dx = hero.x - self.x; var dy = hero.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); self.x += self.speed * (dx / distance); self.y += self.speed * (dy / distance); self.rotation = Math.atan2(dy, dx); }; self.shoot = function () {}; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = XS.getAsset('bullet', 'Bullet Graphics', .5, .5); self.addChild(bulletGraphics); self.speed = 10; self.direction = { x: 0, y: 0 }; self.move = function () { self.x += self.direction.x * self.speed; self.y += self.direction.y * self.speed; }; }); var Game = Container.expand(function () { var self = Container.call(this); XS.stageContainer.setBackgroundColor(0x004000); var score = 0; var heroAliveTime = 0; var targetIndicator = self.addChild(new TargetIndicator()); var hero = self.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 / 2; var scoreTxt = new Text2('0', { size: 150, fill: '#ffffff' }); scoreTxt.anchor.set(.5, 0); XS.gui.topCenter.addChild(scoreTxt); stage.on('down', function (obj) { var pos = obj.event.getLocalPosition(self); hero.target.x = pos.x; hero.target.y = pos.y; }); stage.on('move', function (obj) { var pos = obj.event.getLocalPosition(self); hero.target.x = pos.x; hero.target.y = pos.y; }); var enemies = []; var enemyCount = 0; function spawnEnemy() { var enemy = self.addChild(new Enemy()); var side = Math.floor(Math.random() * 4); switch (side) { case 0: enemy.x = Math.random() * 2048; enemy.y = -100; break; case 1: enemy.x = 2048 + 100; enemy.y = Math.random() * 2732; break; case 2: enemy.x = Math.random() * 2048; enemy.y = 2732 + 100; break; case 3: enemy.x = -100; enemy.y = Math.random() * 2732; break; } enemies.push(enemy); enemyCount++; } for (var i = 0; i < 10; i++) { spawnEnemy(); } var bullets = []; XS.on('tick', function () { heroAliveTime++; if (XS.ticks % Math.max(10, 100 - Math.floor(heroAliveTime / 1000)) === 0) { spawnEnemy(); } hero.move(); var dx = hero.target.x - hero.x; var dy = hero.target.y - hero.y; var distance = Math.sqrt(dx * dx + dy * dy); if (hero.isMoving) { targetIndicator.visible = true; targetIndicator.x = hero.target.x; targetIndicator.y = hero.target.y; } else { targetIndicator.visible = false; } if (XS.ticks % 40 === 0 && !hero.isMoving) { var nearestEnemy = hero.findNearestEnemy(enemies); if (nearestEnemy) { var bullet = hero.shoot(nearestEnemy); bullets.push(bullet); self.addChild(bullet); hero.rotation = Math.atan2(nearestEnemy.y - hero.y, nearestEnemy.x - hero.x); } } for (var i = 0; i < enemies.length; i++) { enemies[i].move(hero); enemies[i].shoot(); if (hero.intersects(enemies[i])) { XS.showGameOver(); return; } } for (var i = 0; i < bullets.length; i++) { bullets[i].move(); for (var j = 0; j < enemies.length; j++) { if (bullets[i].intersects(enemies[j])) { enemies[j].destroy(); enemies.splice(j, 1); bullets[i].destroy(); bullets.splice(i, 1); score++; scoreTxt.setText(score); break; } } } }); });
===================================================================
--- original.js
+++ change.js
@@ -83,9 +83,9 @@
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
- XS.stageContainer.setBackgroundColor(0x008000);
+ XS.stageContainer.setBackgroundColor(0x004000);
var score = 0;
var heroAliveTime = 0;
var targetIndicator = self.addChild(new TargetIndicator());
var hero = self.addChild(new Hero());
Alien organic tank, seen from above, no perspective. Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Tank seen from the top Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.