playerphysics.gd 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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):
  12. vida += arg
  13. print(vida)
  14. var sidebuffer = true
  15. func melee():
  16. attack_buffers.melee += 1
  17. if fmod(attack_buffers.melee,45) == 0:
  18. var newdmg = damage.instance()
  19. newdmg.global_position = global_position + (Vector2(70,0) if sidebuffer else Vector2(-70,0))
  20. get_node('../../dmgbox').add_child(newdmg)
  21. get_node('../..').player_anim('melee',name)
  22. func _physics_process(delta):
  23. if motion.x != 0: sidebuffer = motion.x > 0
  24. for i in attacks:
  25. funcref(self,i).call_func()
  26. match input:
  27. "ui_down":
  28. motion.y = 100
  29. animation = 'walk'
  30. "ui_up":
  31. motion.y = -100
  32. animation = 'walk'
  33. "ui_left":
  34. motion.x = -100
  35. animation = 'walk'
  36. "ui_right":
  37. motion.x = 100
  38. animation = 'walk'
  39. _:
  40. motion = Vector2.ZERO
  41. animation = 'idle'
  42. move_and_slide(motion)