Treasure Diver: Dev Log #0

After building the project tutorial mind the creeps from the GoDot tutorial my goal for this game is to slightly modify the game by doing the following:

  • Add an item pickup script.
  • Change the score system from time based to picked up items.
  • Add a global high score system.
  • Use a larger screen size.

There’s a couple of new things that I will need to learn to complete this project while at the same time reinforcing what was learned in the tutorial. The new things I will need to learn to make these modifications are:

  • How to create an Item Pick up script
  • How to send post and get requests to an external server

The art assets used for the game are from Ansimuz on itch.io

Player Rotation

This one drove me a little insane, there is probably a cleaner solution to the issue than what I ended up doing but hey, it works. The issue was trying to rotate the player character to face in the correct direction to match the direction they are swimming. My first attempt resulted in a rather comical spinning movement.

Not really what I was after. I then spent the next 2 hours trying to set the position, and reset it back to 0 with the help of various youtube tutorials, the GoDot documentation and chat gpt to try and work out why what I was doing in the script was not having any effect on how things were running. The answer, sometimes there’s more than one way to do something and for one thing one way works and for others it does not. So to set the player to face up I did the following:

if abs($AnimatedSprite2D.rotation)<0.01 or abs($AnimatedSprite2D.rotation-3.14)<0.01:
			$AnimatedSprite2D.rotate(-1.57)

Turns out setting rotate in this way for 0 does not work and instead you need to use

$AnimatedSprite2D.rotation=0

Then we had to solve the flipping of the character, that was straight forward enough with a couple of checks to check if the character is flipped (since flipping the character means that down would now be up and vice versa) and then just flipping them back before applying the rotate.

More Challenges

When you step slightly off the road of the tutorial is when the real learning takes place, it’s when you quickly come to realize that while you may have understood everything in the narrow context of the tutorial, you don’t have enough of an understanding to be able to complete even simple changes. I decided I wanted to add some variety into the game in the form of different fish that you need to avoid with each fish being a different size and moving at a different speed, simply replicating how multiple enemies were handled in the tutorial wouldn’t work as they would each need their own collision collider set up which meant they all had to be on their own scene, and this is where the problems started. My original thinking was it would be straight forward and functionally the same just instead of randomly selecting from a list of animations I would just need to randomly select the script that plays that enemy animation. Turns out, while it should have been a simple enough process the information I found on how to do it was outdated and in version 4 of GoDot they renamed some of the built in functions, this lead to a lot of not understanding why things arnt working when the code looks right.

So Now we have our enemies spawning, they bump into each other and knock each other around the screen, this isn’t really the behavior I want and the path system shown in the original GoDot tutorial is not really suitable either since that can have enemies spawning from the top and the bottom of the screen, the enemies knocking each other around was because I forgot to set the collision mask to off. My next goal from this point is to have them spawn at random heights randomly on each side of the screen and not from the bottom or the top.


Now with the enemy movement sorted out, the fish now move on a random trajectory from the left to the right side of the screen and no longer spawn from the top or the bottom. The solution for this was to re-write how the enimes are spawned in by getting the width of the current window and then only spawning at the max width or at 0 which gives us both sides of the screen. The code for that looks like this:

var viewport_size = get_viewport().get_visible_rect().size
var spawn_on_left=randi()%2==0
var y_position = randf_range(0,viewport_size.y)
	if spawn_on_left:
		spawn.position = Vector2(0, y_position)
	else:
		spawn.position = Vector2(viewport_size.x, y_position)
var direction = 0 if spawn_on_left else PI

The next goal now is to add in treasure chests that will either fall from the top of the screen or just appear in the screen for the player to collect. Not sure which way of doing this I like more yet so I will code them both up and see which one feels the best while playing. That will be it for today though and the item pick ups will be in the next dev log where I will do the item pick ups and score system.

Leave a Reply