bullet hell test

This commit is contained in:
Page Asgardius 2024-01-28 19:42:38 -07:00
parent 52c5f20d3a
commit 92e138f163
5 changed files with 60 additions and 21 deletions

View file

@ -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.

View file

@ -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"]

View file

@ -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)

View file

@ -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"]

View file

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