Add all shapes and select randomly
This commit is contained in:
parent
89fd29430e
commit
da193ee953
19
GameBoard.gd
19
GameBoard.gd
@ -1,7 +1,17 @@
|
||||
extends Node2D
|
||||
|
||||
|
||||
onready var active_shape: TetrisShape = $ShapeSquare
|
||||
var shapes = [
|
||||
preload("res://ShapeI.tscn"),
|
||||
preload("res://ShapeJ.tscn"),
|
||||
preload("res://ShapeL.tscn"),
|
||||
preload("res://ShapeZ.tscn"),
|
||||
preload("res://ShapeS.tscn"),
|
||||
preload("res://ShapeT.tscn"),
|
||||
preload("res://ShapeO.tscn")
|
||||
]
|
||||
|
||||
var active_shape: TetrisShape
|
||||
|
||||
const RASTER_SIZE = 64
|
||||
const BOTTOM = RASTER_SIZE * 10
|
||||
@ -9,11 +19,12 @@ const BOTTOM = RASTER_SIZE * 10
|
||||
|
||||
func _ready():
|
||||
$GravityTimer.connect("timeout", self, "update_board")
|
||||
|
||||
active_shape = get_random_shape()
|
||||
|
||||
|
||||
func get_random_shape():
|
||||
# TODO: Make random
|
||||
var new_shape = preload("res://ShapeL.tscn").instance()
|
||||
var new_shape = shapes[randi() % shapes.size()].instance()
|
||||
add_child(new_shape)
|
||||
return new_shape
|
||||
|
||||
@ -33,7 +44,7 @@ func move_active_down():
|
||||
|
||||
|
||||
func can_active_move_down():
|
||||
if active_shape.position.y >= RASTER_SIZE * 10:
|
||||
if active_shape.position.y >= BOTTOM:
|
||||
return false
|
||||
|
||||
for block in active_shape.get_blocks():
|
||||
|
@ -1,8 +1,7 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://background.png" type="Texture" id=1]
|
||||
[ext_resource path="res://GameBoard.gd" type="Script" id=2]
|
||||
[ext_resource path="res://ShapeSquare.tscn" type="PackedScene" id=3]
|
||||
|
||||
[node name="GameBoard" type="Node2D"]
|
||||
script = ExtResource( 2 )
|
||||
@ -16,6 +15,4 @@ process_mode = 0
|
||||
wait_time = 0.5
|
||||
autostart = true
|
||||
|
||||
[node name="ShapeSquare" parent="." instance=ExtResource( 3 )]
|
||||
|
||||
[node name="StaticBlocks" type="Node2D" parent="."]
|
||||
|
19
ShapeI.tscn
Normal file
19
ShapeI.tscn
Normal file
@ -0,0 +1,19 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Block.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://TetrisShape.gd" type="Script" id=2]
|
||||
|
||||
[node name="ShapeI" type="Node2D"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Block" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 32, 32 )
|
||||
|
||||
[node name="Block2" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 32, -32 )
|
||||
|
||||
[node name="Block3" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 32, -96 )
|
||||
|
||||
[node name="Block4" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 32, -160 )
|
19
ShapeJ.tscn
Normal file
19
ShapeJ.tscn
Normal file
@ -0,0 +1,19 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Block.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://TetrisShape.gd" type="Script" id=2]
|
||||
|
||||
[node name="ShapeJ" type="Node2D"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Block" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( -32, 32 )
|
||||
|
||||
[node name="Block2" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 32, 32 )
|
||||
|
||||
[node name="Block3" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 32, -32 )
|
||||
|
||||
[node name="Block4" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 32, -96 )
|
19
ShapeS.tscn
Normal file
19
ShapeS.tscn
Normal file
@ -0,0 +1,19 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Block.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://TetrisShape.gd" type="Script" id=2]
|
||||
|
||||
[node name="ShapeS" type="Node2D"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Block" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( -32, 32 )
|
||||
|
||||
[node name="Block2" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 32, 32 )
|
||||
|
||||
[node name="Block3" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 32, -32 )
|
||||
|
||||
[node name="Block4" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 96, -32 )
|
19
ShapeT.tscn
Normal file
19
ShapeT.tscn
Normal file
@ -0,0 +1,19 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Block.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://TetrisShape.gd" type="Script" id=2]
|
||||
|
||||
[node name="ShapeT" type="Node2D"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Block" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( -32, 32 )
|
||||
|
||||
[node name="Block2" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 32, 32 )
|
||||
|
||||
[node name="Block3" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 32, -32 )
|
||||
|
||||
[node name="Block4" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 96, 32 )
|
19
ShapeZ.tscn
Normal file
19
ShapeZ.tscn
Normal file
@ -0,0 +1,19 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Block.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://TetrisShape.gd" type="Script" id=2]
|
||||
|
||||
[node name="ShapeZ" type="Node2D"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Block" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( -32, -32 )
|
||||
|
||||
[node name="Block2" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 32, -32 )
|
||||
|
||||
[node name="Block3" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 32, 32 )
|
||||
|
||||
[node name="Block4" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 96, 32 )
|
Loading…
x
Reference in New Issue
Block a user