remove explosion delay, double midi with clarinette

This commit is contained in:
adrienmalin 2019-01-01 02:50:58 +01:00
parent b904924241
commit 556f9fca24
4 changed files with 22 additions and 70 deletions

View File

@ -45,7 +45,6 @@ var current_piece_held = false
var autoshift_action = "" var autoshift_action = ""
var exploding_lines = [] var exploding_lines = []
var lines_to_clear = []
var random_bag = [] var random_bag = []
var playing = true var playing = true
@ -90,7 +89,6 @@ func new_piece():
current_piece.emit_trail(true) current_piece.emit_trail(true)
update_ghost_piece() update_ghost_piece()
autoshift_action = "" autoshift_action = ""
update_ghost_piece()
next_piece = random_piece() next_piece = random_piece()
next_piece.translation = NEXT_POSITION next_piece.translation = NEXT_POSITION
if move(movements["soft_drop"]): if move(movements["soft_drop"]):
@ -118,22 +116,18 @@ func process_actions():
for action in movements: for action in movements:
if action != autoshift_action: if action != autoshift_action:
if Input.is_action_pressed(action): if Input.is_action_pressed(action):
if move(movements[action]): move(movements[action])
move_midi()
autoshift_action = action autoshift_action = action
$AutoShiftTimer.stop() $AutoShiftTimer.stop()
$AutoShiftDelay.start() $AutoShiftDelay.start()
if Input.is_action_just_pressed("hard_drop"): if Input.is_action_just_pressed("hard_drop"):
move_midi()
while move(movements["soft_drop"]): while move(movements["soft_drop"]):
pass pass
lock_piece() lock_piece()
if Input.is_action_just_pressed("rotate_clockwise"): if Input.is_action_just_pressed("rotate_clockwise"):
rotate(Tetromino.CLOCKWISE) rotate(Tetromino.CLOCKWISE)
move_midi()
if Input.is_action_just_pressed("rotate_counterclockwise"): if Input.is_action_just_pressed("rotate_counterclockwise"):
rotate(Tetromino.COUNTERCLOCKWISE) rotate(Tetromino.COUNTERCLOCKWISE)
move_midi()
if Input.is_action_just_pressed("hold"): if Input.is_action_just_pressed("hold"):
hold() hold()
@ -182,12 +176,6 @@ func rotate(direction):
else: else:
return false return false
func move_midi():
for channel_id in MIDI_MOVE_CHANNELS:
$MidiPlayer.channel_status[channel_id].pan = current_piece.translation.x / 10.0
$MidiPlayer.mute_midi_channels(MIDI_MOVE_CHANNELS, false)
$MidiPlayer/MoveDelay.start()
func update_ghost_piece(): func update_ghost_piece():
var new_positions = current_piece.positions() var new_positions = current_piece.positions()
var positions var positions
@ -211,29 +199,26 @@ func lock_piece():
func line_clear(): func line_clear():
var NB_MINOES var NB_MINOES
lines_to_clear = [] var lines_cleared = 0
for y in range(NB_LINES-1, -1, -1): for y in range(NB_LINES-1, -1, -1):
NB_MINOES = 0 NB_MINOES = 0
for x in range(NB_COLLUMNS): for x in range(NB_COLLUMNS):
if get_cell_item(x, y, 0) == 0: if get_cell_item(x, y, 0) == 0:
NB_MINOES += 1 NB_MINOES += 1
if NB_MINOES == NB_COLLUMNS: if NB_MINOES == NB_COLLUMNS:
for y2 in range(y, NB_LINES+2):
for x in range(NB_COLLUMNS): for x in range(NB_COLLUMNS):
set_cell_item(x, y, 0, EMPTY_CELL) set_cell_item(x, y2, 0, get_cell_item(x, y2+1, 0))
lines_to_clear.append(y) lines_cleared += 1
exploding_lines[y].restart() exploding_lines[y].restart()
if lines_to_clear: update_ghost_piece()
$ExplosionDelay.start() if lines_cleared or current_piece.t_spin:
update_score() var s = SCORES[lines_cleared][current_piece.t_spin]
func update_score():
if lines_to_clear or current_piece.t_spin:
var s = SCORES[lines_to_clear.size()][current_piece.t_spin]
score += 100 * s score += 100 * s
goal -= 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_to_clear.size() == Tetromino.NB_MINOES: if lines_cleared == Tetromino.NB_MINOES:
for channel in $MidiPlayer.line_clear_notes: for channel in $MidiPlayer.line_clear_notes:
$MidiPlayer.channel_status[channel].vomume = 127 $MidiPlayer.channel_status[channel].vomume = 127
$MidiPlayer/LineCLearTimer.wait_time = 0.86 $MidiPlayer/LineCLearTimer.wait_time = 0.86
@ -249,13 +234,6 @@ func update_score():
else: else:
new_piece() 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))
update_ghost_piece()
func hold(): func hold():
if not current_piece_held: if not current_piece_held:
if held_piece: if held_piece:
@ -264,10 +242,10 @@ func hold():
current_piece = tmp current_piece = tmp
current_piece.translation = START_POSITION current_piece.translation = START_POSITION
current_piece.emit_trail(true) current_piece.emit_trail(true)
update_ghost_piece()
else: else:
held_piece = current_piece held_piece = current_piece
new_piece() new_piece()
update_ghost_piece()
held_piece.translation = HOLD_POSITION held_piece.translation = HOLD_POSITION
held_piece.emit_trail(false) held_piece.emit_trail(false)
current_piece_held = true current_piece_held = true
@ -277,7 +255,6 @@ func resume():
$DropTimer.start() $DropTimer.start()
$LockDelay.start() $LockDelay.start()
$MidiPlayer.resume() $MidiPlayer.resume()
$MidiPlayer.mute_midi_channels(MIDI_MOVE_CHANNELS, true)
$MidiPlayer.mute_midi_channels($MidiPlayer.line_clear_notes, true) $MidiPlayer.mute_midi_channels($MidiPlayer.line_clear_notes, true)
print("RESUME") print("RESUME")
@ -289,10 +266,7 @@ func pause():
print("PAUSE") print("PAUSE")
func game_over(): func game_over():
playing = false pause()
$DropTimer.stop()
$AutoShiftDelay.stop()
$AutoShiftTimer.stop()
print("GAME OVER") print("GAME OVER")
func _notification(what): func _notification(what):
@ -301,8 +275,5 @@ func _notification(what):
if what == MainLoop.NOTIFICATION_WM_FOCUS_IN: if what == MainLoop.NOTIFICATION_WM_FOCUS_IN:
resume() resume()
func _on_MoveDelay_timeout():
$MidiPlayer.mute_midi_channels(MIDI_MOVE_CHANNELS, true)
func _on_LineCLearTimer_timeout(): func _on_LineCLearTimer_timeout():
$MidiPlayer.mute_midi_channels($MidiPlayer.line_clear_notes, true) $MidiPlayer.mute_midi_channels($MidiPlayer.line_clear_notes, true)

View File

@ -65,50 +65,35 @@ wait_time = 0.02
one_shot = false one_shot = false
autostart = true autostart = true
[node name="ExplosionDelay" type="Timer" parent="." index="4"] [node name="GridBack" parent="." index="4" instance=ExtResource( 3 )]
process_mode = 1
wait_time = 0.1
one_shot = true
autostart = false
[node name="GridBack" parent="." index="5" instance=ExtResource( 3 )]
transform = Transform( 10, 0, 0, 0, 20, 0, 0, 0, 0.1, 4.5, 9.5, -1 ) transform = Transform( 10, 0, 0, 0, 20, 0, 0, 0, 0.1, 4.5, 9.5, -1 )
mesh = SubResource( 1 ) mesh = SubResource( 1 )
[node name="HoldBack" parent="." index="6" 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 ) transform = Transform( 7, 0, 0, 0, 7, 0, 0, 0, 0.1, -5, 16, -1 )
mesh = SubResource( 1 ) mesh = SubResource( 1 )
[node name="NextBack" parent="." index="7" 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 ) transform = Transform( 7, 0, 0, 0, 7, 0, 0, 0, 0.1, 14, 16, -1 )
mesh = SubResource( 1 ) mesh = SubResource( 1 )
[node name="GhostPiece" parent="." index="8" instance=ExtResource( 5 )] [node name="GhostPiece" parent="." index="7" instance=ExtResource( 5 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 20, 0 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 20, 0 )
_sections_unfolded = [ "Pause", "Transform" ] _sections_unfolded = [ "Pause", "Transform" ]
[node name="MidiPlayer" parent="." index="9" instance=ExtResource( 6 )] [node name="MidiPlayer" parent="." index="8" instance=ExtResource( 6 )]
file = "res://midi/Tetris - Song A.mid" file = "res://midi/Tetris - Song A.mid"
channel_mute = [ false, true, false, false, false, false, false, true, true, true, true, false, false, false, false, false ] volume_db = -24
volume_db = -3
loop = true loop = true
loop_start = 2 loop_start = 1.81
soundfont = "res://midi/FluidR3 GM.sf2" soundfont = "res://midi/FluidR3 GM.sf2"
[node name="MoveDelay" type="Timer" parent="MidiPlayer" index="1"] [node name="LineCLearTimer" type="Timer" parent="MidiPlayer" index="1"]
process_mode = 1
wait_time = 0.1
one_shot = true
autostart = false
[node name="LineCLearTimer" type="Timer" parent="MidiPlayer" index="2"]
process_mode = 1 process_mode = 1
wait_time = 1.41 wait_time = 1.41
@ -123,10 +108,6 @@ autostart = false
[connection signal="timeout" from="AutoShiftTimer" to="." method="_on_AutoShiftTimer_timeout"] [connection signal="timeout" from="AutoShiftTimer" to="." method="_on_AutoShiftTimer_timeout"]
[connection signal="timeout" from="ExplosionDelay" to="." method="_on_ExplosionDelay_timeout"]
[connection signal="timeout" from="MidiPlayer/MoveDelay" to="." method="_on_MoveDelay_timeout"]
[connection signal="timeout" from="MidiPlayer/LineCLearTimer" to="." method="_on_LineCLearTimer_timeout"] [connection signal="timeout" from="MidiPlayer/LineCLearTimer" to="." method="_on_LineCLearTimer_timeout"]

View File

@ -19,7 +19,7 @@ export var play_speed = 1.0
export var volume_db = -30 export var volume_db = -30
export var key_shift = 0 export var key_shift = 0
export var loop = false export var loop = false
export var loop_start = 0 export var loop_start = 1.81
export var soundfont = "" export var soundfont = ""
export var mix_target = AudioStreamPlayer.MIX_TARGET_STEREO export var mix_target = AudioStreamPlayer.MIX_TARGET_STEREO
export var bus = "Master" export var bus = "Master"

Binary file not shown.