void StaticBox::render(SpriteBatch & spriteBatch) { glm::vec4 destRect; destRect.x = _position.x - _dimension.x; destRect.y = _position.y - _dimension.y; destRect.z = _dimension.x * 2.0f; destRect.w = _dimension.y * 2.0f; spriteBatch.addToBatch(destRect, glm::vec4(0.0f, 0.0f, 1.0f, 1.0f), 2.0f, _texture.id, Color(_brightness, _brightness, _brightness, 255)); }
void Box::render(SpriteBatch& spriteBatch) { glm::vec4 destRect; destRect.x = _body->GetPosition().x - _dimension.x / 2.0f; destRect.y = _body->GetPosition().y - _dimension.y / 2.0f; destRect.z = _dimension.x; destRect.w = _dimension.y; spriteBatch.addToBatch(destRect, _uvRect, 2.0f, _texture.id, Color(_brightness, _brightness, _brightness, 255), _body->GetAngle()); }
void Block::render(SpriteBatch & spriteBatch) { glm::vec4 destRect; glm::vec2 position(_staticBox.getPosition().x, _staticBox.getPosition().y); destRect.x = position.x - _size / 2.0f; destRect.y = position.y - _size / 2.0f; destRect.z = _size; destRect.w = _size; spriteBatch.addToBatch(destRect, glm::vec4(0.0f, 0.0f, 1.0f, 1.0f), _depth, _texture.id, Color(_brightness, _brightness, _brightness, 255)); }
void Player::render(SpriteBatch & spriteBatch) { glm::vec4 destRect; b2Body* body = _collisionBox.getBody(); destRect.x = body->GetPosition().x - _drawDim.x / 2.0f; destRect.y = body->GetPosition().y - _drawDim.y / 2.0f; destRect.z = _drawDim.x; destRect.w = _drawDim.y; glm::vec2 velocity(body->GetLinearVelocity().x, body->GetLinearVelocity().y); //Calculate animation int tileIndex, numTiles; float animationSpeed = 0.2f; if (_onGround) { if (abs(velocity.x) > 1.0f) { //Running tileIndex = 1; numTiles = 6; animationSpeed = abs(velocity.x) * 0.025f; if (_moveState != PlayerMoveState::RUNNING) { _moveState = PlayerMoveState::RUNNING; _animTime = 0.0f; } } else { //Standing numTiles = 1; tileIndex = 0; _moveState = PlayerMoveState::STANDING; } } else { //Falling or Jumping numTiles = 1; tileIndex = 7; _moveState = PlayerMoveState::IN_AIR; } //Increment animation speed; _animTime += animationSpeed; //Stop animation loop if (_animTime > numTiles) { _attacking = false; } //Apply animation tileIndex = tileIndex + (int)_animTime % numTiles; glm::vec4 uvRect = _texture.getUVs(tileIndex); //Flip UVs if player is going left if (_direction == -1) { uvRect.x += 1.0f / _texture.dims.x; uvRect.z *= -1; } spriteBatch.addToBatch(destRect, uvRect, 0.0f, _texture.texture.id, Color(_brightness, _brightness, _brightness, 255), body->GetAngle()); }