當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Vector.add函數代碼示例

本文整理匯總了TypeScript中math/Vector.add函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript add函數的具體用法?TypeScript add怎麽用?TypeScript add使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了add函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: advanceTime

 public advanceTime() {
   this.animation_.update();
   this.position_ = this.position_.add(this.velocity_);
   if (!this.animation_.isRunning()) {
     this.invalidate();
   }
 }
開發者ID:krslynx,項目名稱:dotproduct,代碼行數:7,代碼來源:Effect.ts

示例2: fire

  public fire(angle : number, position : Vector, velocity : Vector, isMine : boolean, commitFireFn : (fireEnergy : number, fireDelay : number, recoilAcceleration : number) => boolean) : any {
    let level = this.level_.getValue();
    if (level < 0) {
      return null;
    }

    let fireEnergy = this.getFireEnergy_();
    let fireDelay = this.getFireDelay_();
    let recoilAcceleration = isMine ? 0 : this.getRecoilAcceleration_();

    if (!commitFireFn(fireEnergy, fireDelay, recoilAcceleration)) {
      return null;
    }

    let lifetime = this.getLifetime_();
    let damage = this.getDamage_();
    let bounceCount = this.getBounceCount_();
    let blastRadius = this.getBlastRadius_();
    let proxRadius = this.getProxRadius_();
    let newVelocity = isMine ? Vector.ZERO : velocity.add(Vector.fromPolar(this.getBombSpeed_(), angle));
    let projectile = this.simulation_.modelObjectFactory.newBomb(this.owner_, level, position, newVelocity, lifetime, damage, bounceCount, blastRadius, proxRadius);

    this.owner_.addProjectile(projectile);

    return {
      'type': this.getType(),
      'level': level,
      'vel': newVelocity.toArray(),
      'bounceCount': bounceCount
    };
  }
開發者ID:krslynx,項目名稱:dotproduct,代碼行數:31,代碼來源:BombBay.ts

示例3: advanceTime

  public advanceTime() {
    if (--this.countdown_ == 0) {
      this.invalidate();
      return;
    }

    // Slow down the animation.
    if (this.countdown_ % 2) {
      return;
    }

    this.position_ = this.position_.add(this.velocity_);
    this.velocity_ = this.velocity_.scale(0.75);
  }
開發者ID:krslynx,項目名稱:dotproduct,代碼行數:14,代碼來源:Exhaust.ts

示例4: fire

  public fire(angle : number, position : Vector, velocity : Vector, commitFireFn : (fireEnergy : number, fireDelay : number) => boolean) : any {
    let fireEnergy = this.getFireEnergy_();
    let fireDelay = this.getFireDelay_();
    let level = this.level_.getValue();

    if (level < 0 || !commitFireFn(fireEnergy, fireDelay)) {
      return null;
    }

    let factory = this.simulation_.modelObjectFactory;
    let lifetime = this.getLifetime_();
    let damage = this.getDamage_();
    let bounceCount = this.getBounceCount_();
    let bulletSpeed = this.getBulletSpeed_();
    let multifireAngle = (this.multifireState_ == ToggleState.ENABLED) ? this.gunSettings_['multifire']['angle'] : 0;

    let bullets = new Array<Bullet>();
    if (this.gunSettings_['doubleBarrel']) {
      let bulletVelocity = velocity.add(Vector.fromPolar(bulletSpeed, angle));
      let leftPosition = position.add(Vector.fromPolar(10, angle - Math.PI / 2));
      let rightPosition = position.add(Vector.fromPolar(10, angle + Math.PI / 2));

      bullets.push(factory.newBullet(this.owner_, level, leftPosition, bulletVelocity, lifetime, damage, bounceCount));
      bullets.push(factory.newBullet(this.owner_, level, rightPosition, bulletVelocity, lifetime, damage, bounceCount));
    } else {
      let bulletVelocity = velocity.add(Vector.fromPolar(bulletSpeed, angle));
      bullets.push(factory.newBullet(this.owner_, level, position, bulletVelocity, lifetime, damage, bounceCount));
    }

    if (this.multifireState_ == ToggleState.ENABLED) {
      let leftVelocity = velocity.add(Vector.fromPolar(bulletSpeed, angle - multifireAngle));
      let rightVelocity = velocity.add(Vector.fromPolar(bulletSpeed, angle + multifireAngle));
      bullets.push(factory.newBullet(this.owner_, level, position, leftVelocity, lifetime, damage, bounceCount));
      bullets.push(factory.newBullet(this.owner_, level, position, rightVelocity, lifetime, damage, bounceCount));
    }

    for (let i = 0; i < bullets.length; ++i) {
      this.owner_.addProjectile(bullets[i]);
    }

    new BulletGroup(bullets);

    return {
      'type': this.getType(),
      'angle': angle,
      'level': level,
      'bounceCount': bounceCount,
      'multifire': this.multifireState_ == ToggleState.ENABLED
    }
  }
開發者ID:krslynx,項目名稱:dotproduct,代碼行數:50,代碼來源:Gun.ts

示例5: onFired

  public onFired(timeDiff : number, position : Vector, velocity : Vector, weaponData : any) {
    assert(weaponData['type'] == this.getType(), 'Cannot fire gun with incorrect weapon type: ' + weaponData['type']);

    let factory = this.simulation_.modelObjectFactory;
    let level = weaponData['level'];
    let angle = weaponData['angle'];
    let bounceCount = weaponData['bounceCount'];
    let isMultifire = weaponData['multifire'];

    // Make sure the level is correct so the following getters use the right value for their calculations.
    this.level_.setValue(level);

    let lifetime = this.getLifetime_();
    let damage = this.getDamage_();
    let bulletSpeed = this.getBulletSpeed_();
    let multifireAngle = isMultifire ? this.gunSettings_['multifire']['angle'] : 0;

    let bullets = new Array<Bullet>();
    if (this.gunSettings_['doubleBarrel']) {
      let bulletVelocity = velocity.add(Vector.fromPolar(bulletSpeed, angle));
      let leftPosition = position.add(Vector.fromPolar(10, angle - Math.PI / 2));
      let rightPosition = position.add(Vector.fromPolar(10, angle + Math.PI / 2));

      bullets.push(factory.newBullet(this.owner_, level, leftPosition, bulletVelocity, lifetime, damage, bounceCount));
      bullets.push(factory.newBullet(this.owner_, level, rightPosition, bulletVelocity, lifetime, damage, bounceCount));
    } else {
      let bulletVelocity = velocity.add(Vector.fromPolar(bulletSpeed, angle));
      bullets.push(factory.newBullet(this.owner_, level, position, bulletVelocity, lifetime, damage, bounceCount));
    }

    if (isMultifire) {
      let leftVelocity = velocity.add(Vector.fromPolar(bulletSpeed, angle - multifireAngle));
      let rightVelocity = velocity.add(Vector.fromPolar(bulletSpeed, angle + multifireAngle));
      bullets.push(factory.newBullet(this.owner_, level, position, leftVelocity, lifetime, damage, bounceCount));
      bullets.push(factory.newBullet(this.owner_, level, position, rightVelocity, lifetime, damage, bounceCount));
    }

    for (let i = 0; i < bullets.length; ++i) {
      this.owner_.addProjectile(bullets[i]);
    }

    new BulletGroup(bullets);

    for (let i = 0; i < timeDiff; ++i) {
      for (let j = 0; j < bullets.length; ++j) {
        bullets[j].advanceTime();
      }
    }
  }
開發者ID:krslynx,項目名稱:dotproduct,代碼行數:49,代碼來源:Gun.ts

示例6: updatePosition_

  protected updatePosition_(bounceFactor? : number) {
    let map = this.simulation_.map;
    let prizeList = this.simulation_.prizeList;
    let flagList = this.simulation_.flagList;
    bounceFactor = bounceFactor || 1;

    let tileWidth = map.getTileWidth();
    let xSpeed = Math.abs(this.velocity_.x);
    for (let i = 0; i < xSpeed; i += tileWidth) {
      let xVel = this.velocity_.x;
      let dx = Math.min(xSpeed - i, tileWidth);
      this.position_ = this.position_.add(new Vector(xVel < 0 ? -dx : dx, 0));

      let collision = map.getCollision(this);
      if (collision) {
        switch (collision.object) {
          case ObjectType.NONE:
            this.position_ = new Vector(xVel >= 0 ? collision.left : collision.right, this.position_.y);
            this.velocity_ = new Vector(-xVel * bounceFactor, this.velocity_.y * bounceFactor);
            xSpeed *= bounceFactor;
            this.bounce_();
            break;
          case ObjectType.PRIZE:
            let prize = prizeList.getPrize(collision.xTile, collision.yTile);
            if (prize && this.shouldCollectPrize_(prize)) {
              this.onPrizeCollected(prize);
              prizeList.removePrize(prize);
            }
            break;
          case ObjectType.FLAG:
            let flag = flagList.getFlag(collision.xTile, collision.yTile);
            if (flag != null) {
              this.captureFlag_(flag);
            } else {
              assert(false, 'Flag at ' + collision.xTile + ', ' + collision.yTile + ' not found.');
            }
            break;
          default:
            break;
        }
      }
    }

    let tileHeight = map.getTileHeight();
    let ySpeed = Math.abs(this.velocity_.y);
    for (let i = 0; i < ySpeed; i += tileHeight) {
      let yVel = this.velocity_.y;
      let dy = Math.min(ySpeed - i, tileHeight);
      this.position_ = this.position_.add(new Vector(0, yVel < 0 ? -dy : dy));

      let collision = this.simulation_.map.getCollision(this);
      if (collision) {
        switch (collision.object) {
          case ObjectType.NONE:
            this.position_ = new Vector(this.position_.x, yVel >= 0 ? collision.top : collision.bottom);
            this.velocity_ = new Vector(this.velocity_.x * bounceFactor, -yVel * bounceFactor);
            ySpeed *= bounceFactor;
            this.bounce_();
            break;
          case ObjectType.PRIZE:
            let prize = prizeList.getPrize(collision.xTile, collision.yTile);
            if (prize && this.shouldCollectPrize_(prize)) {
              this.onPrizeCollected(prize);
              prizeList.removePrize(prize);
            }
            break;
          case ObjectType.FLAG:
            let flag = flagList.getFlag(collision.xTile, collision.yTile);
            if (flag != null) {
              this.captureFlag_(flag);
            } else {
              assert(false, 'Flag at ' + collision.xTile + ', ' + collision.yTile + ' not found.');
            }
            break;
          default:
            break;
        }
      }
    }
  }
開發者ID:krslynx,項目名稱:dotproduct,代碼行數:80,代碼來源:Entity.ts


注:本文中的math/Vector.add函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。