Advertisement
nokiojyn

megaman x movimento

Dec 21st, 2020
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends KinematicBody2D
  2.  
  3. export (int) var run_speed = 400
  4. export (int) var jump_speed = -650
  5. export (int) var gravity = 1400
  6.  
  7. onready var timer =  get_node("Timer")
  8. export (NodePath) onready var label
  9. var velocity = Vector2()
  10. # direção q tá indo 1 = direita 2 = esquerda
  11. var direction = 1
  12. var wallDirection = 0
  13. var jumping = false
  14. var falling = false
  15. # caso o botão não esteja pressionado == true
  16. var released = true
  17. # estado do dash
  18.  
  19. # ground     pra dash do chão
  20. # airDash    pra dash aéreo
  21. # SuperJump  pra o dash com pulo
  22.  
  23. # Não tem wallDash ainda mas isso vc faz
  24. var dashState = ""
  25. # bloqueio de airDash extra no ar
  26. var blockDash = false
  27. # momentum no superJump
  28. var momentum = false
  29. func _ready():
  30.     #timeout do timer
  31.     timer.connect("timeout", null, "Timeout")
  32. func get_input():
  33.     velocity.x = 0
  34.     # escadinha
  35.     var left = Input.is_action_pressed('left')
  36.     var right = Input.is_action_pressed('right')
  37.     var jump = Input.is_action_just_pressed('jump')
  38.     var dash = Input.is_action_just_pressed('dash')
  39.     var stopJump = Input.is_action_just_released('jump')
  40.     var stopDash = Input.is_action_just_released('dash')
  41.    
  42.     if jump and is_on_floor():
  43.         jumping = true
  44.         velocity.y = jump_speed
  45.     if jumping and is_on_wall():
  46.         jumping = false
  47.     if jump and not is_on_floor() and is_on_wall():
  48.         velocity.y = jump_speed
  49.         if wallDirection == 1:
  50.             direction = 2
  51.         dash(false)
  52.     # caso solte o botão de jump no ar ele para o pulo
  53.     if stopJump and not is_on_floor() and not falling and velocity.y < 0:
  54.         falling = true
  55.         velocity.y = 0
  56.     # direita e esquerda
  57.     if right:
  58.         direction = 1
  59.         #if is_on_wall():
  60.             #print("true")
  61.         # eu meio q usei a func do dash pra movimento tmb k
  62.         dash(false)
  63.     if left:
  64.         #if is_on_wall():
  65.             #print("true")
  66.         direction = 2
  67.         dash(false)
  68.     # se apertar o botão de dash, released pra n ficar infinito e o blockDash no airDash
  69.     if dash and released and not blockDash:
  70.         timer.start(timer.get_wait_time())
  71.         timer.set_one_shot(true)
  72.         released = false
  73.         if is_on_floor():
  74.             dashState = "ground"
  75.         else:
  76.             dashState = "airDash"
  77.     # caso solte o botão de dash
  78.     if stopDash:
  79.         # se o dash começou no chão e acabou no ar vira superJump
  80.         if dashState == "ground" and not is_on_floor():
  81.             dashState = "superJump"
  82.         # se n for dash ground ele faz o airDash
  83.         elif dashState == "airDash":
  84.             # pra n ter airDash extra
  85.             blockDash = true
  86.             # sem dash mais
  87.             dashState = ""
  88.         # se for um de ground e tiver no chão, sem dash mais
  89.         elif dashState == "ground" and is_on_floor():
  90.             dashState = ""
  91.         released = true
  92.         timer.stop()
  93.  
  94. func _physics_process(delta):
  95.     get_input()
  96.     #label dali de cima no canto
  97.     get_node(label).text = dashState
  98.     # gravidade
  99.     velocity.y += gravity * delta
  100.     # qualquer tipo de dash
  101.     if dashState != "" and not timer.is_stopped():
  102.         #print(timer.time_left)
  103.         dash(true)
  104.     # ativador instantanio de superJump pra facilitar
  105.     if dashState == "ground" and not is_on_floor():
  106.         dashState = "superJump"
  107.     # pulo (wathever)
  108.     if jumping and is_on_floor():
  109.         jumping = false
  110.     # reseta o blockDash quando encosta no chão
  111.     if blockDash and is_on_floor():
  112.         blockDash = false
  113.     # reseta o falling quando encosta no chão
  114.     if falling and is_on_floor():
  115.         falling = false
  116.  
  117.     # reseta o superJump quando encosta no chão
  118.     if dashState == "superJump" and is_on_floor():
  119.         dashState = ""
  120.     # o segredo do superJump
  121.     if dashState == "superJump" and not is_on_floor():
  122.         momentum = true
  123.     else:
  124.         momentum = false
  125.     velocity = move_and_slide(velocity, Vector2(0, -1))
  126.    
  127. func Timeout():
  128.     print("timeout")
  129.     # se o dash começou no chão e acabou no ar vira superJump
  130.     if dashState == "ground" and not is_on_floor():
  131.         dashState = "superJump"
  132.     # se n for dash ground ele faz o airDash
  133.     elif dashState == "airDash":
  134.         # pra n ter airDash extra
  135.         blockDash = true
  136.         # sem dash mais
  137.         dashState = ""
  138.     # se for um de ground e tiver no chão, sem dash mais
  139.     elif dashState == "ground" and is_on_floor():
  140.         dashState = ""
  141.  
  142. func dash(is_dash):
  143.     var vel = run_speed
  144.     # caso seja dash ou momentum
  145.     if is_dash or momentum:
  146.         # dash é 2x mais rapido
  147.         vel = 600
  148.         # zerando o y pra o airDash
  149.         if dashState == "airDash":
  150.             velocity.y = 0
  151.     # direita
  152.     if direction == 1:
  153.         #print("direita")
  154.         velocity.x += vel
  155.     # esquerda
  156.     elif direction == 2:
  157.         #print("esquerda")
  158.         velocity.x -= vel
  159.     pass
  160.  
  161.  
  162. func _on_esquerda_body_entered(body):
  163.     if body.name != "player":
  164.         wallDirection = 2
  165.         pass
  166.     pass # Replace with function body.
  167.  
  168.  
  169. func _on_direita_body_entered(body):
  170.     if body.name != "player":
  171.         wallDirection = 1
  172.         pass
  173.     pass # Replace with function body.
  174.  
  175.  
  176. func _on_esquerda_body_exited(body):
  177.     if body.name != "player":
  178.         wallDirection = 0
  179.         pass
  180.     pass # Replace with function body.
  181.  
  182.  
  183. func _on_direita_body_exited(body):
  184.     if body.name != "player":
  185.         wallDirection = 0
  186.         pass
  187.     pass # Replace with function body.
  188.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement