Initial commit
This commit is contained in:
25
Tetrominos/TetroI.tscn
Normal file
25
Tetrominos/TetroI.tscn
Normal file
@ -0,0 +1,25 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://TetroI.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Mino/Mino.tscn" type="PackedScene" id=2]
|
||||
|
||||
|
||||
[node name="TetroI" type="Spatial" index="0"]
|
||||
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Mino0" parent="." index="0" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="Mino1" parent="." index="1" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0, 0 )
|
||||
|
||||
[node name="Mino2" parent="." index="2" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0 )
|
||||
|
||||
[node name="Mino3" parent="." index="3" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 0 )
|
||||
|
||||
|
2
Tetrominos/TetroJ.gd
Normal file
2
Tetrominos/TetroJ.gd
Normal file
@ -0,0 +1,2 @@
|
||||
extends "Tetromino.gd"
|
||||
|
24
Tetrominos/TetroJ.tscn
Normal file
24
Tetrominos/TetroJ.tscn
Normal file
@ -0,0 +1,24 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Tetrominos/TetroJ.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Mino/Mino.tscn" type="PackedScene" id=2]
|
||||
|
||||
[node name="TetroJ" type="Spatial"]
|
||||
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Mino0" parent="." index="0" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="Mino1" parent="." index="1" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 1, 0 )
|
||||
|
||||
[node name="Mino2" parent="." index="2" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0, 0 )
|
||||
|
||||
[node name="Mino3" parent="." index="3" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0 )
|
||||
|
||||
|
2
Tetrominos/TetroL.gd
Normal file
2
Tetrominos/TetroL.gd
Normal file
@ -0,0 +1,2 @@
|
||||
extends "Tetromino.gd"
|
||||
|
25
Tetrominos/TetroL.tscn
Normal file
25
Tetrominos/TetroL.tscn
Normal file
@ -0,0 +1,25 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Tetrominos/TetroL.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Mino/Mino.tscn" type="PackedScene" id=2]
|
||||
|
||||
|
||||
[node name="TetroL" type="Spatial" index="0"]
|
||||
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Mino0" parent="." index="0" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="Mino1" parent="." index="1" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0, 0 )
|
||||
|
||||
[node name="Mino2" parent="." index="2" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0 )
|
||||
|
||||
[node name="Mino3" parent="." index="3" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0 )
|
||||
|
||||
|
4
Tetrominos/TetroO.gd
Normal file
4
Tetrominos/TetroO.gd
Normal file
@ -0,0 +1,4 @@
|
||||
extends "Tetromino.gd"
|
||||
|
||||
func rotate(grid, direction):
|
||||
pass
|
25
Tetrominos/TetroO.tscn
Normal file
25
Tetrominos/TetroO.tscn
Normal file
@ -0,0 +1,25 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Tetrominos/TetroO.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Mino/Mino.tscn" type="PackedScene" id=2]
|
||||
|
||||
|
||||
[node name="TetroO" type="Spatial" index="0"]
|
||||
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Mino0" parent="." index="0" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="Mino1" parent="." index="1" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
|
||||
|
||||
[node name="Mino2" parent="." index="2" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0 )
|
||||
|
||||
[node name="Mino3" parent="." index="3" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0 )
|
||||
|
||||
|
2
Tetrominos/TetroS.gd
Normal file
2
Tetrominos/TetroS.gd
Normal file
@ -0,0 +1,2 @@
|
||||
extends "Tetromino.gd"
|
||||
|
25
Tetrominos/TetroS.tscn
Normal file
25
Tetrominos/TetroS.tscn
Normal file
@ -0,0 +1,25 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Tetrominos/TetroS.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Mino/Mino.tscn" type="PackedScene" id=2]
|
||||
|
||||
|
||||
[node name="TetroS" type="Spatial" index="0"]
|
||||
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Mino0" parent="." index="0" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="Mino1" parent="." index="1" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0, 0 )
|
||||
|
||||
[node name="Mino2" parent="." index="2" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
|
||||
|
||||
[node name="Mino3" parent="." index="3" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0 )
|
||||
|
||||
|
23
Tetrominos/TetroT.gd
Normal file
23
Tetrominos/TetroT.gd
Normal file
@ -0,0 +1,23 @@
|
||||
extends "Tetromino.gd"
|
||||
|
||||
const T_SLOT = [
|
||||
Vector3(-1, 1, 0),
|
||||
Vector3(1, 1, 0),
|
||||
Vector3(1, -1, 0),
|
||||
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
|
||||
return true
|
||||
return false
|
25
Tetrominos/TetroT.tscn
Normal file
25
Tetrominos/TetroT.tscn
Normal file
@ -0,0 +1,25 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Tetrominos/TetroT.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Mino/Mino.tscn" type="PackedScene" id=2]
|
||||
|
||||
|
||||
[node name="TetroT" type="Spatial" index="0"]
|
||||
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Mino0" parent="." index="0" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="Mino1" parent="." index="1" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0, 0 )
|
||||
|
||||
[node name="Mino2" parent="." index="2" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
|
||||
|
||||
[node name="Mino3" parent="." index="3" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0 )
|
||||
|
||||
|
2
Tetrominos/TetroZ.gd
Normal file
2
Tetrominos/TetroZ.gd
Normal file
@ -0,0 +1,2 @@
|
||||
extends "Tetromino.gd"
|
||||
|
25
Tetrominos/TetroZ.tscn
Normal file
25
Tetrominos/TetroZ.tscn
Normal file
@ -0,0 +1,25 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Tetrominos/TetroZ.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Mino/Mino.tscn" type="PackedScene" id=2]
|
||||
|
||||
|
||||
[node name="TetroZ" type="Spatial" index="0"]
|
||||
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Mino0" parent="." index="0" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="Mino1" parent="." index="1" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 1, 0 )
|
||||
|
||||
[node name="Mino2" parent="." index="2" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
|
||||
|
||||
[node name="Mino3" parent="." index="3" instance=ExtResource( 2 )]
|
||||
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0 )
|
||||
|
||||
|
125
Tetrominos/Tetromino.gd
Normal file
125
Tetrominos/Tetromino.gd
Normal file
@ -0,0 +1,125 @@
|
||||
extends Spatial
|
||||
|
||||
const NB_MINOES = 4
|
||||
const CLOCKWISE = -1
|
||||
const COUNTERCLOCKWISE = 1
|
||||
const T_SPIN = 2
|
||||
const MINI_T_SPIN = 1
|
||||
const SUPER_ROTATION_SYSTEM = [
|
||||
{
|
||||
COUNTERCLOCKWISE: [
|
||||
Vector3(0, 0, 0),
|
||||
Vector3(1, 0, 0),
|
||||
Vector3(1, 1, 0),
|
||||
Vector3(0, -2, 0),
|
||||
Vector3(1, -2, 0)
|
||||
],
|
||||
CLOCKWISE: [
|
||||
Vector3(0, 0, 0),
|
||||
Vector3(-1, 0, 0),
|
||||
Vector3(-1, 1, 0),
|
||||
Vector3(0, -2, 0),
|
||||
Vector3(-1, -2, 0)
|
||||
],
|
||||
},
|
||||
{
|
||||
COUNTERCLOCKWISE: [
|
||||
Vector3(0, 0, 0),
|
||||
Vector3(1, 0, 0),
|
||||
Vector3(1, -1, 0),
|
||||
Vector3(0, 2, 0),
|
||||
Vector3(1, 2, 0)
|
||||
],
|
||||
CLOCKWISE: [
|
||||
Vector3(0, 0, 0),
|
||||
Vector3(1, 0, 0),
|
||||
Vector3(1, -1, 0),
|
||||
Vector3(0, 2, 0),
|
||||
Vector3(1, 2, 0)
|
||||
],
|
||||
},
|
||||
{
|
||||
COUNTERCLOCKWISE: [
|
||||
Vector3(0, 0, 0),
|
||||
Vector3(-1, 0, 0),
|
||||
Vector3(-1, 1, 0),
|
||||
Vector3(0, -2, 0),
|
||||
Vector3(-1, -2, 0)
|
||||
],
|
||||
CLOCKWISE: [
|
||||
Vector3(0, 0, 0),
|
||||
Vector3(1, 0, 0),
|
||||
Vector3(1, 1, 0),
|
||||
Vector3(0, -2, 0),
|
||||
Vector3(1, -2, 0)
|
||||
],
|
||||
},
|
||||
{
|
||||
COUNTERCLOCKWISE: [
|
||||
Vector3(0, 0, 0),
|
||||
Vector3(-1, 0, 0),
|
||||
Vector3(-1, -1, 0),
|
||||
Vector3(0, 2, 0),
|
||||
Vector3(-1, 2, 0)
|
||||
],
|
||||
CLOCKWISE: [
|
||||
Vector3(0, 0, 0),
|
||||
Vector3(-1, 0, 0),
|
||||
Vector3(-1, -1, 0),
|
||||
Vector3(0, -2, 0),
|
||||
Vector3(-1, 2, 0)
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
var minoes
|
||||
var orientation = 0
|
||||
var t_spin = 0
|
||||
|
||||
func _ready():
|
||||
minoes = [$Mino0, $Mino1, $Mino2, $Mino3]
|
||||
|
||||
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 rotation_movement_liberty(direction):
|
||||
return SUPER_ROTATION_SYSTEM[orientation][direction]
|
||||
|
||||
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)
|
||||
if new_positions:
|
||||
translate(movement)
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
func rotate(grid, 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)
|
||||
if test_position:
|
||||
orientation -= direction
|
||||
orientation %= NB_MINOES
|
||||
apply_positions(rotated_positions)
|
||||
translate(movement)
|
||||
return true
|
||||
return false
|
Reference in New Issue
Block a user