Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4afdec6

Browse files
author
godotg
committedOct 30, 2022
feat[attack]: 加速状态可以击败敌人
1 parent 9777b68 commit 4afdec6

File tree

7 files changed

+54
-8
lines changed

7 files changed

+54
-8
lines changed
 

‎audio/attack.wav

78.8 KB
Binary file not shown.

‎audio/attack.wav.import

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[remap]
2+
3+
importer="wav"
4+
type="AudioStreamWAV"
5+
uid="uid://bewq0uli37q2f"
6+
path="res://.godot/imported/attack.wav-0a120458dbbfd5bc2f7af07d7d5e4f3b.sample"
7+
8+
[deps]
9+
10+
source_file="res://audio/attack.wav"
11+
dest_files=["res://.godot/imported/attack.wav-0a120458dbbfd5bc2f7af07d7d5e4f3b.sample"]
12+
13+
[params]
14+
15+
force/8_bit=false
16+
force/mono=false
17+
force/max_rate=false
18+
force/max_rate_hz=44100
19+
edit/trim=false
20+
edit/normalize=false
21+
edit/loop_mode=0
22+
edit/loop_begin=0
23+
edit/loop_end=-1
24+
compress/mode=0

‎scene/Bird.tscn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=24 format=3 uid="uid://d34k8bhduppp8"]
1+
[gd_scene load_steps=25 format=3 uid="uid://d34k8bhduppp8"]
22

33
[ext_resource type="Script" path="res://script/Bird.gd" id="1_fpmxp"]
44
[ext_resource type="Texture2D" uid="uid://dynec8127lrcn" path="res://image/bird1_0.png" id="1_fqmow"]
@@ -19,6 +19,7 @@
1919
[ext_resource type="AudioStream" uid="uid://dcgu70sdjetco" path="res://audio/point.wav" id="14_w50nl"]
2020
[ext_resource type="AudioStream" uid="uid://bj8hn31xs4f0c" path="res://audio/hp.wav" id="15_yjfpb"]
2121
[ext_resource type="AudioStream" uid="uid://31i6ke7t7jxp" path="res://audio/speedup.wav" id="19_87ta0"]
22+
[ext_resource type="AudioStream" uid="uid://bewq0uli37q2f" path="res://audio/attack.wav" id="19_bmpo8"]
2223
[ext_resource type="AudioStream" uid="uid://c2qyhqm77o3rs" path="res://audio/speedup_end.wav" id="20_ivxwe"]
2324

2425
[sub_resource type="SpriteFrames" id="SpriteFrames_1pjba"]
@@ -82,6 +83,9 @@ stream = ExtResource("14_w50nl")
8283
[node name="hp" type="AudioStreamPlayer" parent="."]
8384
stream = ExtResource("15_yjfpb")
8485

86+
[node name="attack" type="AudioStreamPlayer" parent="."]
87+
stream = ExtResource("19_bmpo8")
88+
8589
[node name="speedup" type="AudioStreamPlayer" parent="."]
8690
stream = ExtResource("19_87ta0")
8791

‎scene/effect/EffectAttack.tscn

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,24 @@ func _ready():
1414
pass
1515

1616

17-
func onAnimationFinished():
17+
func onAnimationFinished(anim_name):
1818
animationPlayer.stop()
19-
animationPlayer.queue_free()
19+
queue_free()
2020
pass
2121
"
2222

2323
[sub_resource type="Animation" id="Animation_xx315"]
24-
length = 0.001
2524
tracks/0/type = "value"
2625
tracks/0/imported = false
2726
tracks/0/enabled = true
2827
tracks/0/path = NodePath("Sprite2D:frame")
2928
tracks/0/interp = 1
3029
tracks/0/loop_wrap = true
3130
tracks/0/keys = {
32-
"times": PackedFloat32Array(0),
33-
"transitions": PackedFloat32Array(1),
31+
"times": PackedFloat32Array(0, 0.001, 0.08, 0.16, 0.24, 0.3, 0.36, 0.42, 0.48, 0.54, 0.6, 0.66, 0.72, 0.8, 0.86, 0.92, 1),
32+
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
3433
"update": 1,
35-
"values": [15]
34+
"values": [15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
3635
}
3736

3837
[sub_resource type="Animation" id="Animation_d5f2h"]

‎script/Bird.gd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ var screen_size
2121

2222
var isSpeedUp = false
2323

24+
var lastLinearVelocity: Vector2
25+
2426
signal hpChangedEvent(oldHp: int, hp: int)
27+
signal attackEvent(other_body)
2528

2629
@onready var animated: AnimatedSprite2D = $AnimatedSprite2d
2730
@onready var speedTimer: Timer = $Timer
@@ -33,6 +36,7 @@ func _ready():
3336
set_linear_velocity(Vector2(speed, 0))
3437
set_linear_damp(0)
3538
set_gravity_scale(Common.birdGravityScale())
39+
lastLinearVelocity = get_linear_velocity()
3640

3741
set_contact_monitor(true)
3842
set_max_contacts_reported(1)
@@ -64,6 +68,8 @@ func _process(delta):
6468
cameraOffset = clamp(cameraOffset + cameraMoveSpeed * delta, cameraInitOffset, cameraSpeedUpOffset)
6569
else:
6670
cameraOffset = clampf(cameraOffset - cameraMoveSpeed * delta, cameraInitOffset, cameraSpeedUpOffset)
71+
72+
lastLinearVelocity = get_linear_velocity()
6773
pass
6874

6975
func _input(event):
@@ -106,6 +112,10 @@ func fly():
106112

107113
func on_body_entered_event(other_body):
108114
if (isSpeedUp):
115+
if (other_body is AnimatableBody2D):
116+
emit_signal("attackEvent", other_body)
117+
$attack.play()
118+
set_linear_velocity(lastLinearVelocity)
109119
return
110120
var oldHp = hp
111121
$hit.play()

‎script/Game.gd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var godotResourcesTimerMap: Dictionary = {}
2828
func _ready():
2929
$ParallaxBackground/ParallaxLayer/Background.texture = Main.currentBackground
3030
bird.hpChangedEvent.connect(onHpChangedEvent)
31+
bird.attackEvent.connect(onAttackEvent)
3132
changeHp(bird.hp)
3233
# 以当前小鸟的位置,每隔pipeInterval间距生成水管
3334
for i in range(30):
@@ -110,6 +111,14 @@ func onHpChangedEvent(oldHp: int, hp: int):
110111
changeHp(bird.hp)
111112
pass
112113

114+
115+
func onAttackEvent(other_body):
116+
var effectAttack = preload("res://scene/effect/EffectAttack.tscn").instantiate()
117+
effectAttack.position = bird.position
118+
add_child(effectAttack)
119+
other_body.queue_free()
120+
pass
121+
113122

114123
# 吃血包加血量
115124
func onHpItemEntered(node: Node2D, other_body):

‎script/effect/EffectHit.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ func _ready():
1010

1111
func onAnimationFinished():
1212
animatedSprite2D.stop()
13-
animatedSprite2D.queue_free()
13+
queue_free()
1414
pass

0 commit comments

Comments
 (0)
Please sign in to comment.