My SplitScreen project optimisation.
2 days to create a simple menu and optimize my scripts.
Create a simple menu
One of my objectives was to create a simple menu in which you could see the keybindings and start the first level. It is really simple, but works perfectly and is all I need at this state of development. As you can see on the right side there is a text to explain what the 2 players look like. To start the 1st level, both of the players need to be on the PLAY button and then need to press the SPACE button.
What does it looks like in the script?
The first function checks if there is a collision between the PLAY button and a body. In this function there is a condition, if the names of the body are Player1 and Player2 then it declares the variable bodyentered as true. Then under it, there is a _process function; this one is read every frame and check if the SPACE button is pressed, and if bodyentered is true, then it loads the scene in which I have all of my viewports and my main script.
Well, eveything else has been optimisation and the way I change the scene between the level 1 and level 2. It was way more complicated than I thought it would be, and I haven't found the solution yet but I'm close to it !
Take a look at what the script looks like:
In my _ready function I duplicate the World (level 1) in the 2nd viewport, and that's how I create the split screen. I set the camera to follow the players and that's all I need to play my first level, everything else are on other scripts inside my World scene. Now, what I did first was to declare in the _ready function that if level == 2 then it will delete my first level and load the 2nd one. But then I realized that it was only working because for my tests I started with my variable level = 2 at launch and since the _ready function is only read at launch it was working well. But since you logicaly have to start with the level 1, everything inside the level == 2 condition wouldn't be read. I needed to find a function which would be read many times to check if the players had finished the 1st level to then load the 2nd level. So, what's the problem ? Well, since the _process function is read at eache frame, when you finish the 1st level the variable level increase by 1 so when level ==2 at each frame the game load the 2nd world and crashes.
I'll find a solution soon, and then i'll start working on the level design again.
I created a new tile. Well, once again it's just a simple visual representation, once I finish the basics of my game I'll start to find a Game Art interested in working with me on this project.
It's just a simple tile that increases or lowers the speed of the player. I will use this one to help the player or slow him down in it's progression.
In this script I create a variable slow_speed that I can change the value of, without changing the script. Then a function checks if there is a collision with a body and if the body is Player1 or Player2 then the value of the this player's speed is changed to the slow_speed value that I declared. This is a really simple way to create this new gameplay mechanic.