rotation rework, deletion of complex objects

This commit is contained in:
Rendo 2025-10-16 19:47:52 +05:00
commit 8dcd7725a9
15 changed files with 103 additions and 147 deletions

View file

@ -4,15 +4,7 @@ extends Node2D
## Game object that interact with other structures in its grid space
class_name Structure
enum Facing {
UNDIRECTIONAL = 0,
RIGHT = 1,
DOWN = 2,
LEFT = 3,
UP = 4
}
signal switched_facing(to: Facing)
signal changed_direction(to: float,max_directions : int)
## Dimensions of structure in grid tiles
@export var dimensions : Rect2i = Rect2i(0,0,1,1):
@ -25,20 +17,8 @@ signal switched_facing(to: Facing)
## Inventory of this structure
@export var inventory : Inventory
@export var facing : Facing
static func facing_to_vector(face : Facing) -> Vector2:
match face:
Facing.RIGHT:
return Vector2.RIGHT
Facing.LEFT:
return Vector2.LEFT
Facing.UP:
return Vector2.UP
Facing.DOWN:
return Vector2.DOWN
_:
return Vector2.ZERO
@export var direction : float
@export var maximum_directions : int
## Debug draw of points
func _draw() -> void:
@ -83,16 +63,21 @@ func get_dimension_points() -> Array[Vector2]:
result[x + y * dimensions.size.x] = (Vector2(x,y)*Globals.GRID_SIZE + Vector2(dimensions.position))
return result
func set_facing(to : Facing) -> void:
facing = to
switched_facing.emit(facing)
func set_direction(to : float) -> void:
direction = to
changed_direction.emit(direction,maximum_directions)
func cycle_up_facing() -> void:
if facing == Facing.UNDIRECTIONAL:
return
set_facing(wrapi(facing+1,1,5))
func increment_direction() -> void:
set_direction(wrapf(direction + TAU/maximum_directions,0,TAU))
func cycle_down_facing() -> void:
if facing == Facing.UNDIRECTIONAL:
return
set_facing(wrapi(facing-1,1,5))
func decrement_direction() -> void:
set_direction(wrapf(direction - TAU/maximum_directions,0,TAU))
func direction_vector() -> Vector2:
return Vector2.from_angle(direction)
func direction_to(structure: Structure):
return (structure.global_position-global_position).angle()
func direction_difference(structure: Structure):
return direction-structure.direction