playerphysics.gd 1.1 KB

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