Added player attack
This commit is contained in:
@@ -15,3 +15,4 @@ export_presets.cfg
|
|||||||
data_*/
|
data_*/
|
||||||
mono_crash.*.json
|
mono_crash.*.json
|
||||||
|
|
||||||
|
export
|
||||||
|
|||||||
@@ -43,8 +43,10 @@ var _current_health: = MAX_HEALTH:
|
|||||||
|
|
||||||
@onready var player_sprite : AnimatedSprite2D = $PlayerSprite
|
@onready var player_sprite : AnimatedSprite2D = $PlayerSprite
|
||||||
@onready var blade_sprite : AnimatedSprite2D = $BladeSprite
|
@onready var blade_sprite : AnimatedSprite2D = $BladeSprite
|
||||||
@onready var attack_left_sprite : AnimatedSprite2D = $AttackLeftSprite
|
@onready var left_attack_sprite : AnimatedSprite2D = $LeftAttackSprite
|
||||||
@onready var attack_right_sprite : AnimatedSprite2D = $AttackRightSprite
|
@onready var right_attack_sprite : AnimatedSprite2D = $RightAttackSprite
|
||||||
|
@onready var left_attack_area : Area2D = $LeftAttackArea
|
||||||
|
@onready var right_attack_area : Area2D = $RightAttackArea
|
||||||
|
|
||||||
@onready var camera : Camera2D = $Camera2D
|
@onready var camera : Camera2D = $Camera2D
|
||||||
@onready var state_machine : StateMachine = $StateMachine
|
@onready var state_machine : StateMachine = $StateMachine
|
||||||
@@ -55,6 +57,7 @@ var _current_health: = MAX_HEALTH:
|
|||||||
@onready var wall_coyote_time_timer : Timer = $WallCoyoteTimeTimer
|
@onready var wall_coyote_time_timer : Timer = $WallCoyoteTimeTimer
|
||||||
|
|
||||||
@onready var wall_attach_timer : Timer = $WallAttachTimer
|
@onready var wall_attach_timer : Timer = $WallAttachTimer
|
||||||
|
@onready var attack_buffer_timer : Timer = $AttackBufferTimer
|
||||||
@onready var attack_cooldown_timer : Timer = $AttackCooldownTimer
|
@onready var attack_cooldown_timer : Timer = $AttackCooldownTimer
|
||||||
|
|
||||||
@onready var wall_left_particles : GPUParticles2D = $WallLeftParticles
|
@onready var wall_left_particles : GPUParticles2D = $WallLeftParticles
|
||||||
@@ -66,7 +69,7 @@ var _current_health: = MAX_HEALTH:
|
|||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
state_machine.init()
|
state_machine.init()
|
||||||
|
|
||||||
for sprite : AnimatedSprite2D in [ attack_left_sprite, attack_right_sprite ]:
|
for sprite : AnimatedSprite2D in [ left_attack_sprite, right_attack_sprite ]:
|
||||||
var lambda := func() -> void:
|
var lambda := func() -> void:
|
||||||
sprite.hide()
|
sprite.hide()
|
||||||
if not is_zero_approx(velocity.x):
|
if not is_zero_approx(velocity.x):
|
||||||
@@ -75,7 +78,7 @@ func _ready() -> void:
|
|||||||
sprite.hide()
|
sprite.hide()
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
if is_on_floor():
|
if is_on_floor():
|
||||||
floor_coyote_time_timer.start()
|
floor_coyote_time_timer.start()
|
||||||
_last_wall_normal = 0.0
|
_last_wall_normal = 0.0
|
||||||
@@ -120,22 +123,27 @@ func _physics_process(delta: float) -> void:
|
|||||||
wall_coyote_time_timer.stop()
|
wall_coyote_time_timer.stop()
|
||||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_wall_jump, global_position)
|
SoundManager.play_sfx_stream(SoundManager.sfx_stream_wall_jump, global_position)
|
||||||
|
|
||||||
|
|
||||||
if input_direction:
|
if input_direction:
|
||||||
var input_velocity := input_direction * _max_speed
|
var input_velocity := input_direction * _max_speed
|
||||||
velocity.x = move_toward(velocity.x, input_velocity, move_acceleration * delta)
|
velocity.x = move_toward(velocity.x, input_velocity, move_acceleration * delta)
|
||||||
else:
|
else:
|
||||||
velocity.x = move_toward(velocity.x, 0, move_acceleration * delta)
|
velocity.x = move_toward(velocity.x, 0, move_acceleration * delta)
|
||||||
|
|
||||||
|
if not attack_buffer_timer.is_stopped():
|
||||||
|
if _can_attack():
|
||||||
|
_attack()
|
||||||
|
attack_buffer_timer.stop()
|
||||||
|
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
state_machine.physics_process(delta)
|
state_machine.physics_process(delta)
|
||||||
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
if event.is_action_pressed("attack"):
|
if event.is_action_pressed("attack"):
|
||||||
if not _slow_down_tween or not _slow_down_tween.is_running():
|
if _can_attack():
|
||||||
if not is_on_wall() and not is_on_floor() or not is_zero_approx(velocity.x):
|
_attack()
|
||||||
_attack()
|
else:
|
||||||
|
attack_buffer_timer.start()
|
||||||
|
|
||||||
|
|
||||||
func deal_damage(value: float) -> void:
|
func deal_damage(value: float) -> void:
|
||||||
@@ -145,15 +153,41 @@ func deal_damage(value: float) -> void:
|
|||||||
dead.emit()
|
dead.emit()
|
||||||
|
|
||||||
|
|
||||||
|
func _can_attack() -> bool:
|
||||||
|
if not attack_cooldown_timer.is_stopped():
|
||||||
|
return false
|
||||||
|
if is_on_wall() and is_on_floor() or is_zero_approx(velocity.x):
|
||||||
|
return false
|
||||||
|
return true
|
||||||
|
|
||||||
|
|
||||||
func _attack() -> void:
|
func _attack() -> void:
|
||||||
var sprite := attack_left_sprite if velocity.x <= 0.0 else attack_right_sprite
|
attack_cooldown_timer.start()
|
||||||
|
var is_left := velocity.x <= 0.0
|
||||||
|
var sprite := left_attack_sprite if is_left else right_attack_sprite
|
||||||
|
var attack_area := left_attack_area if is_left else right_attack_area
|
||||||
sprite.show()
|
sprite.show()
|
||||||
|
attack_area.monitoring = true
|
||||||
blade_sprite.hide()
|
blade_sprite.hide()
|
||||||
sprite.play("attack")
|
sprite.play("attack")
|
||||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_swing, global_position)
|
SoundManager.play_sfx_stream(SoundManager.sfx_stream_swing, global_position)
|
||||||
|
|
||||||
|
_max_speed = move_max_speed_normal
|
||||||
_slow_down_tween = create_tween()
|
_slow_down_tween = create_tween()
|
||||||
_slow_down_tween.tween_property(self, "_max_speed", move_max_speed_slowed, slow_down_attack)
|
_slow_down_tween.tween_property(self, "_max_speed", move_max_speed_slowed, slow_down_attack)
|
||||||
_slow_down_tween.tween_property(self, "_max_speed", move_max_speed_slowed, slow_down_sustain)
|
_slow_down_tween.tween_property(self, "_max_speed", move_max_speed_slowed, slow_down_sustain)
|
||||||
_slow_down_tween.tween_property(self, "_max_speed", move_max_speed_normal, slow_down_release)
|
_slow_down_tween.tween_property(self, "_max_speed", move_max_speed_normal, slow_down_release)
|
||||||
_slow_down_tween.tween_property(sprite, "visible", false, 0.0)
|
_slow_down_tween.tween_property(sprite, "visible", false, 0.0)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_attack_area_entered(area: Area2D) -> void:
|
||||||
|
if area is TurretProjectile:
|
||||||
|
area.queue_free()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_left_attack_sprite_animation_finished() -> void:
|
||||||
|
left_attack_area.monitoring = false
|
||||||
|
|
||||||
|
|
||||||
|
func _on_right_attack_sprite_animation_finished() -> void:
|
||||||
|
right_attack_area.monitoring = false
|
||||||
|
|||||||
@@ -524,6 +524,10 @@ animations = [{
|
|||||||
"speed": 20.0
|
"speed": 20.0
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_riqys"]
|
||||||
|
radius = 8.0
|
||||||
|
height = 24.0
|
||||||
|
|
||||||
[sub_resource type="Gradient" id="Gradient_qr0ht"]
|
[sub_resource type="Gradient" id="Gradient_qr0ht"]
|
||||||
interpolation_mode = 1
|
interpolation_mode = 1
|
||||||
colors = PackedColorArray(0.99215686, 0.99607843, 0.5372549, 1, 1, 0.7529412, 0.46666667, 1)
|
colors = PackedColorArray(0.99215686, 0.99607843, 0.5372549, 1, 1, 0.7529412, 0.46666667, 1)
|
||||||
@@ -558,15 +562,37 @@ position = Vector2(0, 8)
|
|||||||
sprite_frames = SubResource("SpriteFrames_riqys")
|
sprite_frames = SubResource("SpriteFrames_riqys")
|
||||||
animation = &"jump_right"
|
animation = &"jump_right"
|
||||||
|
|
||||||
[node name="AttackLeftSprite" type="AnimatedSprite2D" parent="." unique_id=444979654]
|
[node name="LeftAttackSprite" type="AnimatedSprite2D" parent="." unique_id=444979654]
|
||||||
position = Vector2(-16, 0)
|
position = Vector2(-16, 0)
|
||||||
sprite_frames = SubResource("SpriteFrames_sn0t7")
|
sprite_frames = SubResource("SpriteFrames_sn0t7")
|
||||||
animation = &"attack"
|
animation = &"attack"
|
||||||
|
frame = 5
|
||||||
|
frame_progress = 1.0
|
||||||
|
|
||||||
[node name="AttackRightSprite" type="AnimatedSprite2D" parent="." unique_id=864909741]
|
[node name="RightAttackSprite" type="AnimatedSprite2D" parent="." unique_id=864909741]
|
||||||
position = Vector2(16, 0)
|
position = Vector2(16, 0)
|
||||||
sprite_frames = SubResource("SpriteFrames_i4f54")
|
sprite_frames = SubResource("SpriteFrames_i4f54")
|
||||||
animation = &"attack"
|
animation = &"attack"
|
||||||
|
frame = 5
|
||||||
|
frame_progress = 1.0
|
||||||
|
|
||||||
|
[node name="LeftAttackArea" type="Area2D" parent="." unique_id=829956444]
|
||||||
|
position = Vector2(-20, 0)
|
||||||
|
collision_layer = 16
|
||||||
|
collision_mask = 8
|
||||||
|
monitoring = false
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="LeftAttackArea" unique_id=1938609000]
|
||||||
|
shape = SubResource("CapsuleShape2D_riqys")
|
||||||
|
|
||||||
|
[node name="RightAttackArea" type="Area2D" parent="." unique_id=1656556085]
|
||||||
|
position = Vector2(20, 0)
|
||||||
|
collision_layer = 16
|
||||||
|
collision_mask = 8
|
||||||
|
monitoring = false
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="RightAttackArea" unique_id=1463315605]
|
||||||
|
shape = SubResource("CapsuleShape2D_riqys")
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="." unique_id=1654451713]
|
[node name="Camera2D" type="Camera2D" parent="." unique_id=1654451713]
|
||||||
limit_bottom = 0
|
limit_bottom = 0
|
||||||
@@ -649,9 +675,13 @@ process_callback = 0
|
|||||||
wait_time = 0.5
|
wait_time = 0.5
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
|
||||||
|
[node name="AttackBufferTimer" type="Timer" parent="." unique_id=718116108]
|
||||||
|
wait_time = 0.5
|
||||||
|
|
||||||
[node name="AttackCooldownTimer" type="Timer" parent="." unique_id=1208896947]
|
[node name="AttackCooldownTimer" type="Timer" parent="." unique_id=1208896947]
|
||||||
process_callback = 0
|
process_callback = 0
|
||||||
wait_time = 0.75
|
wait_time = 0.5
|
||||||
|
one_shot = true
|
||||||
|
|
||||||
[node name="WallLeftParticles" type="GPUParticles2D" parent="." unique_id=2009522894]
|
[node name="WallLeftParticles" type="GPUParticles2D" parent="." unique_id=2009522894]
|
||||||
position = Vector2(-4, 4)
|
position = Vector2(-4, 4)
|
||||||
@@ -667,3 +697,8 @@ emitting = false
|
|||||||
amount = 32
|
amount = 32
|
||||||
lifetime = 0.5
|
lifetime = 0.5
|
||||||
process_material = SubResource("ParticleProcessMaterial_bhunq")
|
process_material = SubResource("ParticleProcessMaterial_bhunq")
|
||||||
|
|
||||||
|
[connection signal="animation_finished" from="LeftAttackSprite" to="." method="_on_left_attack_sprite_animation_finished"]
|
||||||
|
[connection signal="animation_finished" from="RightAttackSprite" to="." method="_on_right_attack_sprite_animation_finished"]
|
||||||
|
[connection signal="area_entered" from="LeftAttackArea" to="." method="_on_attack_area_entered"]
|
||||||
|
[connection signal="area_entered" from="RightAttackArea" to="." method="_on_attack_area_entered"]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class_name TurretProjectile
|
class_name TurretProjectile
|
||||||
extends Node2D
|
extends Area2D
|
||||||
|
|
||||||
|
|
||||||
const SPEED = 300
|
const SPEED = 300
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
[ext_resource type="Script" uid="uid://boedoah7a3ew3" path="res://game/entities/turret/turret_projectile.gd" id="1_6obn6"]
|
[ext_resource type="Script" uid="uid://boedoah7a3ew3" path="res://game/entities/turret/turret_projectile.gd" id="1_6obn6"]
|
||||||
[ext_resource type="Texture2D" uid="uid://domd2gwquuiec" path="res://images/entities/turret_projectile.png" id="2_kmlbp"]
|
[ext_resource type="Texture2D" uid="uid://domd2gwquuiec" path="res://images/entities/turret_projectile.png" id="2_kmlbp"]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_bhunq"]
|
||||||
|
radius = 4.0
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_4stq6"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_4stq6"]
|
||||||
atlas = ExtResource("2_kmlbp")
|
atlas = ExtResource("2_kmlbp")
|
||||||
region = Rect2(0, 0, 16, 16)
|
region = Rect2(0, 0, 16, 16)
|
||||||
@@ -123,9 +126,6 @@ animations = [{
|
|||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}]
|
}]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_bhunq"]
|
|
||||||
radius = 4.0
|
|
||||||
|
|
||||||
[sub_resource type="Gradient" id="Gradient_kmlbp"]
|
[sub_resource type="Gradient" id="Gradient_kmlbp"]
|
||||||
interpolation_mode = 1
|
interpolation_mode = 1
|
||||||
offsets = PackedFloat32Array(0, 0.2, 0.4, 0.6, 0.8)
|
offsets = PackedFloat32Array(0, 0.2, 0.4, 0.6, 0.8)
|
||||||
@@ -146,21 +146,19 @@ scale_min = 2.0
|
|||||||
scale_max = 2.0
|
scale_max = 2.0
|
||||||
color_ramp = SubResource("GradientTexture1D_sn0t7")
|
color_ramp = SubResource("GradientTexture1D_sn0t7")
|
||||||
|
|
||||||
[node name="TurretProjectile" type="Node2D" unique_id=740761191]
|
[node name="TurretProjectile" type="Area2D" unique_id=978959486]
|
||||||
z_index = -5
|
z_index = -5
|
||||||
|
collision_layer = 8
|
||||||
|
collision_mask = 3
|
||||||
script = ExtResource("1_6obn6")
|
script = ExtResource("1_6obn6")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1265333400]
|
||||||
|
shape = SubResource("CircleShape2D_bhunq")
|
||||||
|
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1667166835]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1667166835]
|
||||||
sprite_frames = SubResource("SpriteFrames_bhunq")
|
sprite_frames = SubResource("SpriteFrames_bhunq")
|
||||||
animation = &"wobble"
|
animation = &"wobble"
|
||||||
|
|
||||||
[node name="Area2D" type="Area2D" parent="." unique_id=658518046]
|
|
||||||
collision_layer = 8
|
|
||||||
collision_mask = 3
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D" unique_id=1265333400]
|
|
||||||
shape = SubResource("CircleShape2D_bhunq")
|
|
||||||
|
|
||||||
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="." unique_id=1219726055]
|
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="." unique_id=1219726055]
|
||||||
rect = Rect2(-100, -100, 200, 200)
|
rect = Rect2(-100, -100, 200, 200)
|
||||||
|
|
||||||
@@ -169,6 +167,6 @@ amount = 16
|
|||||||
lifetime = 0.2
|
lifetime = 0.2
|
||||||
process_material = SubResource("ParticleProcessMaterial_riqys")
|
process_material = SubResource("ParticleProcessMaterial_riqys")
|
||||||
|
|
||||||
[connection signal="body_entered" from="Area2D" to="." method="_on_body_entered"]
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||||
[connection signal="screen_entered" from="VisibleOnScreenNotifier2D" to="." method="_on_screen_entered"]
|
[connection signal="screen_entered" from="VisibleOnScreenNotifier2D" to="." method="_on_screen_entered"]
|
||||||
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_screen_exited"]
|
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_screen_exited"]
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ text = "MASTER"
|
|||||||
|
|
||||||
[node name="MasterSlider" type="HSlider" parent="MarginContainer/VBoxContainer/GridContainer" unique_id=1600615574]
|
[node name="MasterSlider" type="HSlider" parent="MarginContainer/VBoxContainer/GridContainer" unique_id=1600615574]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(200, 0)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 4
|
size_flags_vertical = 4
|
||||||
step = 10.0
|
step = 10.0
|
||||||
@@ -111,6 +112,7 @@ text = "UI"
|
|||||||
|
|
||||||
[node name="UISlider" type="HSlider" parent="MarginContainer/VBoxContainer/GridContainer" unique_id=2094741924]
|
[node name="UISlider" type="HSlider" parent="MarginContainer/VBoxContainer/GridContainer" unique_id=2094741924]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(200, 0)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 4
|
size_flags_vertical = 4
|
||||||
step = 10.0
|
step = 10.0
|
||||||
@@ -124,6 +126,7 @@ text = "SFX"
|
|||||||
|
|
||||||
[node name="SFXSlider" type="HSlider" parent="MarginContainer/VBoxContainer/GridContainer" unique_id=630139889]
|
[node name="SFXSlider" type="HSlider" parent="MarginContainer/VBoxContainer/GridContainer" unique_id=630139889]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(200, 0)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 4
|
size_flags_vertical = 4
|
||||||
step = 10.0
|
step = 10.0
|
||||||
@@ -137,6 +140,7 @@ text = "MUSIC"
|
|||||||
|
|
||||||
[node name="MusicSlider" type="HSlider" parent="MarginContainer/VBoxContainer/GridContainer" unique_id=537100873]
|
[node name="MusicSlider" type="HSlider" parent="MarginContainer/VBoxContainer/GridContainer" unique_id=537100873]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(200, 0)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 4
|
size_flags_vertical = 4
|
||||||
step = 10.0
|
step = 10.0
|
||||||
|
|||||||
Reference in New Issue
Block a user