Skip to content

Commit

Permalink
Merge branch 'main' into ci
Browse files Browse the repository at this point in the history
  • Loading branch information
ligen131 authored Jan 27, 2024
2 parents 0d06f2b + 68f3adf commit 61d73a5
Show file tree
Hide file tree
Showing 181 changed files with 2,143 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

importer="texture"
type="CompressedTexture2D"
uid="uid://cjdbvf2hsot71"
path="res://.godot/imported/table_cloth1.png-215ff1efff981316f4f6ba2925a0af22.ctex"
uid="uid://bqxbykpxdibm3"
path="res://.godot/imported/=P3.png-0a6b5b000918869b69e00dff49d36c35.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://objects/table_cloth/table_cloth1.png"
dest_files=["res://.godot/imported/table_cloth1.png-215ff1efff981316f4f6ba2925a0af22.ctex"]
source_file="res://=P3.png"
dest_files=["res://.godot/imported/=P3.png-0a6b5b000918869b69e00dff49d36c35.ctex"]

[params]

Expand Down
Binary file added fonts/unifont-15.1.04.otf
Binary file not shown.
33 changes: 33 additions & 0 deletions fonts/unifont-15.1.04.otf.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[remap]

importer="font_data_dynamic"
type="FontFile"
uid="uid://1000owdyvwfg"
path="res://.godot/imported/unifont-15.1.04.otf-4298c95684bf879dc8f193b0b0354484.fontdata"

[deps]

source_file="res://fonts/unifont-15.1.04.otf"
dest_files=["res://.godot/imported/unifont-15.1.04.otf-4298c95684bf879dc8f193b0b0354484.fontdata"]

[params]

Rendering=null
antialiasing=1
generate_mipmaps=false
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=false
hinting=1
subpixel_positioning=1
oversampling=0.0
Fallbacks=null
fallbacks=[]
Compress=null
compress=true
preload=[]
language_support={}
script_support={}
opentype_features={}
131 changes: 110 additions & 21 deletions levels/base_level/base_level.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ extends Node

const Block := preload("res://objects/block/block.tscn")
const CardBase := preload("res://objects/card_base/card_base.tscn")
const LevelMenu := preload("res://levels/chapter_menu/level_menu/level_menu.tscn")
const TableCloth := preload("res://objects/table_cloth/table_cloth.tscn")
const HEIGHT := 1080 / 4
const WIDTH := 1920 / 4
const SEP := 30
const SEP := 28
const CARDS_SEP := 34


var expr := ""
var req_pos = [] # Array[int]
var chap_id : int
var lvl_id : int


const DATA := [
[
Expand All @@ -21,14 +29,24 @@ const DATA := [
["True", "[] {} {} [] 1", "= + P 1"],
["Swap", "Q + [] = {} + []", "P P P P Q Q Q Q"],
["Always True", "[] [] {} = {} [] []", "11++PPdd"],
["Not Really Challenging", "1 [] [] [] {} [] [] [] {} [] {} [] []", "= = + + + + + + 1 1 P q b R"]
["Not Really Challenging", "1 [] [] [] {} [] [] [] {} [] {} [] []", "== ++++++ 11 P q b R"]
],
[
["Laughing", "1 {} {} = []", "XDD"],
["Reset", "0 [] [] {} []", "XD10"],
["Not Necessary", "[] {} {} {} {} []", "QQQQQQDDXX="],
["Reset", "0 [] [] {} []", "XD=0"],
["Not Necessary", "[] {} {} {} {} []", "QQQQQQ DDXX="],
["Golden Experience", "{} {} {} {} {} {} {} {} {} {} {}", "PP DD qq dd bb XXX ="],
],
[
["He Goes First", "[] [] + [] = ( [] {} {} ) [] []", "PP QQ RR X +"],
["Still, He Goes First", "[] + [] [] = [] [] ( [] {} {} )", "PP QQ RR X +"],
["It's My Turn", "P ([] [] []) = {} [] [] [] []", "PP QQ RR ++"],
["[EX] Really Challenging", "[] [] [] [] [] {} {} [] [] [] [] {} {} + [] []", "PPP QQ DD (()) ++ = X"]
],
[
["Why?", "[] [] {} = {} [] {} = []", "PP qq ++ 1"],
["Where is the Equation?", "[] [] {} {} [] + [] [] {} {} []", "(())==01PP"],
]
]


Expand All @@ -42,49 +60,120 @@ func count(choices: String) -> Dictionary:
return res


func init(chap_id: int, lvl_id: int) -> void:
func init(_chap_id: int, _lvl_id: int) -> void:
chap_id = _chap_id
lvl_id = _lvl_id

var lvl_name = DATA[chap_id][lvl_id][0]
var question = DATA[chap_id][lvl_id][1].replace(" ", "").replace("X", "*")
var choices = count(DATA[chap_id][lvl_id][2].replace(" ", "").replace("X", "*"))


$HUDs/Title.set_text("%d-%d %s" % [chap_id + 1, lvl_id + 1, lvl_name])



question = question.replace("[]", ".")
question = question.replace("{}", "_")

var pos : int
pos = WIDTH / 2 - SEP * len(question) / 2 + 12
for ch in question:

var table_cloth = TableCloth.instantiate()
var sep := SEP

if len(question) >= 16:
sep = SEP
else:
sep = int((1 - len(question) / 16.0) * SEP * 0.3) + SEP

table_cloth.size.x = sep * len(question) + 16
table_cloth.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)

var pos := WIDTH / 2 - sep * len(question) / 2 + 12
for i in range(len(question)):
var ch = question[i]

var new_block := Block.instantiate()

new_block.set_word(ch)
if not ch == "." and not ch == "_":
new_block.quest_pos = i
if ch != "." and ch != "_":
new_block.occupied = true
new_block.set_word(ch)
new_block.set_block_type("CONST")
else:
new_block.set_word("_")
if ch == "_":
req_pos.append(i)
new_block.set_block_type("GOLDEN")
else:
new_block.set_block_type("PIT")
new_block.set_position(Vector2(pos, HEIGHT / 2))
pos += SEP
pos += sep

$Blocks.add_child(new_block)

expr = question
print(expr)



pos = WIDTH / 2 - SEP * len(choices) / 2 + 12
pos = WIDTH / 2 - CARDS_SEP * len(choices) / 2 + 20
for ch in choices:
var new_card_base := CardBase.instantiate()

new_card_base.set_word(ch)

# TODO: 调用备选卡牌计数 + 1
# new_card_base.add_card_count()


#new_card_base.set_count(choices[ch])
new_card_base.set_position(Vector2(pos, HEIGHT * 7 / 8))
pos += SEP
new_card_base.set_card_count(choices[ch])
new_card_base.set_position(Vector2(pos, HEIGHT * 6 / 7))
pos += CARDS_SEP

$CardBases.add_child(new_card_base)
new_card_base.card_put.connect(_on_card_put)


func _ready():
pass
$HUDs/BackButton.set_word("<")

func _process(_delta):
pass


func _on_card_put() -> void:
for block : Block in $Blocks.get_children():
if not block.occupied:
print(block.quest_pos, " is not occupied")
return
expr[block.quest_pos] = block.occupied_word

prints("# expr: ", expr)

if expr.count("_") == 0:
var info = $Calculator.check(expr, req_pos)
prints("expr:", expr)
prints("info:", info)

if info[0] != "OK":
$SFXs/WrongAnswer.play()

if info[0] == "INVALID":
for block: Block in $Blocks.get_children():
if block.quest_pos in info[1]:
block.call("shake")
elif info[0] == "SMILE_UNSATISFIED":
for block: Block in $Blocks.get_children():
if block.quest_pos == info[1]:
block.call("shake")
elif info[0] == "NOT_ALWAYS_TRUE":
for block: Block in $Blocks.get_children():
block.call("shake")
else:
$SFXs/LevelClear.play()



func _on_back_button_pressed():
var level_menu = LevelMenu.instantiate()
level_menu.init(chap_id, -1)
get_tree().root.add_child(level_menu)
queue_free()
32 changes: 24 additions & 8 deletions levels/base_level/base_level.tscn
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
[gd_scene load_steps=4 format=3 uid="uid://cother2aiigge"]
[gd_scene load_steps=7 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"]
[ext_resource type="AudioStream" path="res://levels/base_level/level_clear.wav" id="3_ou3kh"]
[ext_resource type="PackedScene" uid="uid://bepyyenjtc0p3" path="res://levels/chapter_menu/level_menu/level_button/level_button.tscn" id="2_0egdl"]
[ext_resource type="AudioStream" uid="uid://cjhl2qr4mau8g" path="res://levels/base_level/level_clear.wav" id="3_ou3kh"]
[ext_resource type="FontFile" uid="uid://1000owdyvwfg" path="res://fonts/unifont-15.1.04.otf" id="3_q0kqv"]
[ext_resource type="AudioStream" uid="uid://c6rflw11edxrt" path="res://levels/base_level/wrong_answer.wav" id="4_yxsxp"]

[node name="BaseLevel" type="Node"]
script = ExtResource("1_diojb")

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

[node name="BackButton" parent="HUDs" instance=ExtResource("2_0egdl")]

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

[node name="Calculator" parent="." instance=ExtResource("1_tpuy7")]

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

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

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

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

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

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

[node name="HUDs" type="Node" parent="."]
[node name="WrongAnswer" type="AudioStreamPlayer2D" parent="SFXs"]
stream = ExtResource("4_yxsxp")
volume_db = 1.0

[node name="Button" type="Button" parent="HUDs"]
offset_right = 8.0
offset_bottom = 8.0
[connection signal="pressed" from="HUDs/BackButton" to="." method="_on_back_button_pressed"]
Binary file added levels/base_level/wrong_answer.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions levels/base_level/wrong_answer.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://c6rflw11edxrt"
path="res://.godot/imported/wrong_answer.wav-84c9832fd72ff8c3b7efd2550837544a.sample"

[deps]

source_file="res://levels/base_level/wrong_answer.wav"
dest_files=["res://.godot/imported/wrong_answer.wav-84c9832fd72ff8c3b7efd2550837544a.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
22 changes: 12 additions & 10 deletions levels/chapter_menu/chapter_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,28 @@ const LevelMenu := preload("res://levels/chapter_menu/level_menu/level_menu.tscn
# Called when the node enters the scene tree for the first time.

@export var chapter_id : int = 0
const button_width : int = 85
const button_heigth : int = 90
const button_width : int = 50
const button_heigth : int = 50

func init(chap_num : int) -> void:
func init() -> void:
print("1")
var chap_num : int = len(BaseLevel.instantiate().DATA)
for chapter_id in range(0, chap_num):
print(chapter_id)
# print(chapter_id)
var level_num : int = len(BaseLevel.instantiate().DATA[chapter_id])
var button = LevelButton.instantiate();
var x : int = button_width * (chapter_id % 4) + 50
var y : int = button_heigth * (chapter_id / 4) + 30
var x : int = button_width * (chapter_id % 9) + 60
var y : int = button_heigth * (chapter_id / 9) + 100
button.init(chapter_id, level_num, Vector2(x, y), 0)
button.enter_chapter.connect(_is_choose_chapter)
add_child(button)


func _ready():
print("ready")
init()
#print(BaseLevel.instantiate().DATA[chapter_id])
var chapter_num : int = len(BaseLevel.instantiate().DATA)
print(chapter_num)
init(chapter_num)
# print(chapter_num)


# Called every frame. 'delta' is the elapsed time since the previous frame.
Expand All @@ -38,6 +40,6 @@ func _process(delta):
func _is_choose_chapter(chapter_id : int, level_num : int):
var level_menu = LevelMenu.instantiate()
level_menu.init(chapter_id, level_num)
print("here ready to change scene to ", chapter_id)
# print("here ready to change scene to ", chapter_id)
get_tree().root.add_child(level_menu)
queue_free()
12 changes: 9 additions & 3 deletions levels/chapter_menu/level_menu/level_button/level_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,26 @@ func _ready():
func _process(delta):
pass

func set_word(value: String) -> void:
$Word.set_word(value)


func init(chapter_id: int, level_id : int, pos : Vector2, type : int) -> void :
chap_id = chapter_id
lvl_id = level_id

var txt
if type == 0:
text = str(chapter_id + 1)
txt = str(chapter_id + 1)
else:
text = str(level_id + 1)
txt = str(level_id + 1)
set_word(txt)

position = pos
button_type = type

func _on_pressed():
print("choose: ",chap_id,"-",lvl_id)
# print("choose: ",chap_id,"-",lvl_id)
if button_type == 1:
enter_level.emit(chap_id, lvl_id)
else:
Expand Down
Loading

0 comments on commit 61d73a5

Please sign in to comment.