examples/grow21/client/js/Target.js
function() {
    var valid = false;
    var destroy = true;
    var target = this;
    Crafty('Card').each(function() {
      if (this.intersect(target.x + target.w + game.config.cardBuffer, target.y, target.w, target.h) ||
          this.intersect(target.x - target.w - game.config.cardBuffer, target.y, target.w, target.h) ||
          this.intersect(target.x, target.y + target.h + game.config.cardBuffer, target.w, target.h) ||
          this.intersect(target.x, target.y - target.h - game.config.cardBuffer, target.w, target.h)
        ) {
        valid = true;
        destroy = false;
      }
      if (this.intersect(target.x, target.y, target.w, target.h)) {
        destroy = false;
      }
    });
    if (valid) {
      this.used = false;
    }
    else if (destroy) {
      this.destroy();
      var currentTarget = this;
      game.targets = _.reject(game.targets, function(thisTarget) { return _.isEqual(thisTarget, currentTarget); });
    }
  }
function() {
    var valid = false;
    var destroy = true;
    var target = this;
    Crafty('Card').each(function() {
      if (this.intersect(target.x + target.w + game.config.cardBuffer, target.y, target.w, target.h) ||
          this.intersect(target.x - target.w - game.config.cardBuffer, target.y, target.w, target.h) ||
          this.intersect(target.x, target.y + target.h + game.config.cardBuffer, target.w, target.h) ||
          this.intersect(target.x, target.y - target.h - game.config.cardBuffer, target.w, target.h)
        ) {
        valid = true;
        destroy = false;
      }
      if (this.intersect(target.x, target.y, target.w, target.h)) {
        destroy = false;
      }
    });
    if (valid) {
      this.used = false;
    }
    else if (destroy) {
      this.destroy();
      var currentTarget = this;
      game.targets = _.reject(game.targets, function(thisTarget) { return _.isEqual(thisTarget, currentTarget); });
    }
  }
function ( ) { var valid = false ; var destroy = true ; var target = this ; Crafty ( 'Card' ) . each ( function ( ) { if ( this . intersect ( target . x + target . w + game . config . cardBuffer , target . y , target . w , target . h ) || this . intersect ( target . x - target . w - game . config . cardBuffer , target . y , target . w , target . h ) || this . intersect ( target . x , target . y + target . h + game . config . cardBuffer , target . w , target . h ) || this . intersect ( target . x , target . y - target . h - game . config . cardBuffer , target . w , target . h ) ) { valid = true ; destroy = false ; } if ( this . intersect ( target . x , target . y , target . w , target . h ) ) { destroy = false ; } } ) ; if ( valid ) { this . used = false ; } else if ( destroy ) { this . destroy ( ) ; var currentTarget = this ; game . targets = _ . reject ( game . targets , function ( thisTarget ) { return _ . isEqual ( thisTarget , currentTarget ) ; } ) ; } }
if I am next to a card, then refresh me, I'm a valid target if I'm under a card, don't refresh me but I should continue to exist otherwise destroy me
if I am next to a card then refresh me I m a valid target if I m under a card don t refresh me but I should continue to exist otherwise destroy me