From 92e138f163870ead52b2433dcaf28db561331f22 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Sun, 28 Jan 2024 19:42:38 -0700 Subject: [PATCH] bullet hell test --- sprites/common/bullet/fireball.gd | 21 ++++++++++++--- sprites/common/bullet/fireball.tscn | 1 + sprites/common/natasha/natasha.gd | 40 +++++++++++++++++++++-------- sprites/common/natasha/natasha.tscn | 6 +++++ sprites/common/player/player.gd | 13 +++++----- 5 files changed, 60 insertions(+), 21 deletions(-) diff --git a/sprites/common/bullet/fireball.gd b/sprites/common/bullet/fireball.gd index a2ce855..0549c41 100644 --- a/sprites/common/bullet/fireball.gd +++ b/sprites/common/bullet/fireball.gd @@ -1,9 +1,12 @@ extends Area2D var velocity: Vector2 = Vector2() - +var direction +var speed = 100 +var btype # Called when the node enters the scene tree for the first time. func _ready(): - pass # Replace with function body. + add_to_group(btype) + #pass # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -11,18 +14,28 @@ func _process(delta): pass func _physics_process(delta): - position += velocity * delta + if direction == null: + position += velocity * delta + else: + position += speed * delta * direction func _on_body_entered(body): + if !body.is_in_group(btype): #if body.is_in_group("players"): # Global.live = 2 #elif body.is_in_group("enemies"): # Global.live = 3 #elif body.is_in_group("boss"): # Global.live = 3 - queue_free() + queue_free() func _on_screen_exited(): queue_free() + + +func _on_area_entered(area): + if !area.is_in_group(btype): + queue_free() + #pass # Replace with function body. diff --git a/sprites/common/bullet/fireball.tscn b/sprites/common/bullet/fireball.tscn index ded6f3a..2a5e735 100644 --- a/sprites/common/bullet/fireball.tscn +++ b/sprites/common/bullet/fireball.tscn @@ -18,4 +18,5 @@ shape = SubResource("RectangleShape2D_g125y") [node name="VisibleOnScreenEnabler2D" type="VisibleOnScreenEnabler2D" parent="."] +[connection signal="area_entered" from="." to="." method="_on_area_entered"] [connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/sprites/common/natasha/natasha.gd b/sprites/common/natasha/natasha.gd index 57d7a05..fc9c236 100644 --- a/sprites/common/natasha/natasha.gd +++ b/sprites/common/natasha/natasha.gd @@ -1,9 +1,16 @@ extends CharacterBody2D +var theta: float = 0.0 +@export_range(0,2*PI) var alpha: float = 1.5 +var bullet = load("res://sprites/common/bullet/fireball.tscn") const SPEED = 300.0 const JUMP_VELOCITY = -400.0 -var angle = 2 +var vangle = 2 + +func get_vector(angle): + theta = angle + alpha + return Vector2(cos(theta),sin(theta)) # Get the gravity from the project settings to be synced with RigidBody nodes. var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") @@ -23,29 +30,40 @@ func _physics_process(delta): #position += velocity position += velocity if velocity.y > 0.3: - angle = 2 + vangle = 2 elif velocity.y < -0.3: - angle = 0 + vangle = 0 elif velocity.x > 0.3: - angle = 1 + vangle = 1 elif velocity.x < -0.3: - angle = 3 + vangle = 3 if velocity.y != 0 || velocity.x != 0: - if angle == 0: + if vangle == 0: anim.play("nwalk") - elif angle == 1: + elif vangle == 1: anim.play("ewalk") - elif angle == 3: + elif vangle == 3: anim.play("wwalk") else: anim.play("swalk") else: - if angle == 0: + if vangle == 0: anim.play("nidle") - elif angle == 1: + elif vangle == 1: anim.play("eidle") - elif angle == 3: + elif vangle == 3: anim.play("widle") else: anim.play("sidle") #move_and_slide() +func shoot(angle): + var new_bullet = bullet.instantiate() + new_bullet.position = Vector2(position.x, position.y) + new_bullet.direction = get_vector(angle) + new_bullet.btype = "boss" + get_parent().call_deferred("add_child",new_bullet) + + +func _on_speed_timeout(): + if Global.live == 1: + shoot(theta) diff --git a/sprites/common/natasha/natasha.tscn b/sprites/common/natasha/natasha.tscn index 4b25d23..dd7a51c 100644 --- a/sprites/common/natasha/natasha.tscn +++ b/sprites/common/natasha/natasha.tscn @@ -178,3 +178,9 @@ shape = SubResource("RectangleShape2D_dj8gt") libraries = { "": SubResource("AnimationLibrary_mh65y") } + +[node name="Speed" type="Timer" parent="."] +wait_time = 0.1 +autostart = true + +[connection signal="timeout" from="Speed" to="." method="_on_speed_timeout"] diff --git a/sprites/common/player/player.gd b/sprites/common/player/player.gd index b6b541e..6712e84 100644 --- a/sprites/common/player/player.gd +++ b/sprites/common/player/player.gd @@ -76,14 +76,15 @@ func _input(event): bullet = load(Global.pbbullets[Global.dparty[Global.dcpchar]]) else: bullet = load(Global.pbbullets[Global.party[Global.cpchar]]) - var new_bullet = bullet.instantiate() - new_bullet.velocity = Vector2(0, -500).rotated(deg_to_rad(angle * 90)) + var new_pbullet = bullet.instantiate() + new_pbullet.btype = "players" + new_pbullet.velocity = Vector2(0, -500).rotated(deg_to_rad(angle * 90)) var rposition = Vector2(0, -96).rotated(deg_to_rad(angle * 90)) if angle == 2: - new_bullet.position = Vector2(position.x + rposition.x, position.y + rposition.y + 98) + new_pbullet.position = Vector2(position.x + rposition.x, position.y + rposition.y + 98) else: - new_bullet.position = Vector2(position.x + rposition.x, position.y + rposition.y) - if new_bullet.position.x > 0 && new_bullet.position.y > 0 && new_bullet.position.x < 1280 && new_bullet.position.y < 720: - get_parent().add_child(new_bullet) + new_pbullet.position = Vector2(position.x + rposition.x, position.y + rposition.y) + if new_pbullet.position.x > 0 && new_pbullet.position.y > 0 && new_pbullet.position.x < 1280 && new_pbullet.position.y < 720: + get_parent().add_child(new_pbullet) elif Input.is_action_just_released("shoot") && bpress: bpress = false