This monday I was told at our weekly meeting that I was to work on a different project than the platform game I have been working on. This came as a surprise to me and I wasn't sure if I was happy about it. It's like when you work on your personal project, abandon it for a few weeks and then come back to it, only to find that you forgot the details/bugs of your project. Comments in the code usually help you to get back in to the project faster, which is why I always try to comment my code, even code that seems rather trivial at the time. But at the same time, a change is nice and when I get back to the platform game there will hopefully be more art available as our artists are continuing work on it.
As Joep mentioned, I'm now working on 2 minigames in the time management game and they're coming along nicely. In the process of making these minigames we found we needed a graphical user interface slider. As sliders are common in user interfaces I made a script which attempts to deal with sliders in a generic way so it can be used across multiple projects. Usually sliders are used either horizontally or vertically, but in our game we have a slider that's placed diagonally. So to keep it generic it would be best to have a slider that can be placed in any orientation. The problem then is when we move the slider to find a correct slider position based on our mouse position. In a horizontal and vertical slider this would just be to take the x- and y-coordinate of the mouse respectively, but in an arbitrary orientation both mouse coordinates need to be taken into account. We do this by projecting the mouse cursor on to the slider (see image): projecting a point on a line in such a way that the distance is minimal (the angle between the slider line and the line between the projected point and the mouse cursor point is 90 degrees).
In the images the slider defines the line segment which is shown as a solid red line. The line segment is part of a line, shown as a dotted red line. The line is parameterized with t in such a way that the start of the line segment is associated with t=0 and the end of the line segment is associated with t=1. When projecting we obtain a t value which corresponds to the projected point P. When 0 <= t <= 1 then the projected point is on the line segment. When t < 0 or t > 1 then the projected point is outside the line segment and we set t to 0 and 1 respectively to keep the slider button on the slider. In this way you can define a slider in any rotation and it will still work correctly :)