Artifact Post 5 – Stars and… well, that’s all there is…

This week has been mostly about getting stuff done for the Beta. That means lots of artifacts done and lots of artifacts to do, so let’s get going with one of those.

This time around, the focus is on the collectibles in the game – stars (because it is always stars) and how they are handled. The stars will pretty much always appear whenever an enemy is defeated and is basically the player’s score in the game.
The Update method looks like this:
bool Star::Update(sf::Time p_xDtime){  
    // Check Overlap
    if (m_xpPlayer->Overlap(getPosition(), 450 * m_fRadius)){
        // m_bCollect is now true, meaning that the star is now being collected
        m_bCollect = true;
    }
  
    // Checks if the star overlaps the player, this one is smaller than the first one and
    // will therefore only be true when the player is right over the star

    if (m_xpPlayer->Overlap(getPosition(), m_fRadius)){
        // The method that runs thsi object will delete it when it returns true
        // …eventually a method that adds a few points to the socre will bhe added here.

        return true;
    }

    if (m_bCollect){
        // When m_bCollcect is true it will move towards the player
        setRotation(atan2f( (m_xpPlayer->getPosition().y – getPosition().y), (m_xpPlayer->getPosition().x – getPosition().x) ) * 180.f / 3.141592f – 90.f);
        m_xVel = m_fSpd * sf::Vector2f(cosf(getRotation() * 3.141592 / 180 + 90.f), sinf(getRotation() * 3.141592 / 180 + 90.f));
    }
    else if (!m_bCollect){
        // When m_bCollect is false the star will move in a random direction
        m_xVel = m_fDeacc * m_fSpd * sf::Vector2f(cosf(getRotation() * 3.141592 / 180 + 90.f), sinf(getRotation() * 3.141592 / 180 + 90.f));
    }

    // Sets the position and Rotation of the Sprite
    m_xpSprite->setPosition(getPosition());
    m_xpSprite->setRotation(getRotation());

    // The Star moves in accordance to it’s Velocity (m_xVel)
    move(m_xVel);

    // slowsly Lowers the speed of the star to zero, the base value of m_fDeacc is randomized between .25f and 1.f
    if (m_fDeacc > 0.f){
        m_fDeacc-= .025f;
    }
    else {
        m_fDeacc = 0.f;
    }

    // By returning false the star will not be deleted in this iteration
    return false;
}

To put things short, the star object has two kinds of “modes” both regulated by a single bool variable, I guess I could have gone the extra mile and made a State Switch for the sake of it, but in this case I don’t think it would really matter all that much. When the star is created it is given a random direction to fly in and also gradually slow down until they’re just lying on the ground. The distance they fly is also random and the effect makes for a very entertaining effect. We’re probably going to make it so that the stars can only be collected when they’re finished flying, the reason for this is because as of now, if you are standing too close to an enemy you will collect all of the stars at once, but it will look like you’re only collecting one.
Anyway, if the player gets close to the star it will fly straight into him and promptly be deleted. Right now the distance is 450 * m_fRadius (m_fRadius being the radius of the star,  about 1.0 or 2.0) I am not certain if 450 will be the final number in this case though. The star’s method for finding it’s way to the player is actually the same that the enemies use for the same purpose (except, they’re not trying to kill him). By using the atan2f method on delta y and delta x (that is, the difference between the player and the star’s current position) and then use cosinus and sinus to calculate the velocity that the star should move in. Of course, if the star isn’t in the collect phase it’s rotation will be randomized and it will act as described in the above paragraph (simply move in a random direction until it stops on its own).

As mentioned above, the stars appear whenever the player kills an enemy. As of right now the enemies all drop 16 stars each but that will probably be modified in the future, we’ve been talking about some sort of “combo” or “chain” system to let the player increase his score, but we’re gonna do one thing at a time.

Wether the star is in chase mode or not, once it touches the player it will be deleted and be added to the counter (said counter is not actually in the code yet…) this is going to be the player’s end-game high-score. I do not know if it’s going to have any other effect as of yet.
 TODO:
– Add Score
– Make the stars collectable only after they’ve stopped moving.
– Maybe add so that the stars are spinning in place – shouldn’t be difficult…
Anyway, I have nothing more to add, good night!

EDIT: Finally managed to post this, I do not know what is up with Blogger but apparently using pictures in my post is out of the question if I want to post. I apologize for the inconvinience for the guy/girl who has to comment on this.