diff --git a/BuildingLevel.gd b/BuildingLevel.gd index e38c421..1ecf20f 100644 --- a/BuildingLevel.gd +++ b/BuildingLevel.gd @@ -230,6 +230,19 @@ func kill_citizen(): return false +func pick_block(): + if Persister.get_value("win") or Persister.get_value("lose"): + return + + var tile = local_to_map(get_global_mouse_position()) + + if building_data.has(tile): + var data = Data.data.buildings[building_data[tile].key] + if (not data.cost.has("wood") or int(data.cost.wood) <= Persister.get_value("wood")) and (not data.cost.has("stone") or int(data.cost.stone) <= Persister.get_value("stone")): + Persister.persist_data("building_mode", true) + Persister.persist_data("building_key", building_data[tile].key) + + func place_building(): if Persister.get_value("win") or Persister.get_value("lose"): return diff --git a/camera.gd b/camera.gd index 5dc9753..3dcc198 100644 --- a/camera.gd +++ b/camera.gd @@ -8,6 +8,14 @@ var zoom_speed = 0.1 # Variables for panning var is_panning = false var last_mouse_position = Vector2() +var pan_speed = 1000 + +@onready var camera_target = position + + +func _process(delta: float) -> void: + position = position.move_toward(camera_target, delta * pan_speed) + func _input(event): if event is InputEventMouseButton: @@ -26,12 +34,13 @@ func _input(event): if event.button_index == MOUSE_BUTTON_RIGHT: if event.pressed: is_panning = true - last_mouse_position = get_global_mouse_position() + last_mouse_position = Cursor.mouse_control.position else: is_panning = false # Handle panning movement if is_panning and event is InputEventMouseMotion: - var mouse_movement = last_mouse_position - get_global_mouse_position() - global_position += mouse_movement * zoom.x # Adjust movement based on zoom level - last_mouse_position = get_global_mouse_position() + var mouse_movement = last_mouse_position - Cursor.mouse_control.position + camera_target += mouse_movement / zoom.x + #global_position += mouse_movement * zoom.x # Adjust movement based on zoom level + last_mouse_position = Cursor.mouse_control.position diff --git a/main.gd b/main.gd index 55329a5..44942e1 100644 --- a/main.gd +++ b/main.gd @@ -34,6 +34,10 @@ func _process(delta: float) -> void: if Persister.get_value("population") <= 0: Persister.persist_data("lose", true) + if Input.is_action_just_pressed("mclick"): + for build_level in building_levels: + build_level.pick_block() + if Input.is_action_just_released("lclick"): if Persister.get_value("drag_mode") and Persister.get_value("building_mode"): for build_level in building_levels: diff --git a/project.godot b/project.godot index 674fc41..023560c 100644 --- a/project.godot +++ b/project.godot @@ -51,6 +51,11 @@ restart={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null) ] } +mclick={ +"deadzone": 0.5, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":4,"position":Vector2(179, 8),"global_position":Vector2(188, 54),"factor":1.0,"button_index":3,"canceled":false,"pressed":true,"double_click":false,"script":null) +] +} [rendering]