first house
This commit is contained in:
@@ -5,6 +5,10 @@ const SPEED: int = 800
|
||||
|
||||
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
|
||||
@onready var cam: Camera2D = $Camera2D
|
||||
@onready var raycast: RayCast2D = $RayCast2D
|
||||
const RAYCAST_RAGE: int = 32
|
||||
|
||||
|
||||
@export var tilemap: TileMapLayer
|
||||
var tilesize: int = 32
|
||||
var position_limit_rect: Rect2
|
||||
@@ -29,10 +33,25 @@ func _ready() -> void:
|
||||
)
|
||||
)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if Input.is_action_just_pressed("interact") && raycast.is_colliding() && raycast.get_collider() is Interactable:
|
||||
var interactable: Interactable = raycast.get_collider()
|
||||
interactable.interact()
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if EventManager.player_free:
|
||||
velocity = Input.get_vector("move_left","move_right","move_up","move_down").normalized() * delta * SPEED * 3
|
||||
|
||||
var input := Input.get_vector("move_left", "move_right", "move_up", "move_down").normalized()
|
||||
|
||||
var raycast_input := Vector2.ZERO
|
||||
if abs(input.x) > abs(input.y):
|
||||
raycast_input.x = sign(input.x)
|
||||
elif abs(input.y) > 0:
|
||||
raycast_input.y = sign(input.y)
|
||||
if raycast_input != Vector2.ZERO:
|
||||
raycast.target_position = raycast_input * RAYCAST_RAGE
|
||||
|
||||
velocity = input * delta * SPEED * 3
|
||||
|
||||
move_and_slide()
|
||||
position = position.clamp(position_limit_rect.position, position_limit_rect.end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user