Skip to content

Commit

Permalink
feat:implement of star wrath explosion
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Aug 25, 2024
1 parent 245b50c commit 3aced7f
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 7 deletions.
6 changes: 4 additions & 2 deletions gdrust/src/bullets/star_wrath_bullet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ use rand::{thread_rng, Rng};
use std::f32::consts::PI;

use crate::player::Player;
use crate::utils::screen_effects::ScreenEffects;
use crate::utils::split_to_vec;
use crate::{debug_check, get_global, godot_debug_assert};
use crate::{debug_check, godot_debug_assert};

#[derive(GodotClass)]
#[class(base=Area2D)]
pub struct StarWrathBullet {
base: Base<Area2D>,
direct: Vector2,
speed: i32,
#[var]
explode: bool,
}

const SPEED_MIN: i32 = 300;
Expand All @@ -31,6 +32,7 @@ impl IArea2D for StarWrathBullet {
base,
direct: Vector2::ZERO,
speed: 0,
explode: false,
}
}

Expand Down
3 changes: 2 additions & 1 deletion gdrust/src/weapons/star_wrath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ impl StarWrath {

#[func]
/// 新建一个从天而降垂直下落的弹幕
fn fall_star(&mut self) {
fn fall_star(&mut self, explode: bool) {
let bullet = self.get_bullet_scene();
let mut star = bullet.instantiate_as::<StarWrathBullet>();
star.bind_mut().set_explode(explode);
const SZ_TO_SIDE: f32 = 200.0;
let sz = self.base_mut().get_viewport_rect().size.x - SZ_TO_SIDE;
let random_x = thread_rng().gen_range(SZ_TO_SIDE..sz);
Expand Down
24 changes: 24 additions & 0 deletions scenes/bullets/star_wrath/little_star.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extends Sprite2D

const SPEED: float = 90
var direct


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
set_process(false)


func shoot(direction: Vector2):
assert(direction.length() > 0)
self.direct = direction.normalized()
set_process(true)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
self.position += delta * SPEED * direct


func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
queue_free()
12 changes: 12 additions & 0 deletions scenes/bullets/star_wrath/little_star.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[gd_scene load_steps=3 format=3 uid="uid://dtboow2wo76hq"]

[ext_resource type="Texture2D" uid="uid://dsq0jnh5u5avq" path="res://scenes/bullets/star_wrath/littlestar.png" id="1_hkmep"]
[ext_resource type="Script" path="res://scenes/bullets/star_wrath/little_star.gd" id="2_kxmji"]

[node name="LittleStar" type="Sprite2D"]
texture = ExtResource("1_hkmep")
script = ExtResource("2_kxmji")

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

[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]
Binary file added scenes/bullets/star_wrath/littlestar.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 scenes/bullets/star_wrath/littlestar.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://dsq0jnh5u5avq"
path="res://.godot/imported/littlestar.png-3be6e558e4d3350cfb1e4879ffa30bd8.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://scenes/bullets/star_wrath/littlestar.png"
dest_files=["res://.godot/imported/littlestar.png-3be6e558e4d3350cfb1e4879ffa30bd8.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 scenes/bullets/star_wrath/littlestar.pxo
Binary file not shown.
16 changes: 16 additions & 0 deletions scenes/bullets/star_wrath/point.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends Sprite2D


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
hide()
set_process(false)


func work():
set_process(true)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
Binary file added scenes/bullets/star_wrath/point.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 scenes/bullets/star_wrath/point.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://cyrklccri8jt4"
path="res://.godot/imported/point.png-0d81272545105e3a341cfa9087101a89.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://scenes/bullets/star_wrath/point.png"
dest_files=["res://.godot/imported/point.png-0d81272545105e3a341cfa9087101a89.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 scenes/bullets/star_wrath/point.pxo
Binary file not shown.
3 changes: 3 additions & 0 deletions scenes/bullets/star_wrath/point.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gd_scene format=3 uid="uid://bgq78c0mfx381"]

[node name="Point" type="Sprite2D"]
18 changes: 17 additions & 1 deletion scenes/bullets/star_wrath/star_wrath_original.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@ extends StarWrathBullet
@export var track: PackedScene
var tween
var block_color: Color = Color8(255, 255, 255, 255)
var littlestar_scene = preload("res://scenes/bullets/star_wrath/little_star.tscn")


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
hide()


func explode_effect(callback):
for i in range(3):
var direct = PI / 12
for j in range(10):
var littlestar = littlestar_scene.instantiate()
littlestar.shoot(direct * j)
add_child(littlestar)
await get_tree().create_timer(0.1).timeout
callback.call()


func _on_killer_screen_exited() -> void:
await get_tree().create_timer(0.5).timeout
queue_free()
if self.explode:
# 爆炸
self.explode_effect(queue_free)
else:
queue_free()
26 changes: 23 additions & 3 deletions scenes/weapons/star_wrath/star_wrath.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ extends StarWrath

@export var star_wrath_origin: PackedScene
var operation_idx = 0
# func(): self.fall_star_process(),
var operations = [func(): self.beam_shoot1(), func(): self.leave()]
var operations = [
func(): self.fall_star_process(),
func(): self.beam_shoot1(),
func(): self.fall_star_explode(),
func(): five_surrounding_points(),
func(): self.leave()
]
@onready var animation_player = $AnimationPlayer
@onready var star_wrath = $StarWrath
var beam_scene: PackedScene = preload("res://scenes/bullets/star_wrath/laser_beam.tscn")
var point_scene: PackedScene = preload("res://scenes/bullets/star_wrath/point.tscn")


func next_operation():
Expand All @@ -20,11 +26,25 @@ func next_operation():

func fall_star_process():
for i in range(10):
self.fall_star()
self.fall_star(false)
await get_tree().create_timer(randf_range(1.0, 2.0)).timeout
next_operation()


func fall_star_explode():
for i in range(4):
self.fall_star(true)
await get_tree().create_timer(randf_range(5.0, 6.0)).timeout
next_operation()


func five_surrounding_points():
var points = []
for i in range(5):
var point = point_scene.instantiate()
points.push_back(point)


func beam_shoot1():
var beam = beam_scene.instantiate()
self.add_child(beam)
Expand Down

0 comments on commit 3aced7f

Please sign in to comment.