diff options
Diffstat (limited to 'demos/2d/tetris')
-rw-r--r-- | demos/2d/tetris/block.png | bin | 556 -> 0 bytes | |||
-rw-r--r-- | demos/2d/tetris/engine.cfg | 17 | ||||
-rw-r--r-- | demos/2d/tetris/grid.gd | 194 | ||||
-rw-r--r-- | demos/2d/tetris/grid.tscn | 47 | ||||
-rw-r--r-- | demos/2d/tetris/tetris.png | bin | 789 -> 0 bytes | |||
-rw-r--r-- | demos/2d/tetris/tetris.tscn | 67 |
6 files changed, 0 insertions, 325 deletions
diff --git a/demos/2d/tetris/block.png b/demos/2d/tetris/block.png Binary files differdeleted file mode 100644 index b7759b35b4..0000000000 --- a/demos/2d/tetris/block.png +++ /dev/null diff --git a/demos/2d/tetris/engine.cfg b/demos/2d/tetris/engine.cfg deleted file mode 100644 index db20f0b888..0000000000 --- a/demos/2d/tetris/engine.cfg +++ /dev/null @@ -1,17 +0,0 @@ -[application] - -name="Tetris" -main_scene="res://tetris.tscn" -icon="res://tetris.png" - -[display] - -width=400 -height=400 - -[input] - -move_left=[key(Left)] -move_right=[key(Right)] -move_down=[key(Down)] -rotate=[key(Space)] diff --git a/demos/2d/tetris/grid.gd b/demos/2d/tetris/grid.gd deleted file mode 100644 index 75fabb4210..0000000000 --- a/demos/2d/tetris/grid.gd +++ /dev/null @@ -1,194 +0,0 @@ - -extends Control - -# Simple Tetris-like demo, (c) 2012 Juan Linietsky -# Implemented by using a regular Control and drawing on it during the _draw() callback. -# The drawing surface is updated only when changes happen (by calling update()) - -# Member variables -var score = 0 -var score_label = null - -const MAX_SHAPES = 7 - -var block = preload("block.png") - -var block_colors = [ - Color(1, 0.5, 0.5), - Color(0.5, 1, 0.5), - Color(0.5, 0.5, 1), - Color(0.8, 0.4, 0.8), - Color(0.8, 0.8, 0.4), - Color(0.4, 0.8, 0.8), - Color(0.7, 0.7, 0.7)] - -var block_shapes = [ - [ Vector2(0, -1), Vector2(0, 0), Vector2(0, 1), Vector2(0, 2) ], # I - [ Vector2(0, 0), Vector2(1, 0), Vector2(1, 1), Vector2(0, 1) ], # O - [ Vector2(-1, 1), Vector2(0, 1), Vector2(0, 0), Vector2(1, 0) ], # S - [ Vector2(1, 1), Vector2(0, 1), Vector2(0, 0), Vector2(-1, 0) ], # Z - [ Vector2(-1, 1), Vector2(-1, 0), Vector2(0, 0), Vector2(1, 0) ], # L - [ Vector2(1, 1), Vector2(1, 0), Vector2(0, 0), Vector2(-1, 0) ], # J - [ Vector2(0, 1), Vector2(1, 0), Vector2(0, 0), Vector2(-1, 0) ]] # T - -var block_rotations = [ - Matrix32(Vector2(1, 0), Vector2(0, 1), Vector2()), - Matrix32(Vector2(0, 1), Vector2(-1, 0), Vector2()), - Matrix32(Vector2(-1, 0), Vector2(0, -1), Vector2()), - Matrix32(Vector2(0, -1), Vector2(1, 0), Vector2())] - -var width = 0 -var height = 0 - -var cells = {} - -var piece_active = false -var piece_shape = 0 -var piece_pos = Vector2() -var piece_rot = 0 - - -func piece_cell_xform(p, er = 0): - var r = (4 + er + piece_rot) % 4 - return piece_pos + block_rotations[r].xform(p) - - -func _draw(): - var sb = get_stylebox("bg", "Tree") # Use line edit bg - draw_style_box(sb, Rect2(Vector2(), get_size()).grow(3)) - - var bs = block.get_size() - for y in range(height): - for x in range(width): - if (Vector2(x, y) in cells): - draw_texture_rect(block, Rect2(Vector2(x, y)*bs, bs), false, block_colors[cells[Vector2(x, y)]]) - - if (piece_active): - for c in block_shapes[piece_shape]: - draw_texture_rect(block, Rect2(piece_cell_xform(c)*bs, bs), false, block_colors[piece_shape]) - - -func piece_check_fit(ofs, er = 0): - for c in block_shapes[piece_shape]: - var pos = piece_cell_xform(c, er) + ofs - if (pos.x < 0): - return false - if (pos.y < 0): - return false - if (pos.x >= width): - return false - if (pos.y >= height): - return false - if (pos in cells): - return false - - return true - - -func new_piece(): - piece_shape = randi() % MAX_SHAPES - piece_pos = Vector2(width/2, 0) - piece_active = true - piece_rot = 0 - if (piece_shape == 0): - piece_pos.y += 1 - - if (not piece_check_fit(Vector2())): - # Game over - game_over() - - update() - - -func test_collapse_rows(): - var accum_down = 0 - for i in range(height): - var y = height - i - 1 - var collapse = true - for x in range(width): - if (Vector2(x, y) in cells): - if (accum_down): - cells[Vector2(x, y + accum_down)] = cells[Vector2(x, y)] - else: - collapse = false - if (accum_down): - cells.erase(Vector2(x, y + accum_down)) - - if (collapse): - accum_down += 1 - - score += accum_down*100 - score_label.set_text(str(score)) - - -func game_over(): - piece_active = false - get_node("gameover").set_text("Game over!") - update() - - -func restart_pressed(): - score = 0 - score_label.set_text("0") - cells.clear() - get_node("gameover").set_text("") - piece_active = true - get_node("../restart").release_focus() - update() - - -func piece_move_down(): - if (!piece_active): - return - if (piece_check_fit(Vector2(0, 1))): - piece_pos.y += 1 - update() - else: - for c in block_shapes[piece_shape]: - var pos = piece_cell_xform(c) - cells[pos] = piece_shape - test_collapse_rows() - new_piece() - - -func piece_rotate(): - var adv = 1 - if (not piece_check_fit(Vector2(), 1)): - return - piece_rot = (piece_rot + adv) % 4 - update() - - -func _input(ie): - if (not piece_active): - return - if (!ie.is_pressed()): - return - - if (ie.is_action("move_left")): - if (piece_check_fit(Vector2(-1, 0))): - piece_pos.x -= 1 - update() - elif (ie.is_action("move_right")): - if (piece_check_fit(Vector2(1, 0))): - piece_pos.x += 1 - update() - elif (ie.is_action("move_down")): - piece_move_down() - elif (ie.is_action("rotate")): - piece_rotate() - - -func setup(w, h): - width = w - height = h - set_size(Vector2(w, h)*block.get_size()) - new_piece() - get_node("timer").start() - - -func _ready(): - setup(10, 20) - score_label = get_node("../score") - - set_process_input(true) diff --git a/demos/2d/tetris/grid.tscn b/demos/2d/tetris/grid.tscn deleted file mode 100644 index 9df85e3817..0000000000 --- a/demos/2d/tetris/grid.tscn +++ /dev/null @@ -1,47 +0,0 @@ -[gd_scene load_steps=2 format=1] - -[ext_resource path="res://grid.gd" type="Script" id=1] - -[node name="Grid" type="Control"] - -focus/ignore_mouse = false -focus/stop_mouse = true -size_flags/horizontal = 2 -size_flags/vertical = 2 -margin/left = 0.0 -margin/top = 0.0 -margin/right = 40.0 -margin/bottom = 40.0 -script/script = ExtResource( 1 ) - -[node name="timer" type="Timer" parent="."] - -process_mode = 1 -wait_time = 1.0 -one_shot = false -autostart = false - -[node name="gameover" type="Label" parent="."] - -anchor/right = 1 -anchor/bottom = 1 -focus/ignore_mouse = true -focus/stop_mouse = true -size_flags/horizontal = 2 -margin/left = 0.0 -margin/top = 0.0 -margin/right = 0.0 -margin/bottom = 0.0 -custom_colors/font_color = Color( 1, 1, 1, 1 ) -custom_colors/font_color_shadow = Color( 0, 0, 0, 1 ) -custom_constants/shadow_offset_x = 1 -custom_constants/shadow_offset_y = 1 -align = 1 -valign = 1 -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - -[connection signal="timeout" from="timer" to="." method="piece_move_down"] - - diff --git a/demos/2d/tetris/tetris.png b/demos/2d/tetris/tetris.png Binary files differdeleted file mode 100644 index 8b63977bfe..0000000000 --- a/demos/2d/tetris/tetris.png +++ /dev/null diff --git a/demos/2d/tetris/tetris.tscn b/demos/2d/tetris/tetris.tscn deleted file mode 100644 index de81044c22..0000000000 --- a/demos/2d/tetris/tetris.tscn +++ /dev/null @@ -1,67 +0,0 @@ -[gd_scene load_steps=2 format=1] - -[ext_resource path="res://grid.tscn" type="PackedScene" id=1] - -[node name="Tetris" type="Panel"] - -focus/ignore_mouse = false -focus/stop_mouse = true -size_flags/horizontal = 2 -size_flags/vertical = 2 -margin/left = 0.0 -margin/top = 0.0 -margin/right = 400.0 -margin/bottom = 400.0 - -[node name="Grid" parent="." instance=ExtResource( 1 )] - -margin/left = 40.0 -margin/top = 35.0 -margin/right = 80.0 -margin/bottom = 75.0 - -[node name="Label" type="Label" parent="."] - -focus/ignore_mouse = true -focus/stop_mouse = true -size_flags/horizontal = 2 -margin/left = 243.0 -margin/top = 36.0 -margin/right = 283.0 -margin/bottom = 49.0 -text = "Score:" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - -[node name="score" type="Label" parent="."] - -focus/ignore_mouse = true -focus/stop_mouse = true -size_flags/horizontal = 2 -margin/left = 252.0 -margin/top = 55.0 -margin/right = 293.0 -margin/bottom = 68.0 -text = "0" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - -[node name="restart" type="Button" parent="."] - -focus/ignore_mouse = false -focus/stop_mouse = true -size_flags/horizontal = 2 -size_flags/vertical = 2 -margin/left = 243.0 -margin/top = 292.0 -margin/right = 303.0 -margin/bottom = 311.0 -toggle_mode = false -text = "Restart" -flat = false - -[connection signal="pressed" from="restart" to="Grid" method="restart_pressed"] - - |