Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- export var player_camera = true
- export var speed = 150
- var moveplayer = Vector2()
- onready var psprite = get_node("AnimatedSprite")
- var facing = 1
- onready var dialog_detect = get_node("dialog_detect")
- var candialog = false
- var dialog_object
- var canmove = true
- onready var dialog = get_owner().get_node("DIALOG/DIALOG")
- onready var dialog_text = get_owner().get_node("DIALOG/DIALOG/Control/RichTextLabel")
- var dialogdetect = 1
- var pressed_right = false
- var pressed_left = false
- var pressed_up = false
- var pressed_down = false
- # Called when the node enters the scene tree for the first time.
- func _ready():
- dialog.visible = false
- pass # Replace with function body.
- func _process(delta):
- if dialog_object != null:
- var wr = weakref(dialog_object);
- if wr.get_ref():
- if candialog == true && Input.is_action_just_pressed("dialog") && dialog_object.started_dialog == false && dialog_object.end != true:
- print("pressed_dialog")
- dialog_object.DIALOG()
- dialog.visible = true
- moveplayer.x = 0
- moveplayer.y = 0
- canmove = false
- if Input.is_action_just_pressed("dialog") && dialog_object.end == true:
- dialog.visible = false
- moveplayer.x = 0
- moveplayer.y = 0
- canmove = true
- dialog_object.end = false
- if global.enddialog == true:
- dialog.visible = false
- moveplayer.x = 0
- moveplayer.y = 0
- canmove = true
- dialog_object.end = false
- global.enddialog = false
- if player_camera == true:
- get_node("Camera2D").current = true
- else:
- get_node("Camera2D").current = false
- if Input.is_action_pressed("ui_down") != Input.is_action_pressed("ui_up") && canmove == true:
- if Input.is_action_pressed("ui_down"):
- moveplayer.y = speed-5
- facing = 1
- dialog_detect.rotation_degrees = 180
- if pressed_down != true && pressed_left != true && pressed_right != true && pressed_up != true:
- pressed_down = true
- elif Input.is_action_pressed("ui_up"):
- moveplayer.y = -speed+5
- facing = 2
- if pressed_down != true && pressed_left != true && pressed_right != true && pressed_up != true:
- pressed_up = true
- dialog_detect.rotation_degrees = 0
- else:
- moveplayer.y = 0
- pressed_down = false
- pressed_up = false
- if Input.is_action_pressed("ui_left") != Input.is_action_pressed("ui_right") && canmove == true:
- if Input.is_action_pressed("ui_left"):
- moveplayer.x = -speed
- if pressed_down != true && pressed_left != true && pressed_right != true && pressed_up != true:
- pressed_left = true
- facing = 3
- dialog_detect.rotation_degrees = -90
- elif Input.is_action_pressed("ui_right"):
- moveplayer.x = speed
- if pressed_down != true && pressed_left != true && pressed_right != true && pressed_up != true:
- pressed_right = true
- facing = 4
- dialog_detect.rotation_degrees = 90
- else:
- moveplayer.x = 0
- pressed_left = false
- pressed_right = false
- if moveplayer.x == 0 && moveplayer.y == 0:
- if facing == 1:
- psprite.play("down")
- dialog_detect.rotation_degrees = 180
- if facing == 2:
- psprite.play("up")
- dialog_detect.rotation_degrees = 0
- if facing == 3:
- psprite.play("left")
- dialog_detect.rotation_degrees = -90
- if facing == 4:
- psprite.play("right")
- dialog_detect.rotation_degrees = 90
- if pressed_right == true:
- psprite.play("right_run")
- if pressed_left == true:
- psprite.play("left_run")
- if pressed_up == true:
- psprite.play("up_run")
- if pressed_down == true:
- psprite.play("down_run")
- move_and_slide(moveplayer)
- position.x = floor(position.x)
- position.y = floor(position.y)
- func _on_dialog_detect_body_entered(body):
- if body.is_in_group("DialogObject"):
- print("candialog")
- candialog = true
- dialog_object = body
- pass # Replace with function body.
- func _on_dialog_detect_body_exited(body):
- if body.is_in_group("DialogObject"):
- print("cant_dialog")
- candialog = false
- pass # Replace with function body.
- func wait(time):
- yield(get_tree().create_timer(time), "timeout")
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement