Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Sheggif |
Hello I have been working on this game and I made this lazer that goes one and one with a spike which when the lazer gets touched for too long the spikes will activate(note that my player doesn’t have any hp so there is no tanking dmg) but when my lazer activates the spike wont close so you will come to an end and will have to go to menu and re play I have also thought of the possiblity of making it when you die just reset that scene but after remembering the finale level reseting the scene will reset your progress in the level so I am trying to avoid that at all costs. I have already made a closing function and it works when I activate it inside of my ready function but if I try to call it when the player dies it doesn’t work(though it wouldn’t be good as it will only close that certain spike). Just to clarify my problem is to reset my spike and I also will need a way to reset the Lazer
Here is my code if you need:
Spike:
extends Area2D
const Open_Spike_Sprite = preload(“res://Assests/Tile Set/Open Spike.png”)
const Spike_Holder_Sprite = preload(“res://Assests/Tile Set/Spike Holder.png.png”)
func _ready():
Close_spike()
func Open_spike():
$Sprite.texture = Open_Spike_Sprite
$CollisionPolygon2D.disabled = false
func Close_spike():
$Sprite.texture = Spike_Holder_Sprite
$CollisionPolygon2D.disabled = true
func _on_Spike_body_entered(body):
if “Player” in body.name:
body._died()
func _on_Lazer_Open_spike():
Open_spike()
func _on_Lazer2_Open_spike():
Open_spike()
func _on_Lazer3_Open_spike():
Open_spike()
func _on_Lazer4_Open_spike():
Open_spike()
func _on_Lazer8_Open_spike():
Open_spike()
Lazer:
extends Area2D
const Green_Lazer = preload(“res://Assests/Tile Set/Green Lazer.png.png”)
const Yellow_Lazer = preload(“res://Assests/Tile Set/Yellow Lazer.png.png”)
const Red_Lazer = preload(“res://Assests/Tile Set/Red Lazer.png.png”)
var Triped = false
var Has_been_Triped = false
var Lazer_detected = false
var Reset = false
signal Open_spike
func _physics_process(delta):
Lazer_Checking()
func Lazer_Checking():
if Triped and !Has_been_Triped:
$Sprite.texture = Yellow_Lazer
Triped = false
$Timer.start(0.05)
Has_been_Triped = true
if Triped and Has_been_Triped:
$Sprite.texture = Red_Lazer
emit_signal(“Open_spike”)
Lazer_detected = true
Reset = true
$Timer.start(5)
else:
$Sprite.texture = Green_Lazer
func _on_Lazer_body_entered(body):
if “Player” in body.name:
#emit_signal(“Open_spike”)
print(“start”)
$Timer.start(0.05)
func _on_Timer_timeout():
if !Reset:
Triped = true
print(“end”)
if Reset:
print(“reseted”)
Reset = false
Has_been_Triped = false
Triped = false
func _on_Lazer_body_exited(body):
if !Lazer_detected:
$Sprite.texture = Green_Lazer
$Timer.stop()