I don’t believe this. Seriously, the types of errors I’m encountering are absolutely fabulous.
Today, I went to start creating level 36, a VERY simple level that aims to introduce the player to yet another new feature I thought of just three days ago – DOORS!
When I first thought of doors, I was thinking it was actually going to be easy to implement it. Just add some sprites, and if the player touches the sprites and presses DOWN, then move their position somewhere! Haha, if only things were that easy.
I faced two frustrating bugs that I spent three hours trying to find the cause of (well, not really full three hours, because I was so frustrated that I ended up watching the TV and walking around the house really angrily).
Refer to the screenshot below.
The first bug is that when player 2 touches the bottom brown door, she gets stuck right below the door! There is nothing wrong with the spawning position, because when my player 1 uses the door, he goes up CORRECTLY! How bizzare! I spent lots of time and gave up, I decided to make it such that the player can ONLY use the door when his feet are on the ground. Strangely, after adding this requirement, the girl player cannot even go through the door because according to the game log, her feet aren’t on the ground!
I did some intensive logging, got really tired, but I finally found that I had positioned my codes wrongly, resulting in the unusual bugs! That’s it! And I could not believe this. The game ran well after that! (If you want to read detail on why the position matters, you can read my chunk of text at the end of this post later)
Both players can now utilize the brown door correctly. I am seriously very tired and exhausted now, because I’ve only had three hours of sleep before going to school today.
What I thought was a simple door concept turned out to be extremely problematic. There is another problem where if player 1 is standing on a door, and player 2 ENTERS the door and pops up on the other side, both players will overlap and one of them will get pushed down until he/she goes off the screen, causing the game to restart. It is rather irritating and I hope to resolve it soon.
For now, I’m just glad that I have finally implemented doors. It is a significant step because if doors are possible, it means I can go on and utilize them in my subsequent levels.
Well, that’s it for today I guess. I need to sleep soon because I am really tired.
My mistake
This part is just me explaining my silly mistake. It’s not very important to you I guess, but if you want to read it, it’s fine.
Apparently, there are two important lines of code regarding collision detection in the above scenario (ignoring all other factors):