コード例 #1
0
void WTextSourceViewerLine::drawFoldingLineVisible(QPainter &p,const QPointF &p1,const QPointF &p2)
{
  QPolygonF area;
  float demi_char_space=char_space/2.0f;
  QPointF pos(0.0f,(p1.y()+p2.y())/2.0f-demi_char_space);
  QRectF  text_pos(pos,QSizeF(char_space,char_space));

  QPointF p3(demi_char_space,p2.y());
  QRectF endPoint2(p2.x()-2,p2.y()-2,4,4);
  QBrush b=p.brush();
  p.setBrush(Qt::black);
  if (p1!=p2)
  {
    QPointF p0(demi_char_space,p1.y());
    QPointF p1b(demi_char_space,pos.y());
    QPointF p2b(demi_char_space,pos.y()+char_space);
    QRectF endPoint1(p1.x()-2,p1.y()-2,4,4);
    area << p0 << p1 ;
    area << p0 << p1b ;
    area << p2b << p3 ;
    area << p3 << p2 ;
    p.drawEllipse(endPoint1);
  }
  else
  {
    QPointF p1c(char_space,p2.y());
    area << p1c << p2 ;
  }

  p.drawEllipse(endPoint2);
  p.setBrush(b);
  p.drawLines(area);
  float pos_size=char_space;
  QRectF rectangle(pos.x(),pos.y(),pos_size,pos_size);
  p.drawRoundRect(rectangle);
  float _x1=pos.x()+3.0f;
  float _y=pos.y()+pos_size/2.0f;
  float _x2=pos.x()+pos_size-3.0f;
  p.drawLine(QPointF(_x1,_y),QPointF(_x2,_y));
}
コード例 #2
0
void MonsterTortoise::checkPosSchedule()
{
	Vec2 newPos = getPosition();
	b2Body * body = getBody();
	b2Vec2 oldVelocity = body->GetLinearVelocity();
	if (newPos.x - m_lastPos.x >= -0.01f && newPos.x - m_lastPos.x <= 0.01f)
	{
		//转向处理
		if (!m_bIsDefend || (m_bIsDefend && m_bIsRoll))
		{
			changeVelocityDirection();
		}
	}
	else
	{
		if (m_bLeft)
		{
			if (!m_bIsDefend)
				body->SetLinearVelocity(b2Vec2(-MMSpeed_Tortoise, oldVelocity.y));
			//else if (oldVelocity.x < -0.00001f)
			//	getBody()->SetLinearVelocity(b2Vec2(-MMSpeed_TortoiseDefense, oldVelocity.y));
		}
		else
		{
			if (!m_bIsDefend)
				body->SetLinearVelocity(b2Vec2(MMSpeed_Tortoise, oldVelocity.y));
			//else if (oldVelocity.x > 0.00001f)
			//	getBody()->SetLinearVelocity(b2Vec2(MMSpeed_TortoiseDefense, oldVelocity.y));
		}
	}

	////防守非滚动状态x轴速度更改
	//if (m_bIsDefend && !m_bIsRoll && (oldVelocity.x < -0.00001f || oldVelocity.x > 0.00001f))
	//{
	//	body->SetAwake(false);
	//	body->SetLinearVelocity(b2Vec2(0.0f, oldVelocity.y));
	//}
	m_lastPos.set(newPos);

	//空中校验,是否踩着物体,光线投射
	if (!m_bIsDefend)
	{
		m_bStepObject = false;
		float fPtm = getPTMRatio();
		b2Vec2 beginPoint1(newPos.x / fPtm, newPos.y / fPtm);	//投射起点
		b2Vec2 endPoint1(beginPoint1.x, beginPoint1.y - getContentSize().height / fPtm);	//投射终点
		b2World * pWorld = GameScene::getInstance()->getWorld();
		pWorld->RayCast(this, beginPoint1, endPoint1);
		if (!m_bStepObject)
		{
			//由于可能透过细小缝隙,故而执行二次投射
			b2Vec2 beginPoint2(beginPoint1.x + (m_bLeft ? -1 : 1) * getContentSize().width / 4 / fPtm, beginPoint1.y);
			b2Vec2 endPoint2(beginPoint2.x, endPoint1.y);
			pWorld->RayCast(this, beginPoint2, endPoint2);
		}

		if (!m_bStepObject)
		{
			//再走将会掉下,掉头
			changeVelocityDirection();
		}
	}
}