Skip to content

Commit

Permalink
clean up plates too far from the camera
Browse files Browse the repository at this point in the history
  • Loading branch information
oneseedfruit committed May 3, 2021
1 parent 0486d26 commit 3c64a6b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
10 changes: 10 additions & 0 deletions game.gd
Expand Up @@ -2,6 +2,8 @@ extends Node2D

export (PackedScene) var _PlateScene: PackedScene

signal screen_scrolled(camera_position)

var _is_ready: bool = false
var _is_game_over: bool = false
var _game_started: bool = false
Expand Down Expand Up @@ -35,6 +37,10 @@ func _physics_process(delta: float) -> void:
if $MainCamera.global_position.y - _last_pos.y > rand_range(50, 80):
var plate: RigidBody2D = _PlateScene.instance()
add_child(plate)

plate.connect("camera_checked", self, "_on_Plate_camera_checked")
connect("screen_scrolled", plate, "_on_Game_screen_scrolled")

randomize()

var left: float = $MainCamera.global_position.x - 400
Expand All @@ -61,3 +67,7 @@ func _on_HammeredNail_nail_died() -> void:

func _on_Timer_timeout() -> void:
_is_ready = true


func _on_Plate_camera_checked() -> void:
emit_signal("screen_scrolled", $MainCamera.global_position)
16 changes: 16 additions & 0 deletions plate/plate.gd
@@ -0,0 +1,16 @@
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
28 changes: 25 additions & 3 deletions plate/plate.tscn
@@ -1,20 +1,36 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]

[ext_resource path="res://plate/plate.PNG" type="Texture" id=1]

[sub_resource type="PhysicsMaterial" id=1]
[sub_resource type="PhysicsMaterial" id=3]
rough = true
absorbent = true

[sub_resource type="GDScript" id=4]
script/source = "extends RigidBody2D

signal camera_checked


func _on_Game_screen_scrolled(camera_position: Vector2) -> void:
if camera_position.y - global_position.y > 1000:
queue_free()


func _on_Timer_timeout():
emit_signal(\"camera_checked\")
"
[sub_resource type="CircleShape2D" id=2]
radius = 41.9254
[node name="Plate" type="RigidBody2D"]
mass = 0.01
physics_material_override = SubResource( 1 )
physics_material_override = SubResource( 3 )
gravity_scale = 0.0
contacts_reported = 2
contact_monitor = true
script = SubResource( 4 )
__meta__ = {
"_edit_lock_": true
}
Expand All @@ -30,3 +46,9 @@ shape = SubResource( 2 )
__meta__ = {
"_edit_lock_": true
}
[node name="Timer" type="Timer" parent="."]
wait_time = 5.0
autostart = true
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]

0 comments on commit 3c64a6b

Please sign in to comment.