forked from team-sg/hero-mark-2
chicken man
This commit is contained in:
parent
a7f5ad6db2
commit
63b24cb614
9 changed files with 1469 additions and 97 deletions
|
@ -1,84 +1,87 @@
|
|||
extends Node2D
|
||||
|
||||
|
||||
export var decisions: Dictionary = {
|
||||
"wait": 2,
|
||||
"chase": 3,
|
||||
"punch": 3,
|
||||
"beam": 1,
|
||||
}
|
||||
export var wait_time: float = 1.0
|
||||
export var chase_speed: float = 50.0
|
||||
export var push_speed: float = 60.0
|
||||
export var chase_speed: float = 40.0
|
||||
export var breath_dps: float = 50.0
|
||||
export var punch_damage: float = 10.0
|
||||
export var hurting: bool = false
|
||||
export var sg2083_path: NodePath
|
||||
|
||||
|
||||
var rng := RandomNumberGenerator.new()
|
||||
var current_action: String = "wait"
|
||||
|
||||
|
||||
onready var punch_cast: RayCast2D = $PunchCast
|
||||
onready var chase_cast: RayCast2D = $ChaseCast
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
rng.seed = "HEROMARK2".hash()
|
||||
_decide_action()
|
||||
onready var animation_player: AnimationPlayer = $"%AnimationPlayer"
|
||||
onready var state_chart: Node = $StateChart
|
||||
onready var in_range_cast: RayCast2D = $InRangeCast
|
||||
onready var out_range_cast: RayCast2D = $OutRangeCast
|
||||
onready var shoot_range_cast: RayCast2D = $ShootRangeCast
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
match current_action:
|
||||
"chase":
|
||||
if chase_cast.is_colliding():
|
||||
print("huh")
|
||||
_decide_action()
|
||||
else:
|
||||
print("hehe")
|
||||
position.x -= chase_speed * delta
|
||||
if not out_range_cast.is_colliding():
|
||||
state_chart.send_event("out_of_range")
|
||||
elif in_range_cast.is_colliding():
|
||||
state_chart.send_event("in_range")
|
||||
|
||||
|
||||
func _decide_action() -> void:
|
||||
# fill array based on weights
|
||||
var weighted_decisions := []
|
||||
for k in decisions.keys():
|
||||
for i in decisions[k]:
|
||||
weighted_decisions.append(k)
|
||||
# choose an action
|
||||
current_action = weighted_decisions[rng.randi() % weighted_decisions.size()]
|
||||
# act based on new action
|
||||
match current_action:
|
||||
"wait":
|
||||
wait()
|
||||
"chase":
|
||||
chase()
|
||||
"punch":
|
||||
if punch_cast.is_colliding():
|
||||
punch()
|
||||
else:
|
||||
current_action = "chase"
|
||||
chase()
|
||||
"beam":
|
||||
beam()
|
||||
func start_push() -> void:
|
||||
state_chart.send_event("start_push")
|
||||
|
||||
|
||||
func wait() -> void:
|
||||
print("waiting")
|
||||
yield(get_tree().create_timer(wait_time, false), "timeout")
|
||||
_decide_action()
|
||||
func stop_push() -> void:
|
||||
state_chart.send_event("stop_push")
|
||||
|
||||
|
||||
func chase() -> void:
|
||||
# TODO: play animation
|
||||
print("chasing")
|
||||
func _attack() -> void:
|
||||
var sg2083 := get_node(sg2083_path)
|
||||
if sg2083.has_method("hurt"):
|
||||
sg2083.hurt(punch_damage)
|
||||
|
||||
|
||||
func punch() -> void:
|
||||
# TODO: play animation
|
||||
print("PUNCH")
|
||||
yield(get_tree().create_timer(wait_time, false), "timeout")
|
||||
_decide_action()
|
||||
func _on_Roar_state_entered() -> void:
|
||||
animation_player.play("roar", 0.25)
|
||||
Audio.play_sound(Audio.a_famira, Audio.ac_boss)
|
||||
|
||||
|
||||
func beam() -> void:
|
||||
# TODO: play animation and stuff
|
||||
print("BEAM")
|
||||
yield(get_tree().create_timer(wait_time, false), "timeout")
|
||||
_decide_action()
|
||||
func _on_Chasing_state_entered() -> void:
|
||||
animation_player.play("chasing", 0.25)
|
||||
|
||||
|
||||
func _on_Punching_state_entered() -> void:
|
||||
animation_player.play("punching", 0.25)
|
||||
|
||||
|
||||
func _on_PunchCooldown_state_entered() -> void:
|
||||
animation_player.play("RESET", 0.5)
|
||||
|
||||
|
||||
func _on_Shooting_state_entered() -> void:
|
||||
animation_player.play("shooting")
|
||||
|
||||
|
||||
func _on_PushedBack_state_entered() -> void:
|
||||
animation_player.play("pushed", 0.25)
|
||||
|
||||
|
||||
func _on_Dying_state_entered() -> void:
|
||||
queue_free()
|
||||
|
||||
|
||||
func _on_PushedBack_event_received(event) -> void:
|
||||
print(event)
|
||||
|
||||
|
||||
func _on_Chasing_state_physics_processing(delta) -> void:
|
||||
position.x -= chase_speed * delta
|
||||
|
||||
|
||||
func _on_PushedBack_state_physics_processing(delta) -> void:
|
||||
position.x += push_speed * delta
|
||||
|
||||
|
||||
func _on_Shooting_state_physics_processing(delta) -> void:
|
||||
if hurting and shoot_range_cast.is_colliding():
|
||||
var sg2083 := get_node(sg2083_path)
|
||||
if sg2083.has_method("hurt"):
|
||||
var distance := shoot_range_cast.to_local(shoot_range_cast.get_collision_point()).x
|
||||
var weight := inverse_lerp(shoot_range_cast.cast_to.x, 0.0, distance)
|
||||
sg2083.hurt(breath_dps * weight * delta, true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue