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