The above image is the key graphic for the game. It can be picked up by the player or the rat. Once picked up it will make a ding sound affect. It looks like this in game:
To get the function working I needed to give the key an array of reference variables. I set this up in the key create menu and called it keySelection. This might sound like it works, but for some reason it won’t let me use the variable when called where I wanted to use it. The fix to this is to give every single object using it a replica variable, which stores the value and uses it in their own code and not an out source.
Once the replica variables were made I added in the pick up key function:
For the player I could adjust the things straight away, but for the rat I need to past over the variables, which is done through this:
To explain the new variables shown above. The doorNum is an array of reference variables and the doorKeys is an array of booleans and the doorNum and doorKeys index will have to be able to be checked, otherwise an error will occur or nothing will happen.
Anyway continuing on from the previous code, I setup the code in the press E action, for the door function if the key has been picked up:
The code above is first checking through every door in the level to check if the player is colliding with it. If the player is colliding it checks if the key has picked up and if it has it will create a new variable called xy, grabbing a reference GoToDoor value, which contains an integer number, which is then used to save the new X and Y spawn points. The integer is used as an index number in the array doorNumb, so it can find the right door.
Once the door is found it will teleport the player to the new location after checking it is in front of the door. If this is done both together, it will teleport the player and then checks if the new door is unlocked and if it is, it will teleport the player back and that’s why the code is like that.
The door now looks like this:
You may have noticed the E above the head. That’s part of the minor improvements I was on about.
The E button uses the same object as the text box, but it uses a boolean to separate the two, but before I could separate them I need the code for the create menu:
The code above is used for opacity, the button and whether the player is colliding with any interactables.
Once done I setup the button to be shown:
The code above is setting up a fade in and fade out. Afterwards I setup the code, which will draw the button:
The extra draw_line_width is to add a border. I wrote similar code for the dialogue box, so now they look like this:
I also altered the menu slightly, so it looks better:
One thought on “Update: Locked Doors, Keys and minor improvements”