playerphysics.gd 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. extends KinematicBody2D
  2. var input = ''
  3. var input2 = ''
  4. var animation = 'idle'
  5. var motion = Vector2()
  6. export var bulletoffset = Vector2()
  7. func _ready():
  8. print('generated clinet physics of id: ' + name)
  9. var attacks = ['melee']
  10. var damage = preload('res://damage_player.tscn')
  11. var attack_buffers = {'melee':0}
  12. var vida = 100
  13. func damage(arg, id):
  14. vida += arg
  15. get_tree().get_nodes_in_group('server')[0].hp_update(vida, name)
  16. if vida <= 0:
  17. get_tree().get_nodes_in_group('server')[0].player_death(name)
  18. queue_free()
  19. func regenhp(arg):
  20. vida += arg
  21. get_tree().get_nodes_in_group('server')[0].hp_update(vida, name)
  22. var sidebuffer = true
  23. export var dmg = 35
  24. var waitframes_bullet = 12
  25. var aux_bullet = 12
  26. var bullet = preload('res://bullet.tscn')
  27. func melee():
  28. attack_buffers.melee += 1
  29. if fmod(attack_buffers.melee,45) == 0:
  30. dmg()
  31. get_tree().get_nodes_in_group('server')[0].player_anim('melee',name)
  32. func dmg(arg = Vector2.ZERO):
  33. var dir = Vector2.ZERO
  34. dir.x = 80 if sidebuffer else -80
  35. func _physics_process(delta):
  36. if motion.x != 0: sidebuffer = motion.x > 0
  37. motion.y += 15
  38. if motion.y < 0 and is_on_ceiling(): motion.y = 0
  39. if motion.y > 0 and is_on_floor(): motion.y = 0
  40. aux_bullet -= 1
  41. match input2:
  42. "ui_attack":
  43. if aux_bullet <= 0:
  44. var instance = bullet.instance()
  45. instance.motion.x = 500 if sidebuffer else -500
  46. instance.global_position = global_position + bulletoffset
  47. instance.id = name
  48. get_tree().get_nodes_in_group('proj')[0].add_child(instance)
  49. get_tree().get_nodes_in_group('server')[0].pshootanim(name)
  50. aux_bullet = waitframes_bullet
  51. match input:
  52. "ui_jump":
  53. if is_on_floor():
  54. motion.y = -400
  55. "ui_left":
  56. motion.x = -200
  57. animation = 'walk'
  58. "ui_right":
  59. motion.x = 200
  60. animation = 'walk'
  61. _:
  62. motion.x = 0
  63. animation = 'idle'
  64. if not is_on_floor():
  65. onair -= 1
  66. else:
  67. onair = 5
  68. if onair <= 0: animation = 'jump'
  69. move_and_slide(motion,Vector2.UP)
  70. var onair = 5
  71. #power code
  72. func add_power(arg):
  73. print(arg)