diff --git a/components/Bullets/Diamond.tscn b/components/Bullets/Diamond.tscn new file mode 100644 index 0000000..eaf0233 --- /dev/null +++ b/components/Bullets/Diamond.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=5 format=3 uid="uid://dbqrmirh6qi7s"] + +[ext_resource type="PackedScene" uid="uid://crtdkysmnkith" path="res://components/Abstracts/BulletBase.tscn" id="1_8udva"] +[ext_resource type="Texture2D" uid="uid://dfptmc7clhtx7" path="res://resources/bullets/diamond/frames/0.svg" id="2_txmup"] +[ext_resource type="Script" path="res://scripts/Contents/Bullets/Diamond.gd" id="2_yxtyj"] + +[sub_resource type="SpriteFrames" id="SpriteFrames_oj6iy"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": ExtResource("2_txmup") +}], +"loop": true, +"name": &"default", +"speed": 5.0 +}] + +[node name="Diamond" instance=ExtResource("1_8udva")] +script = ExtResource("2_yxtyj") +lifeDistance = 500.0 + +[node name="texture" parent="." index="0"] +sprite_frames = SubResource("SpriteFrames_oj6iy") diff --git a/components/Characters/Chick.tscn b/components/Characters/Chick.tscn index 6dd954a..1610a11 100644 --- a/components/Characters/Chick.tscn +++ b/components/Characters/Chick.tscn @@ -39,6 +39,9 @@ position = Vector2(0, -37) sprite_frames = SubResource("SpriteFrames_xji3d") animation = &"walk" +[node name="normal" type="Node2D" parent="texture/weapons" index="0"] +position = Vector2(30, -12) + [node name="movebox" parent="." index="1"] shape = SubResource("RectangleShape2D_rn84j") diff --git a/components/Characters/Hen.tscn b/components/Characters/Hen.tscn new file mode 100644 index 0000000..2dd987c --- /dev/null +++ b/components/Characters/Hen.tscn @@ -0,0 +1,5 @@ +[gd_scene load_steps=2 format=3 uid="uid://c8h1abpbe6cww"] + +[ext_resource type="PackedScene" uid="uid://cvogxi7mktumf" path="res://components/Abstracts/EntityBase.tscn" id="1_twxai"] + +[node name="EntityBase" instance=ExtResource("1_twxai")] diff --git a/components/Scenes/World.tscn b/components/Scenes/World.tscn index b3c5018..aef7ccf 100644 --- a/components/Scenes/World.tscn +++ b/components/Scenes/World.tscn @@ -16,12 +16,3 @@ position = Vector2(394, 274) [node name="chick" parent="." groups=["mobs"] instance=ExtResource("4_tnil0")] position = Vector2(644, 391) isBoss = true - -[node name="Chick" parent="." instance=ExtResource("4_tnil0")] -position = Vector2(261, 468) - -[node name="Chick2" parent="." instance=ExtResource("4_tnil0")] -position = Vector2(837, 492) - -[node name="Chick3" parent="." instance=ExtResource("4_tnil0")] -position = Vector2(897, 185) diff --git a/scripts/Contents/Bullets/Diamond.gd b/scripts/Contents/Bullets/Diamond.gd new file mode 100644 index 0000000..3fc8c59 --- /dev/null +++ b/scripts/Contents/Bullets/Diamond.gd @@ -0,0 +1,6 @@ +extends BulletBase +class_name Diamond + +func ai(): + rotation_degrees += 1 + forward(Vector2.from_angle(rotation)) diff --git a/scripts/Contents/Characters/Chick.gd b/scripts/Contents/Characters/Chick.gd index 6d28a8a..4cf4705 100644 --- a/scripts/Contents/Characters/Chick.gd +++ b/scripts/Contents/Characters/Chick.gd @@ -1,6 +1,17 @@ extends EntityBase class_name Chick +var angle = 0 func _ready(): fields[FieldStore.Entity.MAX_HEALTH] = 1000 + fields[FieldStore.Entity.MOVEMENT_SPEED] = 0.25 super._ready() + +func ai(): + move(currentFocusedBoss.position - position) + if tryAttack(0): + angle += 20 +func attack(type): + if type == 0: + var weaponPos = findWeaponAnchor("normal") + BulletBase.generate(preload("res://components/Bullets/Diamond.tscn"), self, weaponPos, deg_to_rad(angle)) diff --git a/scripts/Contents/Characters/Rooster.gd b/scripts/Contents/Characters/Rooster.gd index 37dd123..55f2fc7 100644 --- a/scripts/Contents/Characters/Rooster.gd +++ b/scripts/Contents/Characters/Rooster.gd @@ -22,4 +22,4 @@ func sprint(): move(Vector2( Input.get_axis("m_left", "m_right"), Input.get_axis("m_up", "m_down") - ) * 6, true) + ) * 8, true) diff --git a/scripts/Statemachine/BossBar.gd b/scripts/Statemachine/BossBar.gd index 7783e31..2e2a43c 100644 --- a/scripts/Statemachine/BossBar.gd +++ b/scripts/Statemachine/BossBar.gd @@ -6,6 +6,6 @@ class_name BossBar func _process(delta): super._process(delta) - if entity: + if is_instance_valid(entity): nameLabel.text = entity.displayName valueLabel.text = "%.2f" % (entity.health / entity.fields[FieldStore.Entity.MAX_HEALTH] * 100) diff --git a/scripts/Statemachine/BulletBase.gd b/scripts/Statemachine/BulletBase.gd index 64cab05..b7d5178 100644 --- a/scripts/Statemachine/BulletBase.gd +++ b/scripts/Statemachine/BulletBase.gd @@ -31,7 +31,7 @@ func hit(target: Node): var entity: EntityBase = EntityTool.fromHurtbox(target) if !entity || !launcher: return if entity == launcher: return - if GameRule.allowFriendlyFire: + if !GameRule.allowFriendlyFire: if entity.isPlayer() == launcher.isPlayer(): return entity.takeDamage(self, MathTool.rate(launcher.fields.get(FieldStore.Entity.CRIT_RATE))) if !MathTool.rate(fullPenerate()): diff --git a/scripts/Statemachine/EntityBase.gd b/scripts/Statemachine/EntityBase.gd index 18b558c..e3d4675 100644 --- a/scripts/Statemachine/EntityBase.gd +++ b/scripts/Statemachine/EntityBase.gd @@ -30,6 +30,8 @@ var sprinting: bool = false func _ready(): health = fields.get(FieldStore.Entity.MAX_HEALTH) statebar.visible = !isBoss + if !isPlayer(): + currentFocusedBoss = get_tree().get_nodes_in_group("players")[0] func _process(_delta): health = clamp(health, 0, fields.get(FieldStore.Entity.MAX_HEALTH)) animatree.set("parameters/blend_position", lerpf(animatree.get("parameters/blend_position"), lastDirection, 0.1)) @@ -40,7 +42,8 @@ func _physics_process(_delta: float) -> void: sprinting = false else: velocity = Vector2.ZERO - ai() + if isPlayer() or is_instance_valid(currentFocusedBoss): + ai() move_and_slide() # 通用方法 @@ -70,8 +73,10 @@ func startCooldown(): lastAttack = Time.get_ticks_msec() return state func tryAttack(type: int): - if startCooldown(): + var state = startCooldown() + if state: attack(type) + return state func trySprint(): sprint() sprinting = true diff --git a/scripts/Statemachine/EntityStateBar.gd b/scripts/Statemachine/EntityStateBar.gd index 5d85233..abcec42 100644 --- a/scripts/Statemachine/EntityStateBar.gd +++ b/scripts/Statemachine/EntityStateBar.gd @@ -6,6 +6,6 @@ class_name EntityStateBar @onready var healthBar: ColorBar = $"%health" func _process(_delta): - if entity: + if is_instance_valid(entity): healthBar.maxValue = entity.fields.get(FieldStore.Entity.MAX_HEALTH) healthBar.setCurrent(entity.health)