added fireballs
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
extends RigidBody2D
|
||||
|
||||
@export var speed = -70
|
||||
@onready var ray_cast_left = $RayCastLeft
|
||||
@onready var ray_cast_right = $RayCastRight
|
||||
@onready var animated_sprite_2d = $AnimatedSprite2D
|
||||
@onready var timer = $Timer
|
||||
@onready var die = $die
|
||||
@onready var ray_cast_left_2 = $RayCastLeft2
|
||||
@onready var ray_cast_right_2 = $RayCastRight2
|
||||
var innocent = false
|
||||
@onready var timer_2 = $Timer2
|
||||
|
||||
func _physics_process(delta):
|
||||
linear_velocity.x = speed
|
||||
|
||||
if ray_cast_left_2 == null:
|
||||
return
|
||||
|
||||
if ray_cast_left.is_colliding() or ray_cast_left_2.is_colliding():
|
||||
speed = abs(speed)
|
||||
elif ray_cast_right.is_colliding() or ray_cast_right_2.is_colliding():
|
||||
speed = abs(speed) * -1
|
||||
|
||||
var body = null
|
||||
if innocent:
|
||||
return
|
||||
if ray_cast_left_2.is_colliding():
|
||||
body = ray_cast_left_2.get_collider()
|
||||
elif ray_cast_right_2.is_colliding():
|
||||
body = ray_cast_right_2.get_collider()
|
||||
if body != null:
|
||||
body.shrink()
|
||||
innocent = true
|
||||
timer_2.start()
|
||||
|
||||
@onready var die_sound = $dieSound
|
||||
|
||||
func f_die():
|
||||
speed = 0
|
||||
animated_sprite_2d.play("die")
|
||||
timer.start()
|
||||
die.queue_free()
|
||||
die_sound.play()
|
||||
ray_cast_left_2.queue_free()
|
||||
ray_cast_right_2.queue_free()
|
||||
|
||||
func _on_die_body_entered(body):
|
||||
f_die()
|
||||
body.velocity.y = body.JUMPt_velocity/1.5
|
||||
|
||||
func _on_timer_timeout():
|
||||
queue_free()
|
||||
|
||||
func _on_timer_2_timeout():
|
||||
innocent = false
|
||||
Reference in New Issue
Block a user