bacteria.gd 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. extends KinematicBody2D
  2. var motion = Vector2()
  3. var dir = Vector2()
  4. export var speed = 100
  5. var attackrange = 80
  6. signal dieproxy
  7. var exppt = 0
  8. var currentxp = 0
  9. var totalxp = 0
  10. var nextxp = 100
  11. var lv = 1
  12. func _ready():
  13. for x in get_node("Icon").get_children():
  14. for y in x.get_children():
  15. var sprite = Sprite.new()
  16. sprite.texture = load('res://leg.png')
  17. y.add_child(sprite)
  18. func _physics_process(delta):
  19. move_and_slide(motion * speed)
  20. $hitbox.position = dir * attackrange
  21. $Icon.rotation = atan2(motion.y,motion.x)
  22. $AnimationPlayer.playback_speed = motion.length() * speed / 100 * 1.5
  23. func _input(event):
  24. if event is InputEventScreenDrag or event is InputEventScreenTouch and event.is_pressed():
  25. dir = (event.position - get_global_transform_with_canvas().origin).normalized()
  26. motion = dir
  27. else:
  28. motion *= .8
  29. func _on_Health_die():
  30. emit_signal('dieproxy')
  31. pass # Replace with function body.
  32. func _on_hitbox_gotxp(arg):
  33. totalxp += arg
  34. currentxp += arg
  35. if currentxp > nextxp:
  36. currentxp -= nextxp
  37. nextxp *= 1.5
  38. lv += 1
  39. print(lv)
  40. $CanvasLayer/VBoxContainer/Label.set_text(str(currentxp))
  41. $CanvasLayer/VBoxContainer/Label3.set_text('Lv.'+str(lv))
  42. $CanvasLayer/VBoxContainer/Label/ProgressBar2.set_value( currentxp )
  43. $CanvasLayer/VBoxContainer/Label/ProgressBar2.set_max( nextxp )
  44. pass # Replace with function body.