@ -1,356 +0,0 @@
|
||||
[gd_scene format=2]
|
||||
|
||||
[node name="Grid" type="Node2D" index="0"]
|
||||
|
||||
[node name="Line2D" type="Line2D" parent="." index="0"]
|
||||
|
||||
position = Vector2( 0, 1 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D2" type="Line2D" parent="." index="1"]
|
||||
|
||||
position = Vector2( 0, 1 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D33" type="Line2D" parent="." index="2"]
|
||||
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D3" type="Line2D" parent="." index="3"]
|
||||
|
||||
position = Vector2( 0, 2 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D4" type="Line2D" parent="." index="4"]
|
||||
|
||||
position = Vector2( 0, 3 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D5" type="Line2D" parent="." index="5"]
|
||||
|
||||
position = Vector2( 0, 4 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D6" type="Line2D" parent="." index="6"]
|
||||
|
||||
position = Vector2( 0, 5 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D7" type="Line2D" parent="." index="7"]
|
||||
|
||||
position = Vector2( 0, 6 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D8" type="Line2D" parent="." index="8"]
|
||||
|
||||
position = Vector2( 0, 7 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D9" type="Line2D" parent="." index="9"]
|
||||
|
||||
position = Vector2( 0, 8 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D10" type="Line2D" parent="." index="10"]
|
||||
|
||||
position = Vector2( 0, 9 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D11" type="Line2D" parent="." index="11"]
|
||||
|
||||
position = Vector2( 0, 10 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D12" type="Line2D" parent="." index="12"]
|
||||
|
||||
position = Vector2( 0, 11 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D13" type="Line2D" parent="." index="13"]
|
||||
|
||||
position = Vector2( 0, 12 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D14" type="Line2D" parent="." index="14"]
|
||||
|
||||
position = Vector2( 0, 13 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D15" type="Line2D" parent="." index="15"]
|
||||
|
||||
position = Vector2( 0, 14 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D16" type="Line2D" parent="." index="16"]
|
||||
|
||||
position = Vector2( 0, 15 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D17" type="Line2D" parent="." index="17"]
|
||||
|
||||
position = Vector2( 0, 16 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D18" type="Line2D" parent="." index="18"]
|
||||
|
||||
position = Vector2( 0, 17 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D19" type="Line2D" parent="." index="19"]
|
||||
|
||||
position = Vector2( 0, 18 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D20" type="Line2D" parent="." index="20"]
|
||||
|
||||
position = Vector2( 0, 19 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D34" type="Line2D" parent="." index="21"]
|
||||
|
||||
position = Vector2( 0, 20 )
|
||||
points = PoolVector2Array( 0, 0, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D21" type="Line2D" parent="." index="22"]
|
||||
|
||||
position = Vector2( 0.890217, 19.8953 )
|
||||
scale = Vector2( 0.0108696, 1.04688 )
|
||||
points = PoolVector2Array( 1, -19, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D22" type="Line2D" parent="." index="23"]
|
||||
|
||||
position = Vector2( 1, 20 )
|
||||
scale = Vector2( 0.0108696, 1.04688 )
|
||||
points = PoolVector2Array( 1, -19, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D31" type="Line2D" parent="." index="24"]
|
||||
|
||||
position = Vector2( 0, 20 )
|
||||
scale = Vector2( 0.0108696, 1.04688 )
|
||||
points = PoolVector2Array( 1, -19, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D23" type="Line2D" parent="." index="25"]
|
||||
|
||||
position = Vector2( 2, 20 )
|
||||
scale = Vector2( 0.0108696, 1.04688 )
|
||||
points = PoolVector2Array( 1, -19, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D24" type="Line2D" parent="." index="26"]
|
||||
|
||||
position = Vector2( 3, 20 )
|
||||
scale = Vector2( 0.0108696, 1.04688 )
|
||||
points = PoolVector2Array( 1, -19, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D25" type="Line2D" parent="." index="27"]
|
||||
|
||||
position = Vector2( 4, 20 )
|
||||
scale = Vector2( 0.0108696, 1.04688 )
|
||||
points = PoolVector2Array( 1, -19, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D26" type="Line2D" parent="." index="28"]
|
||||
|
||||
position = Vector2( 5, 20 )
|
||||
scale = Vector2( 0.0108696, 1.04688 )
|
||||
points = PoolVector2Array( 1, -19, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D27" type="Line2D" parent="." index="29"]
|
||||
|
||||
position = Vector2( 6, 20 )
|
||||
scale = Vector2( 0.0108696, 1.04688 )
|
||||
points = PoolVector2Array( 1, -19, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D28" type="Line2D" parent="." index="30"]
|
||||
|
||||
position = Vector2( 7, 20 )
|
||||
scale = Vector2( 0.0108696, 1.04688 )
|
||||
points = PoolVector2Array( 1, -19, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D29" type="Line2D" parent="." index="31"]
|
||||
|
||||
position = Vector2( 8, 20 )
|
||||
scale = Vector2( 0.0108696, 1.04688 )
|
||||
points = PoolVector2Array( 1, -19, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D30" type="Line2D" parent="." index="32"]
|
||||
|
||||
position = Vector2( 9, 20 )
|
||||
scale = Vector2( 0.0108696, 1.04688 )
|
||||
points = PoolVector2Array( 1, -19, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
[node name="Line2D32" type="Line2D" parent="." index="33"]
|
||||
|
||||
position = Vector2( 10, 20 )
|
||||
scale = Vector2( 0.0108696, 1.04688 )
|
||||
points = PoolVector2Array( 1, -19, 10, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.4, 0.5, 1, 1 )
|
||||
texture_mode = 1881419456
|
||||
sharp_limit = 2.0
|
||||
round_precision = 8
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Tetrominos/Mino/BackMaterial.tres" type="Material" id=1]
|
||||
[ext_resource path="res://GridMap/BackMaterial.tres" type="Material" id=1]
|
||||
|
||||
|
||||
[sub_resource type="CubeMesh" id=3]
|
||||
[sub_resource type="CubeMesh" id=1]
|
||||
|
||||
material = ExtResource( 1 )
|
||||
custom_aabb = AABB( 0, 0, 0, 0, 0, 0 )
|
||||
@ -24,7 +23,7 @@ lod_min_distance = 0.0
|
||||
lod_min_hysteresis = 0.0
|
||||
lod_max_distance = 0.0
|
||||
lod_max_hysteresis = 0.0
|
||||
mesh = SubResource( 3 )
|
||||
mesh = SubResource( 1 )
|
||||
skeleton = NodePath("..")
|
||||
material/0 = null
|
||||
_sections_unfolded = [ "Transform" ]
|
||||
|
@ -1,6 +1,6 @@
|
||||
extends GridMap
|
||||
|
||||
const ExplodingLine = preload("res://ExplodingLine.tscn")
|
||||
const ExplodingLine = preload("res://ExplodingLine/ExplodingLine.tscn")
|
||||
const Tetromino = preload("res://Tetrominos/Tetromino.gd")
|
||||
const TetroI = preload("res://Tetrominos/TetroI.tscn")
|
||||
const TetroJ = preload("res://Tetrominos/TetroJ.tscn")
|
||||
@ -10,11 +10,21 @@ const TetroS = preload("res://Tetrominos/TetroS.tscn")
|
||||
const TetroT = preload("res://Tetrominos/TetroT.tscn")
|
||||
const TetroZ = preload("res://Tetrominos/TetroZ.tscn")
|
||||
|
||||
const NB_LINES = 20
|
||||
const NB_COLLUMNS = 10
|
||||
|
||||
const EMPTY_CELL = -1
|
||||
const NB_MINOES = 4
|
||||
|
||||
const NEXT_POSITION = Vector3(13, 16, 0)
|
||||
const START_POSITION = Vector3(5, 20, 0)
|
||||
const HOLD_POSITION = Vector3(-5, 16, 0)
|
||||
|
||||
const movements = {
|
||||
"move_right": Vector3(1, 0, 0),
|
||||
"move_left": Vector3(-1, 0, 0),
|
||||
"soft_drop": Vector3(0, -1, 0)
|
||||
}
|
||||
|
||||
const SCORES = [
|
||||
[0, 4, 1],
|
||||
[1, 8, 2],
|
||||
@ -23,27 +33,21 @@ const SCORES = [
|
||||
[8]
|
||||
]
|
||||
const LINES_CLEARED_NAMES = ["", "SINGLE", "DOUBLE", "TRIPLE", "TETRIS"]
|
||||
const T_SPIN_NAMES = ["", "MINI T-SPIN", "T-SPIN"]
|
||||
const T_SPIN_NAMES = ["", "T-SPIN", "MINI T-SPIN"]
|
||||
|
||||
export (int) var NB_LINES
|
||||
export (int) var NB_COLLUMNS
|
||||
const MIDI_MOVE_CHANNELS = [] #[7, 8, 9, 11, 12]
|
||||
|
||||
var next_piece = random_piece()
|
||||
var current_piece
|
||||
var held_piece
|
||||
var current_piece_held = false
|
||||
var locked = false
|
||||
|
||||
var autoshift_action = ""
|
||||
var movements = {
|
||||
"move_right": Vector3(1, 0, 0),
|
||||
"move_left": Vector3(-1, 0, 0),
|
||||
"soft_drop": Vector3(0, -1, 0)
|
||||
}
|
||||
|
||||
var exploding_lines = []
|
||||
var lines_to_clear = []
|
||||
var hard_dropping = false
|
||||
var random_bag = []
|
||||
var playing = true
|
||||
|
||||
var level = 0
|
||||
var goal = 0
|
||||
var score = 0
|
||||
@ -54,6 +58,7 @@ func _ready():
|
||||
exploding_lines.append(ExplodingLine.instance())
|
||||
add_child(exploding_lines[y])
|
||||
exploding_lines[y].translation = Vector3(NB_COLLUMNS/2, y, 1)
|
||||
resume()
|
||||
new_level()
|
||||
|
||||
func new_level():
|
||||
@ -68,13 +73,8 @@ func new_level():
|
||||
func random_piece():
|
||||
if not random_bag:
|
||||
random_bag = [
|
||||
TetroI,
|
||||
TetroJ,
|
||||
TetroL,
|
||||
TetroO,
|
||||
TetroS,
|
||||
TetroT,
|
||||
TetroZ
|
||||
TetroI, TetroJ, TetroL, TetroO,
|
||||
TetroS, TetroT, TetroZ
|
||||
]
|
||||
var choice = randi() % random_bag.size()
|
||||
var piece = random_bag[choice].instance()
|
||||
@ -85,6 +85,8 @@ func random_piece():
|
||||
func new_piece():
|
||||
current_piece = next_piece
|
||||
current_piece.translation = START_POSITION
|
||||
current_piece.emit_trail(true)
|
||||
autoshift_action = ""
|
||||
next_piece = random_piece()
|
||||
next_piece.translation = NEXT_POSITION
|
||||
if move(movements["soft_drop"]):
|
||||
@ -101,24 +103,31 @@ func _process(delta):
|
||||
$AutoShiftTimer.stop()
|
||||
autoshift_action = ""
|
||||
if Input.is_action_just_pressed("pause"):
|
||||
pause()
|
||||
if playing and not hard_dropping:
|
||||
for action in movements:
|
||||
if action != autoshift_action:
|
||||
if Input.is_action_pressed(action):
|
||||
move(movements[action])
|
||||
autoshift_action = action
|
||||
$AutoShiftTimer.stop()
|
||||
$AutoShiftDelay.start()
|
||||
if Input.is_action_just_pressed("hard_drop"):
|
||||
hard_dropping = true
|
||||
$HardDropTimer.start()
|
||||
if Input.is_action_just_pressed("rotate_clockwise"):
|
||||
rotate(Tetromino.CLOCKWISE)
|
||||
if Input.is_action_just_pressed("rotate_counterclockwise"):
|
||||
rotate(Tetromino.COUNTERCLOCKWISE)
|
||||
if Input.is_action_just_pressed("hold"):
|
||||
hold()
|
||||
if playing:
|
||||
pause()
|
||||
else:
|
||||
resume()
|
||||
if playing:
|
||||
process_actions()
|
||||
|
||||
func process_actions():
|
||||
for action in movements:
|
||||
if action != autoshift_action:
|
||||
if Input.is_action_pressed(action):
|
||||
move(movements[action])
|
||||
autoshift_action = action
|
||||
$AutoShiftTimer.stop()
|
||||
$AutoShiftDelay.start()
|
||||
if Input.is_action_just_pressed("hard_drop"):
|
||||
while move(movements["soft_drop"]):
|
||||
pass
|
||||
lock_piece()
|
||||
if Input.is_action_just_pressed("rotate_clockwise"):
|
||||
rotate(Tetromino.CLOCKWISE)
|
||||
if Input.is_action_just_pressed("rotate_counterclockwise"):
|
||||
rotate(Tetromino.COUNTERCLOCKWISE)
|
||||
if Input.is_action_just_pressed("hold"):
|
||||
hold()
|
||||
|
||||
func _on_AutoShiftDelay_timeout():
|
||||
if playing and autoshift_action:
|
||||
@ -143,14 +152,13 @@ func possible_positions(initial_positions, movement):
|
||||
position = initial_positions[i] + movement
|
||||
if is_free_cell(position):
|
||||
test_positions.append(position)
|
||||
if test_positions.size() == NB_MINOES:
|
||||
if test_positions.size() == Tetromino.NB_MINOES:
|
||||
return test_positions
|
||||
else:
|
||||
return []
|
||||
|
||||
func move(movement):
|
||||
if current_piece.move(movement):
|
||||
update_ghost_piece()
|
||||
$LockDelay.start()
|
||||
return true
|
||||
else:
|
||||
@ -158,28 +166,14 @@ func move(movement):
|
||||
|
||||
func rotate(direction):
|
||||
if current_piece.rotate(direction):
|
||||
update_ghost_piece()
|
||||
$LockDelay.start()
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
func update_ghost_piece():
|
||||
var positions = current_piece.positions()
|
||||
for i in range(Tetromino.NB_MINOES):
|
||||
$GhostPiece.minoes[i].translation = $GhostPiece.to_local(positions[i])
|
||||
while $GhostPiece.move(movements["soft_drop"]):
|
||||
pass
|
||||
|
||||
func _on_DropTimer_timeout():
|
||||
move(movements["soft_drop"])
|
||||
|
||||
func _on_HardDropTimer_timeout():
|
||||
if not move(movements["soft_drop"]):
|
||||
$HardDropTimer.stop()
|
||||
hard_dropping = false
|
||||
lock_piece()
|
||||
|
||||
func _on_LockDelay_timeout():
|
||||
if not move(movements["soft_drop"]):
|
||||
lock_piece()
|
||||
@ -192,38 +186,40 @@ func lock_piece():
|
||||
|
||||
func line_clear():
|
||||
var NB_MINOES
|
||||
lines_to_clear = []
|
||||
var lines_cleared = 0
|
||||
for y in range(NB_LINES-1, -1, -1):
|
||||
NB_MINOES = 0
|
||||
for x in range(NB_COLLUMNS):
|
||||
if get_cell_item(x, y, 0) == 0:
|
||||
NB_MINOES += 1
|
||||
if NB_MINOES == NB_COLLUMNS:
|
||||
for x in range(NB_COLLUMNS):
|
||||
set_cell_item(x, y, 0, EMPTY_CELL)
|
||||
lines_to_clear.append(y)
|
||||
for y2 in range(y, NB_LINES+2):
|
||||
for x in range(NB_COLLUMNS):
|
||||
set_cell_item(x, y2, 0, get_cell_item(x, y2+1, 0))
|
||||
lines_cleared += 1
|
||||
exploding_lines[y].restart()
|
||||
if lines_to_clear:
|
||||
$ExplosionDelay.start()
|
||||
update_score()
|
||||
|
||||
func update_score():
|
||||
if lines_to_clear or current_piece.t_spin:
|
||||
var s = SCORES[lines_to_clear.size()][current_piece.t_spin]
|
||||
if lines_cleared or current_piece.t_spin:
|
||||
var s = SCORES[lines_cleared][current_piece.t_spin]
|
||||
score += 100 * s
|
||||
goal -= s
|
||||
print(T_SPIN_NAMES[current_piece.t_spin], ' ', LINES_CLEARED_NAMES[lines_to_clear.size()], " Score ", score)
|
||||
print(T_SPIN_NAMES[current_piece.t_spin], ' ', LINES_CLEARED_NAMES[lines_cleared], " Score ", score)
|
||||
|
||||
if lines_cleared == Tetromino.NB_MINOES:
|
||||
for channel in $MidiPlayer.line_clear_notes:
|
||||
$MidiPlayer.channel_status[channel].vomume = 127
|
||||
$MidiPlayer/LineCLearTimer.wait_time = 0.86
|
||||
else:
|
||||
for channel in $MidiPlayer.line_clear_notes:
|
||||
$MidiPlayer.channel_status[channel].vomume = 100
|
||||
$MidiPlayer/LineCLearTimer.wait_time = 0.43
|
||||
$MidiPlayer.mute_midi_channels($MidiPlayer.line_clear_notes, false)
|
||||
$MidiPlayer.play_line_clear()
|
||||
$MidiPlayer/LineCLearTimer.start()
|
||||
if goal <= 0:
|
||||
new_level()
|
||||
else:
|
||||
new_piece()
|
||||
|
||||
func _on_ExplosionDelay_timeout():
|
||||
for cleared_line in lines_to_clear:
|
||||
for y in range(cleared_line, NB_LINES+2):
|
||||
for x in range(NB_COLLUMNS):
|
||||
set_cell_item(x, y, 0, get_cell_item(x, y+1, 0))
|
||||
|
||||
func hold():
|
||||
if not current_piece_held:
|
||||
if held_piece:
|
||||
@ -231,26 +227,38 @@ func hold():
|
||||
held_piece = current_piece
|
||||
current_piece = tmp
|
||||
current_piece.translation = START_POSITION
|
||||
current_piece.emit_trail(true)
|
||||
else:
|
||||
held_piece = current_piece
|
||||
new_piece()
|
||||
held_piece.emit_trail(false)
|
||||
held_piece.translation = HOLD_POSITION
|
||||
current_piece_held = true
|
||||
|
||||
func resume():
|
||||
playing = true
|
||||
$DropTimer.start()
|
||||
$LockDelay.start()
|
||||
$MidiPlayer.resume()
|
||||
$MidiPlayer.mute_midi_channels($MidiPlayer.line_clear_notes, true)
|
||||
print("RESUME")
|
||||
|
||||
func pause():
|
||||
playing = not playing
|
||||
if playing:
|
||||
$DropTimer.start()
|
||||
$LockDelay.start()
|
||||
print("RESUME")
|
||||
else:
|
||||
$DropTimer.stop()
|
||||
$LockDelay.stop()
|
||||
print("PAUSE")
|
||||
|
||||
func game_over():
|
||||
playing = false
|
||||
$DropTimer.stop()
|
||||
$AutoShiftDelay.stop()
|
||||
$AutoShiftTimer.stop()
|
||||
print("GAME OVER")
|
||||
$LockDelay.stop()
|
||||
$MidiPlayer.stop()
|
||||
print("PAUSE")
|
||||
|
||||
func game_over():
|
||||
pause()
|
||||
print("GAME OVER")
|
||||
|
||||
func _notification(what):
|
||||
if what == MainLoop.NOTIFICATION_WM_FOCUS_OUT:
|
||||
pause()
|
||||
if what == MainLoop.NOTIFICATION_WM_FOCUS_IN:
|
||||
resume()
|
||||
|
||||
func _on_LineCLearTimer_timeout():
|
||||
$MidiPlayer.mute_midi_channels($MidiPlayer.line_clear_notes, true)
|
||||
|
@ -3,10 +3,8 @@
|
||||
[ext_resource path="res://Tetrominos/Mino/MinoLibrary.tres" type="MeshLibrary" id=1]
|
||||
[ext_resource path="res://GridMap/GridMap.gd" type="Script" id=2]
|
||||
[ext_resource path="res://GridMap/GridBack.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://Tetrominos/Mino/BackMaterial.tres" type="Material" id=4]
|
||||
[ext_resource path="res://Tetrominos/GhostPiece.tscn" type="PackedScene" id=5]
|
||||
|
||||
|
||||
[ext_resource path="res://GridMap/BackMaterial.tres" type="Material" id=4]
|
||||
[ext_resource path="res://midi/MidiPlayer.tscn" type="PackedScene" id=5]
|
||||
|
||||
[sub_resource type="CubeMesh" id=1]
|
||||
|
||||
@ -17,7 +15,7 @@ subdivide_width = 0
|
||||
subdivide_height = 0
|
||||
subdivide_depth = 0
|
||||
|
||||
[node name="GridMap" type="GridMap" index="0"]
|
||||
[node name="GridMap" type="GridMap"]
|
||||
|
||||
theme = ExtResource( 1 )
|
||||
cell_size = Vector3( 1, 1, 1 )
|
||||
@ -29,16 +27,14 @@ cell_scale = 1.0
|
||||
collision_layer = 1
|
||||
collision_mask = 1
|
||||
data = {
|
||||
"cells": PoolIntArray( 13, 0, 0, 65543, 0, 0 )
|
||||
"cells": PoolIntArray( )
|
||||
}
|
||||
script = ExtResource( 2 )
|
||||
_sections_unfolded = [ "Cell", "Transform" ]
|
||||
__meta__ = {
|
||||
"_editor_clip_": 0,
|
||||
"_editor_floor_": Vector3( 0, 3, 0 )
|
||||
"_editor_clip_": 1,
|
||||
"_editor_floor_": Vector3( 0, -1, 0 )
|
||||
}
|
||||
NB_LINES = 20
|
||||
NB_COLLUMNS = 10
|
||||
|
||||
[node name="DropTimer" type="Timer" parent="." index="0"]
|
||||
|
||||
@ -68,38 +64,35 @@ wait_time = 0.02
|
||||
one_shot = false
|
||||
autostart = true
|
||||
|
||||
[node name="HardDropTimer" type="Timer" parent="." index="4"]
|
||||
|
||||
process_mode = 0
|
||||
wait_time = 0.01
|
||||
one_shot = false
|
||||
autostart = false
|
||||
|
||||
[node name="ExplosionDelay" type="Timer" parent="." index="5"]
|
||||
|
||||
process_mode = 1
|
||||
wait_time = 0.1
|
||||
one_shot = true
|
||||
autostart = false
|
||||
|
||||
[node name="GridBack" parent="." index="6" instance=ExtResource( 3 )]
|
||||
[node name="GridBack" parent="." index="4" instance=ExtResource( 3 )]
|
||||
|
||||
transform = Transform( 10, 0, 0, 0, 20, 0, 0, 0, 0.1, 4.5, 9.5, -1 )
|
||||
mesh = SubResource( 1 )
|
||||
|
||||
[node name="HoldBack" parent="." index="7" instance=ExtResource( 3 )]
|
||||
[node name="HoldBack" parent="." index="5" instance=ExtResource( 3 )]
|
||||
|
||||
transform = Transform( 7, 0, 0, 0, 7, 0, 0, 0, 0.1, -5, 16, -1 )
|
||||
mesh = SubResource( 1 )
|
||||
|
||||
[node name="NextBack" parent="." index="8" instance=ExtResource( 3 )]
|
||||
[node name="NextBack" parent="." index="6" instance=ExtResource( 3 )]
|
||||
|
||||
transform = Transform( 7, 0, 0, 0, 7, 0, 0, 0, 0.1, 14, 16, -1 )
|
||||
mesh = SubResource( 1 )
|
||||
|
||||
[node name="GhostPiece" parent="." index="9" instance=ExtResource( 5 )]
|
||||
[node name="MidiPlayer" parent="." index="7" instance=ExtResource( 5 )]
|
||||
|
||||
_sections_unfolded = [ "Transform" ]
|
||||
file = "res://midi/Tetris - Song A.mid"
|
||||
volume_db = -24
|
||||
loop = true
|
||||
loop_start = 1.81
|
||||
soundfont = "res://midi/FluidR3 GM.sf2"
|
||||
|
||||
[node name="LineCLearTimer" type="Timer" parent="MidiPlayer" index="1"]
|
||||
|
||||
process_mode = 1
|
||||
wait_time = 1.41
|
||||
one_shot = true
|
||||
autostart = false
|
||||
|
||||
[connection signal="timeout" from="DropTimer" to="." method="_on_DropTimer_timeout"]
|
||||
|
||||
@ -109,8 +102,6 @@ _sections_unfolded = [ "Transform" ]
|
||||
|
||||
[connection signal="timeout" from="AutoShiftTimer" to="." method="_on_AutoShiftTimer_timeout"]
|
||||
|
||||
[connection signal="timeout" from="HardDropTimer" to="." method="_on_HardDropTimer_timeout"]
|
||||
|
||||
[connection signal="timeout" from="ExplosionDelay" to="." method="_on_ExplosionDelay_timeout"]
|
||||
[connection signal="timeout" from="MidiPlayer/LineCLearTimer" to="." method="_on_LineCLearTimer_timeout"]
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user