Skip to content

Commit

Permalink
胜利时高亮笑脸和背景
Browse files Browse the repository at this point in the history
  • Loading branch information
ligen131 committed Jan 28, 2024
1 parent 2158fb3 commit 4d64996
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 7 deletions.
8 changes: 8 additions & 0 deletions bg/dynamic_bg/dynamic_bg.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
extends Node2D

signal victory_change(v: bool)

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

var is_victory = false

const WIDTH = 1920 / 4
const HEIGHT = 1080 / 4
Expand All @@ -21,11 +23,17 @@ func spawn(x_offset, y_offset):

new_pattern.position = Vector2(pat_x, pat_y)
new_pattern.velocity = VELOCITY
victory_change.connect(new_pattern._on_victory_change)
new_pattern._on_victory_change(is_victory)
add_child(new_pattern)

pat_x += W_STEP
pat_y += H_STEP

func set_victory(v: bool):
if is_victory != v:
is_victory = v
victory_change.emit(v)

func _ready():
var x_offset = 0
Expand Down
4 changes: 4 additions & 0 deletions bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ func _process(delta):
position += velocity * delta
if position.x > 1920 / 4 + 70 or position.y < -70:
queue_free()

func _on_victory_change(v: bool):
$Word1.set_victory(v)
$Word2.set_victory(v)
15 changes: 15 additions & 0 deletions levels/base_level/base_level.gd
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,13 @@ func stage_clear() -> void:


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")
return
expr[block.quest_pos] = block.occupied_word
block_array.append(block)

prints("# expr: ", expr)

Expand All @@ -182,7 +184,16 @@ func _on_card_put() -> void:
for block: Block in $Blocks.get_children():
block.call("shake")
else:
# victory
get_tree().current_scene.set_victory(true)
stage_clear()
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)

func _input(event: InputEvent):
if event is InputEventKey:
Expand All @@ -192,6 +203,10 @@ func _input(event: InputEvent):
_on_back_button_pressed()


func _exit_tree():
get_tree().current_scene.set_victory(false)


func _on_back_button_pressed():
var level_menu = LevelMenu.instantiate()
level_menu.init(chap_id, -1)
Expand Down
14 changes: 14 additions & 0 deletions main.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends Node


# 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_victory(v: bool):
$Bg/DynamicBg.set_victory(v)
4 changes: 3 additions & 1 deletion main.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[gd_scene load_steps=3 format=3 uid="uid://c17fbsiogbgo1"]
[gd_scene load_steps=4 format=3 uid="uid://c17fbsiogbgo1"]

[ext_resource type="Script" path="res://main.gd" id="1_d0et0"]
[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"]
script = ExtResource("1_d0et0")

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

Expand Down
11 changes: 11 additions & 0 deletions objects/block/block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const SHAKE_AMOUNT := 4

var occupied := false
var occupied_word: String
var occupied_card: Card

var quest_pos := -1
var is_shaking := false
Expand All @@ -31,6 +32,10 @@ func set_word(e: String) -> void:
else:
occupied = false
occupied_word = "_"

func set_card(c: Card) -> void:
occupied_card = c
occupied_word = c.get_word()

func set_block_type(value: String) -> void:
if value == "GOLDEN":
Expand Down Expand Up @@ -64,3 +69,9 @@ func shake():

func _on_shake_timer_timeout():
is_shaking = false

func set_victory(v: bool):
if occupied and occupied_card:
occupied_card.set_victory(v)
else:
$Word.set_victory(v)
5 changes: 4 additions & 1 deletion objects/card/card.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func _on_mouse_release():
last_occupied_area.occupied = false
entered_area.occupied = true
last_occupied_area = entered_area
entered_area.occupied_word = $Word.get_word()
entered_area.set_card(self)
emit_signal("put")
$SFXPutDown.play()
# prints("card", $Word.get_word(), "put at", entered_area.name, "at global_position", global_position, "when origin global_position at", origin_global_position)
Expand Down Expand Up @@ -118,3 +118,6 @@ func _on_mouse_entered():

func _on_mouse_exited():
$CardBackSprite.animation = "default"

func set_victory(v: bool):
$Word.set_victory(v)
7 changes: 7 additions & 0 deletions objects/credits/credits.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends Label

func _process(_delta):
get_tree().current_scene.set_victory(true)

func _exit_tree():
get_tree().current_scene.set_victory(false)
4 changes: 3 additions & 1 deletion objects/credits/credits.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[gd_scene load_steps=2 format=3 uid="uid://cdu8yubd7fyvb"]
[gd_scene load_steps=3 format=3 uid="uid://cdu8yubd7fyvb"]

[ext_resource type="FontFile" uid="uid://1000owdyvwfg" path="res://fonts/unifont-15.1.04.otf" id="1_re7ax"]
[ext_resource type="Script" path="res://objects/credits/credits.gd" id="2_epjvn"]

[node name="Label" type="Label"]
custom_minimum_size = Vector2(480, 256)
Expand All @@ -20,3 +21,4 @@ ligen131 Tsukimaru
THANKS FOR PLAYING! ;-)"
horizontal_alignment = 1
script = ExtResource("2_epjvn")
28 changes: 24 additions & 4 deletions objects/word/word.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extends AnimatedSprite2D


@export var text_id := 1
@export var is_victory = false


const STEP := 30
Expand All @@ -28,11 +29,12 @@ func set_text_id(value: int) -> void:

assert(value > 0, "text id <= 0")

if not sprite_frames.has_animation(str(text_id)):
sprite_frames.add_animation(str(text_id))
var animation_id = str(text_id) + str(is_victory)
if not sprite_frames.has_animation(animation_id):
sprite_frames.add_animation(animation_id)
for i in range(3):
sprite_frames.add_frame(str(text_id), load("res://objects/word/sprites/sprite" + str(i * STEP + text_id) + ".png"))
animation = str(text_id)
sprite_frames.add_frame(animation_id, load_image(i * STEP + text_id, is_victory))
animation = animation_id



Expand All @@ -55,3 +57,21 @@ func _ready():
func _process(delta):
if animation == "default":
set_text_id(text_id)

func set_victory(v: bool):
if v != is_victory:
is_victory = v
set_text_id(text_id)

func load_image(h: int, is_victory: bool):
var image := load("res://objects/word/sprites/sprite" + str(h) + ".png")
if is_victory:
var new_texture = image.get_image()
for x in range(new_texture.get_width()):
for y in range(new_texture.get_height()):
var color = new_texture.get_pixel(x, y)
if color == Color(0, 0, 0, 1): # 如果像素是黑色
new_texture.set_pixel(x, y, Color(0xf5 / 256.0, 0xdf / 256.0, 0x4d / 256.0, 1)) # 将其改为金黄色
return ImageTexture.create_from_image(new_texture)

return image

0 comments on commit 4d64996

Please sign in to comment.