Ghost Piece
This commit is contained in:
1
Tetrominos/GhostPiece.gd
Normal file
1
Tetrominos/GhostPiece.gd
Normal file
@ -0,0 +1 @@
|
||||
extends "Tetromino.gd"
|
134
Tetrominos/GhostPiece.tscn
Normal file
134
Tetrominos/GhostPiece.tscn
Normal file
@ -0,0 +1,134 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Tetrominos/GhostPiece.gd" type="Script" id=1]
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=1]
|
||||
|
||||
render_priority = 0
|
||||
flags_transparent = true
|
||||
flags_unshaded = false
|
||||
flags_vertex_lighting = false
|
||||
flags_no_depth_test = false
|
||||
flags_use_point_size = false
|
||||
flags_world_triplanar = false
|
||||
flags_fixed_size = false
|
||||
flags_albedo_tex_force_srgb = false
|
||||
vertex_color_use_as_albedo = false
|
||||
vertex_color_is_srgb = false
|
||||
params_diffuse_mode = 0
|
||||
params_specular_mode = 0
|
||||
params_blend_mode = 1
|
||||
params_cull_mode = 0
|
||||
params_depth_draw_mode = 0
|
||||
params_line_width = 1.0
|
||||
params_point_size = 1.0
|
||||
params_billboard_mode = 0
|
||||
params_grow = false
|
||||
params_use_alpha_scissor = false
|
||||
albedo_color = Color( 0.201977, 0.22403, 0.310547, 1 )
|
||||
metallic = 0.66
|
||||
metallic_specular = 0.5
|
||||
metallic_texture_channel = 0
|
||||
roughness = 0.0
|
||||
roughness_texture_channel = 0
|
||||
emission_enabled = false
|
||||
normal_enabled = false
|
||||
rim_enabled = false
|
||||
clearcoat_enabled = false
|
||||
anisotropy_enabled = false
|
||||
ao_enabled = false
|
||||
depth_enabled = false
|
||||
subsurf_scatter_enabled = false
|
||||
transmission_enabled = false
|
||||
refraction_enabled = false
|
||||
detail_enabled = false
|
||||
uv1_scale = Vector3( 1, 1, 1 )
|
||||
uv1_offset = Vector3( 0, 0, 0 )
|
||||
uv1_triplanar = false
|
||||
uv1_triplanar_sharpness = 1.0
|
||||
uv2_scale = Vector3( 1, 1, 1 )
|
||||
uv2_offset = Vector3( 0, 0, 0 )
|
||||
uv2_triplanar = false
|
||||
uv2_triplanar_sharpness = 1.0
|
||||
proximity_fade_enable = true
|
||||
proximity_fade_distance = 1.0
|
||||
distance_fade_enable = false
|
||||
_sections_unfolded = [ "Albedo", "Proximity Fade" ]
|
||||
|
||||
[sub_resource type="CubeMesh" id=2]
|
||||
|
||||
material = SubResource( 1 )
|
||||
custom_aabb = AABB( 0, 0, 0, 0, 0, 0 )
|
||||
size = Vector3( 0.9, 0.9, 0.9 )
|
||||
subdivide_width = 0
|
||||
subdivide_height = 0
|
||||
subdivide_depth = 0
|
||||
|
||||
[node name="GhostPiece" type="Spatial"]
|
||||
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Mino0" type="MeshInstance" parent="." index="0"]
|
||||
|
||||
layers = 1
|
||||
material_override = null
|
||||
cast_shadow = 1
|
||||
extra_cull_margin = 0.0
|
||||
use_in_baked_light = false
|
||||
lod_min_distance = 0.0
|
||||
lod_min_hysteresis = 0.0
|
||||
lod_max_distance = 0.0
|
||||
lod_max_hysteresis = 0.0
|
||||
mesh = SubResource( 2 )
|
||||
skeleton = NodePath("..")
|
||||
material/0 = null
|
||||
|
||||
[node name="Mino1" type="MeshInstance" parent="." index="1"]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 3, 0 )
|
||||
layers = 1
|
||||
material_override = null
|
||||
cast_shadow = 1
|
||||
extra_cull_margin = 0.0
|
||||
use_in_baked_light = false
|
||||
lod_min_distance = 0.0
|
||||
lod_min_hysteresis = 0.0
|
||||
lod_max_distance = 0.0
|
||||
lod_max_hysteresis = 0.0
|
||||
mesh = SubResource( 2 )
|
||||
skeleton = NodePath("..")
|
||||
material/0 = null
|
||||
|
||||
[node name="Mino2" type="MeshInstance" parent="." index="2"]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3, 0 )
|
||||
layers = 1
|
||||
material_override = null
|
||||
cast_shadow = 1
|
||||
extra_cull_margin = 0.0
|
||||
use_in_baked_light = false
|
||||
lod_min_distance = 0.0
|
||||
lod_min_hysteresis = 0.0
|
||||
lod_max_distance = 0.0
|
||||
lod_max_hysteresis = 0.0
|
||||
mesh = SubResource( 2 )
|
||||
skeleton = NodePath("..")
|
||||
material/0 = null
|
||||
|
||||
[node name="Mino3" type="MeshInstance" parent="." index="3"]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0 )
|
||||
layers = 1
|
||||
material_override = null
|
||||
cast_shadow = 1
|
||||
extra_cull_margin = 0.0
|
||||
use_in_baked_light = false
|
||||
lod_min_distance = 0.0
|
||||
lod_min_hysteresis = 0.0
|
||||
lod_max_distance = 0.0
|
||||
lod_max_hysteresis = 0.0
|
||||
mesh = SubResource( 2 )
|
||||
skeleton = NodePath("..")
|
||||
material/0 = null
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
extends "Tetromino.gd"
|
||||
|
||||
func rotate(grid, direction):
|
||||
func rotate(direction):
|
||||
pass
|
@ -7,17 +7,20 @@ const T_SLOT = [
|
||||
Vector3(-1, -1, 0)
|
||||
]
|
||||
|
||||
func rotate(grid, direction):
|
||||
if .rotate(grid, direction):
|
||||
var center = to_global(minoes[0].translation)
|
||||
var a = not grid.is_free_cell(center + T_SLOT[orientation])
|
||||
var b = not grid.is_free_cell(center + T_SLOT[(1+orientation)%4])
|
||||
var c = not grid.is_free_cell(center + T_SLOT[(2+orientation)%4])
|
||||
var d = not grid.is_free_cell(center + T_SLOT[(3+orientation)%4])
|
||||
if a and b and (c or d):
|
||||
t_spin = T_SPIN
|
||||
elif c and d and (a or b):
|
||||
if t_spin != T_SPIN:
|
||||
t_spin = MINI_T_SPIN
|
||||
func rotate(direction):
|
||||
if .rotate(direction):
|
||||
detect_t_spin()
|
||||
return true
|
||||
return false
|
||||
return false
|
||||
|
||||
func detect_t_spin():
|
||||
var center = to_global(minoes[0].translation)
|
||||
var a = not get_parent().is_free_cell(center + T_SLOT[orientation])
|
||||
var b = not get_parent().is_free_cell(center + T_SLOT[(1+orientation)%4])
|
||||
var c = not get_parent().is_free_cell(center + T_SLOT[(2+orientation)%4])
|
||||
var d = not get_parent().is_free_cell(center + T_SLOT[(3+orientation)%4])
|
||||
if a and b and (c or d):
|
||||
t_spin = T_SPIN
|
||||
elif c and d and (a or b):
|
||||
if t_spin != T_SPIN:
|
||||
t_spin = MINI_T_SPIN
|
@ -3,8 +3,9 @@ extends Spatial
|
||||
const NB_MINOES = 4
|
||||
const CLOCKWISE = -1
|
||||
const COUNTERCLOCKWISE = 1
|
||||
const T_SPIN = 2
|
||||
const MINI_T_SPIN = 1
|
||||
const NO_T_SPIN = 0
|
||||
const T_SPIN = 1
|
||||
const MINI_T_SPIN = 2
|
||||
const SUPER_ROTATION_SYSTEM = [
|
||||
{
|
||||
COUNTERCLOCKWISE: [
|
||||
@ -74,7 +75,7 @@ const SUPER_ROTATION_SYSTEM = [
|
||||
|
||||
var minoes
|
||||
var orientation = 0
|
||||
var t_spin = 0
|
||||
var t_spin = NO_T_SPIN
|
||||
|
||||
func _ready():
|
||||
minoes = [$Mino0, $Mino1, $Mino2, $Mino3]
|
||||
@ -102,20 +103,20 @@ func apply_positions(positions):
|
||||
for i in range(4):
|
||||
minoes[i].translation = to_local(positions[i])
|
||||
|
||||
func move(grid, movement):
|
||||
var new_positions = grid.possible_positions(positions(), movement)
|
||||
func move(movement):
|
||||
var new_positions = get_parent().possible_positions(positions(), movement)
|
||||
if new_positions:
|
||||
translate(movement)
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
func rotate(grid, direction):
|
||||
func rotate(direction):
|
||||
var rotated_positions = rotated_positions(direction)
|
||||
var movements = rotation_movement_liberty(direction)
|
||||
var test_position
|
||||
for movement in movements:
|
||||
test_position = grid.possible_positions(rotated_positions, movement)
|
||||
test_position = get_parent().possible_positions(rotated_positions, movement)
|
||||
if test_position:
|
||||
orientation -= direction
|
||||
orientation %= NB_MINOES
|
||||
|
Reference in New Issue
Block a user