How to make player die

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Petcharatnp

I would like to make hp of player decrease when run into bomb and when the player run out the hp then player will dead but right now, the player still alive and hp decrease into minus

This is my player code:

extends KinematicBody2D

var speed = 150
var direction = Vector2(0,0)
var jumpValue = 400
var gravity = 700
var anim_idle = "Idle"
var anim_run = "Run"
var anim_jump = "Jump"
var anim_hurt = "Hurt"
var anim_dead = "Dead"
var score = 0
var candy = 0
var health = 100
var alive = true
func _ready(): 
	pass
	
func _process(delta): 
	$ProgressBar.value = health

func _physics_process(delta):
	
	direction.y += gravity * delta 
	
	if Input.is_action_pressed("GO_RIGHT"):
		direction.x = speed
		$AnimatedSprite.play(anim_run)
		$AnimatedSprite.flip_h = false
	elif Input.is_action_pressed("GO_LEFT"):
		direction.x = -speed
		$AnimatedSprite.play(anim_run)
		$AnimatedSprite.flip_h = true
	else:
		$AnimatedSprite.play(anim_idle)
		direction.x = 0
		
	if Input.is_action_pressed("GO_UP") and is_on_floor(): 
		direction.y = -jumpValue
		$AnimatedSprite.play(anim_jump)
	
	
	move_and_slide(direction,Vector2(0,-1))
	pass

func GetCandy(): #Collect Candy	
	candy += 1

func hurt(): #Game over
	health -= 10
	$AnimatedSprite.play(anim_hurt)
	print(health)
	if health <= 0:
		$AnimatedSprite.play(anim_dead)

This is my bomb code:

extends Area2D

var bomb


func _ready():
	pass


func _on_Area2D_body_entered(body):
	if body.has_method("hurt"): 
		body.hurt()

Edited to fix forum code formatting…

jgodfrey | 2023-04-12 19:51

:bust_in_silhouette: Reply From: TheVorkMan_

I think there solution is just delete main character on 0 hp and replace him with another, non-controlable.

:bust_in_silhouette: Reply From: brainbug
set_physics_process(false)