feat: Add diverse game tiles, 3D wall scenes, and player movement and stop-n-go managers.

This commit is contained in:
Yogi Wiguna
2026-03-12 17:47:23 +08:00
parent 739489cd6f
commit e5e99f5853
5 changed files with 100 additions and 69 deletions
+26 -49
View File
@@ -21,6 +21,8 @@ const POWERUP_SPAWN_COUNT: int = 5 # Number of power-up tiles to spawn
var powerups_spawned: bool = false
var stop_phase_occurred: bool = false
var safe_zone_wall_scene = preload("res://scenes/wall_3d.tscn")
const PERMANENT_POWERUP_LOCATIONS: Array[Vector2i] = [
Vector2i(4, 3), # Area 1
Vector2i(8, 7), # Area 2
@@ -657,45 +659,18 @@ func sync_safe_zone(centers: Array, radius: int):
if gridmap.get_cell_item(Vector3i(x, 0, z)) == TILE_WALKABLE:
gridmap.set_cell_item(Vector3i(x, 0, z), TILE_SAFE)
# 2. Paint the walls (item ID 16) ON LAYER 1 to block movement
# We scan from -3 to +3 to handle symmetric wall indices around the 5x5 zone
for dx in range(-radius - 1, radius + 2):
for dz in range(-radius - 1, radius + 2):
var x = center.x + dx
var z = center.y + dz
if x >= 0 and x < gridmap.columns and z >= 0 and z < gridmap.rows:
# big room logic: 5x5 span (Indices -2 to 2)
# North/West use -radius/-radius-1, South/East use radius/radius+1
var is_north = dz == -radius - 1 and dx >= -radius and dx <= radius
var is_south = dz == radius and dx >= -radius and dx <= radius
var is_west = dx == -radius and dz >= -radius and dz <= radius
var is_east = dx == radius + 1 and dz >= -radius and dz <= radius
var orientation = 0
var is_wall = false
if is_north:
orientation = 0
is_wall = true
elif is_south:
orientation = 0
is_wall = true
elif is_west:
orientation = 22
is_wall = true
elif is_east:
orientation = 22
is_wall = true
if is_wall:
# Door logic: Skip center (0) on the respective border line
var is_door = (is_north and dx == 0) or (is_south and dx == 0) or \
(is_west and dz == 0) or (is_east and dz == 0)
if is_door:
continue
gridmap.set_cell_item(Vector3i(x, 1, z), 16, orientation)
# 2. Instantiate North and South walls (Horizontal)
for dx in range(-radius, radius + 1):
if dx == 0: continue # Opening
_instantiate_safe_zone_wall(Vector3(center.x + dx + 0.5, 0.0, center.y - radius), 0)
_instantiate_safe_zone_wall(Vector3(center.x + dx + 0.5, 0.0, center.y + radius + 1), 0)
# 3. Instantiate East and West walls (Vertical - 4 walls each)
# From -2 to 2 (radius), with center opening = 4 walls per side
for dz in range(-radius, radius + 1):
if dz == 0: continue # Opening
_instantiate_safe_zone_wall(Vector3(center.x - radius, 0.0, center.y + dz + 0.5), 90)
_instantiate_safe_zone_wall(Vector3(center.x + radius + 1, 0.0, center.y + dz + 0.5), 90)
# Update pathfinding for bots and movement checks
gridmap.initialize_astar()
@@ -728,16 +703,9 @@ func sync_clear_safe_zone(centers_to_clear: Array):
if current == TILE_SAFE:
gridmap.set_cell_item(Vector3i(x, 0, z), TILE_WALKABLE)
# Also clean up walls ON LAYER 1
# Scan -3 to +3 range to ensure all shifted walls are cleared
for dx in range(-SAFE_ZONE_RADIUS - 1, SAFE_ZONE_RADIUS + 2):
for dz in range(-SAFE_ZONE_RADIUS - 1, SAFE_ZONE_RADIUS + 2):
var x = center.x + dx
var z = center.y + dz
if x >= 0 and x < gridmap.columns and z >= 0 and z < gridmap.rows:
# Clear any wall items on Floor 1
if gridmap.get_cell_item(Vector3i(x, 1, z)) != -1:
gridmap.set_cell_item(Vector3i(x, 1, z), -1)
# Also clean up walls
for wall in get_tree().get_nodes_in_group("SafeZoneWalls"):
wall.queue_free()
# Clear local state
safe_zone_centers = []
@@ -751,6 +719,15 @@ func sync_clear_safe_zone(centers_to_clear: Array):
safe_zone_centers = []
safe_zone_spawned = false
func _instantiate_safe_zone_wall(pos: Vector3, rotation_deg: float):
if not safe_zone_wall_scene: return
var wall = safe_zone_wall_scene.instantiate()
add_child(wall)
wall.add_to_group("SafeZoneWalls")
wall.position = pos
wall.rotation_degrees.y = rotation_deg
# =============================================================================
# Power-Up Tile Spawning (Speed & Ghost)
# =============================================================================