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 Feb 13, 2024
2 parents 5f57900 + 0e3803f commit e1ea2b5
Show file tree
Hide file tree
Showing 33 changed files with 483 additions and 288 deletions.
5 changes: 0 additions & 5 deletions bg/dynamic_bg/dynamic_bg.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ func _ready():
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():
Expand Down
9 changes: 7 additions & 2 deletions bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ func _process(delta):
queue_free()

func _on_victory_change(v: bool):
$Word1.set_victory(v)
$Word2.set_victory(v)
if v:
$Word1.set_color(ImageLib.PALETTE["golden"])
$Word2.set_color(ImageLib.PALETTE["golden"])
else:
$Word1.set_color(ImageLib.PALETTE["default"])
$Word2.set_color(ImageLib.PALETTE["default"])

75 changes: 41 additions & 34 deletions levels/base_level/base_level.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
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 BaseLevel := preload("res://levels/base_level/base_level.tscn")
class_name BaseLevel

# FIXME
# 由于 Godot preload 容易出错,此处改为 load
var BlockScn = load("res://objects/block/block.tscn")
var CardBaseScn = load("res://objects/card_base/card_base.tscn")
var LevelMenuScn = load("res://levels/chapter_menu/level_menu/level_menu.tscn")
var TableClothScn = load("res://objects/table_cloth/table_cloth.tscn")
var BaseLevelScn = load("res://levels/base_level/base_level.tscn")


const HEIGHT := 1080 / 4
const WIDTH := 1920 / 4
const SEP := 28
Expand All @@ -21,14 +27,15 @@ const I_NUMBER = ["I","II","III","VI","V"]

const DATA := [
[
["=P", "P {} {}", "= P"],
["P", "P [] {}", "= P P"],
["=D", "D {} {}", "= D P"],
["Reverse", "{} {} []", "d d = P P D D"]
["=P", "P [] []", "= P"],
["Make a Smile", "P {} {}", "= P P"],
["=D", "[] {} {}", "P = D D"],
["Reversed", "{} [] []", "D D = d d"],
["Watch Out the Direction", "[] {} {}", "d d = R R b b"],
],
[
["False", "[] [] 0 {} {}", "= + P P"],
["True", "[] {} {} [] 1", "= + P 1"],
["0+0=0, 1+0=1", "[] [] {} {} d", "= + 0 d"],
["1+1=1", "[] [] {} {} 1", "= + d 1"],
["Swap", "Q + [] = {} + []", "P P P P Q Q Q Q"],
["Always True", "1 [] {} = {} [] []", "1++PPdd"],
["Make Me Laugh", "1 {} {} = []", "XDD"],
Expand Down Expand Up @@ -83,7 +90,7 @@ func init(_chap_id: int, _lvl_id: int) -> void:
question = question.replace("{}", "_")


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

if len(question) >= 16:
Expand All @@ -103,7 +110,7 @@ func init(_chap_id: int, _lvl_id: int) -> void:
for i in range(len(question)):
var ch = question[i]

var new_block := Block.instantiate()
var new_block = BlockScn.instantiate()

new_block.quest_pos = i
if ch != "." and ch != "_":
Expand All @@ -123,12 +130,12 @@ func init(_chap_id: int, _lvl_id: int) -> void:
$Blocks.add_child(new_block)

expr = question
print(expr)
# print(expr)


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

new_card_base.set_word(ch)

Expand All @@ -151,7 +158,7 @@ func _process(_delta):
func stage_clear() -> void:
$SFXs/LevelClear.play()
for card_base: CardBase in $CardBases.get_children():
card_base.call("set_victory")
card_base.set_victory()

$HUDs/TableCloth/GoldenCloth.set_visible(true)
$HUDs/NextLevelButton.start_fade()
Expand All @@ -161,43 +168,43 @@ func _on_card_put() -> void:
var block_array = []
for block : Block in $Blocks.get_children():
if not block.occupied:
print(block.quest_pos, " is not occupied")
# print(block.quest_pos, " is not occupied")
return
expr[block.quest_pos] = block.occupied_word
block_array.append(block)

prints("# expr: ", expr)
# prints("# expr: ", expr)

if expr.count("_") == 0:
var info = $Calculator.check(expr, req_pos)
prints("expr:", expr)
prints("info:", info)
var info = ExprValidator.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")
block.shake(false)
elif info[0] == "SMILE_UNSATISFIED":
for block: Block in $Blocks.get_children():
if block.quest_pos == info[1]:
block.call("shake")
if block.quest_pos in info[1]:
block.shake(true)
elif info[0] == "NOT_ALWAYS_TRUE":
for block: Block in $Blocks.get_children():
block.call("shake")
block.shake(false)
else:
# victory
get_tree().current_scene.set_victory(true)
stage_clear()
print(block_array)
# print(block_array)
for i in range(len(block_array)):
if i != 0:
if $Calculator.is_smile(expr[i-1]+expr[i]):
print(expr[i-1]+expr[i])
block_array[i-1].set_victory(true)
block_array[i].set_victory(true)
if ExprValidator.is_smile(expr[i-1]+expr[i]):
# print(expr[i-1]+expr[i])
block_array[i-1].set_color(ImageLib.PALETTE["golden"])
block_array[i].set_color(ImageLib.PALETTE["golden"])

func _input(event: InputEvent):
if event is InputEventKey:
Expand All @@ -212,24 +219,24 @@ func _exit_tree():


func _on_back_button_pressed():
var level_menu = LevelMenu.instantiate()
var level_menu = LevelMenuScn.instantiate()
level_menu.init(chap_id, -1)
get_tree().root.add_child(level_menu)
queue_free()

func _on_next_level_button_pressed():
if lvl_id == len(DATA[chap_id]) - 1:
var level_menu := LevelMenu.instantiate()
var level_menu = LevelMenuScn.instantiate()
level_menu.init(chap_id + 1, -1)
get_tree().root.add_child(level_menu)
else:
var base_level := BaseLevel.instantiate()
var base_level = BaseLevelScn.instantiate()
base_level.init(chap_id, lvl_id + 1)
get_tree().root.add_child(base_level)
queue_free()

func _on_replay_button_pressed():
var new_level = BaseLevel.instantiate()
var new_level = BaseLevelScn.instantiate()
new_level.init(chap_id, lvl_id)
get_tree().root.add_child(new_level)
queue_free()
Expand Down
5 changes: 1 addition & 4 deletions levels/base_level/base_level.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[gd_scene load_steps=16 format=3 uid="uid://cother2aiigge"]
[gd_scene load_steps=15 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="PackedScene" uid="uid://bepyyenjtc0p3" path="res://levels/chapter_menu/level_menu/level_button/level_button.tscn" id="2_0egdl"]
[ext_resource type="PackedScene" uid="uid://d1mp3ld6wsrwo" path="res://levels/base_level/next_level_button/next_level_button.tscn" id="2_0363i"]
[ext_resource type="Texture2D" uid="uid://bxda1ilvqwc6f" path="res://objects/styled_button/return1.png" id="3_4xtpo"]
Expand Down Expand Up @@ -82,8 +81,6 @@ sprite_frames = SubResource("SpriteFrames_5hm0m")
animation = &"replay"
centered = false

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

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

[node name="Blocks" type="Node" parent="."]
Expand Down
3 changes: 1 addition & 2 deletions levels/base_level/next_level_button/next_level_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func _ready():
position = Vector2(WIDTH / 2 - 20, HEIGHT + 80)
$Word.set_word(">")

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
func _process(_delta):
if fade_flag:
position.y = HEIGHT + 50 - 120 * (1 - pow($FadeTimer.time_left / $FadeTimer.wait_time, 1.5))
38 changes: 17 additions & 21 deletions levels/chapter_menu/chapter_menu.gd
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
extends Node2D

class_name ChapterMenu


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

# Called when the node enters the scene tree for the first time.

Expand All @@ -13,32 +13,28 @@ const button_width : int = 50
const button_heigth : int = 50

func init() -> void:
var chap_num : int = len(BaseLevel.instantiate().DATA)
for chapter_id in range(0, chap_num):
# print(chapter_id)
var level_num : int = len(BaseLevel.instantiate().DATA[chapter_id])
var button = LevelButton.instantiate();
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)
var chap_num : int = len(BaseLevelScn.instantiate().DATA)
for lvl_id in range(0, chap_num):
# print(lvl_id)
var level_num : int = len(BaseLevelScn.instantiate().DATA[lvl_id])
var button = LevelButtonScn.instantiate();
var x : int = button_width * (lvl_id % 9) + 60
var y : int = button_heigth * (lvl_id / 9) + 100
button.init(lvl_id, level_num, Vector2(x, y), 0)
button.enter_chapter.connect(_is_choose_chapter)
add_child(button)


func _ready():
print("ready")
# print("ready")
init()
#print(BaseLevel.instantiate().DATA[chapter_id])
#print(BaseLevelScn.instantiate().DATA[chapter_id])
# print(chapter_num)


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

func _is_choose_chapter(chapter_id : int, level_num : int):
var level_menu = LevelMenu.instantiate()
level_menu.init(chapter_id, level_num)
func _is_choose_chapter(chap_id : int, level_num : int):
var level_menu = LevelMenuScn.instantiate()
level_menu.init(chap_id, level_num)
# print("here ready to change scene to ", chapter_id)
get_tree().root.add_child(level_menu)
queue_free()
12 changes: 2 additions & 10 deletions levels/chapter_menu/level_menu/level_button/level_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@ signal enter_chapter(chapter_id:int, level_num : int)
var lvl_id = 0 # 如果 type = 0 那么 lvl_id 表示的是该章节的关卡数 lvl_num
var chap_id = 0
var button_type = 0 # type = 0 表示为选择章节的按钮, type = 1 表示为选择关卡的按钮
# Called when the node enters the scene tree for the first time.

func _ready():
pass # Replace with function body.


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

func set_word(value: String) -> void:
$Word.set_word(value)
Expand All @@ -36,8 +28,8 @@ func init(chapter_id: int, level_id : int, pos : Vector2, type : int) -> void :
button_type = type

func _on_pressed():
print("choose: ",chap_id,"-",lvl_id)
print("! ")
# print("choose: ",chap_id,"-",lvl_id)
# print("! ")
$SFXButtonDown.play()
if button_type == 1:
enter_level.emit(chap_id, lvl_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ script = ExtResource("1_wwqfn")
[node name="Word" parent="." index="0" instance=ExtResource("3_js2i2")]
position = Vector2(19, 19)
scale = Vector2(1.5, 1.5)
text_id = 0
25 changes: 11 additions & 14 deletions levels/chapter_menu/level_menu/level_menu.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
extends Node2D


class_name LevelMenu

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

const I_NUMBER = ["I","II","III","VI","V"]

const LevelButton := preload("res://levels/chapter_menu/level_menu/level_button/level_button.tscn")
const BaseLevel := preload("res://levels/base_level/base_level.tscn")
const Credits := preload("res://objects/credits/credits.tscn")
const LevelButtonScn := preload("res://levels/chapter_menu/level_menu/level_button/level_button.tscn")
const BaseLevelScn := preload("res://levels/base_level/base_level.tscn")
const CreditsScn := preload("res://objects/credits/credits.tscn")

# Called when the node enters the scene tree for the first time.

Expand All @@ -19,21 +19,21 @@ const button_heigth : int = 50
func init(chap_id : int, lvl_num : int) -> void:
#print("init?")

if chap_id == len(BaseLevel.instantiate().DATA):
add_child(Credits.instantiate())
if chap_id == len(BaseLevelScn.instantiate().DATA):
add_child(CreditsScn.instantiate())
$Title.set_text("")
return


if lvl_num == -1:
lvl_num = len(BaseLevel.instantiate().DATA[chap_id])
lvl_num = len(BaseLevelScn.instantiate().DATA[chap_id])

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

chapter_id = chap_id
for level_id in range(0, lvl_num):
#print(level_id)
var button = LevelButton.instantiate();
var button = LevelButtonScn.instantiate();
var x : int = button_width * (level_id % 7) + 60
var y : int = button_heigth * (level_id / 7) + 100
button.init(chapter_id, level_id, Vector2(x, y), 1)
Expand All @@ -48,12 +48,9 @@ func _ready():
#print("why not?")
pass

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

func _on_button_enter_level(chap_id: int, lvl_id: int) -> void:
var base_level := BaseLevel.instantiate()
var base_level := BaseLevelScn.instantiate()

# print(chap_id, lvl_id)

Expand All @@ -67,8 +64,8 @@ func _input(event: InputEvent):
_on_back_button_pressed()

func _on_back_button_pressed():
var ChapterMenu = load("res://levels/chapter_menu/chapter_menu.tscn")
var chapter_menu = ChapterMenu.instantiate()
var ChapterMenuScn = load("res://levels/chapter_menu/chapter_menu.tscn")
var chapter_menu = ChapterMenuScn.instantiate()

chapter_menu.init()
get_tree().root.add_child(chapter_menu)
Expand Down
Loading

0 comments on commit e1ea2b5

Please sign in to comment.