Introduced maximum build height
This commit is contained in:
parent
e2420fffbd
commit
27b5d5115a
5 changed files with 23 additions and 11 deletions
|
|
@ -32,7 +32,7 @@ zoom = Vector2(0.12, 0.12)
|
|||
|
||||
[node name="Building Generator" type="Node" parent="."]
|
||||
script = ExtResource("4_1bvp3")
|
||||
initial_buildings = 100
|
||||
initial_buildings = 10
|
||||
|
||||
[node name="Timer" type="Timer" parent="Building Generator"]
|
||||
wait_time = 3.0
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ config_version=5
|
|||
[application]
|
||||
|
||||
config/name="The Dark Side of Earth"
|
||||
run/main_scene="uid://cxo6bq26huau7"
|
||||
run/main_scene="uid://dpkr8yoobtej6"
|
||||
config/features=PackedStringArray("4.5", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ zoom = Vector2(0.12, 0.12)
|
|||
|
||||
[node name="Building Generator" type="Node" parent="."]
|
||||
script = ExtResource("2_d3a7t")
|
||||
initial_buildings = 250
|
||||
initial_buildings = 200
|
||||
initial_spawn_protection = false
|
||||
|
||||
[node name="Timer" type="Timer" parent="Building Generator"]
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ class_name BuildingGenerator extends Node
|
|||
@onready var grid : Grid = %Earth.get_grid()
|
||||
@export var initial_buildings : int;
|
||||
@export var initial_spawn_protection = true
|
||||
@export var spawn_attempts = 5
|
||||
|
||||
func random_oppostite_collumn() -> int:
|
||||
var playerpos = %Player.position
|
||||
|
|
@ -19,16 +20,20 @@ func random_collumn() -> int:
|
|||
|
||||
func _ready():
|
||||
for i in range(initial_buildings):
|
||||
var collumn = random_collumn()
|
||||
if initial_spawn_protection and 43 <= collumn and collumn <= 49:
|
||||
continue
|
||||
var building = randomize_building()
|
||||
grid.add_building_to_collumn(building, collumn)
|
||||
for j in range(spawn_attempts):
|
||||
var collumn = random_collumn()
|
||||
if initial_spawn_protection and 43 <= collumn and collumn <= 49:
|
||||
continue
|
||||
var building = randomize_building()
|
||||
if grid.add_building_to_collumn(building, collumn):
|
||||
break
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
var collumn = random_oppostite_collumn()
|
||||
var building : Building = randomize_building()
|
||||
grid.add_building_to_collumn(building, collumn)
|
||||
for i in range(spawn_attempts):
|
||||
var collumn = random_oppostite_collumn()
|
||||
var building : Building = randomize_building()
|
||||
if grid.add_building_to_collumn(building, collumn):
|
||||
break
|
||||
|
||||
func randomize_building() -> Building:
|
||||
var index = randi() % grid.packed_buildings.size()
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ class_name Grid extends Node2D
|
|||
@export var debug : bool
|
||||
|
||||
@export var packed_buildings : Array[PackedScene]
|
||||
@export var max_build_height = 6
|
||||
|
||||
var buildings : Array[Building] = []
|
||||
|
||||
|
|
@ -30,8 +31,14 @@ func add_building_to_collumn(building : Building, collumn : int):
|
|||
for other in buildings:
|
||||
if other.overlaps(building):
|
||||
spot_clear = false
|
||||
|
||||
if building.location.y + building.dimension.y > max_build_height:
|
||||
building.free()
|
||||
return false
|
||||
|
||||
|
||||
add_child(building)
|
||||
return true
|
||||
|
||||
# for testing
|
||||
#func _ready() -> void:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue