Skip to content

Commit

Permalink
Merge branch 'main' into mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacTheMouse committed Jan 27, 2024
2 parents 22d4cb2 + 4f13181 commit aab2557
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 34 deletions.
11 changes: 10 additions & 1 deletion levels/base_level/base_level.gd
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func init(_chap_id: int, _lvl_id: int) -> void:

table_cloth.size.x = sep * len(question) + 16
table_cloth.size.y = 48
table_cloth.get_child(0).size.x = sep * len(question) + 16
table_cloth.get_child(0).size.y = 48
table_cloth.position.x = WIDTH / 2 - sep * len(question) / 2 - 12
table_cloth.position.y = HEIGHT / 2 - 24
$HUDs.add_child(table_cloth)
Expand Down Expand Up @@ -139,6 +141,13 @@ func _process(_delta):
pass


func stage_clear() -> void:
$SFXs/LevelClear.play()
for card_base: CardBase in $CardBases.get_children():
card_base.call("start_fade")
$HUDs/TableCloth/GoldenCloth.set_visible(true)


func _on_card_put() -> void:
for block : Block in $Blocks.get_children():
if not block.occupied:
Expand Down Expand Up @@ -168,7 +177,7 @@ func _on_card_put() -> void:
for block: Block in $Blocks.get_children():
block.call("shake")
else:
$SFXs/LevelClear.play()
stage_clear()



Expand Down
13 changes: 12 additions & 1 deletion levels/chapter_menu/chapter_menu.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
[gd_scene load_steps=2 format=3 uid="uid://d138qs4pakk22"]
[gd_scene load_steps=3 format=3 uid="uid://d138qs4pakk22"]

[ext_resource type="Script" path="res://levels/chapter_menu/chapter_menu.gd" id="1_sfx21"]
[ext_resource type="FontFile" uid="uid://1000owdyvwfg" path="res://fonts/unifont-15.1.04.otf" id="2_y2jwf"]

[node name="ChapterMenu" type="Node2D"]
script = ExtResource("1_sfx21")

[node name="Label" type="Label" parent="."]
custom_minimum_size = Vector2(480, 1)
offset_top = 8.0
offset_right = 480.0
offset_bottom = 31.0
theme_override_fonts/font = ExtResource("2_y2jwf")
text = "Chapter Select"
horizontal_alignment = 1
vertical_alignment = 1
4 changes: 2 additions & 2 deletions levels/chapter_menu/level_menu/level_button/level_button.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
[ext_resource type="PackedScene" uid="uid://cvx7wowcbfo0r" path="res://objects/word/word.tscn" id="3_js2i2"]

[node name="StyledButton" instance=ExtResource("1_4bgxw")]
offset_right = 42.0
offset_bottom = 42.0
offset_right = 40.0
offset_bottom = 40.0
script = ExtResource("1_wwqfn")

[node name="Word" parent="." index="0" instance=ExtResource("3_js2i2")]
Expand Down
5 changes: 5 additions & 0 deletions levels/chapter_menu/level_menu/level_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ extends Node2D



const CHAP_NAMES = ["=P", "Add", "Multiply", "()", "Equal?"]



const LevelButton := preload("res://levels/chapter_menu/level_menu/level_button/level_button.tscn")
const BaseLevel := preload("res://levels/base_level/base_level.tscn")

Expand All @@ -17,6 +21,7 @@ func init(chap_id : int, lvl_num : int) -> void:
if lvl_num == -1:
lvl_num = len(BaseLevel.instantiate().DATA[chap_id])

$Title.set_text("Ch." + str(chap_id + 1) + " " + CHAP_NAMES[chap_id])

chapter_id = chap_id
for level_id in range(0, lvl_num):
Expand Down
12 changes: 11 additions & 1 deletion levels/chapter_menu/level_menu/level_menu.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
[gd_scene load_steps=3 format=3 uid="uid://doirpa1bwbjhr"]
[gd_scene load_steps=4 format=3 uid="uid://doirpa1bwbjhr"]

[ext_resource type="Script" path="res://levels/chapter_menu/level_menu/level_menu.gd" id="1_sd65g"]
[ext_resource type="PackedScene" uid="uid://bepyyenjtc0p3" path="res://levels/chapter_menu/level_menu/level_button/level_button.tscn" id="2_saprs"]
[ext_resource type="FontFile" uid="uid://1000owdyvwfg" path="res://fonts/unifont-15.1.04.otf" id="3_jlnpm"]

[node name="LevelMenu" type="Node2D"]
script = ExtResource("1_sd65g")

[node name="BackButton" parent="." instance=ExtResource("2_saprs")]

[node name="Title" type="Label" parent="."]
offset_top = 8.0
offset_right = 480.0
offset_bottom = 31.0
theme_override_fonts/font = ExtResource("3_jlnpm")
text = "Title"
horizontal_alignment = 1
vertical_alignment = 1

[connection signal="pressed" from="BackButton" to="." method="_on_back_button_pressed"]
2 changes: 2 additions & 0 deletions objects/block/block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func set_word(e: String) -> void:
func set_block_type(value: String) -> void:
if value == "GOLDEN":
$GoalFrameSprite.set_visible(true)
$GoalFrameSprite.set_texture(load("res://objects/block/goal_frame" + str(int(sqrt(randi_range(1, 16)))) + ".png"))

$PitSprite.set_visible(true)
elif value == "PIT":
$GoalFrameSprite.set_visible(false)
Expand Down
5 changes: 3 additions & 2 deletions objects/block/block.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
[ext_resource type="Texture2D" uid="uid://cb71r50jw2a3i" path="res://objects/block/goal_frame2.png" id="4_v6rgm"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_3if4e"]
size = Vector2(24, 24)
size = Vector2(16, 16)

[node name="Block" type="Area2D"]
script = ExtResource("1_11h57")

[node name="Word" parent="." instance=ExtResource("2_pjs40")]

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
z_index = 2
z_index = 50
shape = SubResource("RectangleShape2D_3if4e")
debug_color = Color(0.968627, 0, 0.470588, 0.419608)

[node name="PitSprite" type="Sprite2D" parent="."]
z_index = -1
Expand Down
28 changes: 27 additions & 1 deletion objects/calculator/calculator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,20 @@ val: Q/0/1
Q 1 1 1 1 1
"""

"""
左/右 * < ( ) Q
* / / 0 / 0
< / 0 0 / 0
( / / 0 / 0
) 0 0 1 0 1
Q 0 0 1 0 1
"""

const IS_PAIR_VALID := [[0, 0, 1, 0, 1], [0, 1, 1, 0, 1], [0, 0, 1, 0, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]

enum {OP, COMP, BRAC_L, BRAC_R, VAL}


func get_char_type(ch: String) -> int:
if ch == "*" or ch == "+":
return OP
Expand All @@ -47,6 +57,9 @@ func get_char_type(ch: String) -> int:
else:
return VAL

func has_implict_prod(string: String) -> bool:
return get_char_type(string[0]) in [BRAC_R, VAL] and get_char_type(string[1]) in [BRAC_L, VAL]

func get_priority(ch: String) -> int:
if ch == "*":
return 4
Expand All @@ -66,8 +79,18 @@ func get_priority(ch: String) -> int:
func infix_to_suffix(expr: String) -> String:
var opt_stack: Array = []
var res := ""
var pre_ch := "@"

for ch in expr:
if pre_ch != "@" and has_implict_prod(pre_ch + ch):
if not opt_stack.is_empty() and (get_char_type("*") != COMP or get_char_type(opt_stack.back()) != COMP):
while not opt_stack.is_empty() and get_priority("*") <= get_priority(opt_stack.back()):
res += opt_stack.back()
opt_stack.pop_back()
opt_stack.push_back("*")



print("ch=", ch, " stk=", opt_stack, " res=", res)
if get_char_type(ch) == VAL:
res += ch
Expand All @@ -84,6 +107,7 @@ func infix_to_suffix(expr: String) -> String:
res += opt_stack.back()
opt_stack.pop_back()
opt_stack.push_back(ch)
pre_ch = ch

while not opt_stack.is_empty():
res += opt_stack.back()
Expand Down Expand Up @@ -184,6 +208,7 @@ func check_always_true(expr: String) -> Dictionary:

# 中缀转后缀
expr = infix_to_suffix(expr)
print(expr)

for ch in expr:
if is_alpha(ch) and not var_names.has(ch):
Expand Down Expand Up @@ -229,7 +254,8 @@ func check(expr: String, req_pos: Array) -> Array:


func _ready():
assert(check("(1=P)+(0=P)", []) == ["OK", 200], "9")
check("q*Pq*bd*b=D", [])
#assert(check("(1=P)+(0=P)", []) == ["OK", 200], "9")
#assert(check("Q+P=P+Q", [3, 4]) == ["OK", 200], "1")
#assert(check("Q+P=P+Q", [4]) == ["OK", 200], "2")
#assert(check("P+Q=Q+P", [3, 4]) == ["SMILE_UNSATISFIED", 3], "3")
Expand Down
14 changes: 11 additions & 3 deletions objects/card/card.tscn
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[gd_scene load_steps=8 format=3 uid="uid://b223s12rqgt4h"]
[gd_scene load_steps=9 format=3 uid="uid://b223s12rqgt4h"]

[ext_resource type="Script" path="res://objects/card/card.gd" id="1_0bviv"]
[ext_resource type="PackedScene" uid="uid://cvx7wowcbfo0r" path="res://objects/word/word.tscn" id="1_ns36n"]
[ext_resource type="Texture2D" uid="uid://cfbqh1k0etr6g" path="res://objects/card/card1.png" id="3_o4f0v"]
[ext_resource type="Texture2D" uid="uid://c8qjbksyn1bqt" path="res://objects/card/card2.png" id="4_c30j1"]
[ext_resource type="Texture2D" uid="uid://bevrfq1hhyqwe" path="res://objects/card/card3.png" id="5_w81n3"]
[ext_resource type="Texture2D" uid="uid://cmcc5xrpkrd0f" path="res://objects/card/card_highlighted.png" id="6_po2i6"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_gu6l6"]
size = Vector2(14, 14)

[sub_resource type="SpriteFrames" id="SpriteFrames_fo0r0"]
animations = [{
Expand All @@ -24,6 +24,14 @@ animations = [{
"loop": true,
"name": &"default",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("6_po2i6")
}],
"loop": true,
"name": &"highlighted",
"speed": 5.0
}]

[node name="Card" type="Area2D"]
Expand All @@ -40,5 +48,5 @@ shape = SubResource("RectangleShape2D_gu6l6")

[node name="CardBackSprite" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_fo0r0")
animation = &"highlighted"
autoplay = "default"
frame_progress = 0.275098
23 changes: 22 additions & 1 deletion objects/card_base/card_base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ extends Area2D
class_name CardBase

const Card := preload("res://objects/card/card.tscn")
const FADE_MOVE_AMOUNT := 70

signal card_put


var fade_flag := false


var card_count = 0
var new_card_node: Card

Expand All @@ -30,7 +35,7 @@ func set_card_count(value):
func draw_card():
if card_count <= 0:
return
set_card_count(card_count - 1)
set_card_count(card_count - 1)
$SFXPickUp.play()
new_card_node = Card.instantiate()
new_card_node.set_word($Word.get_word())
Expand Down Expand Up @@ -70,3 +75,19 @@ func set_word(e: String) -> void:
func _on_card_put():
emit_signal("card_put")





func start_fade() -> void:
fade_flag = true
$FadeTimer.start()
$CollisionShape2D.set_deferred("disabled", true)
$Label.set_visible(false)

func _process(delta) -> void:
if fade_flag:
var offset = $FadeTimer.time_left / $FadeTimer.wait_time
offset = (1 - pow(offset, 1.5)) * FADE_MOVE_AMOUNT
$AnimatedSprite2D.position.y = offset
$Word.position.y = offset
4 changes: 4 additions & 0 deletions objects/card_base/card_base.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,9 @@ sprite_frames = SubResource("SpriteFrames_bhb3x")
stream = ExtResource("7_0c7kt")
volume_db = 8.54

[node name="FadeTimer" type="Timer" parent="."]
wait_time = 0.2
one_shot = true

[connection signal="area_entered" from="." to="." method="_on_area_entered"]
[connection signal="area_exited" from="." to="." method="_on_area_exited"]
2 changes: 1 addition & 1 deletion objects/main_menu/main_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var ChapterMenu = preload("res://levels/chapter_menu/chapter_menu.tscn")

# Called when the node enters the scene tree for the first time.
func _ready():
play()
play("init")
pass # Replace with function body.


Expand Down
8 changes: 6 additions & 2 deletions objects/main_menu/main_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ animations = [{
}, {
"duration": 1.0,
"texture": ExtResource("10_6ukle")
}, {
"duration": 1.0,
"texture": ExtResource("11_j1jkd")
}],
"loop": false,
"name": &"default",
"name": &"init",
"speed": 5.0
}, {
"frames": [{
Expand All @@ -71,7 +74,7 @@ animations = [{
"texture": ExtResource("11_j1jkd")
}],
"loop": true,
"name": &"new_animation",
"name": &"wait_for_start",
"speed": 5.0
}]

Expand Down Expand Up @@ -110,6 +113,7 @@ animations = [{
[node name="MainMenu" type="AnimatedSprite2D"]
scale = Vector2(2.5, 2.5)
sprite_frames = SubResource("SpriteFrames_b4517")
animation = &"init"
centered = false
script = ExtResource("14_npy3s")

Expand Down
32 changes: 14 additions & 18 deletions objects/styled_button/styled_button.tscn
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
[gd_scene load_steps=9 format=3 uid="uid://drl1xe103umpi"]
[gd_scene load_steps=6 format=3 uid="uid://drl1xe103umpi"]

[ext_resource type="Texture2D" uid="uid://b5d2rfms7vyfi" path="res://objects/card_base/card_base1.png" id="1_rsfr7"]
[ext_resource type="Texture2D" uid="uid://cs7vfmsrhpomj" path="res://objects/card_base/card_base_highlighted.png" id="2_hwjbt"]
[ext_resource type="Texture2D" uid="uid://bkjbrw1ppac5q" path="res://objects/card_base/card_base_disabled.png" id="3_eoagx"]
[ext_resource type="Texture2D" uid="uid://cfbqh1k0etr6g" path="res://objects/card/card1.png" id="1_l6dpy"]
[ext_resource type="Texture2D" uid="uid://cmcc5xrpkrd0f" path="res://objects/card/card_highlighted.png" id="2_j1sqk"]

[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_0r0ru"]
texture = ExtResource("1_rsfr7")
[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_c0uot"]
texture = ExtResource("1_l6dpy")

[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_mqko3"]
texture = ExtResource("2_hwjbt")

[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_0m6th"]
texture = ExtResource("3_eoagx")

[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_5rbv7"]
texture = ExtResource("3_eoagx")
[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_eifmj"]
texture = ExtResource("2_j1sqk")
texture_margin_left = 4.0
texture_margin_top = 4.0
texture_margin_right = 4.0
texture_margin_bottom = 4.0

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_tfhr0"]

[node name="StyledButton" type="Button"]
offset_right = 100.0
offset_bottom = 100.0
theme_override_styles/normal = SubResource("StyleBoxTexture_0r0ru")
theme_override_styles/hover = SubResource("StyleBoxTexture_mqko3")
theme_override_styles/pressed = SubResource("StyleBoxTexture_0m6th")
theme_override_styles/disabled = SubResource("StyleBoxTexture_5rbv7")
theme_override_styles/normal = SubResource("StyleBoxTexture_c0uot")
theme_override_styles/hover = SubResource("StyleBoxTexture_eifmj")
theme_override_styles/pressed = SubResource("StyleBoxTexture_eifmj")
theme_override_styles/focus = SubResource("StyleBoxEmpty_tfhr0")
Binary file added objects/table_cloth/golden_cloth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit aab2557

Please sign in to comment.