Project ITV

Project ITV

Monday, June 25, 2012

DOORS, and the bugs they caused



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):
FlxG.overlap(player2, brownDoors, openDoor);
This code checks if my player 2 is touching the brown doors and call openDoor() which does the necessary teleportation. Somewhere below that code, I added this:
FlxG.collide(levelbg, player2);
This above code performs collision for my player 2 with the platforms.

Somehow, player 2 is teleported to the correct position exactly after she opens the door. But as she is teleported in this moment, she somehow falls from the gravity and overlaps onto the platforms, and the second code triggers to push her away. Unfortunately instead of pushing her up, it pushed her down, which is kind of funny because it actually worsens the problem. All I had to do was switch the order of the codes to make sure I always check collision with platforms first. This way the player won't drop below the ground level immediately after teleporting. But it wasn't so obvious to me that this was the source of the problem. I was still thinking it was due to the player being sent to the wrong position and then falling from the gravity. But well, now I learnt that I should ALWAYS perform the checking of collision with platforms at the very top before checking for collisions on other objects. 

This is just one of the many things I learn while working on this project. Thanks to all those frustrating errors that probably show how much my programming needs to improve. I do think I'm getting better though =D

Dang. After typing out my mistake, I suddenly realise that upon solving this crucial bug, I can move on to designing new levels. This makes me excited and happy that suddenly I feel like staying up late to do the levels. But oh well, I think I shall take a break from hours of lifeless programming. I feel like I have no life because of this project. I hardly even play the games I used to play because seeing my own game progress is just extremely rewarding...

No comments:

Post a Comment