Blog

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: https://github.com/fengjiongmax/3D_iso_in_2D

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 main.gd:

func send_command(command:Vector3) -> void:
	var _idle_count:int = 0
	for i in sorted:
		if i.get_node("state_machine").state.name == "idle":
			_idle_count += 1
	if _idle_count == sorted.size():
		sorted = Grid.sort_by_direction(command)
		for i in sorted:
			i.receive_command({"direction":command})
		set_physics_process(true)

Beheavior Tweaking

Create a board as follows:

new_movable(0,0,0)
new_movable(0,1,0)

new_unmovable(1,1,0)
new_unmovable(1,2,0)
new_unmovable(1,3,0)

And you will see this:

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

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:
        _state_machine.switch_state("fall",{})
        pass
    pass

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

Jumpable check

new_movable(0,0,0)
new_movable(0,2,0)
 
new_unmovable(0,1,0)
new_unmovable(0,1,1)
 
new_unmovable(0,0,3)

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: https://github.com/fengjiongmax/3D_iso_in_2D

comments powered by Disqus