Skip to content

Commit

Permalink
Merge pull request #60 from ligen131/feat-20240218-table-cloth-scroll
Browse files Browse the repository at this point in the history
feat(scroll_area, base_level): 添加 scroll_area
  • Loading branch information
cutekibry authored Feb 17, 2024
2 parents dfce327 + 718306c commit ba38d98
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
10 changes: 9 additions & 1 deletion 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://bepyyenjtc0p3" path="res://levels/chapter_menu/level_menu/level_button/level_button.tscn" id="2_0egdl"]
Expand All @@ -12,6 +12,7 @@
[ext_resource type="Texture2D" uid="uid://cuyseoi8y3567" path="res://objects/styled_button/replay1.png" id="7_xfna7"]
[ext_resource type="Texture2D" uid="uid://dhjiokm51casd" path="res://objects/styled_button/replay2.png" id="8_60asn"]
[ext_resource type="Texture2D" uid="uid://btyxqeveaeh6h" path="res://objects/styled_button/replay3.png" id="9_gpaci"]
[ext_resource type="PackedScene" uid="uid://csl5lwjicxroy" path="res://levels/base_level/scroll_area/scroll_area.tscn" id="11_jgqxp"]

[sub_resource type="SpriteFrames" id="SpriteFrames_yulkh"]
animations = [{
Expand Down Expand Up @@ -81,6 +82,13 @@ sprite_frames = SubResource("SpriteFrames_5hm0m")
animation = &"replay"
centered = false

[node name="ScrollLeftArea" parent="HUDs" instance=ExtResource("11_jgqxp")]
position = Vector2(32, 135)

[node name="ScrollRightArea" parent="HUDs" instance=ExtResource("11_jgqxp")]
position = Vector2(448, 135)
is_on_left = false

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

[node name="Blocks" type="Node" parent="."]
Expand Down
41 changes: 41 additions & 0 deletions levels/base_level/scroll_area/scroll_area.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
extends Area2D


const WIDTH := 1920 / 4
const PADDING := 32
const SPEED := 300


@export var is_on_left := true

var is_mouse_on = false



func _process(delta: float):
if self.is_mouse_on:
if get_tree().root.has_node("BaseLevel/HUDs/TableCloth"):
var table_cloth_node = get_tree().root.get_node("BaseLevel/HUDs/TableCloth")
var offset := 0

if table_cloth_node.size.x < WIDTH:
return

if self.is_on_left and table_cloth_node.position.x < PADDING:
offset = min(PADDING - table_cloth_node.position.x, int(delta * SPEED + 0.5))
elif not self.is_on_left and table_cloth_node.position.x + table_cloth_node.size.x > WIDTH - PADDING:
offset = -min(table_cloth_node.position.x + table_cloth_node.size.x - (WIDTH - PADDING), int(delta * SPEED + 0.5))

if offset != 0:
table_cloth_node.position.x += offset
for block: Block in get_tree().root.get_node("BaseLevel/Blocks").get_children():
block.position.x += offset
if block.occupied_card != null:
block.occupied_card.position.x += offset


func _on_mouse_exited():
self.is_mouse_on = false

func _on_mouse_entered():
self.is_mouse_on = true
16 changes: 16 additions & 0 deletions levels/base_level/scroll_area/scroll_area.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[gd_scene load_steps=3 format=3 uid="uid://csl5lwjicxroy"]

[ext_resource type="Script" path="res://levels/base_level/scroll_area/scroll_area.gd" id="1_j4m6q"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_dbovb"]
size = Vector2(64, 200)

[node name="ScrollArea" type="Area2D"]
script = ExtResource("1_j4m6q")

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_dbovb")
debug_color = Color(0, 0.6, 0.701961, 0.419608)

[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]

0 comments on commit ba38d98

Please sign in to comment.