tetris
previews
| -rw-r--r-- | Main.tscn | 1 | ||||
| -rw-r--r-- | Tetris.gd | 30 | ||||
| -rw-r--r-- | project.godot | 1 |
3 files changed, 25 insertions, 7 deletions
@@ -19,6 +19,7 @@ margin_right = 170.0 margin_bottom = 310.0 script = ExtResource( 1 ) colors = PoolColorArray( 0.862745, 0.196078, 0.184314, 1, 0.521569, 0.6, 0, 1, 0.14902, 0.545098, 0.823529, 1, 0.423529, 0.443137, 0.768627, 1, 0.709804, 0.537255, 0, 1, 0.576471, 0.631373, 0.631373, 1, 0.164706, 0.631373, 0.596078, 1 ) +transcolors = PoolColorArray( 0.780392, 0.172549, 0.164706, 0.670588, 0.521569, 0.6, 0, 0.619608, 0.160784, 0.584314, 0.890196, 0.564706, 0.521569, 0.545098, 0.94902, 0.784314, 0.788235, 0.592157, 0, 0.67451, 0.690196, 0.760784, 0.760784, 0.627451, 0.14902, 0.580392, 0.545098, 0.701961 ) grid_color = Color( 0.933333, 0.909804, 0.835294, 1 ) bg_color = Color( 0.992157, 0.964706, 0.890196, 1 ) @@ -5,6 +5,7 @@ const ROWS = 20 const COLUMNS = 10 export(PoolColorArray) var colors +export(PoolColorArray) var transcolors export(Color) var grid_color export(Color) var bg_color @@ -62,6 +63,7 @@ func _ready() -> void: add_child(c) set_process(false) assert(len(colors) == Logic.shapes.size()) # 7 + assert(len(transcolors) == Logic.shapes.size()) ratio = float(COLUMNS) / float(ROWS) init_squares() start() @@ -74,15 +76,29 @@ func start() -> void: tick() -func draw_board(mat: Array = matrix.duplicate(true), shape: TetrisPiece = current_shape) -> void: - shape.embed(mat) +func draw_board() -> void: + var mat := matrix.duplicate(true) + current_shape.embed(mat) + var set_squares = draw_preview() for y in range(ROWS): for x in range(COLUMNS): - get_square(Vector2(x, y)).color = ( - colors[mat[y][x] - 1] - if mat[y][x] > 0 - else Color.transparent - ) + if mat[y][x] > 0: + get_square(Vector2(x, y)).color = colors[mat[y][x] - 1] + elif set_squares.find(Vector2(x, y)) == -1: + get_square(Vector2(x, y)).color = Color.transparent + + +func draw_preview(shape: TetrisPiece = current_shape) -> PoolVector2Array: + var p = shape.position + shape.fall(matrix) + var set_squares: PoolVector2Array = [] + for y in range(4): + for x in range(4): + if Logic.get_index_or_null(shape.shape, y, x) > 0: + set_squares.append(Vector2(x, y) + shape.position) + get_square(Vector2(x, y) + shape.position).color = transcolors[shape.shape_type] + shape.position = p + return set_squares func _input(event): diff --git a/project.godot b/project.godot index 03f5883..878f53f 100644 --- a/project.godot +++ b/project.godot @@ -48,6 +48,7 @@ config/name="tetris" run/main_scene="res://Main.tscn" config/use_custom_user_dir=true config/custom_user_dir_name="tetris" +run/low_processor_mode=true config/icon="res://icon.png" [debug] |