Frogger project going forward

Of course I forgot to update when I meant to. The project is going forward. We now have correct background colors and the purple sidewalks are in place. Since we have a sprite sheet, we figured the easiest way to draw the sidewalks was to make a class for the sidewalk tile, and make several instances of that class. The frog can be moved using the arrow keys, but there is no animation. We decided to postpone implementation of all features that aren’t absolutely necessary.

We also have a moving car, but we need to develop the system that will handle the spawning of those cars. There was a discussion on this because problems arose: since every car is an instance of the same class, there is no simple way for the manager class to tell them apart, so the easiest way to handle the cars is to make each car move and get destroyed when it disappears outside the screen. It can send a message to the GameState class so it can keep track of how many number of cars are on the screen. The reason we were hesitant to use this method is that we used to draw objects in the same order they were created, and if the game destroys and creates new cars, the frog will no longer be drawn on top like we wanted to. So I changed our draw function to draw on different depths. Three different is all we need: bottom for the background tiles, top for the frog, and middle for all other objects. This was achieved with a public method in each entity that returns the depth of that particular object: one of three enum values. Then I changed the drawing loop to what can be seen below.

void GameState::Draw()
    m_systems.draw_manager->DrawBackground(m_systems.width, m_systems.height);

    // Only for clarity. Datatype enum 'EDepth' could cast automatically to 'unsigned int'.
    unsigned int bottom = static_cast<unsigned int>(DEPTH_BOTTOM);
    unsigned int middle = static_cast<unsigned int>(DEPTH_MIDDLE);
    unsigned int top = static_cast<unsigned int>(DEPTH_TOP);

    // Inner loop draws all entities of a certain depth. Outer loop repeats the process for each depth.
    for (unsigned int drawDepth = bottom; drawDepth <= top; drawDepth++)
        for (unsigned int i = 0; i < m_entities.size(); i++)
            if (static_cast<unsigned int>(m_entities[i]->GetDepth()) == drawDepth) // Cast would also here happen automatically.
                Sprite* sprite = m_entities[i]->GetSprite();
                if (sprite)
                    m_systems.draw_manager->Draw(sprite, m_entities[i]->GetX(), m_entities[i]->GetY());

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s