playerphysics.gd 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 = 10000
  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. func _physics_process(delta):
  26. get_node('../..').hp_update(vida, name)
  27. if motion.x != 0: sidebuffer = motion.x > 0
  28. for i in attacks:
  29. funcref(self,i).call_func()
  30. match input:
  31. "ui_down":
  32. motion.y = 100
  33. animation = 'walk'
  34. "ui_up":
  35. motion.y = -100
  36. animation = 'walk'
  37. "ui_left":
  38. motion.x = -100
  39. animation = 'walk'
  40. "ui_right":
  41. motion.x = 100
  42. animation = 'walk'
  43. _:
  44. motion = Vector2.ZERO
  45. animation = 'idle'
  46. move_and_slide(motion)