Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.02 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. export var player_camera = true
  4. export var speed = 150
  5. var moveplayer = Vector2()
  6. onready var psprite = get_node("AnimatedSprite")
  7. var facing = 1
  8. onready var dialog_detect = get_node("dialog_detect")
  9. var candialog = false
  10. var dialog_object
  11. var canmove = true
  12. onready var dialog = get_owner().get_node("DIALOG/DIALOG")
  13. onready var dialog_text = get_owner().get_node("DIALOG/DIALOG/Control/RichTextLabel")
  14. var dialogdetect = 1
  15. var pressed_right = false
  16. var pressed_left = false
  17. var pressed_up = false
  18. var pressed_down = false
  19. # Called when the node enters the scene tree for the first time.
  20. func _ready():
  21.     dialog.visible = false
  22.     pass # Replace with function body.
  23.  
  24.  
  25. func _process(delta):
  26.     if dialog_object != null:
  27.         var wr = weakref(dialog_object);
  28.         if wr.get_ref():
  29.             if candialog == true && Input.is_action_just_pressed("dialog") && dialog_object.started_dialog == false && dialog_object.end != true:
  30.                 print("pressed_dialog")
  31.                 dialog_object.DIALOG()
  32.                 dialog.visible = true
  33.                 moveplayer.x = 0
  34.                 moveplayer.y = 0
  35.                 canmove = false
  36.             if Input.is_action_just_pressed("dialog") && dialog_object.end == true:
  37.                 dialog.visible = false
  38.                 moveplayer.x = 0
  39.                 moveplayer.y = 0
  40.                 canmove = true
  41.                 dialog_object.end = false
  42.             if global.enddialog == true:
  43.                 dialog.visible = false
  44.                 moveplayer.x = 0
  45.                 moveplayer.y = 0
  46.                 canmove = true
  47.                 dialog_object.end = false
  48.                 global.enddialog = false
  49.    
  50.    
  51.     if player_camera == true:
  52.         get_node("Camera2D").current = true
  53.     else:
  54.         get_node("Camera2D").current = false
  55.    
  56.     if Input.is_action_pressed("ui_down") != Input.is_action_pressed("ui_up") && canmove == true:
  57.         if Input.is_action_pressed("ui_down"):
  58.             moveplayer.y = speed-5
  59.            
  60.             facing = 1
  61.             dialog_detect.rotation_degrees = 180
  62.             if pressed_down != true && pressed_left != true && pressed_right != true && pressed_up != true:
  63.                 pressed_down = true
  64.         elif Input.is_action_pressed("ui_up"):
  65.             moveplayer.y = -speed+5
  66.            
  67.             facing = 2
  68.             if pressed_down != true && pressed_left != true && pressed_right != true && pressed_up != true:
  69.                 pressed_up = true
  70.             dialog_detect.rotation_degrees = 0
  71.     else:
  72.         moveplayer.y = 0
  73.         pressed_down = false
  74.         pressed_up = false
  75.    
  76.     if Input.is_action_pressed("ui_left") != Input.is_action_pressed("ui_right") && canmove == true:
  77.         if Input.is_action_pressed("ui_left"):
  78.             moveplayer.x = -speed
  79.            
  80.             if pressed_down != true && pressed_left != true && pressed_right != true && pressed_up != true:
  81.                 pressed_left = true
  82.             facing = 3
  83.             dialog_detect.rotation_degrees = -90
  84.         elif Input.is_action_pressed("ui_right"):
  85.             moveplayer.x = speed
  86.            
  87.             if pressed_down != true && pressed_left != true && pressed_right != true && pressed_up != true:
  88.                 pressed_right = true
  89.             facing = 4
  90.             dialog_detect.rotation_degrees = 90
  91.     else:
  92.         moveplayer.x = 0
  93.         pressed_left = false
  94.         pressed_right = false
  95.     if moveplayer.x == 0 && moveplayer.y == 0:
  96.         if facing == 1:
  97.             psprite.play("down")
  98.             dialog_detect.rotation_degrees = 180
  99.         if facing == 2:
  100.             psprite.play("up")
  101.             dialog_detect.rotation_degrees = 0
  102.         if facing == 3:
  103.             psprite.play("left")
  104.             dialog_detect.rotation_degrees = -90
  105.         if facing == 4:
  106.             psprite.play("right")
  107.             dialog_detect.rotation_degrees = 90
  108.     if pressed_right == true:
  109.         psprite.play("right_run")
  110.     if pressed_left == true:
  111.         psprite.play("left_run")
  112.     if pressed_up == true:
  113.         psprite.play("up_run")
  114.     if pressed_down == true:
  115.         psprite.play("down_run")
  116.     move_and_slide(moveplayer)
  117.     position.x = floor(position.x)
  118.     position.y = floor(position.y)
  119.  
  120.  
  121. func _on_dialog_detect_body_entered(body):
  122.     if body.is_in_group("DialogObject"):
  123.         print("candialog")
  124.         candialog = true
  125.         dialog_object = body
  126.     pass # Replace with function body.
  127.  
  128.  
  129. func _on_dialog_detect_body_exited(body):
  130.     if body.is_in_group("DialogObject"):
  131.         print("cant_dialog")
  132.         candialog = false
  133.     pass # Replace with function body.
  134.  
  135. func wait(time):
  136.     yield(get_tree().create_timer(time), "timeout")
  137.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement