Up to this point, the space monster has two behaviours: wandering and detecting a door through which to escape. As simple as it sounds, I have spent several days testing how to implement this in C, which necessarily required me to learn how to access different types of information within different scripts and objects, which necessarily led me to deepen my knowledge of OOD.
Never surrender!
OOP and more game mechanics
Developing a mechanism to detect which doors are available in each room (remember that they are randomly produced and might range from 1 to 4) proved to be far more difficult than I had anticipated.
The idea is that the player has no control over which doors open individually, but that by pressing a button (yellow on the screen), all of the available accesses in that room will be activated in unison, and that the player will have no way of knowing which of these escape routes the creature will take.
As mentioned above the red creature has two behaviours: wandering and detecting a door to access a new room. The first behaviour was quite simple to implement, making it go from one end of the room to the other did not present major difficulties; however, starting it from this routine so that it goes to one of the doors enabled by the player required many different approaches until a functional solution was found.
To do this, we first have to keep track of how many doors there are in the room in question. If there is only one, simply direct the monster to that opening, but when we have two or three doors the combinations are multiple and it is important to identify them. Later I could think of two criteria to make the character go towards one of them: by proximity or very random. I opted for the latter so that the invader’s behavior is not too predictable. When all four hatches are available, you simply choose one of them and make the character go towards it.
Next, it remains to create a build that I can export to WebGL and continue advancing in the following points:
- Move the camera to reveal new rooms.
- Make the monster move to the next room (where the initial conditions must be reset).
- Set the score counters (the less civilians or soldiers die victims of the creature’s passage the higher the score obtained by the player).
- Randomly generate the decompression airlocks -only available in some parts of the map- so that the player has the possibility of sending the threat that is spreading panic around the base into space.
- Develop the mechanics so that when this happens all the characters in that room are ejected along with the invader.
- Finish the game menus and user interface.
- Make the characters go around or avoid obstacles (furniture, various objects in the rooms).
The browser version worked fine (after tweak a little bit the canvas anchors for the different size configurations) except for the 2D lightning. Yes I tried to add some light effects to illuminate the rooms but only performs well on PC and Mac versions. For some reasons that I’m investigating the WebGL port with 2D lights is a complete disaster. So I put that on stand by to continue with the sound effects.
Adding sound
The most suited for me was to construct a Sound Manager Component that takes care of retrieving audio files (OGG format) from a resources folder and playing them in any other script in the game, in this case when it detects that the button to open the doors has been pushed. Surprisingly, I had some issues playing the audio files on the web version, which I believe was due to the files’ encoding.
I started to develop this with Unity version 2020.3.31f1 and worked flawlessly, then I had the great idea to update the engine to 2020.3.21f1 and -guess what?- some noticiable lag on the sound reproduction appeared, very frustrating. Even more, the WebGL version has some horrible sound glitches too. Still trying to figure out what is going on.
References
Naciejeswki, P. 2020.’Procedural 2D Dungeon in Unity – Using Random Walk Algorithm’. Sunny Valley Studio. [online] available at: <https://www.youtube.com/watch?v=LnbZLnCXSyI>. Accessed [Accessed 6 April 2022].
Short, T. Adams, T. 2017. ’Procedural Generation in Game Design’. CRC Press Taylor & Francis Group, pp 7-10.
Oriz, E, Geig. M. 2019. ’2D Pixel Perfect: How to set up your Unity project for retro 8-bit games’.Unity Blog. [online] available at: <‘https://blog.unity.com/technology/2d-pixel- perfect-how-to-set-up-your-unity-project-for-retro-8-bits-games>. [Accessed 11 March 2022].