forked from team-sg/hero-mark-2
add mine that explodes on contact with player, shot by arrow, or other mine's explosions
This commit is contained in:
parent
c577f0a57c
commit
8a47c20d94
12 changed files with 338 additions and 7 deletions
28
objects/enemy/mine.gd
Normal file
28
objects/enemy/mine.gd
Normal file
|
@ -0,0 +1,28 @@
|
|||
extends "res://objects/enemy/enemy.gd"
|
||||
|
||||
const Explosion = preload("res://objects/enemy/explosion.tscn")
|
||||
|
||||
onready var chain = $Chain
|
||||
onready var hitbox = $Hitbox
|
||||
|
||||
func _ready():
|
||||
var ground_cast = $GroundCast
|
||||
ground_cast.force_raycast_update()
|
||||
if ground_cast.is_colliding():
|
||||
chain.points[1].y = chain.to_local(ground_cast.get_collision_point()).y
|
||||
|
||||
func _process(delta):
|
||||
chain.points[0].x = hitbox.position.x
|
||||
|
||||
func _on_Hitbox_area_entered(area):
|
||||
if area.is_in_group("explosion"):
|
||||
var timer = get_tree().create_timer(0.2, false)
|
||||
timer.connect("timeout", self, "die")
|
||||
if area.is_in_group("player"):
|
||||
die()
|
||||
|
||||
func die():
|
||||
var explosion = Explosion.instance()
|
||||
explosion.global_position = hitbox.global_position
|
||||
get_parent().call_deferred("add_child", explosion)
|
||||
queue_free()
|
Loading…
Add table
Add a link
Reference in a new issue