hide on pause, T-SPIN on rotation 5

This commit is contained in:
adrienmalin 2019-01-02 03:00:47 +01:00
parent 85d26a98bd
commit 792db2f0c8
5 changed files with 35 additions and 25 deletions

27
Main.gd
View File

@ -60,9 +60,9 @@ func _ready():
func new_game(): func new_game():
$Stats.visible = true $Stats.visible = true
$Stats.new_game() $Stats.new_game()
new_piece()
resume() resume()
new_level() new_level()
new_piece()
func new_level(): func new_level():
$Stats.new_level() $Stats.new_level()
@ -129,8 +129,10 @@ func process_autoshift_action():
$Stats/HBC/VBC1/Score.text = str($Stats.score) $Stats/HBC/VBC1/Score.text = str($Stats.score)
func hard_drop(): func hard_drop():
var score = 0
while move(movements["soft_drop"]): while move(movements["soft_drop"]):
$Stats.score += 2 score += 2
$Stats.score += score
$Stats/HBC/VBC1/Score.text = str($Stats.score) $Stats/HBC/VBC1/Score.text = str($Stats.score)
lock() lock()
@ -204,25 +206,34 @@ func resume():
$Stats/Clock.start() $Stats/Clock.start()
$MidiPlayer.resume() $MidiPlayer.resume()
$MidiPlayer.mute_channels(LINE_CLEAR_MIDI_CHANNELS) $MidiPlayer.mute_channels(LINE_CLEAR_MIDI_CHANNELS)
$GridMap.visible = true
next_piece.visible = true
current_piece.visible = true
if held_piece:
held_piece.visible = true
flash_print("GO!")
func pause(): func pause(text = "PAUSE"):
playing = false playing = false
$DropTimer.stop() $DropTimer.stop()
$LockDelay.stop() $LockDelay.stop()
$Stats/Clock.stop() $Stats/Clock.stop()
if text == "PAUSE":
$Stats.time = OS.get_system_time_secs() - $Stats.time $Stats.time = OS.get_system_time_secs() - $Stats.time
$GridMap.visible = false
next_piece.visible = false
current_piece.visible = false
if held_piece:
held_piece.visible = false
$MidiPlayer.stop() $MidiPlayer.stop()
flash_print("PAUSE") flash_print(text)
func game_over(): func game_over():
pause() pause("GAME OVER")
flash_print("GAME OVER")
func _notification(what): func _notification(what):
if what == MainLoop.NOTIFICATION_WM_FOCUS_OUT: if what == MainLoop.NOTIFICATION_WM_FOCUS_OUT:
pause() pause()
#if what == MainLoop.NOTIFICATION_WM_FOCUS_IN:
# resume()
func _on_LineCLearTimer_timeout(): func _on_LineCLearTimer_timeout():
$MidiPlayer.mute_channels(LINE_CLEAR_MIDI_CHANNELS) $MidiPlayer.mute_channels(LINE_CLEAR_MIDI_CHANNELS)

View File

@ -216,7 +216,7 @@ tracks/2/keys = {
"values": [ Vector2( 0, 110 ), Vector2( 0, -50 ), Vector2( 0, -60 ), Vector2( 0, -100 ) ] "values": [ Vector2( 0, 110 ), Vector2( 0, -50 ), Vector2( 0, -60 ), Vector2( 0, -100 ) ]
} }
[node name="Main" type="WorldEnvironment"] [node name="Main" type="WorldEnvironment" index="0"]
environment = SubResource( 2 ) environment = SubResource( 2 )
script = ExtResource( 2 ) script = ExtResource( 2 )
@ -381,7 +381,7 @@ file = "res://midi/Tetris - Song A.mid"
volume_db = -24 volume_db = -24
loop = true loop = true
loop_start = 1.71 loop_start = 1.71
soundfont = "res://midi/FluidR3 GM.sf2" soundfont = "res://midi/TimGM6mb.sf2"
[node name="Stats" parent="." index="12" instance=ExtResource( 6 )] [node name="Stats" parent="." index="12" instance=ExtResource( 6 )]

View File

@ -19,7 +19,7 @@ use_filter = false
font_data = ExtResource( 2 ) font_data = ExtResource( 2 )
_sections_unfolded = [ "Font", "Settings" ] _sections_unfolded = [ "Font", "Settings" ]
[node name="Stats" type="MarginContainer" index="0"] [node name="Stats" type="MarginContainer"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.5 anchor_top = 0.5

View File

@ -8,13 +8,8 @@ const T_SLOT = [
] ]
func rotate(direction): func rotate(direction):
if .rotate(direction): var rotation_point = .rotate(direction)
detect_t_spin() if rotation_point and t_spin != T_SPIN:
return true
return false
func detect_t_spin():
if t_spin != T_SPIN:
var center = to_global(minoes[0].translation) var center = to_global(minoes[0].translation)
var a = not grid_map.is_free_cell(center + T_SLOT[orientation]) var a = not grid_map.is_free_cell(center + T_SLOT[orientation])
var b = not grid_map.is_free_cell(center + T_SLOT[(1+orientation)%4]) var b = not grid_map.is_free_cell(center + T_SLOT[(1+orientation)%4])
@ -23,4 +18,8 @@ func detect_t_spin():
if a and b and (c or d): if a and b and (c or d):
t_spin = T_SPIN t_spin = T_SPIN
elif c and d and (a or b): elif c and d and (a or b):
if rotation_point == 5:
t_spin = T_SPIN
else:
t_spin = MINI_T_SPIN t_spin = MINI_T_SPIN
return rotation_point

View File

@ -113,14 +113,14 @@ func move(movement):
func rotate(direction): func rotate(direction):
var rotated_positions = rotated_positions(direction) var rotated_positions = rotated_positions(direction)
var movements = SUPER_ROTATION_SYSTEM[orientation][direction] var movements = SUPER_ROTATION_SYSTEM[orientation][direction]
for movement in movements: for i in range(movements.size()):
if grid_map.possible_positions(rotated_positions, movement): if grid_map.possible_positions(rotated_positions, movements[i]):
orientation -= direction orientation -= direction
orientation %= NB_MINOES orientation %= NB_MINOES
apply_positions(rotated_positions) apply_positions(rotated_positions)
translate(movement) translate(movements[i])
return true return i+1
return false return 0
func emit_trail(emit): func emit_trail(emit):
var trail var trail