mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-28 06:51:54 +08:00
feat: Add weapon system and attack functionality to Rooster character
- Introduced a weapons node in EntityBase for weapon management. - Updated Rooster to include cooldown for attacks and weapon anchoring. - Implemented attack method in Rooster to generate bullets. - Enhanced BulletBase with life distance and lifetime properties. - Created Chick character with animations and integrated into the world. - Updated PurpleCrystal bullet behavior to move forward based on rotation. - Refactored EntityBase to use a fields dictionary for attributes. - Added FieldStore for managing entity-related constants. - Adjusted GameRule to include bullet speed multiplier.
This commit is contained in:
@@ -114,6 +114,9 @@ tree_root = SubResource("AnimationNodeBlendSpace1D_51ube")
|
||||
anim_player = NodePath("..")
|
||||
parameters/blend_position = 1.0
|
||||
|
||||
[node name="weapons" type="Node2D" parent="texture"]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[node name="movebox" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_ce3to")
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://uj0aqhm8wgy8"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://uj0aqhm8wgy8"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://crtdkysmnkith" path="res://components/Abstracts/BulletBase.tscn" id="1_45mh7"]
|
||||
[ext_resource type="Script" path="res://scripts/Contents/Bullets/PurpleCrystal.gd" id="2_4lnlm"]
|
||||
[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"]
|
||||
@@ -17,10 +18,13 @@ animations = [{
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_ty1as"]
|
||||
|
||||
[node name="PurpleCrystal" instance=ExtResource("1_45mh7")]
|
||||
script = ExtResource("2_4lnlm")
|
||||
speed = 5.0
|
||||
lifeDistance = 700.0
|
||||
|
||||
[node name="texture" parent="." index="0"]
|
||||
sprite_frames = SubResource("SpriteFrames_r86b3")
|
||||
|
||||
[node name="hitbox" parent="." index="1"]
|
||||
position = Vector2(0, -13)
|
||||
position = Vector2(12, 0)
|
||||
shape = SubResource("CircleShape2D_ty1as")
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://b0ncrvm8u4pox"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cvogxi7mktumf" path="res://components/Abstracts/EntityBase.tscn" id="1_goqmy"]
|
||||
[ext_resource type="Texture2D" uid="uid://7pkplcqqxvnp" path="res://resources/characters/chick/chick-a.svg" id="2_syddq"]
|
||||
[ext_resource type="Texture2D" uid="uid://dj5dvqb8gsedr" path="res://resources/characters/chick/chick-b.svg" id="3_064jv"]
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_xji3d"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("2_syddq")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"idle",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("2_syddq")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("3_064jv")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"walk",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[node name="Chick" instance=ExtResource("1_goqmy")]
|
||||
|
||||
[node name="texture" parent="." index="0"]
|
||||
sprite_frames = SubResource("SpriteFrames_xji3d")
|
||||
animation = &"walk"
|
||||
|
||||
[node name="statebar" parent="." index="2" node_paths=PackedStringArray("entity")]
|
||||
entity = NodePath("..")
|
||||
@@ -32,6 +32,7 @@ radius = 41.0122
|
||||
|
||||
[node name="Rooster" instance=ExtResource("1_e5pl8")]
|
||||
script = ExtResource("2_oqdqd")
|
||||
cooldownUnit = 200.0
|
||||
|
||||
[node name="texture" parent="." index="0"]
|
||||
position = Vector2(0, -70)
|
||||
@@ -42,6 +43,9 @@ animation = &"walk"
|
||||
position = Vector2(12, 16)
|
||||
shape = SubResource("CircleShape2D_h1v0q")
|
||||
|
||||
[node name="normal" type="Node2D" parent="texture/weapons" index="0"]
|
||||
position = Vector2(54, -45)
|
||||
|
||||
[node name="statebar" parent="." index="2" node_paths=PackedStringArray("entity")]
|
||||
position = Vector2(0, -151)
|
||||
entity = NodePath("..")
|
||||
|
||||
@@ -41,6 +41,11 @@ m_right={
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
attack={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
|
||||
@@ -1,27 +1 @@
|
||||
<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-->
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="47.11931" height="18.20664" viewBox="0,0,47.11931,18.20664"><g transform="translate(-216.44034,-170.89668)"><g stroke="none" stroke-miterlimit="10"><g><g><path d="M218.66385,177.69052c0,0 28.85361,-7.11049 33.11303,-6.78286c0,0 7.73698,2.76209 11.78277,8.85812c0,0 -5.66245,6.10055 -11.12024,9.29625c0,0 -30.66603,-2.93168 -32.91199,-3.88858c0,0 -2.30342,-2.68221 -2.91204,-4.59783c-0.0772,0.11849 0.58078,-2.5754 2.04846,-2.8851z" fill="#8644b3"/><path d="M263.36396,179.80707l-17.35725,-1.85632c1.15708,-3.71903 5.69297,-6.9246 5.69297,-6.9246c0,0 7.73698,2.76209 11.66428,8.78092z" fill="#ea8be5"/><path d="M263.36396,179.80707l-17.35725,-1.85632c1.15708,-3.71903 5.69297,-6.9246 5.69297,-6.9246c0,0 7.73698,2.76209 11.66428,8.78092z" fill="#ea8be5"/><path d="M251.51751,189.05216c-3.1598,-5.77197 -5.53144,-11.19925 -5.53144,-11.19925l17.3779,1.95416c0.09785,-0.02065 0.11849,0.0772 0.11849,0.0772c0,0 -5.66245,6.10055 -11.14089,9.1984c0,0 -0.19569,0.04129 -0.82406,-0.03052z" fill="#ad59c2"/><path d="M245.90887,177.9714l-29.46853,2.74335c0,0 0.77647,-2.61669 2.14631,-2.90575c0,0 28.85361,-7.11049 33.11303,-6.78286z" fill="#ad59c2"/><path d="M245.98607,177.85291c0,0 -1.58617,0.2325 -3.97575,0.53233c-1.19479,0.14991 -2.60592,0.24328 -4.09425,0.45513c-1.50897,0.11401 -3.09515,0.34651 -4.60412,0.46052c-1.60682,0.13465 -3.21364,0.26931 -4.62477,0.36267c-1.50897,0.11401 -2.9201,0.20737 -4.01705,0.33664c-2.33303,0.08349 -3.93985,0.21814 -3.93985,0.21814c0,0 1.58617,-0.2325 3.97575,-0.53233c1.19479,-0.14991 2.60592,-0.24328 4.09425,-0.45513c1.50897,-0.11401 3.09515,-0.34651 4.60412,-0.46052c1.60682,-0.13465 3.21364,-0.26931 4.62477,-0.36267c1.50897,-0.11401 2.9201,-0.20737 4.01705,-0.33664c2.43088,-0.10414 3.93985,-0.21814 3.93985,-0.21814z" fill="#ea8be5"/><path d="M219.82903,180.30631l-3.31148,0.28996c0,0 0.77647,-2.61669 2.14631,-2.90575c0,0 0.62388,1.50359 1.16518,2.61579z" fill="#a546bd"/><path d="M219.42958,185.19409c0,0 -2.32406,-2.78006 -2.91204,-4.59783l3.31148,-0.28996c0.22172,0.56643 0.4228,1.03501 0.4641,1.2307c0.26302,0.76212 -0.86354,3.65709 -0.86354,3.65709z" fill="#7c36ab"/><path d="M216.53819,180.69411c0.38151,0.83932 0.86087,1.65798 1.31957,2.37881c0.45871,0.72082 1.01526,1.421 1.74686,1.98204l-0.11849,-0.0772c2.08079,0.17414 4.18222,0.44613 6.28365,0.71811c2.10143,0.27199 4.18222,0.44613 6.18581,0.73876c4.20287,0.54397 8.30789,1.10859 12.43356,1.77105c-4.16157,-0.34828 -8.3438,-0.79441 -12.54666,-1.33838c-2.10143,-0.27199 -4.20287,-0.54397 -6.18581,-0.73876c-2.10143,-0.27199 -4.20287,-0.54397 -6.20646,-0.8366c-0.6544,-0.67953 -1.21095,-1.37971 -1.69031,-2.19838c-0.5772,-0.79802 -0.93806,-1.53949 -1.22173,-2.39945z" fill="#6b348f"/><path d="M251.67904,170.92831c0,0 1.34112,4.4183 2.04311,7.74504l-7.73608,-0.82044c1.27557,-3.64183 5.69297,-6.9246 5.69297,-6.9246z" fill="#e17de3"/><path d="M254.13059,182.06204c-0.10772,0.94255 -0.89406,4.48114 -1.51613,6.86086c-0.09785,0.02065 -0.27289,0.15979 -0.37073,0.18043c0,0 -0.21634,-0.05655 -0.72621,-0.05116c-3.1598,-5.77197 -5.53144,-11.19925 -5.53144,-11.19925l7.73608,0.82044c0.33035,1.56553 0.6194,2.93536 0.40845,3.38868z" fill="#9b4dae"/><path d="M251.61536,189.03151c0,0 -0.41742,-0.52513 -0.87612,-1.24596c-0.47936,-0.81867 -1.09785,-1.81238 -1.73699,-2.90394c-0.5413,-1.1122 -1.08259,-2.22441 -1.4641,-3.06372c-0.38151,-0.83932 -0.50539,-1.42639 -0.50539,-1.42639c0,0 0.02065,0.09785 0.18043,0.37073c0.15979,0.27289 0.31957,0.54578 0.52065,1.01436c0.47936,0.81867 1,1.83303 1.63914,2.92459c0.5413,1.1122 1.18044,2.20376 1.56195,3.04308c0.45871,0.72082 0.68043,1.28725 0.68043,1.28725z" fill="#6b348f"/></g><path d="M263.36396,179.80707c0,0 -0.82406,-0.03052 -2.06014,-0.0763c-1.23608,-0.04578 -2.90484,-0.20466 -4.5736,-0.36354c-1.66876,-0.15888 -3.35816,-0.41561 -4.63554,-0.65708c-1.27738,-0.24147 -2.12208,-0.36983 -2.12208,-0.36983c0,0 0.82406,0.03052 2.06014,0.0763c1.33393,0.02513 3.10053,0.16337 4.67145,0.34289c1.66876,0.15888 3.35816,0.41561 4.63554,0.65708c1.25673,0.14362 2.02423,0.39048 2.02423,0.39048z" fill="#ffbcfc"/></g></g></g></svg><!--rotationCenter:23.559655350967233:9.10332241055363-->
|
||||
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 4.1 KiB |
@@ -0,0 +1,5 @@
|
||||
extends BulletBase
|
||||
class_name PurpleCrystal
|
||||
|
||||
func ai():
|
||||
forward(Vector2.from_angle(rotation))
|
||||
@@ -10,3 +10,9 @@ func ai():
|
||||
move(direction)
|
||||
if direction.length() == 0:
|
||||
texture.play("idle")
|
||||
if Input.is_action_pressed("attack"):
|
||||
tryAttack(0)
|
||||
func attack(type):
|
||||
if type == 0:
|
||||
var weaponPos = findWeaponAnchor("normal")
|
||||
BulletBase.generate(preload("res://components/Bullets/PurpleCrystal.tscn"), self, weaponPos, (get_global_mouse_position() - weaponPos).angle())
|
||||
|
||||
@@ -3,11 +3,26 @@ class_name BulletBase
|
||||
|
||||
@export var speed: float = 1
|
||||
@export var damage: float = 10
|
||||
@export var lifeDistance: float = -1 # -1表示无限距离
|
||||
@export var lifeTime: float = -1 # -1表示无限时间
|
||||
|
||||
var launcher: EntityBase = null
|
||||
var spawnInWhen: float = 0
|
||||
var spawnInWhere: Vector2 = Vector2.ZERO
|
||||
|
||||
func _ready():
|
||||
area_entered.connect(hit)
|
||||
spawnInWhen = Time.get_ticks_msec()
|
||||
spawnInWhere = position
|
||||
func _process(_delta: float) -> void:
|
||||
if lifeTime > 0:
|
||||
if Time.get_ticks_msec() - spawnInWhen >= lifeTime:
|
||||
destroy()
|
||||
if lifeDistance > 0:
|
||||
if position.distance_to(spawnInWhere) >= lifeDistance:
|
||||
destroy()
|
||||
func _physics_process(_delta: float) -> void:
|
||||
ai()
|
||||
|
||||
func hit(target: Node):
|
||||
var entity: EntityBase = EntityTool.fromHurtbox(target)
|
||||
@@ -16,6 +31,13 @@ func hit(target: Node):
|
||||
if GameRule.allowFriendlyFire:
|
||||
if entity.isPlayer() == launcher.isPlayer(): return
|
||||
entity.takeDamage(self)
|
||||
func forward(direction: Vector2):
|
||||
position += direction.normalized() * speed * GameRule.bulletSpeedMultiplier
|
||||
|
||||
func ai():
|
||||
pass
|
||||
func destroy():
|
||||
queue_free()
|
||||
|
||||
static func generate(
|
||||
bullet: PackedScene,
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
extends CharacterBody2D
|
||||
class_name EntityBase # 这是个抽象类
|
||||
|
||||
@export var maxHealth: float = 100
|
||||
@export var movementSpeed: float = 1
|
||||
@export var fields: Dictionary = {
|
||||
FieldStore.Entity.MAX_HEALTH: 100,
|
||||
FieldStore.Entity.DAMAGE_MULTIPILER: 1,
|
||||
FieldStore.Entity.MOVEMENT_SPEED: 1,
|
||||
FieldStore.Entity.ATTACK_SPEED: 1,
|
||||
FieldStore.Entity.CRIT_RATE: 0.05, # 0.05 = 5%
|
||||
FieldStore.Entity.CRIT_DAMAGE: 2 # 2 = 200%
|
||||
} # 存一下词条
|
||||
@export var isBoss: bool = false
|
||||
@export var weapons: Array[Node2D] = []
|
||||
@export var cooldownUnit: float = 100 # 100毫秒每次攻击
|
||||
|
||||
@onready var animatree: AnimationTree = $"%animatree"
|
||||
@onready var texture: AnimatedSprite2D = $"%texture"
|
||||
@@ -13,11 +19,12 @@ class_name EntityBase # 这是个抽象类
|
||||
var health: float = 0
|
||||
|
||||
var lastDirection: int = 1
|
||||
var lastAttack: int = 0
|
||||
|
||||
func _ready():
|
||||
health = maxHealth
|
||||
health = fields.get(FieldStore.Entity.MAX_HEALTH)
|
||||
func _process(_delta):
|
||||
health = clamp(health, 0, maxHealth)
|
||||
health = clamp(health, 0, fields.get(FieldStore.Entity.MAX_HEALTH))
|
||||
animatree.set("parameters/blend_position", lerpf(animatree.get("parameters/blend_position"), lastDirection, 0.1))
|
||||
func _physics_process(_delta: float) -> void:
|
||||
velocity = Vector2.ZERO
|
||||
@@ -26,7 +33,7 @@ func _physics_process(_delta: float) -> void:
|
||||
|
||||
# 通用方法
|
||||
func move(direction: Vector2):
|
||||
velocity = direction.normalized() * movementSpeed * 150 * abs(animatree.get("parameters/blend_position"))
|
||||
velocity = direction.normalized() * fields.get(FieldStore.Entity.MOVEMENT_SPEED) * 200 * abs(animatree.get("parameters/blend_position"))
|
||||
var currentDirection = sign(direction.x)
|
||||
if currentDirection != 0:
|
||||
lastDirection = currentDirection
|
||||
@@ -34,6 +41,22 @@ func takeDamage(bullet: BulletBase):
|
||||
health -= bullet.damage
|
||||
if health <= 0:
|
||||
die()
|
||||
func isCooldowned():
|
||||
return Time.get_ticks_msec() - lastAttack >= cooldownUnit
|
||||
func startCooldown():
|
||||
var state = isCooldowned()
|
||||
if state:
|
||||
lastAttack = Time.get_ticks_msec()
|
||||
return state
|
||||
func tryAttack(type: int):
|
||||
if startCooldown():
|
||||
attack(type)
|
||||
func findWeaponAnchor(weaponName: String):
|
||||
var anchor = $"%weapons".get_node(weaponName)
|
||||
if anchor is Node2D:
|
||||
return (anchor.position + texture.position) * Vector2(animatree.get("parameters/blend_position"), 1) + position
|
||||
else:
|
||||
return Vector2.ZERO
|
||||
|
||||
# 关于分组
|
||||
func isPlayer():
|
||||
@@ -51,11 +74,14 @@ static func generate(
|
||||
entity: PackedScene,
|
||||
spawnPosition: Vector2,
|
||||
spawnRotation: float,
|
||||
isMob: bool = true,
|
||||
addtoWorld: bool = true
|
||||
):
|
||||
var instance = entity.instance()
|
||||
var instance: EntityBase = entity.instance()
|
||||
instance.position = spawnPosition
|
||||
instance.rotation = spawnRotation
|
||||
if isMob:
|
||||
instance.add_to_group("mobs")
|
||||
if addtoWorld:
|
||||
WorldTool.rootNode.add_child(instance)
|
||||
return instance
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class_name FieldStore
|
||||
|
||||
enum Entity {
|
||||
MAX_HEALTH,
|
||||
DAMAGE_MULTIPILER,
|
||||
MOVEMENT_SPEED,
|
||||
ATTACK_SPEED,
|
||||
CRIT_RATE,
|
||||
CRIT_DAMAGE,
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
class_name GameRule
|
||||
|
||||
static var allowFriendlyFire: bool = false # 是否允许友军伤害
|
||||
static var bulletSpeedMultiplier: float = 1 # 子弹速度倍率
|
||||
+14
-1
@@ -1,10 +1,23 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://dmxi1ikn6avig"]
|
||||
[gd_scene load_steps=4 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"]
|
||||
[ext_resource type="PackedScene" uid="uid://b0ncrvm8u4pox" path="res://components/Characters/Chick.tscn" id="3_jho84"]
|
||||
|
||||
[node name="world" type="Node2D"]
|
||||
script = ExtResource("1_ei0ch")
|
||||
|
||||
[node name="rooster" parent="." groups=["players"] instance=ExtResource("1_7jr0n")]
|
||||
position = Vector2(394, 274)
|
||||
|
||||
[node name="chick" parent="." groups=["mobs"] instance=ExtResource("3_jho84")]
|
||||
position = Vector2(644, 391)
|
||||
|
||||
[node name="Chick" parent="." instance=ExtResource("3_jho84")]
|
||||
position = Vector2(366, 547)
|
||||
|
||||
[node name="Chick2" parent="." instance=ExtResource("3_jho84")]
|
||||
position = Vector2(686, 551)
|
||||
|
||||
[node name="Chick3" parent="." instance=ExtResource("3_jho84")]
|
||||
position = Vector2(760, 200)
|
||||
|
||||
Reference in New Issue
Block a user