Skip to content

Commit

Permalink
feat: tap or click to move to dot/goal
Browse files Browse the repository at this point in the history
Hopefully this is reused everywhere - may lead to problems in the
two-player puzzles, but, we don't have any right now.
  • Loading branch information
russmatney committed Dec 2, 2024
1 parent be75147 commit c58a34d
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/puzzle/PuzzleScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ func undo_pressed():
var block_move
var last_move

func check_move_input(event=null):
var move_vec = Trolls.grid_move_vector(event)
func check_move_input(event=null, move_vec=null):
if move_vec == null:
move_vec = Trolls.grid_move_vector(event)

if move_vec != last_move:
# allow moving in a new direction
Expand All @@ -271,6 +272,24 @@ func restart_block_move_timer(t=0.2):
block_move = false
check_move_input()).set_delay(t)

func on_dot_pressed(_type, node):
# calc move_vec for tapped dot with first player
var first_player_coord = null
for p in state.players:
if p.coord:
first_player_coord = p.coord
break
if first_player_coord == null:
Log.warn("Cannot move to dot, no player coord found")
return

var move_vec = node.current_coord - first_player_coord
if move_vec.x == 0 or move_vec.y == 0:
check_move_input(null, move_vec.normalized())
else:
Log.info("Cannot move to dot", node, node.current_coord)


## state/grid ##############################################################

# sets up the state grid and some initial data based on the assigned puzzle_def
Expand Down Expand Up @@ -418,9 +437,6 @@ func node_for_object_name(obj_name):
Log.warn("no type for object?", obj_name)
return node

func on_dot_pressed(type, node):
Log.info(type, "dot pressed", node)

## custom nodes ##############################################################

func get_scene_for(obj_name):
Expand Down Expand Up @@ -468,7 +484,7 @@ func cells_in_direction(coord:Vector2, dir:Vector2) -> Array:
return []
var cells = []
var cursor = coord + dir
var last_cursor
var last_cursor = null
while coord_in_grid(cursor) and last_cursor != cursor:
cells.append(cell_at_coord(cursor))
last_cursor = cursor
Expand Down

0 comments on commit c58a34d

Please sign in to comment.