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
+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