From ab188c54e05a88e9886a12a5f34dbc59f4114f90 Mon Sep 17 00:00:00 2001 From: Ategon Date: Mon, 9 Sep 2024 14:19:38 -0400 Subject: [PATCH] Make tilemap use mouse handler --- Main.tscn | 2 ++ tile_map.gd | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Main.tscn b/Main.tscn index 4e5397e..ff92e98 100644 --- a/Main.tscn +++ b/Main.tscn @@ -27,6 +27,7 @@ sources/0 = SubResource("TileSetAtlasSource_dxrqb") sources/1 = SubResource("TileSetAtlasSource_j7eew") [sub_resource type="CircleShape2D" id="CircleShape2D_s8q4l"] +radius = 134.7 [node name="Main" type="Node2D"] @@ -45,6 +46,7 @@ layer_1/name = "Layer1" script = ExtResource("5_v47eg") [node name="MouseHandler" parent="TileMap" instance=ExtResource("5_6lpdu")] +position = Vector2(318, 178) [node name="CollisionShape2D" type="CollisionShape2D" parent="TileMap/MouseHandler"] shape = SubResource("CircleShape2D_s8q4l") diff --git a/tile_map.gd b/tile_map.gd index 480291a..7926b84 100644 --- a/tile_map.gd +++ b/tile_map.gd @@ -14,12 +14,8 @@ func _ready(): set_cell(0, Vector2(x, y), 0, Vector2i(0,0), 0) func _process(delta): - if (Input.is_action_just_pressed("rclick")): - Building_Mode = !Building_Mode - for x in GridSize: - for y in GridSize: - if !Dic[str(Vector2(x,y))].get("Placed"): - erase_cell(1, Vector2(x,y)) + #if (Input.is_action_just_pressed("rclick")): + if Building_Mode: var tile = local_to_map(get_global_mouse_position()) @@ -31,14 +27,17 @@ func _process(delta): if Dic.has(str(tile)): set_cell(1, tile, 1, Vector2i(0,0), 0) - - if Input.is_action_just_pressed("lclick"): - Dic[str(tile)]["Placed"] = true func _on_mouse_handler_clicked(): - pass # Replace with function body. + if Building_Mode: + var tile = local_to_map(get_global_mouse_position()) + Dic[str(tile)]["Placed"] = true func _on_mouse_handler_rclicked(): - pass # Replace with function body. + Building_Mode = !Building_Mode + for x in GridSize: + for y in GridSize: + if !Dic[str(Vector2(x,y))].get("Placed"): + erase_cell(1, Vector2(x,y))