コード例 #1
0
ファイル: QTELayer.cpp プロジェクト: NjAiYo/MonsterGame
void QTELayer::onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event)
{
    if(!enableFight) return;
    Touch *touch = touches.at(0);
    Vec2 delta = touch->getDelta();
    Vec2 lastPos = touch->getPreviousLocation();
    Vec2 pos = touch->getLocation();
    
    float dx = pos.x - startTouchPosition.x;
    float dy = pos.y - startTouchPosition.y;
    float dist = sqrtf(dx*dx+dy*dy);
    
    
    streak->setPosition(pos);
    //刀的判断
    dist = pos.distanceSquared(startTouchPosition);
    
    if (dist > 50) {
        //hit test monster
        bool hit = qteMonster->hittestPoint(pos);
        if (hit) {
            hitQteMonster();
        }
    }
}
コード例 #2
0
Vec2 AirCraftPath::get_heading(Vec2 current_position, Vec2 current_heading) {
  if (_way_points.empty()) return current_heading;

  // check if we are too close to the first path point.
  float dist_to_front = current_position.distanceSquared(_way_points.front());
  if (dist_to_front < 5.0f * 5.0f) {
    pop_first_point();
  }
  
  if (_way_points.empty()) return current_heading;
  
  Vec2 new_heading = _way_points.front() - current_position;
  new_heading.normalize();
  return new_heading;
}