1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-28 06:51:54 +08:00

feat: Enhance game mechanics and structure

- Added `ColorBar` class for visual representation of values.
- Expanded `EntityBase` with new properties: `isBoss` and `weapons`, and implemented damage handling and entity generation methods.
- Updated `EntityStateBar` to use `ColorBar` for health representation.
- Introduced `BulletBase` scene and script for bullet mechanics, including damage handling and generation.
- Created `WorldTool` for managing the game world and root node.
- Implemented `EntityTool` for retrieving entities from hurtboxes.
- Added `GameRule` for managing game rules like friendly fire.
- Updated scene files to reflect new structures and added necessary resources.
This commit is contained in:
2025-08-26 11:39:47 +08:00
parent c6c16d4977
commit ef8fd0db9f
14 changed files with 254 additions and 3 deletions
+16
View File
@@ -0,0 +1,16 @@
[gd_scene load_steps=4 format=3 uid="uid://crtdkysmnkith"]
[ext_resource type="Script" path="res://scripts/Statemachine/BulletBase.gd" id="1_pklpq"]
[sub_resource type="SpriteFrames" id="SpriteFrames_vypy3"]
[sub_resource type="CircleShape2D" id="CircleShape2D_ecl7m"]
[node name="BulletBase" type="Area2D"]
script = ExtResource("1_pklpq")
[node name="texture" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_vypy3")
[node name="hitbox" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_ecl7m")
+26
View File
@@ -0,0 +1,26 @@
[gd_scene load_steps=5 format=3 uid="uid://uj0aqhm8wgy8"]
[ext_resource type="PackedScene" uid="uid://crtdkysmnkith" path="res://components/Abstracts/BulletBase.tscn" id="1_45mh7"]
[ext_resource type="Texture2D" uid="uid://c7hyatbuieaj" path="res://resources/bullets/purple-crystal/frames/0.svg" id="2_ca3pq"]
[sub_resource type="SpriteFrames" id="SpriteFrames_r86b3"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("2_ca3pq")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}]
[sub_resource type="CircleShape2D" id="CircleShape2D_ty1as"]
[node name="PurpleCrystal" instance=ExtResource("1_45mh7")]
[node name="texture" parent="." index="0"]
sprite_frames = SubResource("SpriteFrames_r86b3")
[node name="hitbox" parent="." index="1"]
position = Vector2(0, -13)
shape = SubResource("CircleShape2D_ty1as")
+25
View File
@@ -0,0 +1,25 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="25" height="22.05604362487793" viewBox="2.5 4.043956756591797 25 22.05604362487793" version="1.1" xml:space="preserve">
<!-- Generator: Sketch 49.3 (51167) - http://www.bohemiancoding.com/sketch -->
<defs/>
<g>
<title>crystal-a</title>
<desc>Created with Sketch.</desc>
<g id="crystal-a" fill-rule="evenodd">
<g id="Blue-Crystal" fill-rule="nonzero">
<path d="M 3 12.3 C 3 12.3 5.9 7.1 10 5.6 C 10 5.6 17.9 3.8 20.5 4.9 C 20.5 4.9 25.7 8.5 27 10.5 C 27 10.5 20 23.5 16.7 25.5 C 16.7 25.6 4.3 17.7 3 12.3 Z " id="Shape" fill="#7FCCEF" stroke-width="1" stroke="none"/>
<path d="M 27 10.5 C 26.8 10.2 26.5 9.8 26.1 9.5 L 20.6 12.9 L 15.8 18.7 L 16.7 25.6 C 20.1 23.5 27 10.5 27 10.5 Z " id="Shape" fill="#678FE4" stroke-width="1" stroke="none"/>
<path d="M 11.3 13.9 C 11.3 13.9 13.8 22.6 16.7 25.6 C 16.7 25.6 20.4 16.1 20.6 12.9 L 13.8 9.7 L 11.3 13.9 Z " id="Shape" fill="#73B5E4" stroke-width="1" stroke="none"/>
<path d="M 20.5 4.9 C 17.8 3.8 10 5.6 10 5.6 C 6 7.2 3 12.3 3 12.3 C 3 12.3 9.5 13.9 11.3 13.9 C 11.3 13.9 17 14 20.6 12.9 C 23 12.2 24.5 11.9 27 10.5 C 25.7 8.5 20.5 4.9 20.5 4.9 Z " id="Shape" fill="#92D7EF" stroke-width="1" stroke="none"/>
<path d="M 17.2 4.6 C 15.8 4.7 14.3 4.8 13 5.1 L 11.8 7.5 L 11.4 14 C 11.4 14 17.1 14.1 20.7 13 L 18 6.9 L 17.2 4.6 Z " id="Shape" fill="#7FCCEF" stroke-width="1" stroke="none"/>
<path d="M 11.2 9.6 C 10.4 9.6 6.2 10.9 3.3 11.8 C 3.1 12.1 3 12.3 3 12.3 C 3 12.3 9.5 13.9 11.3 13.9 C 11.3 13.9 17 14 20.6 12.9 C 23 12.2 24.5 11.9 27 10.5 C 26.9 10.4 26.9 10.3 26.8 10.2 C 24.4 9.7 20.2 8.8 19.7 8.8 C 19 8.9 12.4 9.6 11.2 9.6 Z " id="Shape" fill="#83CDEF" stroke-width="1" stroke="none"/>
<path d="M 11.8 7.4 L 18.1 7 C 18.1 7 19.9 6.8 20.6 5 C 17.8 3.8 10 5.6 10 5.6 C 10 5.6 10.6 6.5 11.8 7.4 Z " id="Shape" fill="#BEE6F1" stroke-width="1" stroke="none"/>
<path d="M 20.5 4.9 C 20.3 4.8 20 4.7 19.7 4.7 L 18 6.9 L 20.6 12.8 C 23 12.1 24.5 11.8 27 10.4 C 25.7 8.5 20.5 4.9 20.5 4.9 Z " id="Shape" fill="#73B5E4" stroke-width="1" stroke="none"/>
<path d="M 27 10.5 C 27 10.5 26.9 10.8 26.7 11.2 C 26.5 11.7 26.2 12.3 25.9 13.1 C 25.7 13.5 25.5 13.9 25.3 14.3 C 25.1 14.7 24.8 15.2 24.5 15.7 C 24 16.6 23.3 17.6 22.7 18.6 C 22 19.5 21.3 20.5 20.7 21.3 C 20 22.1 19.4 22.9 18.8 23.5 C 17.6 24.8 16.8 25.5 16.8 25.5 C 16.8 25.5 17.6 24.6 18.6 23.3 C 19.1 22.6 19.7 21.8 20.4 21 C 21 20.1 21.7 19.2 22.4 18.3 C 23.1 17.4 23.7 16.4 24.2 15.5 C 24.8 14.6 25.3 13.7 25.7 13 C 26.1 12.3 26.5 11.6 26.7 11.2 C 26.9 10.8 27 10.5 27 10.5 Z " id="Shape" fill="#3B73E4" stroke-width="1" stroke="none"/>
<path d="M 3 12.3 C 3 12.3 3.5 12.3 4.2 12.4 C 4.9 12.5 5.8 12.6 6.7 12.8 C 7.6 13 8.5 13.2 9.2 13.4 C 9.9 13.6 10.3 13.7 10.3 13.7 C 10.3 13.7 9.8 13.8 9.1 13.7 C 8.4 13.6 7.5 13.5 6.6 13.3 C 5.7 13.1 4.8 12.9 4.1 12.7 C 3.4 12.5 3 12.3 3 12.3 Z " id="Shape" fill="#BEE6F1" stroke-width="1" stroke="none"/>
<path d="M 11.5 14.9 C 11.5 14.9 11.8 15.5 12.1 16.3 C 12.5 17.2 12.9 18.3 13.4 19.4 C 13.8 20.5 14.3 21.7 14.6 22.5 C 14.8 22.9 14.9 23.3 15.1 23.5 C 15.3 23.7 15.3 23.8 15.3 23.8 C 15.3 23.8 15.2 23.7 15 23.5 C 14.8 23.3 14.6 23 14.3 22.6 C 13.8 21.8 13.3 20.7 12.8 19.5 C 12.3 18.3 12 17.2 11.7 16.3 C 11.7 15.5 11.5 14.9 11.5 14.9 Z " id="Shape" fill="#BEE6F1" stroke-width="1" stroke="none"/>
<path d="M 18.9 8.9 L 20.6 12.9 C 23 12.2 24.5 11.9 27 10.5 C 26.9 10.4 26.9 10.3 26.8 10.2 C 24.4 9.7 20.2 8.8 19.7 8.8 C 19.6 8.9 19.3 8.9 18.9 8.9 Z " id="Shape" fill="#679FE4" stroke-width="1" stroke="none"/>
<path d="M 11.6 9.6 L 11.3 13.9 C 11.3 13.9 17 14 20.6 12.9 L 18.9 8.9 C 17.2 9.1 13.2 9.5 11.6 9.6 Z " id="Shape" fill="#7CBFEF" stroke-width="1" stroke="none"/>
</g>
</g>
</g>
</svg><!--rotationCenter:15:15-->

After

Width:  |  Height:  |  Size: 3.8 KiB

@@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dfptmc7clhtx7"
path="res://.godot/imported/0.svg-b76264cbe10324fb670faecc659cdc73.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://resources/bullets/diamond/frames/0.svg"
dest_files=["res://.godot/imported/0.svg-b76264cbe10324fb670faecc659cdc73.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
@@ -0,0 +1,27 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="19.490625381469727" height="47.29999923706055" viewBox="2.2093749046325684 0.40000003576278687 19.490625381469727 47.29999923706055" version="1.1" xml:space="preserve">
<!-- Generator: Sketch 49.3 (51167) - http://www.bohemiancoding.com/sketch -->
<defs/>
<g>
<title>crystal-b</title>
<desc>Created with Sketch.</desc>
<g id="crystal-b" fill-rule="evenodd">
<g id="Purple-Crystal" fill-rule="nonzero">
<g id="Group">
<path d="M 3.1 44.4 C 3.1 44.4 2.1 14.7 3.3 10.6 C 3.3 10.6 7.6 3.6 14.4 0.9 C 14.4 0.9 19.2 7.7 21.2 13.7 C 21.2 13.7 12 43.1 10.6 45.1 C 10.6 45.1 7.5 46.8 5.5 47 C 5.6 47.1 3.1 45.9 3.1 44.4 Z " id="Shape" fill="#8644B3" stroke-width="1" stroke="none"/>
<path d="M 3.4 10.7 C 3.4 10.7 5.6 15.8 9 17.7 L 14.4 1.1 C 7.7 3.7 3.4 10.7 3.4 10.7 Z " id="Shape" fill="#EA8BE5" stroke-width="1" stroke="none"/>
<path d="M 3.4 10.7 C 3.4 10.7 5.6 15.8 9 17.7 L 14.4 1.1 C 7.7 3.7 3.4 10.7 3.4 10.7 Z " id="Shape" fill="#EA8BE5" stroke-width="1" stroke="none"/>
<path d="M 21.2 13.8 C 19.3 7.8 14.5 1 14.5 1 C 14.5 1 14.4 1 14.4 1.1 L 8.9 17.7 C 8.9 17.7 14.7 16.5 21 14.6 C 21.2 14 21.2 13.8 21.2 13.8 Z " id="Shape" fill="#AD59C2" stroke-width="1" stroke="none"/>
<path d="M 3.4 10.7 C 2.2 14.8 3.2 44.5 3.2 44.5 C 3.2 45.9 5.6 47.2 5.6 47.2 L 9 17.8 L 3.4 10.7 Z " id="Shape" fill="#AD59C2" stroke-width="1" stroke="none"/>
<path d="M 8.9 17.7 C 8.9 17.7 8.8 19.3 8.6 21.7 C 8.5 22.9 8.3 24.3 8.2 25.8 C 8 27.3 7.9 28.9 7.7 30.4 C 7.5 32 7.3 33.6 7.1 35 C 6.9 36.5 6.7 37.9 6.6 39 C 6.2 41.3 6 42.9 6 42.9 C 6 42.9 6.1 41.3 6.3 38.9 C 6.4 37.7 6.6 36.3 6.7 34.8 C 6.9 33.3 7 31.7 7.2 30.2 C 7.4 28.6 7.6 27 7.8 25.6 C 8 24.1 8.2 22.7 8.3 21.6 C 8.7 19.2 8.9 17.7 8.9 17.7 Z " id="Shape" fill="#EA8BE5" stroke-width="1" stroke="none"/>
<path d="M 3.1 44.4 C 3.1 45.8 5.5 47.1 5.5 47.1 L 5.9 43.8 C 4.7 44.1 3.1 44.4 3.1 44.4 Z " id="Shape" fill="#A546BD" stroke-width="1" stroke="none"/>
<path d="M 7.2 43.6 C 7 43.6 6.5 43.7 5.9 43.8 L 5.5 47.1 C 7.4 46.9 10.6 45.2 10.6 45.2 C 10.6 45.2 8 43.5 7.2 43.6 Z " id="Shape" fill="#7C36AB" stroke-width="1" stroke="none"/>
<path d="M 5.6 47.1 C 6.5 46.9 7.4 46.6 8.2 46.3 C 9 46 9.8 45.6 10.5 45 L 10.4 45.1 C 11 43.1 11.7 41.1 12.4 39.1 C 13.1 37.1 13.7 35.1 14.4 33.2 C 15.8 29.2 17.2 25.3 18.7 21.4 C 17.5 25.4 16.2 29.4 14.8 33.4 C 14.1 35.4 13.4 37.4 12.8 39.3 C 12.1 41.3 11.4 43.3 10.7 45.2 C 9.9 45.7 9.1 46.1 8.2 46.4 C 7.3 46.8 6.5 47 5.6 47.1 Z " id="Shape" fill="#6B348F" stroke-width="1" stroke="none"/>
<path d="M 8.9 17.7 L 11.3 10.3 C 7.9 10.3 3.3 10.7 3.3 10.7 C 3.3 10.7 5.6 15.7 8.9 17.7 Z " id="Shape" fill="#E17DE3" stroke-width="1" stroke="none"/>
<path d="M 11.3 10.3 L 8.9 17.7 C 8.9 17.7 14.7 16.5 21 14.6 C 21.1 14.1 21.2 13.9 21.2 13.9 C 21.2 13.8 21.1 13.6 21.1 13.5 C 18.9 12.4 15.6 10.9 14.7 10.6 C 14.3 10.3 12.9 10.3 11.3 10.3 Z " id="Shape" fill="#9B4DAE" stroke-width="1" stroke="none"/>
<path d="M 21 14.5 C 21 14.5 20.4 14.8 19.6 15.1 C 18.7 15.4 17.6 15.8 16.4 16.2 C 15.2 16.5 14 16.8 13.1 17 C 12.2 17.2 11.6 17.2 11.6 17.2 C 11.6 17.2 11.7 17.2 12 17.1 C 12.3 17 12.6 16.9 13.1 16.8 C 14 16.5 15.1 16.2 16.3 15.8 C 17.5 15.5 18.7 15.1 19.6 14.9 C 20.4 14.6 21 14.5 21 14.5 Z " id="Shape" fill="#6B348F" stroke-width="1" stroke="none"/>
</g>
<path d="M 14.4 1.1 C 14.4 1.1 14.2 1.9 13.9 3.1 C 13.6 4.3 13.1 5.9 12.6 7.5 C 12.1 9.1 11.5 10.7 11 11.9 C 10.5 13.1 10.2 13.9 10.2 13.9 C 10.2 13.9 10.4 13.1 10.7 11.9 C 11 10.6 11.5 8.9 12 7.4 C 12.5 5.8 13.1 4.2 13.6 3 C 14 1.8 14.4 1.1 14.4 1.1 Z " id="Shape" fill="#FFBCFC" stroke-width="1" stroke="none"/>
</g>
</g>
</g>
</svg><!--rotationCenter:12:24-->

After

Width:  |  Height:  |  Size: 3.8 KiB

@@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c7hyatbuieaj"
path="res://.godot/imported/0.svg-ba68a30343badda4169c625106c39869.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://resources/bullets/purple-crystal/frames/0.svg"
dest_files=["res://.godot/imported/0.svg-ba68a30343badda4169c625106c39869.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
+33
View File
@@ -0,0 +1,33 @@
extends Area2D
class_name BulletBase
@export var speed: float = 1
@export var damage: float = 10
var launcher: EntityBase = null
func _ready():
area_entered.connect(hit)
func hit(target: Node):
var entity: EntityBase = EntityTool.fromHurtbox(target)
if !entity || !launcher: return
if entity == launcher: return
if GameRule.allowFriendlyFire:
if entity.isPlayer() == launcher.isPlayer(): return
entity.takeDamage(self)
static func generate(
bullet: PackedScene,
launchBy: EntityBase,
spawnPosition: Vector2,
spawnRotation: float,
addToWorld: bool = true
):
var instance: BulletBase = bullet.instantiate()
instance.launcher = launchBy
instance.position = spawnPosition
instance.rotation = spawnRotation
if addToWorld:
WorldTool.rootNode.add_child(instance)
return instance
+1
View File
@@ -1,5 +1,6 @@
@tool
extends Control
class_name ColorBar
@export var minValue: float = 0
@export var maxValue: float = 100
+25
View File
@@ -3,6 +3,8 @@ class_name EntityBase # 这是个抽象类
@export var maxHealth: float = 100
@export var movementSpeed: float = 1
@export var isBoss: bool = false
@export var weapons: Array[Node2D] = []
@onready var animatree: AnimationTree = $"%animatree"
@onready var texture: AnimatedSprite2D = $"%texture"
@@ -28,9 +30,32 @@ func move(direction: Vector2):
var currentDirection = sign(direction.x)
if currentDirection != 0:
lastDirection = currentDirection
func takeDamage(bullet: BulletBase):
health -= bullet.damage
if health <= 0:
die()
# 关于分组
func isPlayer():
return is_in_group("players")
# 抽象方法
func ai():
pass
func attack(_type: int):
pass
func die():
queue_free()
static func generate(
entity: PackedScene,
spawnPosition: Vector2,
spawnRotation: float,
addtoWorld: bool = true
):
var instance = entity.instance()
instance.position = spawnPosition
instance.rotation = spawnRotation
if addtoWorld:
WorldTool.rootNode.add_child(instance)
return instance
+1 -1
View File
@@ -2,7 +2,7 @@ extends Node2D
@export var entity: EntityBase
@onready var healthBar = $"%health"
@onready var healthBar: ColorBar = $"%health"
func _process(_delta):
if entity:
+10
View File
@@ -0,0 +1,10 @@
class_name EntityTool
static func fromHurtbox(node: Node) -> EntityBase:
if node is Area2D:
var texture = node.get_parent()
if texture is AnimatedSprite2D:
var entity = texture.get_parent()
if entity is EntityBase:
return entity as EntityBase
return null
+3
View File
@@ -0,0 +1,3 @@
class_name GameRule
static var allowFriendlyFire: bool = false # 是否允许友军伤害
+9
View File
@@ -0,0 +1,9 @@
extends Node2D
class_name WorldTool
static var rootNode: Node2D
static var tree: SceneTree
func _ready():
tree = get_tree()
rootNode = self
+4 -2
View File
@@ -1,8 +1,10 @@
[gd_scene load_steps=2 format=3 uid="uid://dmxi1ikn6avig"]
[gd_scene load_steps=3 format=3 uid="uid://dmxi1ikn6avig"]
[ext_resource type="PackedScene" uid="uid://bm7ymrri6pykb" path="res://components/Characters/Rooster.tscn" id="1_7jr0n"]
[ext_resource type="Script" path="res://scripts/Tools/WorldTool.gd" id="1_ei0ch"]
[node name="world" type="Node2D"]
script = ExtResource("1_ei0ch")
[node name="rooster" parent="." instance=ExtResource("1_7jr0n")]
[node name="rooster" parent="." groups=["players"] instance=ExtResource("1_7jr0n")]
position = Vector2(394, 274)