Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- var dialog
- var collider
- var SoldierRay
- var npc
- var has_response = false
- var is_action_pressed = false
- export var walk = 200
- export var run = 300
- var old_motion = Vector2()
- var anim = "down_idle"
- var timelapse = 0
- func process_movement(delta):
- var motion = Vector2(0,0)
- if Input.is_action_pressed("move_up"):
- motion += Vector2(0, -1)
- if Input.is_action_pressed("move_down"):
- motion += Vector2(0, 1)
- if Input.is_action_pressed("move_left"):
- motion += Vector2(-1, 0)
- if Input.is_action_pressed("move_right"):
- motion += Vector2(1, 0)
- if Input.is_action_pressed("ui_cancel"):
- get_tree().change_scene("scenes/menu.scn")
- var velocity = walk
- if Input.is_action_pressed("run_mod"):
- velocity = run
- motion = motion.normalized() * velocity * delta
- move(motion)
- timelapse += delta
- receive_dialog()
- # animation changes
- if (old_motion == motion):
- return
- old_motion = motion
- if(motion == Vector2(0,0)):
- anim += ("_idle")
- elif(motion.x < 0):
- anim = "left"
- get_node("RayCast2D").set_rot(3*PI/2)
- elif(motion.x > 0):
- anim = "right"
- get_node("RayCast2D").set_rot((PI)/2)
- elif(motion.y < 0):
- anim = "up"
- get_node("RayCast2D").set_rot(PI)
- elif(motion.y > 0):
- anim = "down"
- get_node("RayCast2D").set_rot(0)
- get_node("walk-anim").play(anim)
- func receive_dialog():
- if SoldierRay.is_colliding() and Input.is_action_pressed("action"):
- if is_action_pressed == false:
- npc = SoldierRay.get_collider()
- print(npc.get_name()) # console check
- has_response = npc.has_node("Response")
- print(has_response) # console check
- if has_response:
- dialog = npc.get_node("Response").get_text()
- print(dialog) # console check
- return dialog
- is_action_pressed = true
- else:
- is_action_pressed = false
- func _ready():
- set_process(true)
- set_fixed_process(true)
- SoldierRay = get_node("RayCast2D")
- SoldierRay.add_exception(self)
- func _fixed_process(delta):
- process_movement(delta)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement