feat: update some visual and fixing the bug
This commit is contained in:
@@ -49,17 +49,8 @@ func calculate_spawn_points(count: int, gridmap: Node) -> Array[Vector2i]:
|
||||
|
||||
# Determine Position Type for Bias
|
||||
# 0:TL, 1:TR, 2:BL, 3:BR, 4:Center
|
||||
var pos_type = -1
|
||||
match zone_idx:
|
||||
0: pos_type = 0 # TL
|
||||
2: pos_type = 1 # TR
|
||||
6: pos_type = 2 # BL
|
||||
8: pos_type = 3 # BR
|
||||
4: pos_type = 4 # Center
|
||||
|
||||
# Use PURE RANDOM spot in zone (User Request #2)
|
||||
# instead of biased corner/center logic
|
||||
var pos = _pick_spot_in_zone(zone, gridmap)
|
||||
# We pass zone_idx to _pick_spot_in_zone to snap corners
|
||||
var pos = _pick_spot_in_zone(zone, gridmap, zone_idx)
|
||||
if pos != Vector2i(-1, -1):
|
||||
spawn_points.append(pos)
|
||||
|
||||
@@ -126,11 +117,29 @@ func _is_valid_3x3(center: Vector2i, gridmap: Node) -> bool:
|
||||
return false
|
||||
return true
|
||||
|
||||
func _pick_spot_in_zone(zone: Rect2i, gridmap: Node) -> Vector2i:
|
||||
# Find a valid 3x3 spot in the zone
|
||||
# The returned position is the CENTER of the 3x3 area
|
||||
func _pick_spot_in_zone(zone: Rect2i, gridmap: Node, zone_idx: int = -1) -> Vector2i:
|
||||
"""
|
||||
Find a valid 3x3 spot in the zone.
|
||||
The returned position is the CENTER of the 3x3 area.
|
||||
If zone_idx is a corner (0, 2, 6, 8), we snap to the absolute map corner.
|
||||
"""
|
||||
# CORNER SNAPPING: If this is a corner zone, force it to the extreme corner
|
||||
# to ensure the 3x3 Stand fills the corner completely (no 1-tile gaps).
|
||||
if zone_idx == 0: # Top-Left
|
||||
var center = Vector2i(1, 1)
|
||||
if _is_valid_3x3(center, gridmap): return center
|
||||
elif zone_idx == 2: # Top-Right
|
||||
var center = Vector2i(gridmap.columns - 2, 1)
|
||||
if _is_valid_3x3(center, gridmap): return center
|
||||
elif zone_idx == 6: # Bottom-Left
|
||||
var center = Vector2i(1, gridmap.rows - 2)
|
||||
if _is_valid_3x3(center, gridmap): return center
|
||||
elif zone_idx == 8: # Bottom-Right
|
||||
var center = Vector2i(gridmap.columns - 2, gridmap.rows - 2)
|
||||
if _is_valid_3x3(center, gridmap): return center
|
||||
|
||||
# Fallback/Random logic for non-corner zones or if preferred corner was invalid
|
||||
var attempts = 0
|
||||
|
||||
while attempts < 30:
|
||||
attempts += 1
|
||||
# Ensure center is at least 1 tile away from edges of the map to fit 3x3
|
||||
|
||||
Reference in New Issue
Block a user