added coopa
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
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
|
||||
var is_down = false
|
||||
@onready var collision_shape_2d = $CollisionShape2D
|
||||
@onready var ray_cast_left_3 = $RayCastLeft3
|
||||
@onready var ray_cast_right_3 = $RayCastRight3
|
||||
|
||||
func _ready():
|
||||
collision_shape_2d.shape.height = 24
|
||||
|
||||
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)
|
||||
animated_sprite_2d.flip_h = true
|
||||
elif ray_cast_right.is_colliding() or ray_cast_right_2.is_colliding():
|
||||
speed = -abs(speed)
|
||||
animated_sprite_2d.flip_h = false
|
||||
|
||||
var other = null
|
||||
if ray_cast_left_3.is_colliding():
|
||||
other = ray_cast_left_3.get_collider()
|
||||
elif ray_cast_right_3.is_colliding():
|
||||
other = ray_cast_right_3.get_collider()
|
||||
|
||||
if is_down and speed != 0 and other != null:
|
||||
other.f_die()
|
||||
|
||||
if innocent:
|
||||
return
|
||||
|
||||
var body = null
|
||||
if ray_cast_left_2.is_colliding():
|
||||
if speed != 0:
|
||||
body = ray_cast_left_2.get_collider()
|
||||
else:
|
||||
speed = 160
|
||||
innocent = true
|
||||
die_sound.play()
|
||||
timer_2.start()
|
||||
elif ray_cast_right_2.is_colliding():
|
||||
if speed != 0:
|
||||
body = ray_cast_right_2.get_collider()
|
||||
else:
|
||||
speed = -160
|
||||
innocent = true
|
||||
die_sound.play()
|
||||
timer_2.start()
|
||||
|
||||
if body != null:
|
||||
body.shrink()
|
||||
innocent = true
|
||||
timer_2.start()
|
||||
|
||||
|
||||
@onready var die_sound = $dieSound
|
||||
|
||||
func f_die():
|
||||
die_sound.play()
|
||||
speed = 0
|
||||
innocent = true
|
||||
timer.start()
|
||||
|
||||
func f_shrink(body):
|
||||
die_sound.play()
|
||||
if not is_down:
|
||||
speed = 0
|
||||
collision_shape_2d.shape.height -= 9
|
||||
die.position.y += 2
|
||||
animated_sprite_2d.play("shrink")
|
||||
is_down = true
|
||||
elif speed == 0:
|
||||
speed = 160 if body.position.x < position.x else -160
|
||||
else:
|
||||
speed = 0
|
||||
|
||||
func _on_timer_2_timeout():
|
||||
innocent = false
|
||||
|
||||
|
||||
func _on_die_body_entered(body):
|
||||
f_shrink(body)
|
||||
body.velocity.y = body.JUMPt_velocity/1.5
|
||||
|
||||
|
||||
func _on_timer_timeout():
|
||||
queue_free()
|
||||
@@ -38,6 +38,7 @@ func _physics_process(delta):
|
||||
@onready var die_sound = $dieSound
|
||||
|
||||
func f_die():
|
||||
innocent = true
|
||||
speed = 0
|
||||
animated_sprite_2d.play("die")
|
||||
timer.start()
|
||||
|
||||
Reference in New Issue
Block a user