interact
This commit is contained in:
@@ -2,8 +2,11 @@ extends Node
|
||||
|
||||
# Player AI
|
||||
var ignore_input = false
|
||||
var body_exit_signal = false # interact_input()
|
||||
var interact_target = null
|
||||
var velocity_sum = Vector2(0.0,0.0)
|
||||
|
||||
# Setters + Getters
|
||||
func set_ignore_input(new_bool):
|
||||
ignore_input = new_bool
|
||||
func get_ignore_input():
|
||||
@@ -11,10 +14,55 @@ func get_ignore_input():
|
||||
func get_user():
|
||||
return get_parent()
|
||||
|
||||
### LOGIC ###
|
||||
|
||||
# Get Player Input
|
||||
func get_input():
|
||||
if not ignore_input:
|
||||
get_movement_input()
|
||||
get_interact_input()
|
||||
|
||||
### INTERACTING ###
|
||||
|
||||
# Listen for Hotkey for Interacting
|
||||
func get_interact_input():
|
||||
## Interact Hotkey
|
||||
if Input.is_action_just_pressed('interact'):
|
||||
## Get overlapping bodies from range bubble
|
||||
var bodies = get_user().get_overlapping_bodies()
|
||||
#var areas = get_user().get_overlapping_areas()
|
||||
## Exclusions
|
||||
for body in bodies:
|
||||
if !body.has_method("get_user"):
|
||||
bodies.erase(body)
|
||||
if body.has_method("get_user") and body.get_user().is_player():
|
||||
bodies.erase(body)
|
||||
#for area in areas:
|
||||
# if area.has_method("get_user"):
|
||||
# areas.erase(area)
|
||||
## Collect Interactable Targets in Range
|
||||
var interact_targets = []
|
||||
for b in bodies:
|
||||
if b.get_user().is_in_group("can_interact"):
|
||||
interact_targets.append(b.get_user())
|
||||
#for a in areas:
|
||||
# if a.get_user().is_in_group("can_interact"):
|
||||
# interact_targets.append(a.get_user())
|
||||
## Find Nearest Interactable Target
|
||||
if interact_targets:
|
||||
interact_targets.sort_custom(FoeSorter.new(get_user().get_gpos()), "sort")
|
||||
#get_user().set_target(interact_targets[0])
|
||||
interact_targets[0].interact()
|
||||
|
||||
# Foe Finder System
|
||||
class FoeSorter:
|
||||
var point = null
|
||||
func _init(new_point):
|
||||
self.point = new_point
|
||||
func sort(a, b):
|
||||
return self.point.distance_to(a.get_gpos()) < self.point.distance_to(b.get_gpos())
|
||||
|
||||
### MOVEMENT ###
|
||||
|
||||
# Get Movement Key Input
|
||||
func get_movement_input():
|
||||
@@ -65,6 +113,8 @@ func movement_key_released(direction):
|
||||
get_user().animate("Idle")
|
||||
get_user().set_internal_velocity(velocity_sum)
|
||||
|
||||
### PHYSICS PROCESS
|
||||
|
||||
# Physics Process
|
||||
func _physics_process(_delta):
|
||||
## Keyboard Movement
|
||||
|
||||
@@ -5,6 +5,8 @@ func get_body_node():
|
||||
return $KinematicBody2D
|
||||
func get_sprite_node():
|
||||
return $KinematicBody2D/AnimatedSprite
|
||||
func is_player():
|
||||
return true
|
||||
|
||||
## Parameters
|
||||
func set_gpos(new_pos):
|
||||
@@ -13,6 +15,10 @@ func get_gpos():
|
||||
return get_body_node().get_gpos()
|
||||
func set_internal_velocity(new_vel):
|
||||
get_body_node().set_internal_velocity(new_vel)
|
||||
func get_overlapping_areas():
|
||||
return get_body_node().get_overlapping_areas()
|
||||
func get_overlapping_bodies():
|
||||
return get_body_node().get_overlapping_bodies()
|
||||
|
||||
## Logic
|
||||
func animate(animation):
|
||||
|
||||
@@ -35,6 +35,10 @@ func get_internal_velocity():
|
||||
if not get_can_move():
|
||||
return Vector2(0.0,0.0)
|
||||
return internal_velocity
|
||||
func get_overlapping_areas():
|
||||
return $PersonalSpace.get_overlapping_areas()
|
||||
func get_overlapping_bodies():
|
||||
return $PersonalSpace.get_overlapping_bodies()
|
||||
func get_speed():
|
||||
if !get_can_move():
|
||||
return 0
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
extends Node
|
||||
|
||||
func get_user():
|
||||
return get_parent()
|
||||
|
||||
func is_player():
|
||||
return false
|
||||
|
||||
func interact():
|
||||
print_debug("HI")
|
||||
@@ -0,0 +1,7 @@
|
||||
extends StaticBody2D
|
||||
|
||||
func get_user():
|
||||
return get_parent()
|
||||
|
||||
func interact():
|
||||
print_debug("HI")
|
||||
Reference in New Issue
Block a user