playerphysics.gd 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. get_node('../..').hp_update(vida, name)
  15. queue_free()
  16. var sidebuffer = true
  17. #func melee():
  18. # attack_buffers.melee += 1
  19. # if fmod(attack_buffers.melee,45) == 0:
  20. # var newdmg = damage.instance()
  21. # newdmg.global_position = global_position + (Vector2(70,0) if sidebuffer else Vector2(-70,0))
  22. # newdmg.attacker = name
  23. # get_node('../../dmgbox').add_child(newdmg)
  24. # get_node('../..').player_anim('melee',name)
  25. export var dmg = 50
  26. func melee():
  27. attack_buffers.melee += 1
  28. if fmod(attack_buffers.melee,45) == 0:
  29. dmg(70,0)
  30. get_node('../..').player_anim('melee',name)
  31. func dmg(arg,arg1):
  32. get_node('../../../Server/enemies').damage_detection(global_position + (Vector2(arg,arg1) if sidebuffer else Vector2(-arg,arg1)),dmg,name)
  33. func _physics_process(delta):
  34. get_node('../..').hp_update(vida, name)
  35. if motion.x != 0: sidebuffer = motion.x > 0
  36. for i in attacks:
  37. funcref(self,i).call_func()
  38. match input:
  39. "ui_down":
  40. motion.y = 100
  41. animation = 'walk'
  42. "ui_up":
  43. motion.y = -100
  44. animation = 'walk'
  45. "ui_left":
  46. motion.x = -100
  47. animation = 'walk'
  48. "ui_right":
  49. motion.x = 100
  50. animation = 'walk'
  51. _:
  52. motion = Vector2.ZERO
  53. animation = 'idle'
  54. move_and_slide(motion)