Skip to content

Commit

Permalink
Merge pull request #4 from dpDeadlyPuzzles/main
Browse files Browse the repository at this point in the history
formatted
  • Loading branch information
limuy2022 authored Jun 6, 2024
2 parents 675f1de + 78df77d commit a349031
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 65 deletions.
13 changes: 8 additions & 5 deletions scripts/bullets/enchanted_beam.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
extends Area2D

@export var direction : Vector2
@export var speed : float
@export var direction: Vector2
@export var speed: float


# Called when the node enters the scene tree for the first time.
func _ready():
func _ready():
rotation = PI / 4 + Vector2(0, 0).angle_to_point(direction)
direction = direction.normalized()
set_process(0)
Expand All @@ -14,10 +16,11 @@ func _ready():
func start():
set_process(1)


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


func _on_out_screen_screen_exited():
queue_free()
9 changes: 6 additions & 3 deletions scripts/bullets/star_wrath_original_bullet.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ extends Sprite2D

# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
pass # Replace with function body.

var direct = Vector2(0,0)

var direct = Vector2(0, 0)
var speed


func init(x_pos, y_pos):
#print("new bullet")
self.position.x = x_pos
self.position.y = y_pos
self.speed = randi_range(300,400)
self.speed = randi_range(300, 400)
show()
direct.x = randf_range(-30, -100)
direct.y = randf_range(30, 100)
self.transform = self.transform.rotated_local(atan(direct.y / direct.x))


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
self.position += direct.normalized() * delta * speed
Expand Down
173 changes: 124 additions & 49 deletions scripts/weapons/enchanted_sword.gd
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
extends Sprite2D


var finished : bool

var finished: bool


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

@export var enchanted_beam : PackedScene
var now_func : Callable # 当前动作对应函数

@export var enchanted_beam: PackedScene
var now_func: Callable # 当前动作对应函数

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

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


func exit():
finished = true

func radToVector(rad : float) -> Vector2:
finished = true


func radToVector(rad: float) -> Vector2:
return Vector2(cos(rad), sin(rad))


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



#返回是否达到指定位置
# 旋转并移动到指定位置 #剑头的角度
func normalMove(end_point : Vector2, end_rotation : float , speed : float, delta : float) -> bool:
while end_rotation > PI * 2:
end_rotation -= PI * 2
while end_rotation < -PI * 2:
end_rotation += PI * 2
# 旋转并移动到指定位置 #剑头的角度
func normalMove(end_point: Vector2, end_rotation: float, speed: float, delta: float) -> bool:
if (position - end_point).length() <= speed / 100:
return true
# 起点指向终点的向量
Expand All @@ -43,25 +44,32 @@ func normalMove(end_point : Vector2, end_rotation : float , speed : float, delta
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# 向指定位置移动

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

# ---swing---


# ---swing---
var start_point: Vector2
var target : Vector2
var times : int
var toTargetRad : float
var wait : Timer # 挥舞后的等待
var shot : Timer
var target: Vector2
var times: int
var totTimes: int
var toTargetRad: float
var wait: Timer # 挥舞后的等待
var shot: Timer


func swingExit():
exit()
wait.queue_free()
shot.queue_free()

func swingStart(point : Vector2, to : Vector2):
start(swing)

func swingStart(point: Vector2, to: Vector2, tim: int):
if !start(swing):
return
totTimes = tim
start_point = point
target = to
# 初始化wait
Expand All @@ -73,28 +81,90 @@ func swingStart(point : Vector2, to : Vector2):
shot = Timer.new()
shot.wait_time = 0.08
add_child(shot)
shot.timeout.connect(shotBeam)
shot.timeout.connect(swingShotBeam)
toTargetRad = start_point.angle_to_point(target)


func evenTimes() -> bool:
return times % 2 == 0


#发射附魔光束
func shotBeam():
func swingShotBeam():
var beam = enchanted_beam.instantiate()
beam.get_node("Start").wait_time = 0.05
#偶数次弹幕收拢
beam.direction = target - position
if !evenTimes(): #奇数次弹幕发散
beam.direction = Vector2(beam.direction.x, -beam.direction.y)
beam.position = position + beam.direction.normalized() * 50
beam.speed = 1000
get_parent().add_child(beam)
beam.get_node("Start").start()


# 在大概start_point这个位置, 向target挥舞攻击
func swing(delta: float):
if wait.time_left != 0:
return
if shot.time_left == 0 && times != 0:
shot.start()
if times >= totTimes:
swingExit()
return
# 移到(从start_point向(start_point与target连线垂直方向)一定距离)
var to_position = 150 * radToVector(toTargetRad + (-PI / 2 if evenTimes() else PI / 2))
var arrive = normalMove(
start_point + to_position,
toTargetRad + ((-PI * 1.8 / 3) if evenTimes() else (PI / 3)),
1150,
delta
)
if arrive:
wait.start()
shot.stop()
times += 1


# -----------

#---vertical---
# 垂直攻击

# 在这两个点间反复横跳


func verticalStart(point: Vector2, to: Vector2):
if !start(vertical):
return
start_point = point
target = to
# 初始化wait
wait = Timer.new()
wait.one_shot = true
wait.wait_time = 0.35
add_child(wait)
# 初始化shot
shot = Timer.new()
shot.wait_time = 0.08
add_child(shot)
shot.timeout.connect(verticalShotBeam)


func verticalShotBeam():
var beam = enchanted_beam.instantiate()
beam.get_node("Start").wait_time = 0.1
beam.get_node("Start").wait_time = 0.05
#偶数次弹幕收拢
beam.direction = target - position
if !evenTimes(): #奇数次弹幕发散
if !evenTimes(): #奇数次弹幕发散
beam.direction = Vector2(beam.direction.x, -beam.direction.y)
beam.position = position + beam.direction.normalized() * 50
beam.speed = 1000
get_parent().add_child(beam)
beam.get_node("Start").start()



# 在大概start_point这个位置, 向target挥舞攻击
func swing(delta : float):


func vertical(delta: float):
if wait.time_left != 0:
return
if shot.time_left == 0 && times != 0:
Expand All @@ -103,18 +173,23 @@ func swing(delta : float):
swingExit()
return
# 移到(从start_point向(start_point与target连线垂直方向)一定距离)
var to_position = 150 * radToVector(toTargetRad + (- PI / 2 if evenTimes() else PI / 2))
var arrive = normalMove(start_point + to_position, toTargetRad + ((- PI * 1.8 / 3) if evenTimes() else (PI / 3)), 1000, delta)
if arrive:
var to_position = 150 * radToVector(toTargetRad + (-PI / 2 if evenTimes() else PI / 2))
var arrive = normalMove(
start_point + to_position,
toTargetRad + ((-PI * 1.8 / 3) if evenTimes() else (PI / 3)),
1150,
delta
)
if arrive:
wait.start()
shot.stop()
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 :
# 应该有个默认状态保持竖直朝下 并上下漂浮?
# else :
# 应该有个默认状态保持竖直朝下 并上下漂浮?
18 changes: 10 additions & 8 deletions scripts/weapons/star_wrath.gd
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
extends Sprite2D

var start_flag = true
enum States{
Wave1,
Wave2,
WaveReSet,
None
}
enum States { Wave1, Wave2, WaveReSet, None }
var state = States.Wave1


# Called when the node enters the scene tree for the first time.
func _ready():
#print("star ready")
#new_bullet()
if get_tree().current_scene == self:
$Fight_Timer.start()


func wave():
self.state = States.Wave1
new_bullet()

@export var star_wrath_bullet:PackedScene
@export var BULLETS_NUM:int

@export var star_wrath_bullet: PackedScene
@export var BULLETS_NUM: int


func new_bullet():
for i in range(BULLETS_NUM):
Expand All @@ -30,6 +29,7 @@ func new_bullet():
star.init(sz, 0)
$"..".add_child.call_deferred(star)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if !start_flag:
Expand All @@ -43,9 +43,11 @@ func _process(delta):
elif self.state == States.WaveReSet:
pass


func start():
start_flag = true


func _on_fight_t_imer_timeout():
new_bullet()

Expand Down

0 comments on commit a349031

Please sign in to comment.