stuff
This commit is contained in:
@ -73,51 +73,48 @@ const SUPER_ROTATION_SYSTEM = [
|
||||
}
|
||||
]
|
||||
|
||||
var minoes
|
||||
var minoes = []
|
||||
var grid_map
|
||||
var orientation = 0
|
||||
var t_spin = NO_T_SPIN
|
||||
|
||||
func _ready():
|
||||
randomize()
|
||||
minoes = [$Mino0, $Mino1, $Mino2, $Mino3]
|
||||
for i in range(NB_MINOES):
|
||||
minoes.append(get_node("Mino"+str(i)))
|
||||
grid_map = get_parent().get_node("GridMap")
|
||||
|
||||
func positions():
|
||||
var p = []
|
||||
for mino in minoes:
|
||||
p.append(to_global(mino.translation))
|
||||
return p
|
||||
|
||||
func rotated_positions(direction):
|
||||
var translations = [to_global(minoes[0].translation) ]
|
||||
for i in range(1, 4):
|
||||
var v = to_global(minoes[i].translation)
|
||||
v -= to_global(minoes[0].translation)
|
||||
v = Vector3(-1*direction*v.y, direction*v.x, 0)
|
||||
v += to_global(minoes[0].translation)
|
||||
translations.append(v)
|
||||
return translations
|
||||
|
||||
func apply_positions(positions):
|
||||
func set_translations(translations):
|
||||
for i in range(NB_MINOES):
|
||||
minoes[i].translation = to_local(positions[i])
|
||||
minoes[i].translation = to_local(translations[i])
|
||||
|
||||
func get_translations():
|
||||
var translations = []
|
||||
for mino in minoes:
|
||||
translations.append(to_global(mino.translation))
|
||||
return translations
|
||||
|
||||
func move(movement):
|
||||
if grid_map.possible_positions(positions(), movement):
|
||||
if grid_map.possible_positions(get_translations(), movement):
|
||||
translate(movement)
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
return false
|
||||
|
||||
func rotate(direction):
|
||||
var rotated_positions = rotated_positions(direction)
|
||||
var t = get_translations()
|
||||
var rotated_translations = [t[0]]
|
||||
for i in range(1, NB_MINOES):
|
||||
var v = t[i]
|
||||
v -= t[0]
|
||||
v = Vector3(-1*direction*v.y, direction*v.x, 0)
|
||||
v += t[0]
|
||||
rotated_translations.append(v)
|
||||
var movements = SUPER_ROTATION_SYSTEM[orientation][direction]
|
||||
for i in range(movements.size()):
|
||||
if grid_map.possible_positions(rotated_positions, movements[i]):
|
||||
if grid_map.possible_positions(rotated_translations, movements[i]):
|
||||
orientation -= direction
|
||||
orientation %= NB_MINOES
|
||||
apply_positions(rotated_positions)
|
||||
set_translations(rotated_translations)
|
||||
translate(movements[i])
|
||||
return i+1
|
||||
return 0
|
||||
|
Reference in New Issue
Block a user