second one
This commit is contained in:
+12
-36
@@ -19,30 +19,32 @@ var stun_timer: float = 0.0
|
||||
var contact_timer: float = 0.0
|
||||
var target: Node3D = null
|
||||
|
||||
var mesh_node: MeshInstance3D
|
||||
@onready var mesh_node: MeshInstance3D = $BodyMesh
|
||||
var mat: StandardMaterial3D
|
||||
|
||||
var COLOR_CHASE = Color(1.0, 0.28, 0.18)
|
||||
var COLOR_FLY = Color(1.0, 0.85, 0.1)
|
||||
var COLOR_STUN = Color(0.55, 0.55, 0.65)
|
||||
var COLOR_CHASE = Color(1.0, 0.28, 0.18)
|
||||
var COLOR_FLY = Color(1.0, 0.85, 0.1)
|
||||
var COLOR_STUN = Color(0.55, 0.55, 0.65)
|
||||
|
||||
const CONTACT_CD = 0.7
|
||||
const AIR_FRICTION = 0.86
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("enemies")
|
||||
_build_mesh()
|
||||
_build_collider()
|
||||
mat = mesh_node.material_override.duplicate() as StandardMaterial3D
|
||||
mesh_node.material_override = mat
|
||||
COLOR_CHASE = mat.albedo_color
|
||||
|
||||
func setup(type: String, wave: int) -> void:
|
||||
match type:
|
||||
"slime":
|
||||
move_speed = 2.8 + wave * 0.12
|
||||
health = 28 + wave * 4
|
||||
health = 28 + wave * 4
|
||||
score_value = 10
|
||||
damage_to_player = 8
|
||||
"bat":
|
||||
move_speed = 5.5 + wave * 0.15
|
||||
health = 14 + wave * 2
|
||||
health = 14 + wave * 2
|
||||
score_value = 15
|
||||
damage_to_player = 6
|
||||
base_scale = 0.7
|
||||
@@ -51,7 +53,7 @@ func setup(type: String, wave: int) -> void:
|
||||
mat.albedo_color = COLOR_CHASE
|
||||
"ogre":
|
||||
move_speed = 1.8 + wave * 0.08
|
||||
health = 80 + wave * 12
|
||||
health = 80 + wave * 12
|
||||
score_value = 25
|
||||
damage_to_player = 18
|
||||
base_scale = 1.5
|
||||
@@ -59,26 +61,6 @@ func setup(type: String, wave: int) -> void:
|
||||
COLOR_CHASE = Color(0.3, 0.7, 0.3)
|
||||
mat.albedo_color = COLOR_CHASE
|
||||
|
||||
func _build_mesh() -> void:
|
||||
mesh_node = MeshInstance3D.new()
|
||||
var box := BoxMesh.new()
|
||||
box.size = Vector3(0.85, 0.85, 0.85)
|
||||
mesh_node.mesh = box
|
||||
mesh_node.position.y = 0.425
|
||||
mat = StandardMaterial3D.new()
|
||||
mat.albedo_color = COLOR_CHASE
|
||||
mat.roughness = 0.8
|
||||
mesh_node.material_override = mat
|
||||
add_child(mesh_node)
|
||||
|
||||
func _build_collider() -> void:
|
||||
var col := CollisionShape3D.new()
|
||||
var shape := BoxShape3D.new()
|
||||
shape.size = Vector3(0.85, 0.85, 0.85)
|
||||
col.shape = shape
|
||||
col.position.y = 0.425
|
||||
add_child(col)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
match state:
|
||||
State.CHASING: _chase(delta)
|
||||
@@ -90,16 +72,13 @@ func _chase(delta: float) -> void:
|
||||
if not is_instance_valid(target):
|
||||
return
|
||||
contact_timer = max(0.0, contact_timer - delta)
|
||||
|
||||
var diff := target.global_position - global_position
|
||||
diff.y = 0.0
|
||||
var dist := diff.length()
|
||||
|
||||
if dist < 1.0 and contact_timer <= 0.0:
|
||||
contact_timer = CONTACT_CD
|
||||
if target.has_method("take_damage"):
|
||||
target.take_damage(damage_to_player)
|
||||
|
||||
if dist > 0.05:
|
||||
var dir := diff.normalized()
|
||||
velocity.x = dir.x * move_speed
|
||||
@@ -120,10 +99,8 @@ func _fly(delta: float) -> void:
|
||||
var col3d := col.get_collider() as Node3D
|
||||
if col3d == null:
|
||||
continue
|
||||
|
||||
if col3d.has_meta("is_wall"):
|
||||
var dmg := int(speed_now * wall_damage_mult)
|
||||
_take_hit(dmg)
|
||||
_take_hit(int(speed_now * wall_damage_mult))
|
||||
_wall_impact_effect()
|
||||
fly_vel = Vector3.ZERO
|
||||
velocity = Vector3.ZERO
|
||||
@@ -145,7 +122,6 @@ func _fly(delta: float) -> void:
|
||||
if Vector2(fly_vel.x, fly_vel.z).length() < 0.4:
|
||||
_enter_chase()
|
||||
|
||||
# Spin while airborne
|
||||
mesh_node.rotation.y += delta * 10.0
|
||||
|
||||
func _stun_tick(delta: float) -> void:
|
||||
|
||||
Reference in New Issue
Block a user