KoopaTroopa.gd 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. extends Enemy
  2. const MOVE_SPEED := 32
  3. @export var winged := false
  4. @export_file("*.tscn") var shell_scene = ""
  5. @onready var starting_position := global_position
  6. var fly_wave := PI
  7. var dead := false
  8. func _ready() -> void:
  9. if has_meta("fly_2"):
  10. fly_wave = 0
  11. func _physics_process(delta: float) -> void:
  12. if winged and (has_meta("is_red") or has_meta("fly_2")):
  13. handle_fly_movement(delta)
  14. else:
  15. $BasicEnemyMovement.bounce_on_land = winged
  16. $BasicEnemyMovement.handle_movement(delta)
  17. $Sprite.play("Walk")
  18. %Wing.visible = winged
  19. $Sprite.scale.x = direction
  20. func handle_fly_movement(delta: float) -> void:
  21. velocity = Vector2.ZERO
  22. fly_wave += delta
  23. var old_x = global_position.x
  24. if has_meta("fly_2"):
  25. global_position.x = starting_position.x + (cos(fly_wave) * 48) - 48
  26. global_position.y = starting_position.y + (sin(fly_wave * 4) * 2)
  27. direction = sign(global_position.x - old_x + 0.001)
  28. else:
  29. global_position.y = starting_position.y + (cos(fly_wave) * 48) + 48
  30. func stomped_on(player: Player) -> void:
  31. if dead:
  32. return
  33. player.enemy_bounce_off()
  34. AudioManager.play_sfx("enemy_stomp", global_position)
  35. if winged:
  36. DiscoLevel.combo_meter = 100
  37. DiscoLevel.combo_amount += 1
  38. velocity.y = 0
  39. winged = false
  40. var direction_to_change = sign(player.global_position.x - global_position.x)
  41. if direction_to_change != 0:
  42. direction = direction_to_change
  43. return
  44. dead = true
  45. await get_tree().physics_frame
  46. summon_shell(not is_on_floor(), false)
  47. queue_free()
  48. func block_bounced() -> void:
  49. summon_shell(true, true)
  50. queue_free()
  51. func summon_shell(flipped := false, launch := false) -> void:
  52. if is_queued_for_deletion():
  53. return
  54. DiscoLevel.combo_amount += 1
  55. var shell = load(shell_scene).instantiate()
  56. shell.flipped = flipped
  57. shell.old_entity = self.duplicate()
  58. if launch:
  59. AudioManager.play_sfx("kick", global_position)
  60. shell.can_air_kick = true
  61. shell.velocity = Vector2(50 * direction, -150)
  62. shell.global_position = global_position
  63. if $TrackJoint.is_attached:
  64. get_parent().owner.add_sibling(shell)
  65. else:
  66. add_sibling(shell)