I've finally gotten around to working on Visitor a bit more. I must admit that I've been procrastinating - mostly because gamedev is intimidating and I never feel completely in the know on what's happening (for now!). I don't expect to be done this little game by the end of March, as I had planned as part of my "Quarterly Projects" - but I'm still glad I took it on.
I left off on the previous post hypothesizing how I might create the "absorb light" mechanism. Most of the pseudo code I wrote ended up being pretty much what I needed to do. Let's walk through the code (it's pretty rough.)
extends Area2D var in_contact_with_player = false var rate_of_absorption = Vector2(0.005, 0.005) var has_been_absorbed = false var original_size var rng = RandomNumberGenerator.new() # NOTE: this might not be ideal if every node gets the player from the tree? # guess it might not matter much if there will never be that many light nodes on the screen... onready var player = get_node("/root/Game/Player")
Above we setup the "class properties" so to speak. I can't remember if gdscript is technically thought of this way, but whatever.
Next up, we have the
func get_absorbed(): if has_been_absorbed: queue_free() if in_contact_with_player and not has_been_absorbed: scale -= self.rate_of_absorption player._handle_absorb_light(Vector2(rate_of_absorption / 2)) # emit_signal("transfer_to_player", self.rate_of_absorption) if scale <= Vector2(0, 0): has_been_absorbed = true func _process(_delta): get_absorbed() # I guess I call this on every frame?
Originally, I was going to dispatch a signal whenever the player entered one of these areas to tell the player to get larger while the scale shrank for the piece of light. You can see that I left a comment in in the above code sample where I tried that. I think I either got confused by signals or decided it was unnecessary and instead I pull the player node directly into this node and call it's
So, I've maybe got some code smells, but I'm not going to dwell on it - my goal is to make a functioning game, not write the most idiomatic gdscript code (but believe me, the desire is real). I also am not sure if I should be calling the get_absorbed function on every frame. Oh well.
It seems one of the ways to get things done is to let go of the desire to do all things right.
Connecting the compass
After finishing up the light absorption mechanism (for now) I started on prototyping a compass. This was particularly challenging because I'm not sold entirely on the mechanism of having this compass taking up a chunk of the bottom of the screen, nor do I believe I'll have it working nicely on the first try. All said, I ended up doing the following:
- Prototyping a basic (and mysterious!) compass in Affinity Designer
- Create a new GUI node/scene combo with a
texturerectnode holding the image of the compass.
- Finding resources on detecting input touch in godot and converting it to a directional value
- Converting the degrees to radians and applying that to player movement.
All in all it seems pretty janky and difficult to move the player - at least to change directions smoothly. At the moment I'm downloading the sdk's to enable exporting android builds - if I'm lucky I can skip a bunch of export-plumbing and just send an apk over to my phone quickly to start testing physically (simulating finger touches with a mouse is not super intuitive). Check in next time!