EEEEELLLLLLSSSSS uuuuuuuuuuuuuuuuuuuuuu

This commit is contained in:
Haze Weathers 2023-05-27 22:01:03 -04:00
parent 4c31420e52
commit 7df261b58e
11 changed files with 277 additions and 1 deletions

55
objects/enemy/eel.gd Normal file
View file

@ -0,0 +1,55 @@
extends "res://objects/enemy/enemy.gd"
const SEGMENT_LENGTH: float = 4.0
const BASE_LENGTH: float = 20.0 # combined length of head and tail
export var segments: int = 8
export var speed: float = 32.0
export var wave_length: float = 8.0
export var wave_amplitude: float = 4.0
onready var sector: Vector2 = Game.get_sector(global_position)
onready var hitbox: Area2D = $Hitbox
onready var first_segment: CollisionShape2D = $"%Segment"
onready var segment_start: Position2D = $"%SegmentStart"
func _ready() -> void:
hitbox.remove_child(first_segment)
for i in segments:
var new_segment = first_segment.duplicate()
new_segment.position.x = segment_start.position.x + SEGMENT_LENGTH * float(i)
hitbox.add_child(new_segment)
$Hitbox/TailShape.position.x = segment_start.position.x + SEGMENT_LENGTH * segments
_wave_segments()
func _physics_process(delta: float) -> void:
# move
global_position.x -= speed * delta * sign(scale.x)
# make segments wibble
_wave_segments()
# check for wrapping
var sector_rect = Rect2(sector * Game.resolution, Game.resolution)
var total_length = BASE_LENGTH + (SEGMENT_LENGTH * float(segments))
var eel_rect = Rect2(global_position + Vector2(-2.0, 4.0), Vector2(total_length, 0.0))
if not sector_rect.intersects(eel_rect):
global_position.x += (Game.resolution.x + total_length) * sign(scale.x)
func _wave_segments() -> void:
for segment in hitbox.get_children():
if segment is Node2D:
segment.position.y = sin(segment.global_position.x / wave_length) * wave_amplitude
func die() -> void:
for segment in hitbox.get_children():
if segment is Node2D:
var death_particles = DeathParticles.instance()
death_particles.global_position = segment.global_position
death_particles.emitting = true
get_parent().add_child(death_particles)
.die()