diff --git a/objects/enemy/turtle.gd b/objects/enemy/turtle.gd index 44a3493..42f87cf 100644 --- a/objects/enemy/turtle.gd +++ b/objects/enemy/turtle.gd @@ -14,8 +14,6 @@ export (SpikeDirection) var spike_direction: int = SpikeDirection.BOTH var can_spike: bool = true var spike_tween: SceneTreeTween -# index of the current spike position to check for -onready var current_spike_position: int = 0 onready var sprite: Sprite = $"%Sprite" onready var spike_shape: CollisionShape2D = $"%SpikeShape" @@ -24,14 +22,9 @@ func _ready() -> void: if Engine.editor_hint: return - # positions must be in order - spike_positions.sort() + # scale to be in tiles for i in spike_positions.size(): - # scale to be in tiles spike_positions[i] = spike_positions[i] * 8.0 - # should start with the first positive spike position - if spike_positions[i] < 0.0: - current_spike_position = i + 1 func _process(delta: float) -> void: # update debug graphics in editor @@ -52,26 +45,36 @@ func _physics_process(delta: float) -> void: # use positions in correct axis var pos = position.x if move_direction == Direction.HORIZONTAL else position.y var pos_start = startpos.x if move_direction == Direction.HORIZONTAL else startpos.y + # only spike if matching direction + if spike_direction == SpikeDirection.LEFT and sign(direction) == 1.0: + return + if spike_direction == SpikeDirection.RIGHT and sign(direction) == -1.0: + return + # spike if close enough to an activation point + for spike_pos in spike_positions: + if abs(pos_start + spike_pos - pos) <= 2.0: + spike() + break # slightly different logic depending on forward/backwards unfortunately :I - match sign(direction): - 1.0: - # make sure there are any positions left to check in this direction - if current_spike_position < spike_positions.size(): - # check if passed the spike position - if pos >= pos_start + spike_positions[current_spike_position]: - # move on to next position - current_spike_position += 1 - if spike_direction != SpikeDirection.LEFT: - spike() - -1.0: - # make sure there are still positions left in this direction - if current_spike_position - 1 >= 0: - # check if passed the position - if pos <= pos_start + spike_positions[current_spike_position - 1]: - # move on to next (previous because backwards) position - current_spike_position -= 1 - if spike_direction != SpikeDirection.RIGHT: - spike() +# match sign(direction): +# 1.0: +# # make sure there are any positions left to check in this direction +# if current_spike_position < spike_positions.size(): +# # check if passed the spike position +# if pos >= pos_start + spike_positions[current_spike_position]: +# # move on to next position +# current_spike_position += 1 +# if spike_direction != SpikeDirection.LEFT: +# spike() +# -1.0: +# # make sure there are still positions left in this direction +# if current_spike_position - 1 >= 0: +# # check if passed the position +# if pos <= pos_start + spike_positions[current_spike_position - 1]: +# # move on to next (previous because backwards) position +# current_spike_position -= 1 +# if spike_direction != SpikeDirection.RIGHT: +# spike() ## performs the spike animation func spike() -> void: