From 4486f3ace302e709e2cea6329931869438456d69 Mon Sep 17 00:00:00 2001 From: dusoleil Date: Sat, 23 Jul 2022 11:30:20 -0400 Subject: Randomly Spawn Chickens --- Main.gd | 18 ++++++++++++++++++ Main.tscn | 41 +---------------------------------------- 2 files changed, 19 insertions(+), 40 deletions(-) diff --git a/Main.gd b/Main.gd index 68447ee..f7fdec7 100644 --- a/Main.gd +++ b/Main.gd @@ -1,4 +1,22 @@ extends Node +export (PackedScene) var chicken +export var num_chickens = 5 +export var spawn_radius = 4.0 + +func spawn_chicken(): + var loc = Vector2(randf()-0.5,randf()-0.5).normalized() * randf() * spawn_radius + var c = chicken.instance() + c.scale = Vector3(0.25,0.25,0.25) + c.translation = Vector3(loc.x,1.25,loc.y) + c.rotate(Vector3.UP, randf()*TAU) + c.mov_length_max = 3.0 + c.flap_chance = 2.0 + c.squack_chance = 2.0 + c.peck_chance = 3.0 + add_child(c) + func _ready(): randomize() + for i in range(num_chickens): + spawn_chicken() diff --git a/Main.tscn b/Main.tscn index 180f5e6..5f502df 100644 --- a/Main.tscn +++ b/Main.tscn @@ -27,6 +27,7 @@ extents = Vector3( 0.05, 1, 5 ) [node name="Main" type="Node"] script = ExtResource( 1 ) +chicken = ExtResource( 4 ) [node name="DirectionalLight" type="DirectionalLight" parent="."] transform = Transform( -0.586145, -0.773475, 0.241185, -0.715288, 0.633826, 0.294324, -0.380522, 0, -0.924772, 6.17321, 8.45611, -11.9247 ) @@ -83,46 +84,6 @@ shape = SubResource( 6 ) [node name="Player" parent="." instance=ExtResource( 3 )] transform = Transform( 1, 0, 0, 0, 0.968718, 0.248166, 0, -0.248166, 0.968718, 0, 5.05733, 7 ) -[node name="Chicken" parent="." instance=ExtResource( 4 )] -transform = Transform( 0.25, 0, 0, 0, 0.25, 0, 0, 0, 0.25, 0, 1.25, 0 ) -rot_chance = 10.0 -mov_length_max = 3.0 -flap_chance = 2.0 -squack_chance = 2.0 -peck_chance = 3.0 - -[node name="Chicken2" parent="." instance=ExtResource( 4 )] -transform = Transform( -0.157042, 0, 0.19452, 0, 0.25, 0, -0.19452, 0, -0.157042, 2.50059, 1.25, -2.25906 ) -rot_chance = 10.0 -mov_length_max = 3.0 -flap_chance = 2.0 -squack_chance = 2.0 -peck_chance = 3.0 - -[node name="Chicken3" parent="." instance=ExtResource( 4 )] -transform = Transform( 0.181922, 0, -0.171477, 0, 0.25, 0, 0.171477, 0, 0.181922, 0, 1.25, -2.79105 ) -rot_chance = 10.0 -mov_length_max = 3.0 -flap_chance = 2.0 -squack_chance = 2.0 -peck_chance = 3.0 - -[node name="Chicken4" parent="." instance=ExtResource( 4 )] -transform = Transform( 0.177798, 0, 0.175749, 0, 0.25, 0, -0.175749, 0, 0.177798, -3.31942, 1.25, 0 ) -rot_chance = 10.0 -mov_length_max = 3.0 -flap_chance = 2.0 -squack_chance = 2.0 -peck_chance = 3.0 - -[node name="Chicken5" parent="." instance=ExtResource( 4 )] -transform = Transform( -0.24986, 0, 0.00835422, 0, 0.25, 0, -0.00835422, 0, -0.24986, -1.33975, 1.25, -1.28165 ) -rot_chance = 10.0 -mov_length_max = 3.0 -flap_chance = 2.0 -squack_chance = 2.0 -peck_chance = 3.0 - [node name="UI" type="Control" parent="."] anchor_right = 1.0 anchor_bottom = 1.0 -- cgit v1.2.3