mirror of
https://github.com/RYGhub/the-cold-night.git
synced 2024-11-22 04:34:19 +00:00
🔧 Remove projectiles when their shape is off-screen
This commit is contained in:
parent
5621f27d7c
commit
f57f85612e
6 changed files with 39 additions and 3 deletions
|
@ -59,6 +59,11 @@ _global_script_classes=[ {
|
|||
"language": "GDScript",
|
||||
"path": "res://src/behaviours/graphics/FourSidedSprite.gd"
|
||||
}, {
|
||||
"base": "VisibilityNotifier2D",
|
||||
"class": "FreeWhenShapeIsOffScreen",
|
||||
"language": "GDScript",
|
||||
"path": "res://src/behaviours/spawning/FreeWhenShapeIsOffScreen.gd"
|
||||
}, {
|
||||
"base": "Node",
|
||||
"class": "Ownership",
|
||||
"language": "GDScript",
|
||||
|
@ -115,6 +120,7 @@ _global_script_class_icons={
|
|||
"FireExtinguisherEnemy": "",
|
||||
"Flammable": "",
|
||||
"FourSidedSprite": "",
|
||||
"FreeWhenShapeIsOffScreen": "",
|
||||
"Ownership": "",
|
||||
"PlayerMovement": "",
|
||||
"RNG": "",
|
||||
|
|
16
src/behaviours/spawning/FreeWhenShapeIsOffScreen.gd
Normal file
16
src/behaviours/spawning/FreeWhenShapeIsOffScreen.gd
Normal file
|
@ -0,0 +1,16 @@
|
|||
extends VisibilityNotifier2D
|
||||
class_name FreeWhenShapeIsOffScreen
|
||||
|
||||
|
||||
onready var shape: Node = get_parent()
|
||||
onready var target: Node = shape.get_parent()
|
||||
|
||||
|
||||
func _ready():
|
||||
# This is gonna break.
|
||||
var ext = shape.shape.extents
|
||||
rect = Rect2(-ext.x, -ext.y, ext.x * 2, ext.y * 2)
|
||||
|
||||
|
||||
func freedom():
|
||||
target.queue_free()
|
8
src/behaviours/spawning/FreeWhenShapeIsOffScreen.tscn
Normal file
8
src/behaviours/spawning/FreeWhenShapeIsOffScreen.tscn
Normal file
|
@ -0,0 +1,8 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://src/behaviours/spawning/FreeWhenShapeIsOffScreen.gd" type="Script" id=1]
|
||||
|
||||
[node name="FreeWhenShapeIsOffScreen" type="VisibilityNotifier2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[connection signal="screen_exited" from="." to="." method="freedom"]
|
|
@ -23,9 +23,9 @@ func get_cooldown() -> float:
|
|||
|
||||
func shoot(target):
|
||||
var node = bullet.instance()
|
||||
container.add_child(node)
|
||||
node.set_position(global_position)
|
||||
node.set_rotation(node.get_angle_to(target))
|
||||
container.add_child(node)
|
||||
node.get_node("Ownership").entity_owner = parent
|
||||
node.add_collision_exception_with(parent)
|
||||
emit_signal("shot")
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://src/entities/bullets/AbstractBullet.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://src/entities/bullets/Arrow.png" type="Texture" id=2]
|
||||
[ext_resource path="res://src/behaviours/spawning/FreeWhenShapeIsOffScreen.tscn" type="PackedScene" id=3]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 16, 6 )
|
||||
|
@ -14,5 +15,7 @@ shape = SubResource( 1 )
|
|||
[node name="Sprite" type="Sprite" parent="Shape" index="0"]
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[node name="FreeWhenShapeIsOffScreen" parent="Shape" index="1" instance=ExtResource( 3 )]
|
||||
|
||||
[node name="BulletMovement" parent="." index="1"]
|
||||
movement_per_second = 400.0
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
[gd_scene load_steps=7 format=2]
|
||||
[gd_scene load_steps=8 format=2]
|
||||
|
||||
[ext_resource path="res://src/entities/bullets/AbstractBullet.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://src/entities/bullets/ArrowAlternative.png" type="Texture" id=2]
|
||||
[ext_resource path="res://src/entities/bullets/ArrowAlternative.gd" type="Script" id=3]
|
||||
[ext_resource path="res://src/behaviours/damage/Flammable.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://src/mechanics/Light.png" type="Texture" id=5]
|
||||
[ext_resource path="res://src/behaviours/spawning/FreeWhenShapeIsOffScreen.tscn" type="PackedScene" id=6]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 6, 1.5 )
|
||||
|
@ -18,6 +19,8 @@ shape = SubResource( 1 )
|
|||
[node name="Sprite" type="Sprite" parent="Shape" index="0"]
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[node name="FreeWhenShapeIsOffScreen" parent="Shape" index="1" instance=ExtResource( 6 )]
|
||||
|
||||
[node name="BulletMovement" parent="." index="1"]
|
||||
movement_per_second = 400.0
|
||||
|
||||
|
|
Loading…
Reference in a new issue