reorganize
This commit is contained in:
parent
74e288c870
commit
47b7bc24b0
@ -6,16 +6,17 @@ const ExplodingLine = preload("res://ExplodingLine.tscn")
|
||||
const EMPTY_CELL = -1
|
||||
const MINO = 0
|
||||
|
||||
export (int) var NB_LINES = 20
|
||||
export (int) var NB_COLLUMNS = 10
|
||||
|
||||
var exploding_lines = []
|
||||
var nb_collumns
|
||||
var nb_lines
|
||||
|
||||
func _ready():
|
||||
for y in range(NB_LINES):
|
||||
nb_collumns = int($Matrix.scale.x)
|
||||
nb_lines = int($Matrix.scale.y)
|
||||
for y in range(nb_lines):
|
||||
exploding_lines.append(ExplodingLine.instance())
|
||||
add_child(exploding_lines[y])
|
||||
exploding_lines[y].translation = Vector3(NB_COLLUMNS/2, y, 1)
|
||||
exploding_lines[y].translation = Vector3(nb_collumns/2, y, 1)
|
||||
|
||||
func clear():
|
||||
for position in get_used_cells():
|
||||
@ -23,7 +24,7 @@ func clear():
|
||||
|
||||
func is_free_cell(position):
|
||||
return (
|
||||
0 <= position.x and position.x < NB_COLLUMNS
|
||||
0 <= position.x and position.x < nb_collumns
|
||||
and position.y >= 0
|
||||
and get_cell_item(position.x, position.y, 0) == GridMap.INVALID_CELL_ITEM
|
||||
)
|
||||
@ -43,7 +44,7 @@ func possible_positions(initial_positions, movement):
|
||||
func lock(piece):
|
||||
var minoes_over_grid = 0
|
||||
for position in piece.positions():
|
||||
if position.y >= NB_LINES:
|
||||
if position.y >= nb_lines:
|
||||
minoes_over_grid += 1
|
||||
set_cell_item(position.x, position.y, 0, MINO)
|
||||
return minoes_over_grid < Tetromino.NB_MINOES
|
||||
@ -51,15 +52,15 @@ func lock(piece):
|
||||
func clear_lines():
|
||||
var line_cleared
|
||||
var lines_cleared = 0
|
||||
for y in range(NB_LINES-1, -1, -1):
|
||||
for y in range(nb_lines-1, -1, -1):
|
||||
line_cleared = true
|
||||
for x in range(NB_COLLUMNS):
|
||||
for x in range(nb_collumns):
|
||||
if not get_cell_item(x, y, 0) == MINO:
|
||||
line_cleared = false
|
||||
break
|
||||
if line_cleared:
|
||||
for y2 in range(y, NB_LINES+2):
|
||||
for x in range(NB_COLLUMNS):
|
||||
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].emitting = true
|
||||
|
@ -11,9 +11,6 @@ const TetroZ = preload("res://Tetrominos/TetroZ.tscn")
|
||||
|
||||
const password = "TETRIS 3000"
|
||||
|
||||
const NEXT_POSITION = Vector3(13, 16, 0)
|
||||
const START_POSITION = Vector3(5, 20, 0)
|
||||
const HOLD_POSITION = Vector3(-5, 16, 0)
|
||||
const THERE = Vector3(0, 0, 0)
|
||||
|
||||
const movements = {
|
||||
@ -67,10 +64,10 @@ func new_piece():
|
||||
if current_piece:
|
||||
remove_child(current_piece)
|
||||
current_piece = next_piece
|
||||
current_piece.translation = START_POSITION
|
||||
current_piece.translation = $GridMap/Matrix/Position3D.translation
|
||||
current_piece.emit_trail(true)
|
||||
next_piece = random_piece()
|
||||
next_piece.translation = NEXT_POSITION
|
||||
next_piece.translation = $GridMap/Next/Position3D.translation
|
||||
if move(THERE):
|
||||
$DropTimer.start()
|
||||
$LockDelay.start()
|
||||
@ -191,9 +188,9 @@ func hold():
|
||||
current_piece = held_piece
|
||||
held_piece = swap
|
||||
held_piece.emit_trail(false)
|
||||
held_piece.translation = HOLD_POSITION
|
||||
held_piece.translation = $GridMap/Hold/Position3D.translation
|
||||
if current_piece:
|
||||
current_piece.translation = START_POSITION
|
||||
current_piece.translation = $GridMap/Matrix/Position3D.translation
|
||||
current_piece.emit_trail(true)
|
||||
else:
|
||||
new_piece()
|
||||
@ -208,7 +205,6 @@ func resume():
|
||||
$controls_ui.visible = false
|
||||
$Stats.visible = true
|
||||
$GridMap.visible = true
|
||||
$Backs.visible = true
|
||||
current_piece.visible = true
|
||||
if held_piece:
|
||||
held_piece.visible = true
|
||||
@ -220,7 +216,6 @@ func pause(hide=true):
|
||||
if hide:
|
||||
$Stats.visible = false
|
||||
$GridMap.visible = false
|
||||
$Backs.visible = false
|
||||
current_piece.visible = false
|
||||
if held_piece:
|
||||
held_piece.visible = false
|
||||
|
@ -313,6 +313,7 @@ _sections_unfolded = [ "Light", "Transform" ]
|
||||
|
||||
[node name="GridMap" type="GridMap" parent="." index="3"]
|
||||
|
||||
visible = false
|
||||
theme = ExtResource( 3 )
|
||||
cell_size = Vector3( 1, 1, 1 )
|
||||
cell_octant_size = 8
|
||||
@ -331,16 +332,10 @@ __meta__ = {
|
||||
"_editor_clip_": 1,
|
||||
"_editor_floor_": Vector3( 0, -1, 0 )
|
||||
}
|
||||
NB_LINES = 20
|
||||
NB_COLLUMNS = 10
|
||||
|
||||
[node name="Backs" type="Spatial" parent="." index="4"]
|
||||
[node name="Matrix" type="MeshInstance" parent="GridMap" index="0"]
|
||||
|
||||
visible = false
|
||||
|
||||
[node name="GridBack" type="MeshInstance" parent="Backs" index="0"]
|
||||
|
||||
transform = Transform( 10, 0, 0, 0, 20, 0, 0, 0, 1, 4.5, 9.5, 0 )
|
||||
transform = Transform( 8.5, 0, 0, 0, 20, 0, 0, 0, 1, 4.5, 9.5, 0 )
|
||||
layers = 1
|
||||
material_override = null
|
||||
cast_shadow = 1
|
||||
@ -355,7 +350,12 @@ skeleton = NodePath("..")
|
||||
material/0 = null
|
||||
_sections_unfolded = [ "Transform" ]
|
||||
|
||||
[node name="HoldBack" type="MeshInstance" parent="Backs" index="1"]
|
||||
[node name="Position3D" type="Position3D" parent="GridMap/Matrix" index="0"]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 20, 0 )
|
||||
_sections_unfolded = [ "Transform" ]
|
||||
|
||||
[node name="Hold" type="MeshInstance" parent="GridMap" index="1"]
|
||||
|
||||
transform = Transform( 7, 0, 0, 0, 7, 0, 0, 0, 1, -5, 16, 0 )
|
||||
layers = 1
|
||||
@ -372,7 +372,12 @@ skeleton = NodePath("..")
|
||||
material/0 = null
|
||||
_sections_unfolded = [ "Transform" ]
|
||||
|
||||
[node name="NextBack" type="MeshInstance" parent="Backs" index="2"]
|
||||
[node name="Position3D" type="Position3D" parent="GridMap/Hold" index="0"]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5, 16, 0 )
|
||||
_sections_unfolded = [ "Transform" ]
|
||||
|
||||
[node name="Next" type="MeshInstance" parent="GridMap" index="2"]
|
||||
|
||||
transform = Transform( 7, 0, 0, 0, 7, 0, 0, 0, 1, 14, 16, 0 )
|
||||
layers = 1
|
||||
@ -389,41 +394,47 @@ skeleton = NodePath("..")
|
||||
material/0 = null
|
||||
_sections_unfolded = [ "Transform" ]
|
||||
|
||||
[node name="DropTimer" type="Timer" parent="." index="5"]
|
||||
[node name="Position3D" type="Position3D" parent="GridMap/Next" index="0"]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 13, 16, 0 )
|
||||
_sections_unfolded = [ "Transform" ]
|
||||
|
||||
[node name="DropTimer" type="Timer" parent="." index="4"]
|
||||
|
||||
process_mode = 1
|
||||
wait_time = 1.0
|
||||
one_shot = false
|
||||
autostart = false
|
||||
|
||||
[node name="LockDelay" type="Timer" parent="." index="6"]
|
||||
[node name="LockDelay" type="Timer" parent="." index="5"]
|
||||
|
||||
process_mode = 1
|
||||
wait_time = 0.5
|
||||
one_shot = true
|
||||
autostart = false
|
||||
|
||||
[node name="AutoShiftDelay" type="Timer" parent="." index="7"]
|
||||
[node name="AutoShiftDelay" type="Timer" parent="." index="6"]
|
||||
|
||||
process_mode = 1
|
||||
wait_time = 0.2
|
||||
one_shot = true
|
||||
autostart = false
|
||||
|
||||
[node name="AutoShiftTimer" type="Timer" parent="." index="8"]
|
||||
[node name="AutoShiftTimer" type="Timer" parent="." index="7"]
|
||||
|
||||
process_mode = 1
|
||||
wait_time = 0.04
|
||||
one_shot = false
|
||||
autostart = false
|
||||
|
||||
[node name="MidiPlayer" parent="." index="9" instance=ExtResource( 5 )]
|
||||
[node name="MidiPlayer" parent="." index="8" instance=ExtResource( 5 )]
|
||||
|
||||
editor/display_folded = true
|
||||
script = ExtResource( 6 )
|
||||
file = "res://midi/Tetris - Song A.mid"
|
||||
volume_db = -24
|
||||
loop = true
|
||||
loop_start = 1.81
|
||||
soundfont = "res://midi/TimGM6mb.sf2"
|
||||
|
||||
[node name="LineCLearTimer" type="Timer" parent="MidiPlayer" index="1"]
|
||||
@ -433,7 +444,7 @@ wait_time = 1.41
|
||||
one_shot = true
|
||||
autostart = false
|
||||
|
||||
[node name="FlashText" type="Control" parent="." index="10"]
|
||||
[node name="FlashText" type="Control" parent="." index="9"]
|
||||
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
@ -487,7 +498,7 @@ anims/Flash = SubResource( 7 )
|
||||
blend_times = [ ]
|
||||
_sections_unfolded = [ "Playback Options" ]
|
||||
|
||||
[node name="Stats" parent="." index="11" instance=ExtResource( 9 )]
|
||||
[node name="Stats" parent="." index="10" instance=ExtResource( 9 )]
|
||||
|
||||
visible = false
|
||||
anchor_left = 0.0
|
||||
@ -499,13 +510,13 @@ margin_top = -260.0
|
||||
margin_right = 130.0
|
||||
margin_bottom = -50.0
|
||||
|
||||
[node name="controls_ui" parent="." index="12" instance=ExtResource( 10 )]
|
||||
[node name="controls_ui" parent="." index="11" instance=ExtResource( 10 )]
|
||||
|
||||
visible = false
|
||||
|
||||
[node name="Start" parent="." index="13" instance=ExtResource( 11 )]
|
||||
[node name="Start" parent="." index="12" instance=ExtResource( 11 )]
|
||||
|
||||
[node name="ReplayButton" type="Button" parent="." index="14"]
|
||||
[node name="ReplayButton" type="Button" parent="." index="13"]
|
||||
|
||||
visible = false
|
||||
anchor_left = 1.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user