Devlog Day 10

Vim window management and Godot Area2D physics
vim
gamedev
godot
Author

Evan Lesmez

Published

August 11, 2024

Vim windows

Today I learned about splitting and managing windows in Vim.
I had some experience with this before but it was a good refresher.
My problem is that I sometimes get mixed up with tmux cmds and Vim ones.
In tmux, Ctrl-B is the beginning of commands.
In Vim, Ctrl-W is the beginning of window commands.

<Ctrl-w>s # split window intro rows
<Ctrl-w>v # split window vertically into columns
:sp {file} # split rows loading file into new window
:vsp {file} # split cols loading file into new window

<Ctrl-w>w or <Ctrl-w> # cycle between windows
# you can also ctrl-w into any hjkl move

:clo # close active window but use :q its easier or <Ctrl-w>c
:on[ly] or <Ctrl-w>o # close all other windows except current
<Ctrl-w>= # equalize the dimensions of all windows
<Ctrl-w>_ # max the current window height
<Ctrl-w>| # max the current window width

# Moving windows
<Ctrl-w>r or R # rotates the windows for viewing
<Ctrl-w>x # swap neighbor window for current
<Ctrl-w>[hjkl] # bring window to the top of that direction

The moving section came from this vimcast on Vim windows.

Godot Area2D Collision physics

So in previous lessons, I only had tinkered with the Sprite2D node which is for visuals and animations.
However, to get some real physics going between objects, like a collision, Area2D is the node for the job.
It needs a CollisionObject2D as a child node which in turn needs a shape to use.
With those nodes setup, the Area2D signal area_entered may be connected to respond to when another Area2D node collides with this one.
area_entered.connect can be used in the attached script instead of using the signal editor.
It is common to place it in the _ready() function which is what loads the node in the node tree kind of like __init__ or constructor for a class in OOP.
The convention for the callback to connect is to name it _on_area_entered implying it is a private method for this node and that it is connected to that signal name.
That pattern will be reused for other signals.

The callback for the case of loot being picked up by a player will likely cause the node to disappear, which means we will use queue_free.
queue_free means to queue up freeing the memory allocated to the node so it will deleted.

func _ready():
  area_entered.connect(_on_area_entered)
  
func _on_area_entered(area_that_entered: Area2D):
  queue_free()

That pattern all together is used in scenes like this:

Thank for reading.