My first 2D game in Godot 4.4
This commit is contained in:
28
monster.gd
Normal file
28
monster.gd
Normal file
@@ -0,0 +1,28 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
var health = 3
|
||||
|
||||
@onready var player = get_node("/root/Game/Player")
|
||||
|
||||
func _ready() -> void:
|
||||
%Slime.play_walk()
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var direction = global_position.direction_to(player.global_position)
|
||||
velocity = direction * 200.0
|
||||
move_and_slide()
|
||||
|
||||
func take_damage() -> void:
|
||||
const SMOKE_EXPLOSION = preload("res://smoke_explosion/smoke_explosion.tscn")
|
||||
|
||||
%Slime.play_hurt()
|
||||
health -= 1
|
||||
|
||||
if health == 0:
|
||||
queue_free()
|
||||
var s = SMOKE_EXPLOSION.instantiate()
|
||||
get_parent().add_child(s)
|
||||
s.global_transform = global_transform
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user