Test
This commit is contained in:
parent
5643fee9d3
commit
99d5016ac2
9 changed files with 171 additions and 149 deletions
|
|
@ -38,18 +38,49 @@ func _physics_process(delta: float) -> void:
|
|||
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
|
||||
|
||||
else:
|
||||
if stopped and not isBottomColliding():
|
||||
position.y += GLOBAL.GRID
|
||||
snapPosition()
|
||||
if Input.is_action_pressed("down") and isCurrent():
|
||||
velocity = get_gravity() * delta * GLOBAL.SPEED.MAX
|
||||
else:
|
||||
velocity = get_gravity() * delta * GLOBAL.currentSpeed
|
||||
#if isBottomColliding():
|
||||
#print(global_position)
|
||||
#print(global_position.snapped(Vector2(64,64)))
|
||||
#print(global_position.snapped(Vector2(64,64)) - Vector2(32,32))
|
||||
#print(int((global_position.snapped(Vector2(64,64)) - Vector2(32,32)).y))
|
||||
#print(int((global_position.snapped(Vector2(64,64)) - Vector2(32,32)).x))
|
||||
#print(int(global_position.x-32) % GLOBAL.GRID)
|
||||
#print(int(global_position.y-32) % GLOBAL.GRID)
|
||||
#print(name + ": " + str(not isBottomColliding() and not isCurrent()))
|
||||
#print(global_position)
|
||||
#print(int(global_position.x-32) % GLOBAL.GRID)
|
||||
#print(int(global_position.y-32) % GLOBAL.GRID)
|
||||
#if isBottomColliding():
|
||||
#
|
||||
#if not int(global_position.x-32) % GLOBAL.GRID == 0:
|
||||
#global_position.x = global_position.snapped(Vector2(64,64)).x -32
|
||||
#if not int(global_position.y-32) % GLOBAL.GRID == 0:
|
||||
#global_position.y = global_position.snapped(Vector2(64,64)).y -32
|
||||
#global_position = global_position.snapped(Vector2(64,64))
|
||||
|
||||
#position.y += GLOBAL.GRID
|
||||
|
||||
if is_on_floor():
|
||||
position = position.snapped(Vector2(32,32))
|
||||
#if is_on_floor():
|
||||
#position = position.snapped(Vector2(32,32))
|
||||
|
||||
#if not is_on_floor() and not isCurrent() and not isBottomColliding():
|
||||
#position += Vector2(0,64)
|
||||
#print(not isBottomColliding())
|
||||
#if stopped and not isBottomColliding():
|
||||
#position += Vector2(0,64)
|
||||
if isCurrent() and not expanding and not GLOBAL.blockStopped:
|
||||
move_and_slide()
|
||||
else:
|
||||
|
||||
velocity = Vector2.ZERO
|
||||
|
||||
func expandBlocks():
|
||||
|
|
@ -77,10 +108,10 @@ func expandBlocks():
|
|||
position.x += GLOBAL.GRID
|
||||
if isCollidingBorder():
|
||||
position.y -= GLOBAL.GRID
|
||||
|
||||
|
||||
for i in partsContainer.get_children():
|
||||
if i != null:
|
||||
i.removeOverlapp()
|
||||
#print(i)
|
||||
i.removeOverlapp()
|
||||
#splitParts()
|
||||
|
||||
func addParts():
|
||||
|
|
@ -96,31 +127,11 @@ func addParts():
|
|||
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()
|
||||
|
|
@ -129,7 +140,11 @@ func isCurrent():
|
|||
return GLOBAL.currentID == id
|
||||
|
||||
func snapPosition(): #x :bool, y: bool
|
||||
position = position.snapped(Vector2(64,64))
|
||||
if not offset and not expand:
|
||||
global_position = global_position.snapped(Vector2(64,64)) - Vector2(32,32)
|
||||
else:
|
||||
global_position = global_position.snapped(Vector2(64,64))
|
||||
#position = position.snapped(Vector2(64,64))
|
||||
|
||||
func rotateBlock(direction):
|
||||
match direction:
|
||||
|
|
@ -232,7 +247,41 @@ func _on_animation_player_animation_finished(anim_name: StringName) -> void:
|
|||
|
||||
func _on_coyote_timer_timeout() -> void:
|
||||
if isBottomColliding():
|
||||
snapPosition()
|
||||
stopped = true
|
||||
GLOBAL.blockStopped = true
|
||||
if expand:
|
||||
expandBlocks()
|
||||
|
||||
func init(pos):
|
||||
if expand and stopped:
|
||||
#$AnimationPlayer.play("Expand")
|
||||
scale = Vector2(2,2)
|
||||
addParts()
|
||||
id = GLOBAL.getNewID()
|
||||
GLOBAL.currentID = id
|
||||
snapPosition()
|
||||
global_position = pos
|
||||
if offset:
|
||||
snapPosition()
|
||||
|
||||
|
||||
func splitParts():
|
||||
for i in $PartsContainer.get_children():
|
||||
var newBlock = load(block1x1).instantiate()
|
||||
get_parent().add_child(newBlock)
|
||||
newBlock.clone(expand, type, stopped)
|
||||
newBlock.init(i.global_position)
|
||||
newBlock.setColor(modulate)
|
||||
queue_free()
|
||||
|
||||
func clone(newExpand=false, newType=GLOBAL.BLOCKTYPES.LIGHT, newStopped=false):
|
||||
expand = newExpand
|
||||
stopped = newStopped
|
||||
type = newType
|
||||
#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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
extends Node2D
|
||||
extends Area2D
|
||||
|
||||
@onready var spriteBlock = $Sprites/Block
|
||||
@onready var spriteSpecialBlock = $Sprites/SpecialBlock
|
||||
|
|
@ -27,15 +27,32 @@ func isOverlapping() -> bool:
|
|||
|
||||
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()
|
||||
var removeBlock = []
|
||||
for i in $Area2D.get_overlapping_areas():
|
||||
|
||||
|
||||
if i.is_in_group("Part") and i.get_parent().get_parent().id != GLOBAL.currentID:
|
||||
print(i)
|
||||
var block = i.get_parent().get_parent()
|
||||
blocksSplit.append(block)
|
||||
i.free()
|
||||
#if GLOBAL.currentMode == GLOBAL.MODES.TIME:
|
||||
#GLOBAL.time += block.type
|
||||
#if block.expand:
|
||||
#GLOBAL.points += block.type * 2
|
||||
#else:
|
||||
#GLOBAL.points += block.type
|
||||
for j in blocksSplit:
|
||||
j.splitParts()
|
||||
#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
|
||||
|
|
|
|||
|
|
@ -9,35 +9,11 @@
|
|||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ix7xn"]
|
||||
size = Vector2(48, 48)
|
||||
|
||||
[node name="Part" type="StaticBody2D"]
|
||||
collision_layer = 24
|
||||
collision_mask = 24
|
||||
[node name="Part" type="Area2D" groups=["Part"]]
|
||||
collision_layer = 8
|
||||
collision_mask = 16
|
||||
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")
|
||||
|
||||
|
|
@ -84,3 +60,10 @@ position = Vector2(-32, 0)
|
|||
target_position = Vector2(0, 0)
|
||||
collision_mask = 3
|
||||
hit_from_inside = true
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
collision_layer = 16
|
||||
collision_mask = 8
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
shape = SubResource("RectangleShape2D_ix7xn")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue