Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Spawn more rocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ekokind committed Jun 17, 2021
1 parent 38c0adb commit fcd2b8a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
4 changes: 3 additions & 1 deletion RockSpawner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ func _spawn_rock():

func _set_rock_position(rock):
var rect = get_viewport().size
rock.position = Vector2(rand_range(0, rect.x), -100)
#rock.position = Vector2(rand_range(0, rect.x), -100)
rock.position = Vector2(250, rand_range(-10, 400))
# 250 so they spawn off screen, -10 to 400 so they spawn somewhere above or below the platy


func _on_SpawnTimer_timeout():
Expand Down
11 changes: 10 additions & 1 deletion RockSpawner.tscn
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
[gd_scene format=2]
[gd_scene load_steps=2 format=2]

[ext_resource path="res://RockSpawner.gd" type="Script" id=1]

[node name="RockSpawner" type="Node"]
script = ExtResource( 1 )

[node name="SpawnTimer" type="Timer" parent="."]
wait_time = 3.0
autostart = true

[connection signal="timeout" from="SpawnTimer" to="." method="_on_SpawnTimer_timeout"]
20 changes: 20 additions & 0 deletions rock1.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
extends RigidBody2D


# Declare member variables here. Examples:
# var a = 2
# var b = "text"


# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass


func _on_VisibilityNotifier2D_viewport_exited(viewport):
queue_free()
14 changes: 11 additions & 3 deletions rock1.tscn
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]

[ext_resource path="res://assets/textures/rock1.png" type="Texture" id=1]
[ext_resource path="res://rock1.gd" type="Script" id=2]

[sub_resource type="CircleShape2D" id=1]
radius = 32.0067

[node name="rock1" type="RigidBody2D"]
position = Vector2( 258.349, 4.97968 )
[node name="rock1" type="RigidBody2D" groups=[
"rocks",
]]
position = Vector2( 262.839, -114.001 )
gravity_scale = 0.0
linear_velocity = Vector2( -100, 0 )
script = ExtResource( 2 )

[node name="Sprite" type="Sprite" parent="."]
position = Vector2( -6.89056, 239.487 )
Expand All @@ -18,3 +22,7 @@ texture = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( -6.61053, 238.888 )
shape = SubResource( 1 )

[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]

[connection signal="viewport_exited" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_viewport_exited"]

0 comments on commit fcd2b8a

Please sign in to comment.