make turtles use super slime logic instead (fixes #146)
This commit is contained in:
parent
298e31c5d5
commit
071ff439b9
1 changed files with 30 additions and 27 deletions
|
@ -14,8 +14,6 @@ export (SpikeDirection) var spike_direction: int = SpikeDirection.BOTH
|
||||||
var can_spike: bool = true
|
var can_spike: bool = true
|
||||||
var spike_tween: SceneTreeTween
|
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 sprite: Sprite = $"%Sprite"
|
||||||
onready var spike_shape: CollisionShape2D = $"%SpikeShape"
|
onready var spike_shape: CollisionShape2D = $"%SpikeShape"
|
||||||
|
|
||||||
|
@ -24,14 +22,9 @@ func _ready() -> void:
|
||||||
if Engine.editor_hint:
|
if Engine.editor_hint:
|
||||||
return
|
return
|
||||||
|
|
||||||
# positions must be in order
|
# scale to be in tiles
|
||||||
spike_positions.sort()
|
|
||||||
for i in spike_positions.size():
|
for i in spike_positions.size():
|
||||||
# scale to be in tiles
|
|
||||||
spike_positions[i] = spike_positions[i] * 8.0
|
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:
|
func _process(delta: float) -> void:
|
||||||
# update debug graphics in editor
|
# update debug graphics in editor
|
||||||
|
@ -52,26 +45,36 @@ func _physics_process(delta: float) -> void:
|
||||||
# use positions in correct axis
|
# use positions in correct axis
|
||||||
var pos = position.x if move_direction == Direction.HORIZONTAL else position.y
|
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
|
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
|
# slightly different logic depending on forward/backwards unfortunately :I
|
||||||
match sign(direction):
|
# match sign(direction):
|
||||||
1.0:
|
# 1.0:
|
||||||
# make sure there are any positions left to check in this direction
|
# # make sure there are any positions left to check in this direction
|
||||||
if current_spike_position < spike_positions.size():
|
# if current_spike_position < spike_positions.size():
|
||||||
# check if passed the spike position
|
# # check if passed the spike position
|
||||||
if pos >= pos_start + spike_positions[current_spike_position]:
|
# if pos >= pos_start + spike_positions[current_spike_position]:
|
||||||
# move on to next position
|
# # move on to next position
|
||||||
current_spike_position += 1
|
# current_spike_position += 1
|
||||||
if spike_direction != SpikeDirection.LEFT:
|
# if spike_direction != SpikeDirection.LEFT:
|
||||||
spike()
|
# spike()
|
||||||
-1.0:
|
# -1.0:
|
||||||
# make sure there are still positions left in this direction
|
# # make sure there are still positions left in this direction
|
||||||
if current_spike_position - 1 >= 0:
|
# if current_spike_position - 1 >= 0:
|
||||||
# check if passed the position
|
# # check if passed the position
|
||||||
if pos <= pos_start + spike_positions[current_spike_position - 1]:
|
# if pos <= pos_start + spike_positions[current_spike_position - 1]:
|
||||||
# move on to next (previous because backwards) position
|
# # move on to next (previous because backwards) position
|
||||||
current_spike_position -= 1
|
# current_spike_position -= 1
|
||||||
if spike_direction != SpikeDirection.RIGHT:
|
# if spike_direction != SpikeDirection.RIGHT:
|
||||||
spike()
|
# spike()
|
||||||
|
|
||||||
## performs the spike animation
|
## performs the spike animation
|
||||||
func spike() -> void:
|
func spike() -> void:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue