forked from team-sg/hero-mark-2
arrows now get deleted when offscreen
This commit is contained in:
parent
2d3fc72ebe
commit
b53c776021
4 changed files with 21 additions and 8 deletions
6
game.gd
6
game.gd
|
@ -28,15 +28,21 @@ onready var a_shoot = preload("res://audio/sounds/a_egg_shoot.ogg")
|
||||||
#Objects
|
#Objects
|
||||||
onready var block_text = preload("res://objects/hud/blocktext.tscn")
|
onready var block_text = preload("res://objects/hud/blocktext.tscn")
|
||||||
|
|
||||||
|
#Instances a node
|
||||||
func instance_node(node:PackedScene,x:float,y:float,parent):
|
func instance_node(node:PackedScene,x:float,y:float,parent):
|
||||||
var Instance = node.instance()
|
var Instance = node.instance()
|
||||||
Instance.global_position = Vector2(x,y)
|
Instance.global_position = Vector2(x,y)
|
||||||
parent.add_child(Instance)
|
parent.add_child(Instance)
|
||||||
|
|
||||||
|
#Plays a sound
|
||||||
func play_sound(snd,player):
|
func play_sound(snd,player):
|
||||||
player.set_stream(snd)
|
player.set_stream(snd)
|
||||||
player._set_playing(true)
|
player._set_playing(true)
|
||||||
|
|
||||||
|
#Get position in sectors
|
||||||
|
func get_sector(pos):
|
||||||
|
return (pos / resolution).floor()
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
#Restart scene
|
#Restart scene
|
||||||
if Input.is_action_just_pressed("debug_restart"):
|
if Input.is_action_just_pressed("debug_restart"):
|
||||||
|
|
|
@ -152,6 +152,10 @@ scale = Vector2( -1, 1 )
|
||||||
position = Vector2( 232, 168 )
|
position = Vector2( 232, 168 )
|
||||||
scale = Vector2( -1, 1 )
|
scale = Vector2( -1, 1 )
|
||||||
|
|
||||||
|
[node name="Slime4" parent="Enemies" instance=ExtResource( 11 )]
|
||||||
|
position = Vector2( 264, 168 )
|
||||||
|
scale = Vector2( -1, 1 )
|
||||||
|
|
||||||
[node name="Bat" parent="Enemies" instance=ExtResource( 13 )]
|
[node name="Bat" parent="Enemies" instance=ExtResource( 13 )]
|
||||||
position = Vector2( 104, 48 )
|
position = Vector2( 104, 48 )
|
||||||
left_up_boundry = 3.0
|
left_up_boundry = 3.0
|
||||||
|
|
|
@ -1,12 +1,21 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
|
onready var cull_edge = Vector2(5 * scale.x,0) #Edge to check culling, if this edge is offscreen, delete the arrow
|
||||||
|
onready var player = get_parent().get_node("Player")
|
||||||
|
onready var initial_sector = Game.get_sector(player.global_position)
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
scale.x = get_parent().get_node("Player").sprite.scale.x
|
#Flip depending on player facing
|
||||||
|
scale.x = player.sprite.scale.x
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
|
#Move in flip direction
|
||||||
position.x += 4 * scale.x
|
position.x += 4 * scale.x
|
||||||
|
#Delete when offscreen
|
||||||
|
if Game.get_sector(global_position + cull_edge) != initial_sector:
|
||||||
|
queue_free()
|
||||||
|
|
||||||
|
#Wall Collision
|
||||||
func _on_Area2D_body_entered(body):
|
func _on_Area2D_body_entered(body):
|
||||||
if body is TileMap or body is StaticBody2D:
|
if body is TileMap or body is StaticBody2D:
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|
|
@ -21,15 +21,9 @@ z_index = -1
|
||||||
texture = ExtResource( 2 )
|
texture = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Area2D" type="Area2D" parent="." groups=["arrow"]]
|
[node name="Area2D" type="Area2D" parent="." groups=["arrow"]]
|
||||||
visible = false
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||||
position = Vector2( -0.5, -0.5 )
|
position = Vector2( -0.5, -0.5 )
|
||||||
shape = SubResource( 2 )
|
shape = SubResource( 2 )
|
||||||
|
|
||||||
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]
|
|
||||||
position = Vector2( -0.5, -0.5 )
|
|
||||||
scale = Vector2( 0.55, 0.35 )
|
|
||||||
|
|
||||||
[connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]
|
[connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]
|
||||||
[connection signal="screen_exited" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_screen_exited"]
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue