summaryrefslogtreecommitdiff
path: root/demos/2d/tetris
diff options
context:
space:
mode:
Diffstat (limited to 'demos/2d/tetris')
-rw-r--r--demos/2d/tetris/block.pngbin556 -> 0 bytes
-rw-r--r--demos/2d/tetris/engine.cfg17
-rw-r--r--demos/2d/tetris/grid.gd194
-rw-r--r--demos/2d/tetris/grid.xml209
-rw-r--r--demos/2d/tetris/tetris.pngbin789 -> 0 bytes
-rw-r--r--demos/2d/tetris/tetris.xml217
6 files changed, 0 insertions, 637 deletions
diff --git a/demos/2d/tetris/block.png b/demos/2d/tetris/block.png
deleted file mode 100644
index b7759b35b4..0000000000
--- a/demos/2d/tetris/block.png
+++ /dev/null
Binary files differ
diff --git a/demos/2d/tetris/engine.cfg b/demos/2d/tetris/engine.cfg
deleted file mode 100644
index b80a736c39..0000000000
--- a/demos/2d/tetris/engine.cfg
+++ /dev/null
@@ -1,17 +0,0 @@
-[application]
-
-name="Tetris"
-main_scene="res://tetris.xml"
-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.xml b/demos/2d/tetris/grid.xml
deleted file mode 100644
index 49ad4ccc41..0000000000
--- a/demos/2d/tetris/grid.xml
+++ /dev/null
@@ -1,209 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<resource_file type="PackedScene" subresource_count="2" version="2.0" version_name="Godot Engine v2.0.alpha.custom_build">
- <ext_resource path="res://grid.gd" type="Script" index="0"></ext_resource>
- <main_resource>
- <dictionary name="_bundled" shared="false">
- <string> "conn_count" </string>
- <int> 1 </int>
- <string> "conns" </string>
- <int_array len="6"> 1, 0, 30, 29, 2, 0 </int_array>
- <string> "editable_instances" </string>
- <array len="0" shared="false">
- </array>
- <string> "names" </string>
- <string_array len="31">
- <string> "Grid" </string>
- <string> "margin/right" </string>
- <string> "margin/bottom" </string>
- <string> "focus/ignore_mouse" </string>
- <string> "focus/stop_mouse" </string>
- <string> "size_flags/horizontal" </string>
- <string> "size_flags/vertical" </string>
- <string> "script/script" </string>
- <string> "__meta__" </string>
- <string> "Control" </string>
- <string> "timer" </string>
- <string> "process_mode" </string>
- <string> "wait_time" </string>
- <string> "one_shot" </string>
- <string> "autostart" </string>
- <string> "Timer" </string>
- <string> "gameover" </string>
- <string> "anchor/right" </string>
- <string> "anchor/bottom" </string>
- <string> "custom_colors/font_color" </string>
- <string> "custom_colors/font_color_shadow" </string>
- <string> "custom_constants/shadow_offset_x" </string>
- <string> "custom_constants/shadow_offset_y" </string>
- <string> "align" </string>
- <string> "valign" </string>
- <string> "percent_visible" </string>
- <string> "lines_skipped" </string>
- <string> "max_lines_visible" </string>
- <string> "Label" </string>
- <string> "piece_move_down" </string>
- <string> "timeout" </string>
- </string_array>
- <string> "node_count" </string>
- <int> 3 </int>
- <string> "node_paths" </string>
- <array len="0" shared="false">
- </array>
- <string> "nodes" </string>
- <int_array len="73"> -1, -1, 9, 0, -1, 8, 1, 0, 2, 0, 3, 1, 4, 2, 5, 3, 6, 3, 7, 4, 8, 5, 0, 0, 0, 15, 10, -1, 4, 11, 6, 12, 7, 13, 1, 14, 1, 0, 0, 0, 28, 16, -1, 14, 17, 6, 18, 6, 3, 2, 4, 2, 5, 3, 19, 8, 20, 9, 21, 6, 22, 6, 23, 6, 24, 6, 25, 7, 26, 10, 27, 11, 0 </int_array>
- <string> "variants" </string>
- <array len="12" shared="false">
- <real> 40 </real>
- <bool> False </bool>
- <bool> True </bool>
- <int> 2 </int>
- <resource external="0"> </resource>
- <dictionary shared="false">
- <string> "__editor_plugin_screen__" </string>
- <string> "2D" </string>
- <string> "__editor_plugin_states__" </string>
- <dictionary shared="false">
- <string> "2D" </string>
- <dictionary shared="false">
- <string> "ofs" </string>
- <vector2> -229.129, -80 </vector2>
- <string> "snap_grid" </string>
- <bool> False </bool>
- <string> "snap_offset" </string>
- <vector2> 0, 0 </vector2>
- <string> "snap_pixel" </string>
- <bool> False </bool>
- <string> "snap_relative" </string>
- <bool> False </bool>
- <string> "snap_rotation" </string>
- <bool> False </bool>
- <string> "snap_rotation_offset" </string>
- <real> 0 </real>
- <string> "snap_rotation_step" </string>
- <real> 0.261799 </real>
- <string> "snap_show_grid" </string>
- <bool> False </bool>
- <string> "snap_step" </string>
- <vector2> 10, 10 </vector2>
- <string> "zoom" </string>
- <real> 1 </real>
- </dictionary>
- <string> "3D" </string>
- <dictionary shared="false">
- <string> "ambient_light_color" </string>
- <color> 0.15, 0.15, 0.15, 1 </color>
- <string> "default_light" </string>
- <bool> True </bool>
- <string> "default_srgb" </string>
- <bool> False </bool>
- <string> "deflight_rot_x" </string>
- <real> 0.942478 </real>
- <string> "deflight_rot_y" </string>
- <real> 0.628319 </real>
- <string> "fov" </string>
- <real> 45 </real>
- <string> "show_grid" </string>
- <bool> True </bool>
- <string> "show_origin" </string>
- <bool> True </bool>
- <string> "viewport_mode" </string>
- <int> 1 </int>
- <string> "viewports" </string>
- <array len="4" shared="false">
- <dictionary shared="false">
- <string> "distance" </string>
- <real> 4 </real>
- <string> "listener" </string>
- <bool> True </bool>
- <string> "pos" </string>
- <vector3> 0, 0, 0 </vector3>
- <string> "use_environment" </string>
- <bool> False </bool>
- <string> "use_orthogonal" </string>
- <bool> False </bool>
- <string> "x_rot" </string>
- <real> 0 </real>
- <string> "y_rot" </string>
- <real> 0 </real>
- </dictionary>
- <dictionary shared="false">
- <string> "distance" </string>
- <real> 4 </real>
- <string> "listener" </string>
- <bool> False </bool>
- <string> "pos" </string>
- <vector3> 0, 0, 0 </vector3>
- <string> "use_environment" </string>
- <bool> False </bool>
- <string> "use_orthogonal" </string>
- <bool> False </bool>
- <string> "x_rot" </string>
- <real> 0 </real>
- <string> "y_rot" </string>
- <real> 0 </real>
- </dictionary>
- <dictionary shared="false">
- <string> "distance" </string>
- <real> 4 </real>
- <string> "listener" </string>
- <bool> False </bool>
- <string> "pos" </string>
- <vector3> 0, 0, 0 </vector3>
- <string> "use_environment" </string>
- <bool> False </bool>
- <string> "use_orthogonal" </string>
- <bool> False </bool>
- <string> "x_rot" </string>
- <real> 0 </real>
- <string> "y_rot" </string>
- <real> 0 </real>
- </dictionary>
- <dictionary shared="false">
- <string> "distance" </string>
- <real> 4 </real>
- <string> "listener" </string>
- <bool> False </bool>
- <string> "pos" </string>
- <vector3> 0, 0, 0 </vector3>
- <string> "use_environment" </string>
- <bool> False </bool>
- <string> "use_orthogonal" </string>
- <bool> False </bool>
- <string> "x_rot" </string>
- <real> 0 </real>
- <string> "y_rot" </string>
- <real> 0 </real>
- </dictionary>
- </array>
- <string> "zfar" </string>
- <real> 500 </real>
- <string> "znear" </string>
- <real> 0.1 </real>
- </dictionary>
- <string> "Anim" </string>
- <dictionary shared="false">
- <string> "visible" </string>
- <bool> False </bool>
- </dictionary>
- </dictionary>
- <string> "__editor_run_settings__" </string>
- <dictionary shared="false">
- <string> "custom_args" </string>
- <string> "-l $scene" </string>
- <string> "run_mode" </string>
- <int> 0 </int>
- </dictionary>
- </dictionary>
- <int> 1 </int>
- <real> 1 </real>
- <color> 1, 1, 1, 1 </color>
- <color> 0, 0, 0, 1 </color>
- <int> 0 </int>
- <int> -1 </int>
- </array>
- <string> "version" </string>
- <int> 2 </int>
- </dictionary>
-
- </main_resource>
-</resource_file> \ No newline at end of file
diff --git a/demos/2d/tetris/tetris.png b/demos/2d/tetris/tetris.png
deleted file mode 100644
index 8b63977bfe..0000000000
--- a/demos/2d/tetris/tetris.png
+++ /dev/null
Binary files differ
diff --git a/demos/2d/tetris/tetris.xml b/demos/2d/tetris/tetris.xml
deleted file mode 100644
index a8e47a8ae4..0000000000
--- a/demos/2d/tetris/tetris.xml
+++ /dev/null
@@ -1,217 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<resource_file type="PackedScene" subresource_count="2" version="2.0" version_name="Godot Engine v2.0.alpha.custom_build">
- <ext_resource path="res://grid.xml" type="PackedScene" index="0"></ext_resource>
- <main_resource>
- <dictionary name="_bundled" shared="false">
- <string> "conn_count" </string>
- <int> 1 </int>
- <string> "conns" </string>
- <int_array len="6"> 4, 1, 23, 22, 2, 0 </int_array>
- <string> "editable_instances" </string>
- <array len="0" shared="false">
- </array>
- <string> "names" </string>
- <string_array len="24">
- <string> "Tetris" </string>
- <string> "margin/right" </string>
- <string> "margin/bottom" </string>
- <string> "focus/ignore_mouse" </string>
- <string> "focus/stop_mouse" </string>
- <string> "size_flags/horizontal" </string>
- <string> "size_flags/vertical" </string>
- <string> "__meta__" </string>
- <string> "Panel" </string>
- <string> "Grid" </string>
- <string> "margin/left" </string>
- <string> "margin/top" </string>
- <string> "Label" </string>
- <string> "text" </string>
- <string> "percent_visible" </string>
- <string> "lines_skipped" </string>
- <string> "max_lines_visible" </string>
- <string> "score" </string>
- <string> "restart" </string>
- <string> "toggle_mode" </string>
- <string> "flat" </string>
- <string> "Button" </string>
- <string> "restart_pressed" </string>
- <string> "pressed" </string>
- </string_array>
- <string> "node_count" </string>
- <int> 5 </int>
- <string> "node_paths" </string>
- <array len="0" shared="false">
- </array>
- <string> "nodes" </string>
- <int_array len="123"> -1, -1, 8, 0, -1, 7, 1, 0, 2, 0, 3, 1, 4, 2, 5, 3, 6, 3, 7, 4, 0, 0, 0, 2147483647, 9, 5, 4, 10, 6, 11, 7, 1, 8, 2, 9, 0, 0, 0, 12, 12, -1, 11, 10, 10, 11, 11, 1, 12, 2, 13, 3, 2, 4, 2, 5, 3, 13, 14, 14, 15, 15, 16, 16, 17, 0, 0, 0, 12, 17, -1, 11, 10, 18, 11, 19, 1, 20, 2, 21, 3, 2, 4, 2, 5, 3, 13, 22, 14, 15, 15, 16, 16, 17, 0, 0, 0, 21, 18, -1, 11, 10, 10, 11, 23, 1, 24, 2, 25, 3, 1, 4, 2, 5, 3, 6, 3, 19, 1, 13, 26, 20, 1, 0 </int_array>
- <string> "variants" </string>
- <array len="27" shared="false">
- <real> 400 </real>
- <bool> False </bool>
- <bool> True </bool>
- <int> 2 </int>
- <dictionary shared="false">
- <string> "__editor_plugin_screen__" </string>
- <string> "2D" </string>
- <string> "__editor_plugin_states__" </string>
- <dictionary shared="false">
- <string> "2D" </string>
- <dictionary shared="false">
- <string> "ofs" </string>
- <vector2> -229.129, -54.344 </vector2>
- <string> "snap_grid" </string>
- <bool> False </bool>
- <string> "snap_offset" </string>
- <vector2> 0, 0 </vector2>
- <string> "snap_pixel" </string>
- <bool> False </bool>
- <string> "snap_relative" </string>
- <bool> False </bool>
- <string> "snap_rotation" </string>
- <bool> False </bool>
- <string> "snap_rotation_offset" </string>
- <real> 0 </real>
- <string> "snap_rotation_step" </string>
- <real> 0.261799 </real>
- <string> "snap_show_grid" </string>
- <bool> False </bool>
- <string> "snap_step" </string>
- <vector2> 10, 10 </vector2>
- <string> "zoom" </string>
- <real> 1.360374 </real>
- </dictionary>
- <string> "3D" </string>
- <dictionary shared="false">
- <string> "ambient_light_color" </string>
- <color> 0.15, 0.15, 0.15, 1 </color>
- <string> "default_light" </string>
- <bool> True </bool>
- <string> "default_srgb" </string>
- <bool> False </bool>
- <string> "deflight_rot_x" </string>
- <real> 0.942478 </real>
- <string> "deflight_rot_y" </string>
- <real> 0.628319 </real>
- <string> "fov" </string>
- <real> 45 </real>
- <string> "show_grid" </string>
- <bool> True </bool>
- <string> "show_origin" </string>
- <bool> True </bool>
- <string> "viewport_mode" </string>
- <int> 1 </int>
- <string> "viewports" </string>
- <array len="4" shared="false">
- <dictionary shared="false">
- <string> "distance" </string>
- <real> 4 </real>
- <string> "listener" </string>
- <bool> True </bool>
- <string> "pos" </string>
- <vector3> 0, 0, 0 </vector3>
- <string> "use_environment" </string>
- <bool> False </bool>
- <string> "use_orthogonal" </string>
- <bool> False </bool>
- <string> "x_rot" </string>
- <real> 0 </real>
- <string> "y_rot" </string>
- <real> 0 </real>
- </dictionary>
- <dictionary shared="false">
- <string> "distance" </string>
- <real> 4 </real>
- <string> "listener" </string>
- <bool> False </bool>
- <string> "pos" </string>
- <vector3> 0, 0, 0 </vector3>
- <string> "use_environment" </string>
- <bool> False </bool>
- <string> "use_orthogonal" </string>
- <bool> False </bool>
- <string> "x_rot" </string>
- <real> 0 </real>
- <string> "y_rot" </string>
- <real> 0 </real>
- </dictionary>
- <dictionary shared="false">
- <string> "distance" </string>
- <real> 4 </real>
- <string> "listener" </string>
- <bool> False </bool>
- <string> "pos" </string>
- <vector3> 0, 0, 0 </vector3>
- <string> "use_environment" </string>
- <bool> False </bool>
- <string> "use_orthogonal" </string>
- <bool> False </bool>
- <string> "x_rot" </string>
- <real> 0 </real>
- <string> "y_rot" </string>
- <real> 0 </real>
- </dictionary>
- <dictionary shared="false">
- <string> "distance" </string>
- <real> 4 </real>
- <string> "listener" </string>
- <bool> False </bool>
- <string> "pos" </string>
- <vector3> 0, 0, 0 </vector3>
- <string> "use_environment" </string>
- <bool> False </bool>
- <string> "use_orthogonal" </string>
- <bool> False </bool>
- <string> "x_rot" </string>
- <real> 0 </real>
- <string> "y_rot" </string>
- <real> 0 </real>
- </dictionary>
- </array>
- <string> "zfar" </string>
- <real> 500 </real>
- <string> "znear" </string>
- <real> 0.1 </real>
- </dictionary>
- <string> "Anim" </string>
- <dictionary shared="false">
- <string> "visible" </string>
- <bool> False </bool>
- </dictionary>
- </dictionary>
- <string> "__editor_run_settings__" </string>
- <dictionary shared="false">
- <string> "custom_args" </string>
- <string> "-l $scene" </string>
- <string> "run_mode" </string>
- <int> 0 </int>
- </dictionary>
- </dictionary>
- <resource external="0"> </resource>
- <real> 40 </real>
- <real> 35 </real>
- <real> 80 </real>
- <real> 75 </real>
- <real> 243 </real>
- <real> 36 </real>
- <real> 283 </real>
- <real> 49 </real>
- <string> "Score:" </string>
- <real> 1 </real>
- <int> 0 </int>
- <int> -1 </int>
- <real> 252 </real>
- <real> 55 </real>
- <real> 293 </real>
- <real> 68 </real>
- <string> "0" </string>
- <real> 292 </real>
- <real> 303 </real>
- <real> 311 </real>
- <string> "Restart" </string>
- </array>
- <string> "version" </string>
- <int> 2 </int>
- </dictionary>
-
- </main_resource>
-</resource_file> \ No newline at end of file