Fixed many Bugy and added Labels for Time and Score
This commit is contained in:
parent
632eeddc64
commit
ee5e17c3e0
14 changed files with 430 additions and 179 deletions
|
|
@ -7,6 +7,7 @@
|
|||
[node name="BlockPattern" instance=ExtResource("1_sj41y")]
|
||||
|
||||
[node name="PositionMarker" parent="Positions" index="0" instance=ExtResource("2_csenr")]
|
||||
turningPoint = true
|
||||
|
||||
[node name="PositionMarker2" parent="Positions" index="1" instance=ExtResource("2_csenr")]
|
||||
position = Vector2(0, -64)
|
||||
|
|
|
|||
|
|
@ -5,67 +5,113 @@ extends Node2D
|
|||
|
||||
var lastDirection = null
|
||||
|
||||
var type = GLOBAL.BLOCKTYPES.LIGHT
|
||||
var expand = false
|
||||
|
||||
func getPositions():
|
||||
return positions.get_children()
|
||||
|
||||
func checkDirection():
|
||||
var leftCollision = true
|
||||
var rightCollision = true
|
||||
positions.position.x = 0
|
||||
collision.position.x = 0
|
||||
if await getCollidingAreas() != []:
|
||||
positions.position.x += GLOBAL.GRID
|
||||
collision.position.x += GLOBAL.GRID
|
||||
if await getCollidingAreas() == []:
|
||||
rightCollision = false
|
||||
else:
|
||||
rightCollision = true
|
||||
positions.position.x = 0
|
||||
collision.position.x = 0
|
||||
if await getCollidingAreas() != []:
|
||||
positions.position.x -= GLOBAL.GRID
|
||||
collision.position.x -= GLOBAL.GRID
|
||||
if await getCollidingAreas() == []:
|
||||
leftCollision = false
|
||||
else:
|
||||
leftCollision = true
|
||||
positions.position.x = 0
|
||||
collision.position.x = 0
|
||||
if not rightCollision:
|
||||
positions.position.x += GLOBAL.GRID
|
||||
collision.position.x += GLOBAL.GRID
|
||||
elif not leftCollision:
|
||||
positions.position.x -= GLOBAL.GRID
|
||||
collision.position.x -= GLOBAL.GRID
|
||||
else:
|
||||
positions.position.x = 0
|
||||
collision.position.x = 0
|
||||
print("xfsdfdsfd")
|
||||
var leftCollision = false
|
||||
var rightCollision = false
|
||||
|
||||
func turn(direction,newPosition):
|
||||
positions.position.x = 0
|
||||
collision.position.x = 0
|
||||
position = newPosition
|
||||
match direction:
|
||||
GLOBAL.Direction.LEFT:
|
||||
positions.rotation_degrees += 90
|
||||
collision.rotation_degrees += 90
|
||||
if await getCollidingAreas() != []:
|
||||
checkDirection()
|
||||
if await getCollidingAreas() != []:
|
||||
positions.rotation_degrees += 90
|
||||
collision.rotation_degrees += 90
|
||||
|
||||
GLOBAL.Direction.RIGHT:
|
||||
positions.rotation_degrees -= 90
|
||||
collision.rotation_degrees -= 90
|
||||
if await getCollidingAreas() != []:
|
||||
checkDirection()
|
||||
if await getCollidingAreas() != []:
|
||||
positions.rotation_degrees -= 90
|
||||
collision.rotation_degrees -= 90
|
||||
#positions.rotation_degrees += 90
|
||||
#collision.rotation_degrees += 90
|
||||
movePattern(GLOBAL.Direction.RIGHT)
|
||||
print("0: ", await isColliding())
|
||||
if await isColliding():
|
||||
movePattern(GLOBAL.Direction.LEFT)
|
||||
print("1: ", await isColliding())
|
||||
#if await isColliding():
|
||||
#movePattern(GLOBAL.Direction.RIGHT, 2)
|
||||
#print("2: ", await isColliding())
|
||||
#if await isColliding():
|
||||
#movePattern(GLOBAL.Direction.LEFT, 2)
|
||||
#print("3: ", await isColliding())
|
||||
#if await isColliding():
|
||||
#resetPosition()
|
||||
#print("4: ", await isColliding())
|
||||
#if await isColliding():
|
||||
#rightCollision = true
|
||||
#resetPosition()
|
||||
#movePattern(GLOBAL.Direction.LEFT)
|
||||
#if await isColliding():
|
||||
#leftCollision = true
|
||||
#print(" LEFT: ", leftCollision, "\n RIGHT: ", rightCollision)
|
||||
#resetPosition()
|
||||
#if await getCollidingAreas() != []:
|
||||
#rightCollision = true
|
||||
#resetPosition()
|
||||
#movePattern(GLOBAL.Direction.LEFT)
|
||||
#if await getCollidingAreas() != []:
|
||||
#leftCollision = true
|
||||
#resetPosition()
|
||||
#
|
||||
#if leftCollision:
|
||||
#movePattern(GLOBAL.Direction.RIGHT)
|
||||
#elif rightCollision:
|
||||
#movePattern(GLOBAL.Direction.LEFT)
|
||||
|
||||
|
||||
#else:
|
||||
|
||||
#resetPosition()
|
||||
|
||||
func moveToPosition(newPosition):
|
||||
resetPosition()
|
||||
position = newPosition
|
||||
|
||||
func turn(direction, newPosition):
|
||||
reset(newPosition)
|
||||
#moveToPosition(newPosition)
|
||||
rotatePattern(direction)
|
||||
|
||||
#if await isColliding():
|
||||
#print(1)
|
||||
#movePattern(GLOBAL.Direction.RIGHT, 1)
|
||||
#if await isColliding():
|
||||
#print(2)
|
||||
#movePattern(GLOBAL.Direction.LEFT,2)
|
||||
#if await isColliding():
|
||||
#print(3)
|
||||
#movePattern(GLOBAL.Direction.RIGHT, 3)
|
||||
#if await isColliding():
|
||||
#print(4)
|
||||
#movePattern(GLOBAL.Direction.LEFT, 4)
|
||||
|
||||
#if await isColliding():
|
||||
#print(1)
|
||||
#movePattern(GLOBAL.Direction.RIGHT, 2)
|
||||
#if await isColliding():
|
||||
#print(2)
|
||||
#movePattern(GLOBAL.Direction.LEFT,4)
|
||||
#
|
||||
if await isColliding():
|
||||
movePattern(GLOBAL.Direction.RIGHT, 1)
|
||||
if await isColliding():
|
||||
movePattern(GLOBAL.Direction.RIGHT, 1)
|
||||
if await isColliding():
|
||||
movePattern(GLOBAL.Direction.LEFT,3)
|
||||
if await isColliding():
|
||||
movePattern(GLOBAL.Direction.LEFT,1)
|
||||
|
||||
#if await isColliding():
|
||||
#print(2)
|
||||
#movePattern(GLOBAL.Direction.RIGHT, 1)
|
||||
#if await isColliding():
|
||||
#print(3)
|
||||
#movePattern(GLOBAL.Direction.LEFT,3)
|
||||
#if await isColliding():
|
||||
#print(4)
|
||||
#movePattern(GLOBAL.Direction.LEFT,1)
|
||||
#if await isColliding():
|
||||
#print(3)
|
||||
#movePattern(GLOBAL.Direction.LEFT, 1)
|
||||
#movePattern(GLOBAL.Direction.RIGHT, 3)
|
||||
#if await isColliding():
|
||||
#movePattern(GLOBAL.Direction.LEFT, 2)
|
||||
if await isColliding():
|
||||
resetPosition()
|
||||
|
||||
|
||||
|
||||
func getCollidingAreas():
|
||||
|
|
@ -81,7 +127,31 @@ func getCollidingAreas():
|
|||
else:
|
||||
collidingAreas.append(i)
|
||||
return collidingAreas
|
||||
|
||||
func isColliding():
|
||||
return await getCollidingAreas() != []
|
||||
|
||||
func getCollidingBorder():
|
||||
await get_tree().process_frame
|
||||
await get_tree().process_frame
|
||||
await get_tree().process_frame
|
||||
await get_tree().process_frame
|
||||
var collidingAreas = []
|
||||
for i in collision.get_overlapping_areas():
|
||||
if not i.is_in_group("Block"):
|
||||
collidingAreas.append(i)
|
||||
return collidingAreas
|
||||
|
||||
func getCollidingBlocks():
|
||||
await get_tree().process_frame
|
||||
await get_tree().process_frame
|
||||
await get_tree().process_frame
|
||||
var collidingAreas = []
|
||||
for i in collision.get_overlapping_areas():
|
||||
if i.is_in_group("Block"):
|
||||
if i.UID != GLOBAL.currentUID:
|
||||
collidingAreas.append(i)
|
||||
return collidingAreas
|
||||
|
||||
#func _on_collision_test_area_entered(area: Area2D) -> void:
|
||||
#if lastDirection == null:
|
||||
|
|
@ -102,3 +172,30 @@ func reset(newPosition):
|
|||
positions.position.x = 0
|
||||
collision.position.x = 0
|
||||
rotation_degrees = 0
|
||||
|
||||
func movePattern(direction, steps = 1):
|
||||
match direction:
|
||||
GLOBAL.Direction.LEFT:
|
||||
positions.position.x -= GLOBAL.GRID * steps
|
||||
collision.position.x -= GLOBAL.GRID * steps
|
||||
#print("Left")
|
||||
#print(positions.position)
|
||||
GLOBAL.Direction.RIGHT:
|
||||
positions.position.x += GLOBAL.GRID * steps
|
||||
collision.position.x += GLOBAL.GRID * steps
|
||||
#print("Right")
|
||||
#print(positions.position)
|
||||
|
||||
func resetPosition():
|
||||
#print("RESET")
|
||||
positions.position.x = 0
|
||||
collision.position.x = 0
|
||||
|
||||
func rotatePattern(direction):
|
||||
match direction:
|
||||
GLOBAL.Direction.LEFT:
|
||||
positions.rotation_degrees += 90
|
||||
collision.rotation_degrees += 90
|
||||
GLOBAL.Direction.RIGHT:
|
||||
positions.rotation_degrees -= 90
|
||||
collision.rotation_degrees -= 90
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ extends Area2D
|
|||
@onready var floorRaycast = $RaycastFloor
|
||||
@onready var raycastLeft = $RaycastLeft
|
||||
@onready var raycastRight = $RaycastRight
|
||||
@onready var raycastTop = $RaycastTop
|
||||
|
||||
@export var UID = 1
|
||||
|
||||
|
|
@ -15,40 +16,6 @@ var type = GLOBAL.BLOCKTYPES.LIGHT
|
|||
func _ready() -> void:
|
||||
secretPosition = position
|
||||
|
||||
#func _physics_process(delta: float) -> void:
|
||||
#print(secretPosition)
|
||||
#print(getNeighbours())
|
||||
#print(getNeighboursUID(UID))
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _physics_process(delta: float) -> void:
|
||||
#if not getIsOnFloor():
|
||||
# position = secretPosition.snapped(Vector2(64,64))
|
||||
#if Input.is_action_just_pressed("left"):
|
||||
# if not raycastLeft.is_colliding():
|
||||
# secretPosition.x -= GLOBAL.GRID
|
||||
#if Input.is_action_just_pressed("right"):
|
||||
# if not raycastRight.is_colliding():
|
||||
# secretPosition.x += GLOBAL.GRID
|
||||
#secretPosition.y += GLOBAL.currentSpeed * delta * 30
|
||||
|
||||
func getIsOnFloor() -> bool:
|
||||
return floorRaycast.is_colliding()
|
||||
|
||||
#func getFloorCollider():
|
||||
#return floorRaycast.get_collider()
|
||||
#
|
||||
#func getLeftCollider():
|
||||
#return raycastLeft.get_collider()
|
||||
#
|
||||
#func getRightCollider():
|
||||
#return raycastRight.get_collider()
|
||||
|
||||
func getLeftColliding() -> bool:
|
||||
return raycastLeft.is_colliding()
|
||||
|
||||
func getRightColliding() -> bool:
|
||||
return raycastRight.is_colliding()
|
||||
|
||||
func getCollider(direction : GLOBAL.Direction):
|
||||
match direction:
|
||||
GLOBAL.Direction.BOTTOM:
|
||||
|
|
@ -57,7 +24,8 @@ func getCollider(direction : GLOBAL.Direction):
|
|||
return raycastLeft.get_collider()
|
||||
GLOBAL.Direction.RIGHT:
|
||||
return raycastRight.get_collider()
|
||||
|
||||
GLOBAL.Direction.TOP:
|
||||
return raycastTop.get_collider()
|
||||
|
||||
func getNeighbours():
|
||||
var neighbours = []
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://do8gr42oq2a0y"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://do8gr42oq2a0y"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/Blocks/block.gd" id="1_t1hpt"]
|
||||
|
||||
|
|
@ -7,6 +7,9 @@
|
|||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_gvev2"]
|
||||
size = Vector2(80, 80)
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ti23g"]
|
||||
size = Vector2(48, 48)
|
||||
|
||||
[node name="Block" type="Area2D" groups=["Block"]]
|
||||
collision_layer = 2
|
||||
collision_mask = 14
|
||||
|
|
@ -19,21 +22,28 @@ mesh = SubResource("QuadMesh_lsuac")
|
|||
|
||||
[node name="RaycastFloor" type="RayCast2D" parent="."]
|
||||
position = Vector2(32, 72)
|
||||
target_position = Vector2(0, 32)
|
||||
target_position = Vector2(0, 8)
|
||||
collision_mask = 3
|
||||
hit_from_inside = true
|
||||
collide_with_areas = true
|
||||
|
||||
[node name="RaycastLeft" type="RayCast2D" parent="."]
|
||||
position = Vector2(-8, 32)
|
||||
target_position = Vector2(-32, 0)
|
||||
target_position = Vector2(-8, 0)
|
||||
collision_mask = 3
|
||||
hit_from_inside = true
|
||||
collide_with_areas = true
|
||||
|
||||
[node name="RaycastRight" type="RayCast2D" parent="."]
|
||||
position = Vector2(72, 32)
|
||||
target_position = Vector2(32, 0)
|
||||
target_position = Vector2(8, 0)
|
||||
collision_mask = 3
|
||||
hit_from_inside = true
|
||||
collide_with_areas = true
|
||||
|
||||
[node name="RaycastTop" type="RayCast2D" parent="."]
|
||||
position = Vector2(32, -8)
|
||||
target_position = Vector2(0, -8)
|
||||
collision_mask = 3
|
||||
hit_from_inside = true
|
||||
collide_with_areas = true
|
||||
|
|
@ -41,3 +51,10 @@ collide_with_areas = true
|
|||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(32, 32)
|
||||
shape = SubResource("RectangleShape2D_gvev2")
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="." groups=["Block"]]
|
||||
collision_layer = 16
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
position = Vector2(32, 32)
|
||||
shape = SubResource("RectangleShape2D_ti23g")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue