Second Prototype
This commit is contained in:
parent
885351b624
commit
632eeddc64
60 changed files with 680 additions and 1013 deletions
104
scenes/Blocks/Patterns/block_pattern.gd
Normal file
104
scenes/Blocks/Patterns/block_pattern.gd
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
extends Node2D
|
||||
|
||||
@onready var positions = $Positions
|
||||
@onready var collision = $CollisionTest
|
||||
|
||||
var lastDirection = null
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
func getCollidingAreas():
|
||||
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 i.is_in_group("Block"):
|
||||
if i.UID != GLOBAL.currentUID:
|
||||
collidingAreas.append(i)
|
||||
else:
|
||||
collidingAreas.append(i)
|
||||
return collidingAreas
|
||||
|
||||
|
||||
#func _on_collision_test_area_entered(area: Area2D) -> void:
|
||||
#if lastDirection == null:
|
||||
#checkLeft()
|
||||
#else:
|
||||
#if lastDirection == GLOBAL.Direction.LEFT:
|
||||
#print(getCollidingAreas())
|
||||
#checkRight()
|
||||
#if lastDirection == GLOBAL.Direction.LEFT:
|
||||
#print(getCollidingAreas())
|
||||
#print(collision.get_overlapping_areas())
|
||||
#print(getCollidingAreas())
|
||||
#print(checkLeft())
|
||||
#print(checkRight())
|
||||
|
||||
func reset(newPosition):
|
||||
position = newPosition
|
||||
positions.position.x = 0
|
||||
collision.position.x = 0
|
||||
rotation_degrees = 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue