# Tool States var active_tool: String = "pickaxe" # Can be: "pickaxe", "dynamite", "tnt" # Tool Penalties var dynamite_instability_penalty: float = 15.0 var tnt_instability_penalty: float = 30.0 var drill_instability_penalty: float = 20.0 ### extends Area2D # We add a new clicked signal! signal clicked(grid_pos: Vector2) signal mined(grid_pos: Vector2, loot_type: String) var grid_pos: Vector2 var hardness: int = 1 var clicks_taken: int = 0 var current_loot: String = "copper" const ORE_TIERS = ["copper", "iron", "titanium", "tungsten", "mythril", "adamant"] const GEMS = ["emerald", "diamond", "sapphire", "ruby"] func _ready(): input_pickable = true func initialize(depth_level: int, danger_level: int = 0): hardness = randi_range(1 + depth_level, 2 + depth_level) var loot_index = clampi(depth_level + randi_range(0, 1), 0, ORE_TIERS.size() - 1) current_loot = ORE_TIERS[loot_index] if randf() <= 0.05: current_loot = GEMS.pick_random() if danger_level > 0 and depth_level > 0: var obsidian_chance = 0.15 * danger_level if randf() <= obsidian_chance: current_loot = "obsidian" hardness += 2 func _input_event(viewport: Node, event: InputEvent, shape_idx: int): if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed: # Just tell the game we were clicked, don't take damage yet! clicked.emit(grid_pos) # New function for standard pickaxe hits func take_pickaxe_damage(): clicks_taken += 1 if clicks_taken >= hardness: mined.emit(grid_pos, current_loot) else: play_hit_animation() # New function for Dynamite/TNT instant destruction func instant_break(): mined.emit(grid_pos, current_loot) func play_hit_animation(): var tween = create_tween() var original_x = position.x tween.tween_property(self, "position:x", original_x + 5, 0.05) tween.tween_property(self, "position:x", original_x - 5, 0.1) tween.tween_property(self, "position:x", original_x, 0.05) #### rock.mined.connect(_on_rock_mined) rock.clicked.connect(_on_rock_clicked) # Add this line! ##### func _on_rock_clicked(pos: Vector2): if not is_run_active: return var rock = grid[pos] if active_tool == "pickaxe": rock.take_pickaxe_damage() # (Future: Deduct stamina here) elif active_tool == "dynamite": use_dynamite(rock) elif active_tool == "tnt": use_tnt(pos.y) ##### func use_dynamite(rock: Area2D): print("BOOM! Dynamite used!") # Spike the instability heavily current_instability += dynamite_instability_penalty current_instability = min(current_instability, 100.0) roll_for_danger() check_instability_thresholds() # Break the rock instantly (this will trigger _on_rock_mined) if is_run_active: rock.instant_break() # Reset tool active_tool = "pickaxe" #### func use_tnt(row_y: int): print("KABOOM! TNT cleared row ", row_y) # Apply massive instability once current_instability += tnt_instability_penalty current_instability = min(current_instability, 100.0) roll_for_danger() check_instability_thresholds() if not is_run_active: return # Collect loot and destroy all rocks in this row for x in range(grid_width): var pos = Vector2(x, row_y) if grid.has(pos): var rock = grid[pos] var loot = rock.current_loot if current_run_loot.has(loot): current_run_loot[loot] += 1 else: current_run_loot[loot] = 1 grid.erase(pos) rock.queue_free() update_loot_ui() # Trigger a physics-only cascade for each column (so rocks above drop down) if row_y > 0: for x in range(grid_width): trigger_cascade(Vector2(x, row_y), false) # Reset tool active_tool = "pickaxe" ##### # We add apply_penalty = true as a default func trigger_cascade(mined_pos: Vector2, apply_penalty: bool = true): if apply_penalty: print("Mine destabilized! Rocks are falling!") current_instability += cascade_instability_penalty current_instability = min(current_instability, 100.0) roll_for_danger() check_instability_thresholds() if not is_run_active: return # ... (Keep all your existing tweening and falling loop code exactly as it is below this) for y in range(mined_pos.y - 1, -1, -1): # etc... #### func unlock_next_row(use_drill: bool = false): if current_depth >= max_depth: print("You have reached the maximum depth!") return if not use_drill: # Using Stamina logic (keep your existing code here) pass else: # Using a Drill print("Row unlocked using Drill! Warning: Instability spikes!") current_instability += drill_instability_penalty current_instability = min(current_instability, 100.0) roll_for_danger() check_instability_thresholds() if not is_run_active: return # Stop if the drill caused a collapse! # Expand the grid (keep your existing code here) current_depth += 1 var new_row_y = current_depth - 1 for x in range(grid_width): spawn_rock(Vector2(x, new_row_y))