playerphysics.gd 1.9 KB

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