Game
Flatlander
4 years ago

Important Change to the coding of Flatlander


For levels 1-9 (9 to be released with 10), Flatlander was coded in a very specific way. The entire space you were playing with would get deleted when you switch to a different space, and the new space would get loaded in.

In Godot, this was by calling the function get_tree().change_scene()

However, everything would be deleted, player position, positions of boxes, all the stuff that changes after the scene has been initialised. This meant that I had a special scene, one with nothing in it that would exist above all other scenes containing a variable dump.

screenshot_2021-02-05_at_144715.png

Each time the player switches between levels, first all things would be saved if they existed. The player position (playposition), whether any doors have opened, what level, what scene etc. Then when the new scene is loaded in, all of that stuff is then initialised if it is relevant.

This was fine for the first few levels of the game, but then it began to get extremely complicated. And extremely repetitive. This also began to affect my productivity, I have been unwilling to code level 10 simply because it was getting too complicated, would need too many things, 4 separate times.

So I decided to switch to the other method I could code this game with. And it will need some explaining.


In Godot there is a thing called the Viewport. What the viewport does is it forms the basis for where the player is looking, and how the screen resizes. There can also be a camera, which can change where the player is looking.

Now obviously the solution is simple, simply change the player location and the camera location each time the player switches! Except for one simple little problem. The method used to keep the player character from moving beyond bounds.

Using the box as an example since it shares the same method:

screenshot_2021-02-05_at_145810.png

The viewport is first used to get the bounds area, which is the same as the screen size.

screenshot_2021-02-05_at_145821.png

Then every frame, the position is clamped. What this does is it compares the current position of the box, with a minimum value and a maximum value, the maximum value being (1024,600) for the screen_size. If the position is greater than the maximum value, or less than the minimum value, it is forced to go to the value. In easier terms, if the boxes position is (1000, 700) it will be forced to go to (1000, 600).

This is why previously I didn't simply change the players and cameras location, because it would clamp the player down to fit inside the viewport.

Until today that is. I managed to figure out the necessary code needed when switching in order to also change the minimum and maximum values depending on what part of the level the Player is at. And. It. Works.

Not only does it work, but it also makes my life a lot easier. Here is some comparison switching code.

screenshot_2021-02-05_at_150730.png
screenshot_2021-02-05_at_150739.png

Those are the two statements in two different files needed to switch between the two parts of level 1

screenshot_2021-02-05_at_151006.png

That is the equivalent code to achieve the same task in the test I've been doing. This might seem, equivalent. Not much of a difference. The real difference comes in the initialisation code.

screenshot_2021-02-05_at_151602.png

That is the initialiser needed for level 1. Just one of the scenes. It's almost exactly the same for the other, though differences arise in the future.

screenshot_2021-02-05_at_151610.png

Meanwhile this is all that is needed for the test scene.

The differenced will get even wider as more stuff is introduced. Not having to follow up on ever boxes position ever will certainly be very nice. The important question arises with the portals, as in my implementation it appeared that the box would only corporate and teleport properly if I reloaded the scene. If I don't manage to make a workaround, I may yet have use for the old variable dump, but a small one.

I will not yet change the first 9 levels to work with this new system, and I will also need to change the pause menu to work differently, but in the future I will go back and change the 9 levels, possibly closer to the game leaving early access.

Ohhhh boi that was a text dump, how about seeing a bit of Flatlander in action?

screen-recording-2021-02-05-at-1.gif

(Test level for new code)
(I also apologise if you didn't understand anything)



0 comments

Loading...

Next up

Art and Sprites

As of right now, the sprites are temporary. In the next update I will change the player sprite to the same one as is in the icon for the game.

New update! (video is a spoiler)

Flatlander 0.5: The levelling.

Our 2024 Advent Calendar has opened! Day 18: @Otis_Le_PoOtis is the Creator of Bondee’s Barnyard and posts updates about their dev journey and their work on the sequel!) Accept the quest and give them a follow to get Coins and a seasonal sticker!

I made a prototype partially to see if Godot could provide the tools I'd need to create my full game, and I can confidently say that it does!

Play the prototype here: https://gamejolt.com/games/draconian_union/713453

Our 2024 Advent Calendar has opened! Day 24: @NickPerson is a great Creator who makes Five Nights at Freddy's fan games! Accept the quest and give them a follow to get Coins and a seasonal sticker!

Waves of Emotion has been remade!

Our 2024 Advent Calendar has opened! Day 20: @MarcDWyz is a great Creator who develops fan games! Accept the quest and give them a follow to get Coins and a seasonal sticker!

Another house i made long time ago.

Today I was setting up the location of the first boss. His name is "Father" and he is the first of the Patagonians. His task is to guard the road to the House.🛡🗡 Bookmark pre-launch page🔖🔖🔖

https://www.kickstarter.com/projects/rdvindiegame/the-patagonian…