playerphysics.gd 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. extends KinematicBody2D
  2. var input = ''
  3. var input2 = ''
  4. var animation = 'idle'
  5. var motion = Vector2()
  6. func _ready():
  7. print('generated clinet physics of id: ' + name)
  8. var attacks = ['melee']
  9. var damage = preload('res://damage_player.tscn')
  10. var attack_buffers = {'melee':0}
  11. var vida = 100
  12. func damage(arg, id):
  13. vida += arg
  14. get_node('../..').hp_update(vida, name)
  15. if vida <= 0:
  16. queue_free()
  17. func regenhp(arg):
  18. vida += arg
  19. get_node('../..').hp_update(vida, name)
  20. var sidebuffer = true
  21. export var dmg = 35
  22. var waitframes_bullet = 12
  23. var aux_bullet = 12
  24. var bullet = preload('res://bullet.tscn')
  25. func melee():
  26. attack_buffers.melee += 1
  27. if fmod(attack_buffers.melee,45) == 0:
  28. dmg()
  29. get_node('../..').player_anim('melee',name)
  30. func dmg(arg = Vector2.ZERO):
  31. var dir = Vector2.ZERO
  32. dir.x = 80 if sidebuffer else -80
  33. func _physics_process(delta):
  34. if motion.x != 0: sidebuffer = motion.x > 0
  35. motion.y += 15
  36. if motion.y < 0 and is_on_ceiling(): motion.y = 0
  37. aux_bullet -= 1
  38. match input2:
  39. "ui_attack":
  40. if aux_bullet <= 0:
  41. var instance = bullet.instance()
  42. instance.motion.x = 500 if sidebuffer else -500
  43. instance.global_position = global_position
  44. get_parent().get_parent().get_node('projectiles').add_child(instance)
  45. aux_bullet = waitframes_bullet
  46. match input:
  47. "ui_jump":
  48. if is_on_floor():
  49. motion.y = -400
  50. animation = 'walk'
  51. "ui_left":
  52. motion.x = -200
  53. animation = 'walk'
  54. "ui_right":
  55. motion.x = 200
  56. animation = 'walk'
  57. _:
  58. motion.x = 0
  59. animation = 'idle'
  60. move_and_slide(motion,Vector2.UP)
  61. #power code
  62. func add_power(arg):
  63. print(arg)