User prompt
Enemies should move faster
User prompt
isMovingRight should be true when hero moving right and false otherwise
User prompt
isMovingRight should not stuck on true
User prompt
Enemy should disappear only when colliding while hero moving from left to right, at other cases nothing happens
User prompt
Enemies spawn every second out of right side of the screen and move to the left
User prompt
When hero collide the enemy, the enemy disappers
User prompt
After dash the hero should always come back to same point on the middle-left of the screen
User prompt
Hero should dash when I click out of hero, not on hero
User prompt
When I click anywhere the hero should move fast and straight to click point, than come back a bit slower
User prompt
When I tap hero should dash at this point and then come back
User prompt
Enemy should be at the bottom
User prompt
Change daemon to enemy
User prompt
Enemy should stay on the right
User prompt
Hero should stay on the left
User prompt
Help
Initial prompt
Daemon vs. The World
===================================================================
--- original.js
+++ change.js
@@ -2,8 +2,37 @@
var self = Container.call(this);
var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
self.move = function () {};
self.shoot = function () {};
+ self.dashToPointAndBack = function (targetX, targetY, onCompletion) {
+ var originalX = self.x;
+ var originalY = self.y;
+ var dashSpeed = 20;
+ var returnSpeed = 5;
+ var dashComplete = false;
+ self.move = function () {
+ if (!dashComplete) {
+ if (Math.abs(self.x - targetX) > dashSpeed || Math.abs(self.y - targetY) > dashSpeed) {
+ self.x += (targetX - self.x > 0 ? 1 : -1) * dashSpeed;
+ self.y += (targetY - self.y > 0 ? 1 : -1) * dashSpeed;
+ } else {
+ dashComplete = true;
+ }
+ } else {
+ if (Math.abs(self.x - originalX) > returnSpeed || Math.abs(self.y - originalY) > returnSpeed) {
+ self.x += (originalX - self.x > 0 ? 1 : -1) * returnSpeed;
+ self.y += (originalY - self.y > 0 ? 1 : -1) * returnSpeed;
+ } else {
+ self.x = originalX;
+ self.y = originalY;
+ self.move = function () {};
+ if (typeof onCompletion === 'function') {
+ onCompletion();
+ }
+ }
+ }
+ };
+ };
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('enemy', 'Enemy character', .5, .5);
@@ -29,8 +58,15 @@
var hero = self.addChild(new Hero());
hero.x = 2048 * 0.1;
hero.y = 2732 / 2;
heroes.push(hero);
+ hero.on('down', function (obj) {
+ var event = obj.event;
+ var position = event.getLocalPosition(self);
+ hero.dashToPointAndBack(position.x, position.y, function () {
+ console.log('Hero has returned to the original position.');
+ });
+ });
var enemy = self.addChild(new Enemy());
enemy.x = 2048 - enemy.width / 2;
enemy.y = 2732 - enemy.height / 2;
enemies.push(enemy);