mob_data as Dictionary

master
Sascha 2025-01-05 11:22:49 +07:00
parent 1ed76cdf19
commit 4e8e37867d
5 changed files with 17 additions and 17 deletions

@ -41,7 +41,7 @@ position=Vector2i(2560, 28)
[ScriptEditor]
open_scripts=["res://scripts/audio_controller.gd", "res://scripts/bullet.gd", "res://scripts/game.gd", "res://scripts/gun.gd", "res://scripts/mob.gd", "res://scripts/player.gd", "res://scripts/ui.gd"]
selected_script="res://scripts/game.gd"
selected_script="res://scripts/mob.gd"
open_help=[]
script_split_offset=200
list_split_offset=0

@ -4,3 +4,4 @@ res://scenes/player.tscn
res://scenes/gun.tscn
res://scenes/boss.tscn
res://scenes/tree.tscn
res://scripts/mob.gd

@ -73,11 +73,11 @@ state={
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 0,
"column": 17,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 57,
"scroll_position": 37.0,
"row": 63,
"scroll_position": 31.0,
"selection": false,
"syntax_highlighter": "GDScript"
}
@ -101,11 +101,11 @@ state={
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 0,
"column": 13,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 32,
"scroll_position": 0.0,
"row": 12,
"scroll_position": 1.0,
"selection": false,
"syntax_highlighter": "GDScript"
}

@ -220,9 +220,6 @@ scale = Vector2(1.5, 1.5)
collision_layer = 2
collision_mask = 7
script = ExtResource("1_2cdgk")
health = 20
speed = 50
xp = 10
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, -25)

@ -9,9 +9,11 @@ const SMOKE_EXPLOSION = preload("res://smoke_explosion/smoke_explosion.tscn")
@onready var player = get_node("/root/Game/Player")
@export var health = 2
@export var speed = 100
@export var xp = 1
@export var mob_data := {
"health": 2,
"speed": 100,
"xp": 1
}
func _ready() -> void:
animation_player.play("walk")
@ -19,18 +21,18 @@ func _ready() -> void:
func _physics_process(_delta: float) -> void:
if not player: return
var direction = global_position.direction_to(player.global_position)
velocity = direction * speed
velocity = direction * mob_data.speed
move_and_slide()
func take_damage() -> void:
health -= 1
if health <= 0:
mob_data.health -= 1
if mob_data.health <= 0:
var smoke = SMOKE_EXPLOSION.instantiate()
get_parent().add_child(smoke)
smoke.global_position = global_position
explosion_sound.play()
await explosion_sound.finished
mob_died.emit(xp)
mob_died.emit(mob_data.xp)
queue_free()
else:
take_damage_sound.play()