-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmob.gd
More file actions
52 lines (40 loc) · 1.32 KB
/
mob.gd
File metadata and controls
52 lines (40 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
extends CharacterBody2D
signal killed_mob(mob_resource)
@export var resource: Resource
@export var health : int
@onready var player = get_node("/root/Game/TileMap/Player")
@onready var monster = %Monster
@onready var freeze_timer = $FreezeTimer
@onready var audio_player = $AudioStreamPlayer
var is_freezed = false
var is_dead = false
func _ready():
health = resource.health
monster.get_node("Monster").texture = resource.texture
func _physics_process(delta):
var direction = global_position.direction_to(player.global_position)
velocity = direction * 50.0
if !is_freezed:
move_and_slide()
%Monster.play_walk_animation(direction)
func take_damage(damage):
health -= damage
%Monster.play_hurt_animation()
if is_dead: # fixed a bug where the player can hit a dead enemy
return
if health <= 0:
is_dead = true
#audio_player.play()
monster.hide() # fixed a bug where it takes too long for the mob node to be freed
get_tree().call_group("Player","killed_mob",resource)
const SMOKE_SCENE = preload("res://smoke_explosion/smoke_explosion.tscn")
var smoke = SMOKE_SCENE.instantiate()
get_parent().add_child(smoke)
smoke.global_position = global_position
#await audio_player.finished
queue_free()
func freeze():
is_freezed = true
freeze_timer.start()
func _on_freeze_timer_timeout():
is_freezed = false