Skip to content

Commit

Permalink
Add moving car and object placement.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemens-tolboom committed Nov 11, 2020
1 parent f3afa55 commit cd31899
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 9 deletions.
22 changes: 20 additions & 2 deletions addons/spawn/SpawnPoint.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ class_name SpawnPoint, "res://addons/spawn/SpawnPoint.png"

extends Spatial

signal is_depleted(who)
signal item_placed(item)

# Can tool cleanup the interface?
# https://docs.godotengine.org/en/stable/tutorials/misc/running_code_in_the_editor.html#doc-running-code-in-the-editor
# tool
Expand All @@ -13,11 +16,13 @@ export (float) var new_wave_every_seconds = 2.0

export (int) var capacity = 50
export (int) var wave_size = 5
export (NodePath) var place_products_into
export (Array, PackedScene) var products

onready var add_to_parent = get_node("..")
onready var timer:Timer = $Timer

onready var node_to_place_products_into:Node = get_node(place_products_into)
var products_left: int = capacity

var spawn_point: SpawnPointClass
Expand All @@ -37,9 +42,22 @@ func _on_Timer_timeout():
do_wave()

func do_wave():
if not visible:
return

if spawn_point.is_depleted():
emit_signal("is_depleted", self)
return

var items:Array = spawn_point.do_wave()

for p in items:
add_to_parent.call_deferred("add_child", p)
node_to_place_products_into.call_deferred("add_child", p)

p.translation = global_transform.origin - node_to_place_products_into.global_transform.origin

emit_signal("item_placed", p)

p.translation = translation
# React on the item being placed
func _on_SpawnPoint_item_placed(item):
pass
11 changes: 6 additions & 5 deletions addons/spawn/demos/3D/Ball.tscn
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
[gd_scene load_steps=3 format=2]

[sub_resource type="SpatialMaterial" id=3]
[sub_resource type="SpatialMaterial" id=1]
albedo_color = Color( 0.415686, 0.0431373, 0.0431373, 1 )

[sub_resource type="SphereShape" id=4]
radius = 0.1
[sub_resource type="SphereShape" id=2]
margin = 0.001
radius = 0.05

[node name="Ball" type="RigidBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.8557, 0 )

[node name="CSGSphere" type="CSGSphere" parent="."]
radius = 0.1
material = SubResource( 3 )
material = SubResource( 1 )

[node name="CollisionShape" type="CollisionShape" parent="."]
shape = SubResource( 4 )
shape = SubResource( 2 )
14 changes: 14 additions & 0 deletions addons/spawn/demos/3D/BallGreen.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://addons/spawn/demos/3D/Ball.tscn" type="PackedScene" id=1]

[sub_resource type="SpatialMaterial" id=1]
albedo_color = Color( 0.0862745, 0.776471, 0.0784314, 1 )

[node name="BallGreen" instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
mass = 0.2

[node name="CSGSphere" parent="." index="0"]
radius = 0.05
material = SubResource( 1 )
11 changes: 11 additions & 0 deletions addons/spawn/demos/3D/Car.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extends CSGBox


func _process(delta):
translation.x += 0.01


func _on_SpawnPoint_item_placed(item):
# Place dropped items a little randomly
item.translation.x += (randf() - 0.5) / 10.0
item.translation.z += (randf() - 0.5) / 10.0
24 changes: 22 additions & 2 deletions addons/spawn/demos/3D/SpawnPointDemo3D.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=9 format=2]

[ext_resource path="res://addons/spawn/SpawnPoint.tscn" type="PackedScene" id=1]
[ext_resource path="res://addons/spawn/demos/3D/Ball.tscn" type="PackedScene" id=2]
[ext_resource path="res://addons/spawn/demos/3D/Car.gd" type="Script" id=3]
[ext_resource path="res://addons/spawn/demos/3D/BallGreen.tscn" type="PackedScene" id=4]

[sub_resource type="SpatialMaterial" id=4]
albedo_color = Color( 0.87451, 0.0666667, 0.0666667, 1 )

[sub_resource type="QuadMesh" id=1]

Expand All @@ -17,9 +22,10 @@ extents = Vector3( 1, 1, 0.1 )
transform = Transform( 1, 0, 0, 0, 0.947891, 0.318595, 0, -0.318595, 0.947891, 0, 1.60121, 2.20038 )

[node name="SpawnPoint" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.47483, 0 )
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.902502, 1.47483, 0.527088 )
new_wave_every_seconds = 1.0
wave_size = 1
place_products_into = NodePath("..")
products = [ ExtResource( 2 ) ]

[node name="CSGTorus" type="CSGTorus" parent="SpawnPoint"]
Expand All @@ -30,6 +36,7 @@ ring_sides = 10

[node name="SpawnPoint2" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.65414, 0.634445, -3.17343 )
place_products_into = NodePath("..")
products = [ ExtResource( 2 ) ]

[node name="CSGTorus" type="CSGTorus" parent="SpawnPoint2"]
Expand All @@ -38,6 +45,18 @@ outer_radius = 0.4
sides = 32
ring_sides = 10

[node name="Car" type="CSGBox" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -2.596, 2, 0 )
width = 0.5
height = 0.1
depth = 0.5
material = SubResource( 4 )
script = ExtResource( 3 )

[node name="SpawnPoint" parent="Car" instance=ExtResource( 1 )]
place_products_into = NodePath("../..")
products = [ ExtResource( 4 ) ]

[node name="KinematicBody" type="KinematicBody" parent="."]
transform = Transform( 10, 0, 0, 0, -4.37114e-07, 1, 0, -10, -4.37114e-08, 0, 0, 0 )

Expand All @@ -48,3 +67,4 @@ material = SubResource( 2 )

[node name="CollisionShape" type="CollisionShape" parent="KinematicBody"]
shape = SubResource( 3 )
[connection signal="item_placed" from="Car/SpawnPoint" to="Car" method="_on_SpawnPoint_item_placed"]

0 comments on commit cd31899

Please sign in to comment.