Corona-cation (Day 23)

Refactoring... yay


    Today I felt the full impact of all my impromptu decisions during the jam. Every, "oh, this'll do for now" had to be cleaned up and thoughtfully reworked. The majority of it had to do with the communication between buttons and the objects they activate. I had originally planned for there to be one or maybe two plate/button per stair/door. I was very wrong.
    Today I was sent a screenshot of a prototype for level 6, and well, it speaks for itself...
Credit: Destin LeClear
    It became apparent I had to prepare for multiple buttons per object. I thought that it would do nicely if I had an array of buttons that could activate a door or something. Then I realized that to do that I would need to rework the activation/deactivation system, but then I would also need to be able to generalize activation objects, and I'm sure you can see where this is going. 
    I settled on the following system. One parent class for buttons (the things that do the activating) and one for doors, stairs, etc. (the things that get activated). This way I could see base activation stats that were universal to any object without having to copy/paste the same code every time. It also allowed me to change the activation/deactivation system from earlier. 
    The reason it had to change was that for example: if a door was closed and two buttons were able to open it, if both were on but one turned off the door would close. Basically the activated object would go with the most recent command. What I wanted though was for the open state to take priority. This was now easier with the new system as I could just get the activation state of every object and as long as one is on then it will not close. 
    This refactor did mean that I had to go through all the current levels replacing object references, but I'm glad I did it now and not later. 

    I also fixed a smaller bug that had to do with the pressure plates, similar to the one described above. The problem was that if you put a box on a plate (activating the plate) but then stepped on and off the plate yourself it would deactivate the plate; because again it would respond to the most recent command. This was solved in a similar way in having an array of objects that are on the plate so only when the array has no entries will it turn off. 

    Last fix had to do with the box-fly bug I thought I had solved yesterday. I found a way to break it again. It was slightly harder than the original box-fly but it was still possible. I fixed it (for now) by replacing the check if the player is looking down to a check seeing if the box is below the player, then it will force the player to drop the box.

Comments

Popular posts from this blog

Polishing the Foundation

Progress Update #13

A New Chapter