Next on the list: raycasting! Much to my suprise, it wasn’t that difficult. So I won’t be ranting today. I’m so glad it all worked out nicely, I expected this to be a very difficult task. Not so difficult that I couldn’t finish it, but I was kind of worried about the time it would take me to finish it. To be honest, testing the system I coded for raycasting was harder than actually coding the system itself, haha. At some point I had to hop back and forth between on-screen- and world-coordinates and messed up a few lines. That, combined with the fact that sometimes my brain switches around variable names (for example l1x turns into x1) gave some unexpected results. After an hour of explaining how the code works to my rubber duck and making a special function for converting on-screen- and world-coordinates the prototype worked.
“A picture says more than a thousand words.” They say. Well, to lift the word count of this blog a bit, here are some “pictures”.
It’s nice that implementing raycasting was really easy, because I can now finally move on to the interesting part of my project: the AI! The AI needs raycasting for their field of view. Later on I will (hopefully) also be using the raycasting system to display the field of view of the guards, and also maybe the field of view of the player. But I’ll only be able to implement that if I have enough time. So we’ll see.