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)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,17 +1,19 @@
|
|||
extends Node2D
|
||||
|
||||
|
||||
enum State {STAND, FORWARD, BACK, DUCK, BEAM}
|
||||
enum State {STAND, FORWARD, BACK, DUCK, BEAM, DEAD}
|
||||
|
||||
const Bullet = preload("res://objects/enemy/2600_bullet.tscn")
|
||||
const SmallExplosion = preload("res://objects/enemy/boss/2600_small_explosion.tscn")
|
||||
|
||||
|
||||
export var hp: float = 100.0
|
||||
export var shot_speed: float = 50.0
|
||||
export var move_speed: float = 30.0
|
||||
export var safe_from_breath: bool = false
|
||||
export var make_explosions: bool = false
|
||||
export var explosion_rect: Rect2
|
||||
export var famira_path: NodePath
|
||||
|
||||
|
||||
var state: int = State.STAND
|
||||
|
@ -24,6 +26,8 @@ onready var head_sprite = $"%Head"
|
|||
|
||||
func _physics_process(delta: float) -> void:
|
||||
match state:
|
||||
State.DEAD:
|
||||
return
|
||||
State.STAND:
|
||||
if Input.is_action_pressed("move_down"):
|
||||
state = State.DUCK
|
||||
|
@ -44,17 +48,16 @@ func _physics_process(delta: float) -> void:
|
|||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
|
||||
if state == State.DEAD:
|
||||
return
|
||||
if event.is_action_pressed("shoot") and (state == State.STAND or state == State.FORWARD or state == State.BACK):
|
||||
shoot()
|
||||
if event.is_action_pressed("jump") and state == State.STAND:
|
||||
beam()
|
||||
if event.is_action_pressed("move_up"):
|
||||
anims.play("die")
|
||||
|
||||
|
||||
func shoot() -> void:
|
||||
Audio.play_sound(Audio.a_bullet_barrage,Audio.ac_boss)
|
||||
Audio.play_sound(Audio.a_bullet_barrage,Audio.ac_collectible)
|
||||
for pos in bullet_positions.get_children():
|
||||
var bullet = Bullet.instance()
|
||||
bullet.global_position = pos.global_position
|
||||
|
@ -68,18 +71,32 @@ func beam() -> void:
|
|||
anims.play("Beam")
|
||||
|
||||
|
||||
func hurt(amount: float, can_duck: bool = false) -> void:
|
||||
if can_duck and state == State.DUCK:
|
||||
return
|
||||
hp -= amount
|
||||
if state != State.DEAD and hp <= 0.0:
|
||||
state = State.DEAD
|
||||
anims.play("die")
|
||||
|
||||
|
||||
func _play_laser_sound(play: bool):
|
||||
var famira = get_node(famira_path)
|
||||
if play:
|
||||
Audio.play_sound(Audio.a_rainbow_laser,Audio.ac_boss)
|
||||
if famira.has_method("start_push"):
|
||||
famira.start_push()
|
||||
Audio.play_sound(Audio.a_rainbow_laser,Audio.ac_collectible)
|
||||
else:
|
||||
Audio.ac_boss.playing = false
|
||||
if famira.has_method("stop_push"):
|
||||
famira.stop_push()
|
||||
Audio.ac_collectible.playing = false
|
||||
|
||||
|
||||
func _play_charge_sound(play: bool):
|
||||
if play:
|
||||
Audio.play_sound(Audio.a_2600_charge,Audio.ac_boss)
|
||||
Audio.play_sound(Audio.a_2600_charge,Audio.ac_collectible)
|
||||
else:
|
||||
Audio.ac_boss.playing = false
|
||||
Audio.ac_collectible.playing = false
|
||||
|
||||
|
||||
func _spawn_explosions() -> void:
|
||||
|
@ -106,3 +123,5 @@ func _on_animation_finished(anim_name: String) -> void:
|
|||
state = State.STAND
|
||||
"Beam":
|
||||
state = State.STAND
|
||||
"die":
|
||||
pass
|
||||
|
|
|
@ -1292,7 +1292,7 @@ tracks/1/keys = {
|
|||
}
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=26]
|
||||
extents = Vector2( 33.5, 76 )
|
||||
extents = Vector2( 42, 76 )
|
||||
|
||||
[node name="2083" type="Node2D"]
|
||||
z_index = 5
|
||||
|
@ -1644,7 +1644,7 @@ collision_mask = 0
|
|||
monitoring = false
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="DetectionBox"]
|
||||
position = Vector2( 53.5, 92 )
|
||||
position = Vector2( 62, 92 )
|
||||
shape = SubResource( 26 )
|
||||
|
||||
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_finished"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue