Tetris Clone written in Godot, primarily for mobile devices
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

35 lines
1.1 KiB

extends Control
func _ready():
_set_safe_area()
func update_score(new_score):
$VBoxContainer/HBoxContainer/Score.text = str(new_score)
func set_next_shape(shape_scene):
for child in $VBoxContainer/HBoxContainer/NextShape/Origin.get_children():
child.free()
$VBoxContainer/HBoxContainer/NextShape/Origin.add_child(shape_scene.instance())
func on_game_over():
$GameOverUI.visible = true
# Resizes the UI to accomodate for notches, rounded corners, etc on mobile
# Adapted from https://github.com/godotengine/godot/issues/49887
func _set_safe_area():
var window_to_root = Transform2D.IDENTITY.scaled(get_tree().root.size / OS.window_size)
var safe_area_root = window_to_root.xform(OS.get_window_safe_area())
assert(get_viewport() == get_tree().root, "Assumption: control is not in a nested Viewport")
var parent_to_root = get_viewport_transform() * get_global_transform() * get_transform().affine_inverse()
var root_to_parent = parent_to_root.affine_inverse()
var safe_area_relative_to_parent = root_to_parent.xform(safe_area_root)
rect_position = safe_area_relative_to_parent.position
rect_size = safe_area_relative_to_parent.size