Week 5 – With Intent (group 4)

This week I’ve been working on the Furniture Manager and the Door class, I’m going to work on the Door Manager tomorrow.

Bild

The furniture have 3 light modes (2 are shown), mode 1 is see-through, mode 2 is semi-transparent (bottom one) and mode 3 is solid (left one).

I did encounter some trouble making this manager, since sf::Shape doesn’t move the vertices when you set rotation for the image, the Hull Manager took the position of the original vertices, which resulted in the shadows staying when I rotated the shape. Add that to the fact that y = 0 for the Light Engine is the bottom of the ”view”, meaning that the y-axis is inverted.

I solved this problem by using cos and sin, since y is inverted I had to invert the rotation as well.

vector.x = (hull->m_vertices[i].x * cosf(-rotation * (M_PI/180)) – hull->m_vertices[i].y * sinf(-rotation * (M_PI / 180)));
vector.y = (hull->m_vertices[i].x * sinf(-rotation * (M_PI/180)) + hull->m_vertices[i].y * cosf(-rotation * (M_PI / 180)));

Bild

This is the code for the Door class I worked on this morning, haven’t tried if it actually works, but I’ll explain the reasoning behind the functions.

Update() change the transparency of the use radius, because a static coloured circle seemed boring, I was reluctant to add another bool to check if it should increase or decrease the transparency.

Draw() draws the use radius and the door shape, easier than to call for the individual objects, they are connected anyway.

Open() tries to open/close the door, if it’s locked, it calls the Unlock function to try and unlock it, if it’s the wrong key, it will return false and won’t open the door. We decided that the use radius should have the same color as the key it’s tied to, so the player will be able to see if he has the key before trying to open the door (failing to open a door would make sounds), or which key he needs to find if the player doesn’t have it.

IsOpen() returns a bool weather it’s open or closed, I thought ahead here, if the guards can open doors, it could get ugly if he runs into an open door and close it, so with this he won’t close a door, only open it.

Unlock() is called by Open() if m_locked = true, if the keys color match the doors, it’s unlocked and return true to Open(), which then proceed as normal. I decided to have it a private function so that it only can be called by Open(), so you can’t bypass trying to open the door (and less code in the program later).