playerphysics.gd 1.7 KB

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