This is part 6 of the 2d/3d(game/engine) conversion used in my puzzle game: Ladder Box, which is available on Steam:

get it on steam

You can find all the textures, scripts in this GitHub repo:

Godot 3.2.x is used in this project, you can check the commits for what’s new in each part of this series.

Limit user input

In the last 5 part of this series, we’ve made all the states working, but we did not limit user input when the movable are moving, so this could happen(I’m hitting a,z,x,s randomly):

We should be processing user input when all movables are in idle state, let’s do this. Just add these code at the beginning of send_command function in

func send_command(command:Vector3) -> void:
	var _idle_count:int = 0
	for i in sorted:
		if i.get_node("state_machine") == "idle":
			_idle_count += 1
	if _idle_count == sorted.size():
		sorted = Grid.sort_by_direction(command)
		for i in sorted:

Beheavior Tweaking

Create a board as follows:



And you will see this:

We need to check if movable can fall in idle, add this to the end of the _command in

elif _msg.keys().has("reach_target"):
    if Grid.coordinate_within_rangev(movable.game_pos + Vector3.DOWN) &&\
    Grid.get_game_axisv(movable.game_pos + Vector3.DOWN) == null:

it falls, but then jump to the roof, because when from idle to fall, the msg does not contain direction, and in, move_direcion is default value, which is V3(0,0,0), and we need to check move_direction.

Jumpable check


This can be fixed in movable.is_direction_jumpable:

func is_direction_jumpable(direction:Vector3) -> bool:
    if direction in [Vector3.UP,Vector3.DOWN]:
        return false

    var _self_up_coordinate = game_pos + Vector3.UP
    if !Grid.coordinate_within_rangev(_self_up_coordinate):
        return false
    var _self_up_item = Grid.get_game_axisv(_self_up_coordinate)
    if _self_up_item != null:
        return false

    var _self_up_up_coordinate = game_pos + Vector3.UP*2
    if !Grid.coordinate_within_rangev(_self_up_up_coordinate):
        return false
    var _self_up_up_item = Grid.get_game_axisv(_self_up_up_coordinate)
    if _self_up_up_item != null:
        return false

    var _direction_up_axie = game_pos + direction + Vector3.UP
    if !Grid.coordinate_within_rangev(_direction_up_axie):
        return false

    var _direction_up_item = Grid.get_game_axisv(_direction_up_axie)
    if _direction_up_item != null:
        return false

    return true

And the result:

That’s it for this part. If you read all the way through, thank you and congratulation! It took me years to figure out how to make these things work as expected, and make a game out of it. And by the way, the code in the Github repo is wayyy better than the code in Ladder Box.

Hope you can make something fun out of it!

You can find all the textures, scripts in this GitHub repo:

comments powered by Disqus