Cleaned up the Code; reworked the Block Physics

This commit is contained in:
Exobyt 2024-08-27 22:35:24 +02:00
parent ed9f671256
commit 9f6750b08a
48 changed files with 1237 additions and 1116 deletions

View file

@ -0,0 +1,24 @@
[gd_scene load_steps=2 format=3 uid="uid://bq06tih243hte"]
[ext_resource type="PackedScene" uid="uid://cbjkurbgojqac" path="res://scenes/NewBlocks/block.tscn" id="1_wcbl2"]
[node name="1x1" instance=ExtResource("1_wcbl2")]
modulate = Color(0.690196, 0, 1, 1)
[node name="CollisionPolygon2D" parent="." index="0"]
position = Vector2(-8, -8)
polygon = PackedVector2Array(40, -24, 40, 40, -24, 40, -24, -24)
[node name="Marker2D" type="Marker2D" parent="PartPoints" index="0"]
[node name="CollisionRayContainer#RayCast2D" type="RayCast2D" parent="." index="4"]
position = Vector2(-16, -24)
target_position = Vector2(0, 48)
collision_mask = 3
hit_from_inside = true
[node name="CollisionRayContainer#RayCast2D2" type="RayCast2D" parent="." index="5"]
position = Vector2(16, -24)
target_position = Vector2(0, 48)
collision_mask = 3
hit_from_inside = true

View file

@ -0,0 +1,47 @@
[gd_scene load_steps=2 format=3 uid="uid://def2bs6whjhkc"]
[ext_resource type="PackedScene" uid="uid://cbjkurbgojqac" path="res://scenes/NewBlocks/block.tscn" id="1_r8yrj"]
[node name="1x3" instance=ExtResource("1_r8yrj")]
modulate = Color(1, 1, 0, 1)
[node name="CollisionPolygon2D" parent="." index="0"]
polygon = PackedVector2Array(-95, -31, -95, 31, 95, 31, 95, -31)
[node name="Marker2D" type="Marker2D" parent="PartPoints" index="0"]
position = Vector2(-64, 0)
[node name="Marker2D2" type="Marker2D" parent="PartPoints" index="1"]
[node name="Marker2D3" type="Marker2D" parent="PartPoints" index="2"]
position = Vector2(64, 0)
[node name="RayCast2D" type="RayCast2D" parent="." index="4"]
position = Vector2(-80, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D2" type="RayCast2D" parent="." index="5"]
position = Vector2(-48, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D3" type="RayCast2D" parent="." index="6"]
position = Vector2(-16, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D4" type="RayCast2D" parent="." index="7"]
position = Vector2(16, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D5" type="RayCast2D" parent="." index="8"]
position = Vector2(48, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D6" type="RayCast2D" parent="." index="9"]
position = Vector2(80, -24)
collision_mask = 3
hit_from_inside = true

View file

@ -0,0 +1,62 @@
[gd_scene load_steps=2 format=3 uid="uid://bev38s1mpx8ej"]
[ext_resource type="PackedScene" uid="uid://cbjkurbgojqac" path="res://scenes/NewBlocks/block.tscn" id="1_sbl0g"]
[node name="1x4" instance=ExtResource("1_sbl0g")]
modulate = Color(1, 0, 0, 1)
metadata/_edit_vertical_guides_ = [-168.0]
[node name="CollisionPolygon2D" parent="." index="0"]
position = Vector2(32, 0)
polygon = PackedVector2Array(-127, -31, -127, 31, 127, 31, 127, -31)
[node name="Marker2D" type="Marker2D" parent="PartPoints" index="0"]
position = Vector2(-64, 0)
[node name="Marker2D2" type="Marker2D" parent="PartPoints" index="1"]
[node name="Marker2D3" type="Marker2D" parent="PartPoints" index="2"]
position = Vector2(64, 0)
[node name="Marker2D4" type="Marker2D" parent="PartPoints" index="3"]
position = Vector2(128, 0)
[node name="RayCast2D" type="RayCast2D" parent="." index="4"]
position = Vector2(-80, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D3" type="RayCast2D" parent="." index="5"]
position = Vector2(-48, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D2" type="RayCast2D" parent="." index="6"]
position = Vector2(-16, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D4" type="RayCast2D" parent="." index="7"]
position = Vector2(16, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D5" type="RayCast2D" parent="." index="8"]
position = Vector2(48, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D6" type="RayCast2D" parent="." index="9"]
position = Vector2(80, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D7" type="RayCast2D" parent="." index="10"]
position = Vector2(112, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D8" type="RayCast2D" parent="." index="11"]
position = Vector2(144, -24)
collision_mask = 3
hit_from_inside = true

View file

@ -0,0 +1,62 @@
[gd_scene load_steps=2 format=3 uid="uid://c203pse4172mc"]
[ext_resource type="PackedScene" uid="uid://cbjkurbgojqac" path="res://scenes/NewBlocks/block.tscn" id="1_wdx08"]
[node name="2x2" instance=ExtResource("1_wdx08")]
modulate = Color(1, 0.627451, 0, 1)
offset = true
[node name="CollisionPolygon2D" parent="." index="0"]
polygon = PackedVector2Array(63, 63, 63, -63, -63, -63, -63, 63)
[node name="Marker2D" type="Marker2D" parent="PartPoints" index="0"]
position = Vector2(-32, -32)
[node name="Marker2D2" type="Marker2D" parent="PartPoints" index="1"]
position = Vector2(32, -32)
[node name="Marker2D3" type="Marker2D" parent="PartPoints" index="2"]
position = Vector2(-32, 32)
[node name="Marker2D4" type="Marker2D" parent="PartPoints" index="3"]
position = Vector2(32, 32)
[node name="RayCast2D" type="RayCast2D" parent="." index="4"]
position = Vector2(-48, -56)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D2" type="RayCast2D" parent="." index="5"]
position = Vector2(-16, -56)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D3" type="RayCast2D" parent="." index="6"]
position = Vector2(16, -56)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D4" type="RayCast2D" parent="." index="7"]
position = Vector2(48, -56)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D5" type="RayCast2D" parent="." index="8"]
position = Vector2(-48, 8)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D6" type="RayCast2D" parent="." index="9"]
position = Vector2(-16, 8)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D7" type="RayCast2D" parent="." index="10"]
position = Vector2(16, 8)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D8" type="RayCast2D" parent="." index="11"]
position = Vector2(48, 8)
collision_mask = 3
hit_from_inside = true

60
scenes/NewBlocks/L/L.tscn Normal file
View file

@ -0,0 +1,60 @@
[gd_scene load_steps=2 format=3 uid="uid://d2orqrqnsxuec"]
[ext_resource type="PackedScene" uid="uid://cbjkurbgojqac" path="res://scenes/NewBlocks/block.tscn" id="1_5vf0h"]
[node name="L" instance=ExtResource("1_5vf0h")]
modulate = Color(0, 0, 1, 1)
[node name="CollisionPolygon2D" parent="." index="0"]
polygon = PackedVector2Array(-95, -31, -95, 31, 95, 31, 95, -95, 33, -95, 33, -31)
[node name="Marker2D" type="Marker2D" parent="PartPoints" index="0"]
position = Vector2(-64, 0)
[node name="Marker2D2" type="Marker2D" parent="PartPoints" index="1"]
[node name="Marker2D3" type="Marker2D" parent="PartPoints" index="2"]
position = Vector2(64, 0)
[node name="Marker2D4" type="Marker2D" parent="PartPoints" index="3"]
position = Vector2(64, -64)
[node name="RayCast2D" type="RayCast2D" parent="." index="6"]
position = Vector2(-80, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D2" type="RayCast2D" parent="." index="7"]
position = Vector2(-48, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D3" type="RayCast2D" parent="." index="8"]
position = Vector2(-16, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D4" type="RayCast2D" parent="." index="9"]
position = Vector2(16, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D5" type="RayCast2D" parent="." index="10"]
position = Vector2(48, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D6" type="RayCast2D" parent="." index="11"]
position = Vector2(80, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D7" type="RayCast2D" parent="." index="12"]
position = Vector2(48, -88)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D8" type="RayCast2D" parent="." index="13"]
position = Vector2(80, -88)
collision_mask = 3
hit_from_inside = true

View file

@ -0,0 +1,60 @@
[gd_scene load_steps=2 format=3 uid="uid://rcxcslbfovej"]
[ext_resource type="PackedScene" uid="uid://cbjkurbgojqac" path="res://scenes/NewBlocks/block.tscn" id="1_05evo"]
[node name="L_Reverse" instance=ExtResource("1_05evo")]
modulate = Color(0, 1, 0, 1)
[node name="CollisionPolygon2D" parent="." index="0"]
polygon = PackedVector2Array(-95, -95, -95, 31, 95, 31, 95, -31, -33, -31, -33, -95)
[node name="Marker2D" type="Marker2D" parent="PartPoints" index="0"]
position = Vector2(-64, -64)
[node name="Marker2D2" type="Marker2D" parent="PartPoints" index="1"]
position = Vector2(-64, 0)
[node name="Marker2D3" type="Marker2D" parent="PartPoints" index="2"]
[node name="Marker2D4" type="Marker2D" parent="PartPoints" index="3"]
position = Vector2(64, 0)
[node name="RayCast2D" type="RayCast2D" parent="." index="6"]
position = Vector2(-80, -88)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D2" type="RayCast2D" parent="." index="7"]
position = Vector2(-48, -88)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D3" type="RayCast2D" parent="." index="8"]
position = Vector2(-80, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D4" type="RayCast2D" parent="." index="9"]
position = Vector2(-48, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D5" type="RayCast2D" parent="." index="10"]
position = Vector2(-16, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D6" type="RayCast2D" parent="." index="11"]
position = Vector2(16, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D7" type="RayCast2D" parent="." index="12"]
position = Vector2(48, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D8" type="RayCast2D" parent="." index="13"]
position = Vector2(80, -24)
collision_mask = 3
hit_from_inside = true

60
scenes/NewBlocks/Z/Z.tscn Normal file
View file

@ -0,0 +1,60 @@
[gd_scene load_steps=2 format=3 uid="uid://xpcbf85u5d65"]
[ext_resource type="PackedScene" uid="uid://cbjkurbgojqac" path="res://scenes/NewBlocks/block.tscn" id="1_yvspj"]
[node name="Z" instance=ExtResource("1_yvspj")]
modulate = Color(1, 0, 1, 1)
[node name="CollisionPolygon2D" parent="." index="0"]
polygon = PackedVector2Array(-95, 31, 31, 31, 31, -33, 95, -33, 95, -95, -31, -95, -31, -31, -95, -31)
[node name="Marker2D" type="Marker2D" parent="PartPoints" index="0"]
position = Vector2(-64, 0)
[node name="Marker2D2" type="Marker2D" parent="PartPoints" index="1"]
[node name="Marker2D3" type="Marker2D" parent="PartPoints" index="2"]
position = Vector2(0, -64)
[node name="Marker2D4" type="Marker2D" parent="PartPoints" index="3"]
position = Vector2(64, -64)
[node name="RayCast2D" type="RayCast2D" parent="." index="6"]
position = Vector2(-80, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D2" type="RayCast2D" parent="." index="7"]
position = Vector2(-48, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D3" type="RayCast2D" parent="." index="8"]
position = Vector2(-16, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D4" type="RayCast2D" parent="." index="9"]
position = Vector2(16, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D5" type="RayCast2D" parent="." index="10"]
position = Vector2(-16, -88)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D6" type="RayCast2D" parent="." index="11"]
position = Vector2(16, -88)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D7" type="RayCast2D" parent="." index="12"]
position = Vector2(48, -88)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D8" type="RayCast2D" parent="." index="13"]
position = Vector2(80, -88)
collision_mask = 3
hit_from_inside = true

View file

@ -0,0 +1,60 @@
[gd_scene load_steps=2 format=3 uid="uid://bbf3thu7apoov"]
[ext_resource type="PackedScene" uid="uid://cbjkurbgojqac" path="res://scenes/NewBlocks/block.tscn" id="1_bjj8c"]
[node name="Z_Reverse" instance=ExtResource("1_bjj8c")]
modulate = Color(0, 1, 1, 1)
[node name="CollisionPolygon2D" parent="." index="0"]
polygon = PackedVector2Array(-95, -95, -95, -33, -31, -33, -31, 31, 95, 31, 95, -31, 31, -31, 31, -95)
[node name="Marker2D" type="Marker2D" parent="PartPoints" index="0"]
position = Vector2(-64, -64)
[node name="Marker2D2" type="Marker2D" parent="PartPoints" index="1"]
position = Vector2(0, -64)
[node name="Marker2D3" type="Marker2D" parent="PartPoints" index="2"]
[node name="Marker2D4" type="Marker2D" parent="PartPoints" index="3"]
position = Vector2(64, 0)
[node name="RayCast2D" type="RayCast2D" parent="." index="6"]
position = Vector2(-80, -88)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D2" type="RayCast2D" parent="." index="7"]
position = Vector2(-48, -88)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D3" type="RayCast2D" parent="." index="8"]
position = Vector2(-16, -88)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D4" type="RayCast2D" parent="." index="9"]
position = Vector2(16, -88)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D5" type="RayCast2D" parent="." index="10"]
position = Vector2(-16, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D6" type="RayCast2D" parent="." index="11"]
position = Vector2(16, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D7" type="RayCast2D" parent="." index="12"]
position = Vector2(48, -24)
collision_mask = 3
hit_from_inside = true
[node name="RayCast2D8" type="RayCast2D" parent="." index="13"]
position = Vector2(80, -24)
collision_mask = 3
hit_from_inside = true

238
scenes/NewBlocks/block.gd Normal file
View file

@ -0,0 +1,238 @@
extends CharacterBody2D
@onready var partPoints = $PartPoints
@onready var partsContainer = $PartsContainer
@onready var coyoteTimer = $CoyoteTimer
var part = "res://scenes/NewBlocks/part.tscn"
var block1x1 = "res://scenes/NewBlocks/1x1/1x1.tscn"
var coyoteTime = 0.5
var type = GLOBAL.BLOCKTYPES.LIGHT
var expand = false
@export var id = 0
var expanding = false
var stopped = false
@export var offset = false
func _physics_process(delta: float) -> void:
if isCurrent() and not GLOBAL.blockStopped and not stopped:
if isBottomColliding():
if coyoteTimer.is_stopped():
coyoteTimer.start(coyoteTime)
if Input.is_action_just_pressed("rotate_left"):
rotateBlock(1)
elif Input.is_action_just_pressed("rotate_right"):
rotateBlock(2)
if Input.is_action_just_pressed("left"):
if not isLeftColliding():
global_position.x -= GLOBAL.GRID
elif Input.is_action_just_pressed("right"):
if not isRightColliding():
global_position.x += GLOBAL.GRID
if Input.is_action_pressed("down"):
velocity = get_gravity() * delta * GLOBAL.SPEED.MAX
else:
velocity = get_gravity() * delta * GLOBAL.currentSpeed
if is_on_floor():
position = position.snapped(Vector2(32,32))
if isCurrent() and not expanding and not GLOBAL.blockStopped:
move_and_slide()
else:
velocity = Vector2.ZERO
func expandBlocks():
expanding = true
scale = Vector2(2,2)
position -= Vector2(32,32)
snapPosition()
for i in range(0,5):
if isCollidingBorder():
if isCollidingBorder():
position.x += GLOBAL.GRID
if isCollidingBorder():
position.x += GLOBAL.GRID
if isCollidingBorder():
position.x -= GLOBAL.GRID
if isCollidingBorder():
position.x -= GLOBAL.GRID
if isCollidingBorder():
position.x -= GLOBAL.GRID
if isCollidingBorder():
position.x -= GLOBAL.GRID
if isCollidingBorder():
position.x += GLOBAL.GRID
if isCollidingBorder():
position.x += GLOBAL.GRID
if isCollidingBorder():
position.y -= GLOBAL.GRID
for i in partsContainer.get_children():
if i != null:
i.removeOverlapp()
#splitParts()
func addParts():
for i in partPoints.get_children():
var newPart = load(part).instantiate()
partsContainer.add_child(newPart)
var look = 0
if not expand and type == GLOBAL.BLOCKTYPES.HEAVY:
look = 1
elif expand and not type == GLOBAL.BLOCKTYPES.HEAVY:
look = 2
elif expand and type == GLOBAL.BLOCKTYPES.HEAVY:
look = 3
newPart.init(i.position,look)
func splitParts():
for i in $PartsContainer.get_children():
var newBlock = load(block1x1).instantiate()
get_parent().add_child(newBlock)
newBlock.init(i.global_position, expand)
newBlock.setColor(modulate)
queue_free()
func setColor(color):
modulate = color
func init(pos, scaler=null):
if scaler != null:
if scaler:
expand = scaler
#$AnimationPlayer.play("Expand")
scale = Vector2(2,2)
addParts()
id = GLOBAL.getNewID()
GLOBAL.currentID = id
snapPosition()
global_position = pos
if offset:
snapPosition()
func setNewID():
id = GLOBAL.getNewID()
func isCurrent():
return GLOBAL.currentID == id
func snapPosition(): #x :bool, y: bool
position = position.snapped(Vector2(64,64))
func rotateBlock(direction):
match direction:
1:
rotation_degrees -= 90
for i in partsContainer.get_children():
i.rotation_degrees += 90
for j in range(0,3):
if isColliding():
global_position.x -= GLOBAL.GRID
if isColliding():
global_position.x += GLOBAL.GRID*2
if isColliding():
global_position.x -= GLOBAL.GRID
for s in range(0,3):
rotation_degrees -= 90
for i in partsContainer.get_children():
i.rotation_degrees += 90
else:
break
else:
break
else:
break
2:
rotation_degrees += 90
for i in partsContainer.get_children():
i.rotation_degrees -= 90
for j in range(0,3):
if isColliding():
global_position.x -= GLOBAL.GRID
if isColliding():
global_position.x += GLOBAL.GRID*2
if isColliding():
global_position.x -= GLOBAL.GRID
for s in range(0,3):
rotation_degrees += 90
for i in partsContainer.get_children():
i.rotation_degrees -= 90
else:
break
else:
break
else:
break
func isLeftColliding():
var colliding = false
for i in partsContainer.get_children():
if i.isLeftColliding():
colliding = true
return colliding
func isRightColliding():
var colliding = false
for i in partsContainer.get_children():
if i.isRightColliding():
colliding = true
return colliding
func isBottomColliding():
var colliding = false
for i in partsContainer.get_children():
if i.isBottomColliding():
colliding = true
return colliding
func isColliding() -> bool:
var collided = false
for i in get_children():
if is_instance_of(i,RayCast2D):
i.force_raycast_update()
var collider = i.get_collider()
if collider != null:
if collider.is_in_group("Block"):
if collider.id != GLOBAL.currentID:
collided = true
elif collider.is_in_group("Border"):
collided = true
return collided
func isCollidingBorder() -> bool:
var collided = false
for i in get_children():
if is_instance_of(i,RayCast2D):
i.force_raycast_update()
var collider = i.get_collider()
if collider != null:
if collider.is_in_group("Border"):
collided = true
return collided
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
if anim_name == "Expand":
snapPosition()
#position -= Vector2(32,32)
splitParts()
func _on_coyote_timer_timeout() -> void:
if isBottomColliding():
stopped = true
GLOBAL.blockStopped = true
if expand:
expandBlocks()

View file

@ -0,0 +1,64 @@
[gd_scene load_steps=5 format=3 uid="uid://cbjkurbgojqac"]
[ext_resource type="Script" path="res://scenes/NewBlocks/block.gd" id="1_booro"]
[sub_resource type="Animation" id="Animation_1j0va"]
resource_name = "Expand"
length = 0.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector2(1, 1), Vector2(2, 2)]
}
[sub_resource type="Animation" id="Animation_8wn5l"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(1, 1)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_u3jpa"]
_data = {
"Expand": SubResource("Animation_1j0va"),
"RESET": SubResource("Animation_8wn5l")
}
[node name="Block" type="CharacterBody2D" groups=["Block"]]
collision_layer = 2
collision_mask = 3
script = ExtResource("1_booro")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
[node name="PartPoints" type="Node2D" parent="."]
[node name="RotationPoint" type="Marker2D" parent="."]
[node name="PartsContainer" type="Node2D" parent="."]
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_u3jpa")
}
[node name="CoyoteTimer" type="Timer" parent="."]
one_shot = true
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_player_animation_finished"]
[connection signal="timeout" from="CoyoteTimer" to="." method="_on_coyote_timer_timeout"]

108
scenes/NewBlocks/part.gd Normal file
View file

@ -0,0 +1,108 @@
extends Node2D
@onready var spriteBlock = $Sprites/Block
@onready var spriteSpecialBlock = $Sprites/SpecialBlock
@onready var spriteExpandBlock = $Sprites/ExpandBlock
@onready var spriteSpecialExpandedBlock = $Sprites/SpecialExpandedBlock
@onready var rayTop = $Raycasts/RayTop
@onready var rayRight = $Raycasts/RayRight
@onready var rayBottom = $Raycasts/RayBottom
@onready var rayLeft = $Raycasts/RayLeft
#func _physics_process(delta: float) -> void:
##if GLOBAL.blockStopped and not GLOBAL.rowRemoved:
#if GLOBAL.currentID != get_parent().get_parent().id:
#removeOverlapp()
func isOverlapping() -> bool:
var collided = false
for i in get_children():
if is_instance_of(i,RayCast2D):
i.force_raycast_update()
var collider = i.get_collider()
if collider != null:
collided = true
return collided
func removeOverlapp():
var blocksSplit = []
for i in get_children():
if is_instance_of(i,RayCast2D):
i.force_raycast_update()
var collider = i.get_collider()
if collider != null and collider.get_parent().get_parent().id != GLOBAL.currentID:
blocksSplit.append(i.get_collider().get_parent().get_parent())
collider.free()
for j in blocksSplit:
j.splitParts()
func init(pos, look=0):
position = pos
match look:
0:
spriteBlock.show()
1:
spriteSpecialBlock.show()
2:
spriteExpandBlock.show()
3:
spriteSpecialExpandedBlock.show()
func isTopColliding():
rayTop.force_raycast_update()
if rayTop.get_collider() == null:
return false
elif rayTop.get_collider().is_in_group("Block"):
if rayTop.get_collider().id == GLOBAL.currentID:
return false
else:
return true
else:
return true
func isRightColliding():
rayRight.force_raycast_update()
#print(rayRight.get_collider())
if rayRight.get_collider() == null:
return false
elif rayRight.get_collider().is_in_group("Block"):
#print(rayRight.get_collider().id)
if rayRight.get_collider().id == GLOBAL.currentID:
return false
else:
return true
else:
return true
func isBottomColliding():
rayBottom.force_raycast_update()
if rayBottom.get_collider() == null:
return false
elif rayBottom.get_collider().is_in_group("Block"):
if rayBottom.get_collider().id == GLOBAL.currentID:
return false
else:
return true
else:
return true
func isLeftColliding():
rayLeft.force_raycast_update()
#print(rayLeft.get_collider())
if rayLeft.get_collider() == null:
return false
elif rayLeft.get_collider().is_in_group("Block"):
#print(rayLeft.get_collider().id)
if rayLeft.get_collider().id == GLOBAL.currentID:
return false
else:
return true
else:
return true

View file

@ -0,0 +1,86 @@
[gd_scene load_steps=7 format=3 uid="uid://dj8heengghud2"]
[ext_resource type="Script" path="res://scenes/NewBlocks/part.gd" id="1_hlmu7"]
[ext_resource type="Texture2D" uid="uid://cbuxv7iwn0qm7" path="res://assets/Blocks/Block.png" id="1_m2ybm"]
[ext_resource type="Texture2D" uid="uid://dni2qahrw2p0k" path="res://assets/Blocks/SpecialBlock.png" id="2_jv3te"]
[ext_resource type="Texture2D" uid="uid://jmobplsqdy6o" path="res://assets/Blocks/ExpandBlock.png" id="3_yu63x"]
[ext_resource type="Texture2D" uid="uid://13wfksnp806p" path="res://assets/Blocks/SpecialExpandedBlock.png" id="4_yg0r6"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ix7xn"]
size = Vector2(48, 48)
[node name="Part" type="StaticBody2D"]
collision_layer = 24
collision_mask = 24
script = ExtResource("1_hlmu7")
[node name="Overlap Test" type="RayCast2D" parent="."]
position = Vector2(-16, -16)
target_position = Vector2(8, 0)
collision_mask = 24
hit_from_inside = true
[node name="Overlap Test2" type="RayCast2D" parent="."]
position = Vector2(-16, 16)
target_position = Vector2(8, 0)
collision_mask = 24
hit_from_inside = true
[node name="Overlap Test3" type="RayCast2D" parent="."]
position = Vector2(16, -16)
target_position = Vector2(-8, 0)
collision_mask = 24
hit_from_inside = true
[node name="Overlap Test4" type="RayCast2D" parent="."]
position = Vector2(16, 16)
target_position = Vector2(-8, 0)
collision_mask = 24
hit_from_inside = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_ix7xn")
[node name="Sprites" type="Node2D" parent="."]
[node name="Block" type="Sprite2D" parent="Sprites"]
visible = false
texture = ExtResource("1_m2ybm")
[node name="SpecialBlock" type="Sprite2D" parent="Sprites"]
visible = false
texture = ExtResource("2_jv3te")
[node name="ExpandBlock" type="Sprite2D" parent="Sprites"]
visible = false
texture = ExtResource("3_yu63x")
[node name="SpecialExpandedBlock" type="Sprite2D" parent="Sprites"]
visible = false
texture = ExtResource("4_yg0r6")
[node name="Raycasts" type="Node2D" parent="."]
[node name="RayTop" type="RayCast2D" parent="Raycasts"]
position = Vector2(0, -32)
target_position = Vector2(0, -16)
collision_mask = 3
hit_from_inside = true
[node name="RayRight" type="RayCast2D" parent="Raycasts"]
position = Vector2(32, 0)
target_position = Vector2(16, 0)
collision_mask = 3
hit_from_inside = true
[node name="RayBottom" type="RayCast2D" parent="Raycasts"]
position = Vector2(0, 32)
target_position = Vector2(0, 16)
collision_mask = 3
hit_from_inside = true
[node name="RayLeft" type="RayCast2D" parent="Raycasts"]
position = Vector2(-32, 0)
target_position = Vector2(-16, 0)
collision_mask = 3
hit_from_inside = true