bacteria.gd 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. var dict = {
  13. 'a': load('res://leg3.png'),
  14. 'b': load('res://leg2.png'),
  15. 'c': load('res://leg.png'),
  16. }
  17. func _ready():
  18. for x in get_node("Icon").get_children():
  19. for y in x.get_children():
  20. var sprite = Sprite.new()
  21. sprite.texture = dict[y.name]
  22. y.add_child(sprite)
  23. func _physics_process(delta):
  24. move_and_slide(motion * speed)
  25. $hitbox.position = dir * attackrange
  26. $Icon.rotation = atan2(motion.y,motion.x)
  27. $AnimationPlayer.playback_speed = motion.length() * speed / 100 * 1.5
  28. func _input(event):
  29. if event is InputEventScreenDrag or event is InputEventScreenTouch and event.is_pressed():
  30. dir = (event.position - get_global_transform_with_canvas().origin).normalized()
  31. motion = dir
  32. else:
  33. motion *= .8
  34. func _on_Health_die():
  35. emit_signal('dieproxy')
  36. pass # Replace with function body.
  37. func _on_hitbox_gotxp(arg):
  38. totalxp += arg
  39. currentxp += arg
  40. if currentxp > nextxp:
  41. currentxp -= nextxp
  42. nextxp *= 1.5
  43. lv += 1
  44. print(lv)
  45. $CanvasLayer/VBoxContainer/Label.set_text(str(currentxp))
  46. $CanvasLayer/VBoxContainer/Label3.set_text('Lv.'+str(lv))
  47. $CanvasLayer/VBoxContainer/Label/ProgressBar2.set_value( currentxp )
  48. $CanvasLayer/VBoxContainer/Label/ProgressBar2.set_max( nextxp )
  49. pass # Replace with function body.