Beispiel #1
0
void Character::draw(sf::RenderTarget& target, int x, int y) const
{
  bool shouldDraw = true;

  if (m_flash.isFlashing())
  {
    shouldDraw = m_flash.odd();
  }

  if (shouldDraw)
  {
    sf::Sprite sprite;
    sprite.setTexture(*m_faceTexture);
    sprite.setTextureRect(m_textureRect);
    sprite.setColor(m_color);
    sprite.setScale(m_textureScale, m_textureScale);
    sprite.setPosition(x, y);
    
    if (m_flash.isFading())
    {
      sprite.setColor(sf::Color(255, 255, 255, m_flash.fadeCounter()));
    }
    
    if (m_flash.isShaking())
    {
      int xPow = random_range(-m_flash.shakePower(), m_flash.shakePower());
      int yPow = random_range(-m_flash.shakePower(), m_flash.shakePower());

      sprite.setPosition(x + xPow, y + yPow);
    }

    target.draw(sprite);
  }

  if (m_flash.activeBattleAnimation())
  {
    int posX = x + spriteWidth() / 2;
    int posY = y + spriteHeight() / 2;

    m_flash.activeBattleAnimation()->setOrigin(posX, posY);
    m_flash.activeBattleAnimation()->render(target);
  }

  auto damageText = m_flash.damageText();
  for (auto it = damageText.begin(); it != damageText.end(); ++it)
  {
    int xPos = x + spriteWidth() / 2 - (8 * it->text.size()) / 2;
    int yPos = y - it->life;

    while (xPos < 4)
      xPos++;

    while ((xPos + it->text.size() * 8) > (config::GAME_RES_X - 4))
      xPos--;

    draw_text_bmp_ex(target, xPos+1, yPos+1, sf::Color::Black, "%s", it->text.c_str());
    draw_text_bmp_ex(target, xPos, yPos, it->color, "%s", it->text.c_str());
  }
}
Beispiel #2
0
	void GameObject::draw(WindowModule* wm, float now) {
		sf::RenderWindow* w = wm->getWindow();
		if(body) {
			
			/*int width = w->GetWidth();
			if (screenWidth != width) {
				screenWidth = width;
				sprite = getDrawable();
			}*/

			if(sprite) {

				float deltaTime = (now - lastTime) / timeStep;

				b2Vec2 nextPos = body->GetPosition();
				b2Vec2 deltaPos = nextPos - lastPos;
				deltaPos *= deltaTime;
				b2Vec2 renderPos = lastPos + deltaPos;


				float rot = body->GetAngle();

				float scaleW = wm->meterToPixel(shapeWidth())
					/ (float) spriteWidth();
				float scaleH = wm->meterToPixel(shapeHeight())
					/ (float) spriteHeight();

				sprite->SetCenter(spriteWidth()/2.0f, spriteHeight()/2.0f);
				sprite->SetScale(scaleW, scaleH);
				sprite->SetRotation( -rot * (180/3.14));
				sprite->SetPosition(wm->meterToPixel(renderPos.x),
					wm->meterToPixel(renderPos.y));
				w->Draw(*sprite);
			}
		}
	}