Skip to content

Commit

Permalink
Merge pull request #1 from dpDeadlyPuzzles/main
Browse files Browse the repository at this point in the history
initial EnchantedSword swing
  • Loading branch information
limuy2022 authored Jun 6, 2024
2 parents 2a2c400 + 6f95df8 commit b9ad7dd
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 0 deletions.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions resources/images/bullets/Enchanted_Sword/Enchanted_Beam.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://doavl47vaddfj"
path="res://.godot/imported/Enchanted_Beam.png-77e6b4cc215e0e022de9ea8b0a52747d.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://resources/images/bullets/Enchanted_Sword/Enchanted_Beam.png"
dest_files=["res://.godot/imported/Enchanted_Beam.png-77e6b4cc215e0e022de9ea8b0a52747d.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
Binary file added resources/images/weapons/Enchanted_Sword.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions resources/images/weapons/Enchanted_Sword.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://ckmjjonp8tx4"
path="res://.godot/imported/Enchanted_Sword.png-2ceb888fecf100f517e156722a58f2d0.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://resources/images/weapons/Enchanted_Sword.png"
dest_files=["res://.godot/imported/Enchanted_Sword.png-2ceb888fecf100f517e156722a58f2d0.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
29 changes: 29 additions & 0 deletions scenes/bullets/enchanted_beam.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[gd_scene load_steps=4 format=3 uid="uid://c6uw0pckwbylu"]

[ext_resource type="Texture2D" uid="uid://doavl47vaddfj" path="res://resources/images/bullets/Enchanted_Sword/Enchanted_Beam.png" id="1_185ht"]
[ext_resource type="Script" path="res://scripts/bullets/enchanted_beam.gd" id="2_quqb1"]

[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_fb1sb"]
radius = 8.48529
height = 70.7107

[node name="Enchanted_Beam" type="Area2D"]
position = Vector2(629, 285)
script = ExtResource("2_quqb1")
direction = Vector2(-1, -1.5)
speed = 500.0
metadata/_edit_group_ = true

[node name="Out_Screen" type="VisibleOnScreenNotifier2D" parent="."]

[node name="Start" type="Timer" parent="."]
one_shot = true
autostart = true

[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(2, 2)
texture = ExtResource("1_185ht")

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
rotation = 0.785398
shape = SubResource("CapsuleShape2D_fb1sb")
12 changes: 12 additions & 0 deletions scenes/weapons/enchanted_sword.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[gd_scene load_steps=3 format=3 uid="uid://dikatje0ca8i5"]

[ext_resource type="Texture2D" uid="uid://ckmjjonp8tx4" path="res://resources/images/weapons/Enchanted_Sword.png" id="1_cwcxs"]
[ext_resource type="Script" path="res://scripts/weapons/enchanted_sword.gd" id="2_h56vq"]

[node name="Enchanted_Sword" type="Sprite2D"]
position = Vector2(600, 300)
rotation = -2.2218
scale = Vector2(2, 2)
texture = ExtResource("1_cwcxs")
script = ExtResource("2_h56vq")
metadata/_edit_group_ = true
20 changes: 20 additions & 0 deletions scripts/bullets/enchanted_beam.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
extends Area2D

@export var direction : Vector2
@export var speed : float
# Called when the node enters the scene tree for the first time.
func _ready():
rotation = PI / 4 + Vector2(0, 0).angle_to_point(direction)
direction = direction.normalized()
set_process(0)
$Start.timeout.connect(start)
$Out_Screen.screen_exited.connect(queue_free)

func start():
set_process(1)

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
position += delta * speed * direction


74 changes: 74 additions & 0 deletions scripts/weapons/enchanted_sword.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
extends Sprite2D


var finished : bool
func _ready():
finished = true
swingStart(Vector2(330, 330), Vector2(600, 300))


var now_func : Callable # 当前动作对应函数


func start(func_name : Callable):
if !finished: # 没完成
return
finished = false
now_func = func_name

func exit():
finished = true

func radToVector(rad : float) -> Vector2:
return Vector2(cos(rad), sin(rad))
# 剑头指向某一方向的rotation
func swordToRotation(rad : float) -> float:
return rad + PI / 4

#返回是否达到指定位置
# 旋转并移动到指定位置 #剑头的角度
func normalMove(end_point : Vector2, end_rotation : float , speed : float, delta : float) -> bool:
if (position - end_point).length() <= speed / 100:
return true
# 起点指向终点的向量
var vector = end_point - position
# 起点到终点转的角度
var direction = radToVector(rotation).angle_to(radToVector(swordToRotation(end_rotation)))
var rotate_speed = direction / vector.length() * speed
vector = vector.normalized() * speed

rotation += rotate_speed * delta #旋转
position += vector * delta# 向指定位置移动
return false

# ---swing---
var start_point : Vector2
var target : Vector2
var times : int
func swingStart(point : Vector2, to : Vector2):
start(swing)
start_point = point
target = to



# 在大概start_point这个位置, 向target挥舞攻击
func swing(delta : float):
if times >= 5:
exit()
return
# 移到(从start_point向(start_point与target连线垂直方向)一定距离)
var even = times % 2 == 0
var rad = start_point.angle_to_point(target)
var to_position = 200 * radToVector(rad + (- PI / 2 if even else PI / 2))
var arrive = normalMove(start_point + to_position, rad -PI / 3 if even else PI / 3, 600, delta)
if arrive:
times += 1

# -----------
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if !finished && now_func:
now_func.call(delta)
# else :
# 应该有个默认状态保持竖直朝下 并上下漂浮?

0 comments on commit b9ad7dd

Please sign in to comment.