Skip to content

Commit

Permalink
添加动态背景
Browse files Browse the repository at this point in the history
  • Loading branch information
cutekibry authored and ligen131 committed Jan 28, 2024
1 parent ee03aa1 commit 11d15cd
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 3 deletions.
46 changes: 46 additions & 0 deletions bg/dynamic_bg/dynamic_bg.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
extends Node2D


const DynamicBgPattern = preload("res://bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.tscn")


const WIDTH = 1920 / 4
const HEIGHT = 1080 / 4

const W_STEP := 60
const H_STEP := 6

var VELOCITY = 30 * Vector2.from_angle(-atan(2))

func spawn(x_offset, y_offset):
var pat_x = -WIDTH + x_offset
var pat_y = HEIGHT + y_offset

while pat_x < WIDTH + 50:
var new_pattern = DynamicBgPattern.instantiate()

new_pattern.position = Vector2(pat_x, pat_y)
new_pattern.velocity = VELOCITY
add_child(new_pattern)

pat_x += W_STEP
pat_y += H_STEP


func _ready():
var x_offset = 0
var y_offset = 0
while HEIGHT + y_offset + (WIDTH / W_STEP) * H_STEP > -50:
spawn(x_offset, y_offset)
x_offset += $Timer.wait_time * VELOCITY.x
x_offset -= int(x_offset / W_STEP) * W_STEP
y_offset += $Timer.wait_time * VELOCITY.y
print(y_offset)

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass


func _on_timer_timeout():
spawn(0, 0)
13 changes: 13 additions & 0 deletions bg/dynamic_bg/dynamic_bg.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[gd_scene load_steps=2 format=3 uid="uid://d3geq38s5fjc6"]

[ext_resource type="Script" path="res://bg/dynamic_bg/dynamic_bg.gd" id="1_g3cph"]

[node name="DynamicBg" type="Node2D"]
z_index = -4096
script = ExtResource("1_g3cph")

[node name="Timer" type="Timer" parent="."]
wait_time = 2.0
autostart = true

[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
14 changes: 14 additions & 0 deletions bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends Node2D


var velocity : Vector2


func _ready():
$Word1.set_word("=*"[randi_range(0, 1)])
$Word2.set_word("DPb"[randi_range(0, 2)])

func _process(delta):
position += velocity * delta
if position.x > 1920 / 4 + 70 or position.y < -70:
queue_free()
14 changes: 14 additions & 0 deletions bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[gd_scene load_steps=3 format=3 uid="uid://dkm7ljv01kwma"]

[ext_resource type="Script" path="res://bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.gd" id="1_hrrmh"]
[ext_resource type="PackedScene" uid="uid://cvx7wowcbfo0r" path="res://objects/word/word.tscn" id="2_7jm3n"]

[node name="DynamicBgPattern" type="Node2D"]
modulate = Color(1, 1, 1, 0.12549)
script = ExtResource("1_hrrmh")

[node name="Word1" parent="." instance=ExtResource("2_7jm3n")]
position = Vector2(-6, 0)

[node name="Word2" parent="." instance=ExtResource("2_7jm3n")]
position = Vector2(6, 0)
4 changes: 2 additions & 2 deletions levels/base_level/base_level.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=15 format=3 uid="uid://cother2aiigge"]
[gd_scene load_steps=16 format=3 uid="uid://cother2aiigge"]

[ext_resource type="Script" path="res://levels/base_level/base_level.gd" id="1_diojb"]
[ext_resource type="PackedScene" uid="uid://xom5kpqs1rue" path="res://objects/calculator/calculator.tscn" id="1_tpuy7"]
Expand Down Expand Up @@ -94,7 +94,7 @@ centered = false

[node name="LevelClear" type="AudioStreamPlayer2D" parent="SFXs"]
stream = ExtResource("3_ou3kh")
volume_db = -26.29
volume_db = -5.0

[node name="WrongAnswer" type="AudioStreamPlayer2D" parent="SFXs"]
stream = ExtResource("4_yxsxp")
Expand Down
7 changes: 6 additions & 1 deletion main.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://c17fbsiogbgo1"]
[gd_scene load_steps=3 format=3 uid="uid://c17fbsiogbgo1"]

[ext_resource type="PackedScene" uid="uid://c07co5p46apu7" path="res://objects/main_menu/main_menu.tscn" id="1_fk6j6"]
[ext_resource type="PackedScene" uid="uid://d3geq38s5fjc6" path="res://bg/dynamic_bg/dynamic_bg.tscn" id="2_8k4il"]

[node name="Main" type="Node"]

[node name="MainMenu" parent="." instance=ExtResource("1_fk6j6")]

[node name="Bg" type="Node" parent="."]

[node name="DynamicBg" parent="Bg" instance=ExtResource("2_8k4il")]

0 comments on commit 11d15cd

Please sign in to comment.