Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- #var global
- var dialog
- var collider
- 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
- if get_node("RayCast2D").is_colliding() and Input.is_action_pressed("action"):
- var collider = get_node("RayCast2D").get_collider()
- send_to_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 _ready():
- set_fixed_process(true)
- get_node("RayCast2D").add_exception(self)
- func _fixed_process(delta):
- process_movement(delta)
- func send_to_dialog():
- var dialog_send = get_tree().get_root().get_node("dialog-box") # Attempt to call function 'recieve_text' in base 'null instance' on a null instance.
- dialog_send.receive_text(str(collider)) # naturally does not execute see above comment
- print (collider, str(timelapse))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement